X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mainwindow.cpp;h=3ccc89303dd946dc1ff5a1ed1bde37582f048cd8;hb=4159eda78000e5ce498cd6ce31da5e750c2c0a42;hp=0289dbf1ac60d457a1961539535393920a176323;hpb=8a9455f522b3d6eaad094c5bfaf89000e6ae1a55;p=nageru diff --git a/mainwindow.cpp b/mainwindow.cpp index 0289dbf..3ccc893 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "context.h" #include "mixer.h" @@ -17,8 +18,8 @@ using namespace std; Q_DECLARE_METATYPE(std::vector); MainWindow::MainWindow() + : ui(new Ui::MainWindow) { - Ui::MainWindow *ui = new Ui::MainWindow; ui->setupUi(this); ui->me_live->set_output(Mixer::OUTPUT_LIVE); @@ -80,6 +81,48 @@ MainWindow::MainWindow() this, SLOT(set_transition_names(std::vector))); } +void MainWindow::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 MainWindow::relayout() +{ + int width = size().width(); + int height = size().height(); + + // Allocate the height; the most important part is to keep the main displays + // at 16:9 if at all possible. + double me_width = ui->me_preview->width(); + double me_height = me_width * 9.0 / 16.0 + ui->label_preview->height(); + + // TODO: Scale the widths when we need to do this. + if (me_height / double(height) > 0.8) { + me_height = height * 0.8; + } + + // The previews will be constrained by the remaining height, and the width. + // FIXME: spacing? + double preview_height = std::min(height - me_height, (width / 4.0) * 9.0 / 16.0); + + ui->vertical_layout->setStretch(0, lrintf(me_height)); + ui->vertical_layout->setStretch(1, std::max(1, lrintf(height - me_height - preview_height))); + ui->vertical_layout->setStretch(2, lrintf(preview_height)); + + // Set the widths for the previews. + double preview_width = preview_height * 16.0 / 9.0; // FIXME: spacing? + + ui->preview_displays->setStretch(0, lrintf(preview_width)); + ui->preview_displays->setStretch(1, lrintf(preview_width)); + ui->preview_displays->setStretch(2, lrintf(preview_width)); + ui->preview_displays->setStretch(3, lrintf(preview_width)); + ui->preview_displays->setStretch(4, lrintf(width - 4.0 * preview_width)); +} + void MainWindow::set_transition_names(vector transition_names) { if (transition_names.size() < 1) {