From e77e92cf93ccbb223f568ab645c3b1c519faf07f Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 11 May 2017 23:46:40 +0200 Subject: [PATCH] Make the analyzer UI responsive. --- analyzer.cpp | 97 +++++++++ analyzer.h | 4 + ui_analyzer.ui | 530 +++++++++++++++++++++++++++++-------------------- 3 files changed, 419 insertions(+), 212 deletions(-) diff --git a/analyzer.cpp b/analyzer.cpp index a73058f..90d61ac 100644 --- a/analyzer.cpp +++ b/analyzer.cpp @@ -239,3 +239,100 @@ bool Analyzer::eventFilter(QObject *watched, QEvent *event) } return false; } + +void Analyzer::resizeEvent(QResizeEvent* event) +{ + QMainWindow::resizeEvent(event); + + // Ask for a relayout, but only after the event loop is done doing relayout + // on everything else. + QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection); +} + +void Analyzer::relayout() +{ + double aspect = double(global_flags.width) / global_flags.height; + + // Left pane (2/5 of the width). + { + int width = ui->left_pane->geometry().width(); + int height = ui->left_pane->geometry().height(); + + // Figure out how much space everything that's non-responsive needs. + int remaining_height = height - ui->left_pane->spacing() * (ui->left_pane->count() - 1); + + remaining_height -= ui->grab_btn->geometry().height(); + ui->left_pane->setStretch(2, ui->grab_btn->geometry().height()); + + remaining_height -= ui->histogram_label->geometry().height(); + ui->left_pane->setStretch(4, ui->histogram_label->geometry().height()); + + // The histogram's minimumHeight returns 0, so let's set a reasonable minimum for it. + int min_histogram_height = 50; + remaining_height -= min_histogram_height; + + // Allocate so that the display is 16:9, if possible. + unsigned wanted_display_height = width / aspect; + unsigned display_height; + unsigned margin = 0; + if (remaining_height >= int(wanted_display_height)) { + display_height = wanted_display_height; + } else { + display_height = remaining_height; + int display_width = lrint(display_height * aspect); + margin = (width - display_width) / 2; + } + ui->left_pane->setStretch(1, display_height); + ui->display_left_spacer->changeSize(margin, 1); + ui->display_right_spacer->changeSize(margin, 1); + + remaining_height -= display_height; + + // Figure out if we can do the histogram at 16:9. + remaining_height += min_histogram_height; + unsigned histogram_height; + if (remaining_height >= int(wanted_display_height)) { + histogram_height = wanted_display_height; + } else { + histogram_height = remaining_height; + } + remaining_height -= histogram_height; + ui->left_pane->setStretch(3, histogram_height); + + ui->left_pane->setStretch(0, remaining_height / 2); + ui->left_pane->setStretch(5, remaining_height / 2); + } + + // Right pane (remaining 3/5 of the width). + { + int width = ui->right_pane->geometry().width(); + int height = ui->right_pane->geometry().height(); + + // Figure out how much space everything that's non-responsive needs. + int remaining_height = height - ui->right_pane->spacing() * (ui->right_pane->count() - 1); + remaining_height -= ui->grabbed_frame_sublabel->geometry().height(); + remaining_height -= ui->coord_label->geometry().height(); + remaining_height -= ui->color_hbox->geometry().height(); + + // Allocate so that the display is 16:9, if possible. + unsigned wanted_display_height = width / aspect; + unsigned display_height; + unsigned margin = 0; + if (remaining_height >= int(wanted_display_height)) { + display_height = wanted_display_height; + } else { + display_height = remaining_height; + int display_width = lrint(display_height * aspect); + margin = (width - display_width) / 2; + } + ui->right_pane->setStretch(1, display_height); + ui->grabbed_frame_left_spacer->changeSize(margin, 1); + ui->grabbed_frame_right_spacer->changeSize(margin, 1); + remaining_height -= display_height; + + if (remaining_height < 0) remaining_height = 0; + + ui->right_pane->setStretch(0, remaining_height / 2); + ui->right_pane->setStretch(5, remaining_height / 2); + } +} diff --git a/analyzer.h b/analyzer.h index 6c74906..d9bd8b8 100644 --- a/analyzer.h +++ b/analyzer.h @@ -28,10 +28,14 @@ public: ~Analyzer(); void mixer_shutting_down(); +public slots: + void relayout(); + private: void grab_clicked(); void signal_changed(); bool eventFilter(QObject *watched, QEvent *event) override; + void resizeEvent(QResizeEvent *event) override; Ui::Analyzer *ui; QSurface *surface; diff --git a/ui_analyzer.ui b/ui_analyzer.ui index d73734e..eba57ca 100644 --- a/ui_analyzer.ui +++ b/ui_analyzer.ui @@ -14,218 +14,324 @@ Analyzer - - - - 10 - 410 - 321 - 21 - - - - RGB histogram - - - Qt::AlignCenter - - - - - - 600 - 320 - 191 - 16 - - - - Color (8-bit sRGB): - - - Qt::AlignCenter - - - - - - 10 - 230 - 320 - 180 - - - - false - - - background: rgb(173, 127, 168) - - - - - - 270 - 190 - 61 - 23 - - - - Grab - - - - - - 10 - 190 - 251 - 23 - - - - - - - 600 - 340 - 191 - 80 - - - - - - - Green: - - - - - - - 127 - - - - - - - 127 - - - - - - - Hex: - - - - - - - 127 - - - - - - - Blue: - - - - - - - #7f7f7f - - - - - - - Red: - - - - - - - - - 350 - 0 - 480 - 270 - - - - CrossCursor - - - true - - - false - - - background: color(0,0,0) - - - - - - true - - - - - - 350 - 270 - 481 - 21 - - - - Grabbed frame - - - Qt::AlignCenter - - - - - - 370 - 300 - 421 - 21 - - - - Selected coordinate (x,y): (123,456) - - - - - - 10 - 0 - 320 - 180 - - - - false - - - background: rgb(233, 185, 110) - - + + + + + + + Qt::Vertical + + + + 20 + 5 + + + + + + + + 0 + + + + + Qt::Horizontal + + + + 5 + 20 + + + + + + + + true + + + true + + + background: rgb(233, 185, 110) + + + + + + + Qt::Horizontal + + + + 5 + 20 + + + + + + + + + + + + + + + Grab + + + + + + + + + false + + + background: rgb(173, 127, 168) + + + + + + + + 0 + 0 + + + + RGB histogram + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 5 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 5 + + + + + + + + 0 + + + + + Qt::Horizontal + + + + 5 + 20 + + + + + + + + + 1 + 1 + + + + CrossCursor + + + true + + + false + + + background: color(0,0,0) + + + + + + true + + + + + + + Qt::Horizontal + + + + 5 + 20 + + + + + + + + + + Grabbed frame + + + Qt::AlignCenter + + + + + + + Selected coordinate (x,y): (123,456) + + + Qt::AlignCenter + + + + + + + + + + + TextLabel + + + + + + + + + + + Color (8-bit sRGB): + + + Qt::AlignCenter + + + + + + + + + Green: + + + + + + + 127 + + + + + + + 127 + + + + + + + Hex: + + + + + + + 127 + + + + + + + Blue: + + + + + + + #7f7f7f + + + + + + + Red: + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 5 + + + + + + + -- 2.39.2