From a9208294a0152d45c07fd296b81c4352a871fdfe Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 1 May 2020 00:49:09 +1000 Subject: [PATCH] exportdialog: automatically snap resolutions to even numbers --- app/dialog/export/export.cpp | 28 +++++++++++++++++++++++++--- app/dialog/export/export.h | 2 ++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/dialog/export/export.cpp b/app/dialog/export/export.cpp index 222b00e2e..23480684b 100644 --- a/app/dialog/export/export.cpp +++ b/app/dialog/export/export.cpp @@ -417,10 +417,27 @@ void ExportDialog::ResolutionChanged() if (video_tab_->maintain_aspect_checkbox()->isChecked()) { // Keep aspect ratio maintained if (sender() == video_tab_->height_slider()) { - video_tab_->width_slider()->SetValue(qRound(static_cast(video_tab_->height_slider()->GetValue()) * video_aspect_ratio_)); + + // Convert height to float + double new_width = video_tab_->height_slider()->GetValue(); + + // Generate width from aspect ratio + new_width *= video_aspect_ratio_; + + // Align to even number and set + video_tab_->width_slider()->SetValue(AlignEvenNumber(new_width)); + } else { - // This catches both the width slider changing and the maintain aspect ratio checkbox changing - video_tab_->height_slider()->SetValue(qRound(static_cast(video_tab_->width_slider()->GetValue()) / video_aspect_ratio_)); + + // Convert width to float + double new_height = video_tab_->width_slider()->GetValue(); + + // Generate height from aspect ratio + new_height /= video_aspect_ratio_; + + // Align to even number and set + video_tab_->height_slider()->SetValue(AlignEvenNumber(new_height)); + } } @@ -545,6 +562,11 @@ void ExportDialog::SetUIElementsEnabled(bool enabled) remaining_label_->setEnabled(!enabled); } +int ExportDialog::AlignEvenNumber(double d) +{ + return qCeil(d * 0.5) * 2; +} + ExportParams ExportDialog::GenerateParams() const { RenderMode::Mode render_mode = RenderMode::kOnline; diff --git a/app/dialog/export/export.h b/app/dialog/export/export.h index 82d610ced..25dd21d7d 100644 --- a/app/dialog/export/export.h +++ b/app/dialog/export/export.h @@ -55,6 +55,8 @@ private: void SetUIElementsEnabled(bool enabled); + static int AlignEvenNumber(double d); + ExportParams GenerateParams() const; static QString TimeToString(int64_t ms);