]> git.sesse.net Git - nageru/blobdiff - mainwindow.cpp
Use std::bind instead of the QSignalMapper, since evidently it can take a std::functi...
[nageru] / mainwindow.cpp
index 430ec0f0a8b5af09231308451ec1e5a1f5b2eaf9..23249960546652525749be035c5872341995cc8f 100644 (file)
 #include <QPushButton>
 #include <QResizeEvent>
 #include <QShortcut>
-#include <QSignalMapper>
 #include <QSize>
 #include <QString>
 
 #include "glwidget.h"
 #include "lrameter.h"
 #include "mixer.h"
+#include "ui_display.h"
 #include "ui_mainwindow.h"
 #include "vumeter.h"
 
@@ -41,24 +41,16 @@ MainWindow::MainWindow()
 
        // Hook up the transition buttons.
        // TODO: Make them dynamic.
-       {
-               QSignalMapper *mapper = new QSignalMapper(this);
-               mapper->setMapping(ui->transition_btn1, 0),
-               mapper->setMapping(ui->transition_btn2, 1);
-               mapper->setMapping(ui->transition_btn3, 2);
-               connect(ui->transition_btn1, SIGNAL(clicked()), mapper, SLOT(map()));
-               connect(ui->transition_btn2, SIGNAL(clicked()), mapper, SLOT(map()));
-               connect(ui->transition_btn3, SIGNAL(clicked()), mapper, SLOT(map()));
-               connect(mapper, SIGNAL(mapped(int)), this, SLOT(transition_clicked(int)));
-       }
+       connect(ui->transition_btn1, &QPushButton::clicked, std::bind(&MainWindow::transition_clicked, this, 0));
+       connect(ui->transition_btn2, &QPushButton::clicked, std::bind(&MainWindow::transition_clicked, this, 1));
+       connect(ui->transition_btn3, &QPushButton::clicked, std::bind(&MainWindow::transition_clicked, this, 2));
 
        // Aiee...
        transition_btn1 = ui->transition_btn1;
        transition_btn2 = ui->transition_btn2;
        transition_btn3 = ui->transition_btn3;
        qRegisterMetaType<std::vector<std::string>>("std::vector<std::string>");
-       connect(ui->me_preview, SIGNAL(transition_names_updated(std::vector<std::string>)),
-               this, SLOT(set_transition_names(std::vector<std::string>)));
+       connect(ui->me_preview, &GLWidget::transition_names_updated, this, &MainWindow::set_transition_names);
 }
 
 void MainWindow::resizeEvent(QResizeEvent* event)
@@ -74,26 +66,27 @@ void MainWindow::mixer_created(Mixer *mixer)
 {
        // Make the previews.
        unsigned num_previews = mixer->get_num_channels();
-       QSignalMapper *mapper = new QSignalMapper(this);
 
        for (unsigned i = 0; i < num_previews; ++i) {
-               GLWidget *preview = new GLWidget(this);
-               preview->set_output(Mixer::Output(Mixer::OUTPUT_INPUT0 + i));
+               Mixer::Output output = Mixer::Output(Mixer::OUTPUT_INPUT0 + i);
+
+               QWidget *preview = new QWidget(this);
+               Ui::Display *ui_display = new Ui::Display;
+               ui_display->setupUi(preview);
+               ui_display->label->setText(mixer->get_channel_name(output).c_str());
+               ui_display->wb_button->setVisible(mixer->get_supports_set_wb(output));
+               ui_display->display->set_output(output);
                ui->preview_displays->insertWidget(previews.size(), preview, 1);
-               previews.push_back(preview);
+               previews.push_back(ui_display);
 
                // Hook up the click.
-               mapper->setMapping(preview, i);
-               connect(preview, SIGNAL(clicked()), mapper, SLOT(map()));
+               connect(ui_display->display, &GLWidget::clicked, std::bind(&MainWindow::channel_clicked, this, i));
 
                // Hook up the keyboard key.
                QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_1 + i), this);
-               mapper->setMapping(shortcut, i);
-               connect(shortcut, SIGNAL(activated()), mapper, SLOT(map()));
+               connect(shortcut, &QShortcut::activated, std::bind(&MainWindow::channel_clicked, this, i));
        }
 
-       connect(mapper, SIGNAL(mapped(int)), this, SLOT(channel_clicked(int)));
-
        mixer->set_audio_level_callback([this](float level_lufs, float peak_db, float global_level_lufs, float range_low_lufs, float range_high_lufs){
                ui->vu_meter->set_level(level_lufs);
                ui->lra_meter->set_levels(global_level_lufs, range_low_lufs, range_high_lufs);
@@ -126,11 +119,12 @@ void MainWindow::relayout()
 
        // The previews will be constrained by the remaining height, and the width.
        // FIXME: spacing?
-       double preview_height = std::min(height - me_height, (width / double(previews.size())) * 9.0 / 16.0);
+       double preview_label_height = previews[0]->label->height();
+       double preview_height = std::min(height - me_height - preview_label_height, (width / double(previews.size())) * 9.0 / 16.0);
 
        ui->vertical_layout->setStretch(0, lrintf(me_height));
        ui->vertical_layout->setStretch(1, std::max<int>(1, lrintf(height - me_height - preview_height)));
-       ui->vertical_layout->setStretch(2, lrintf(preview_height));
+       ui->vertical_layout->setStretch(2, lrintf(preview_height + preview_label_height));
 
        // Set the widths for the previews.
        double preview_width = preview_height * 16.0 / 9.0;  // FIXME: spacing?