]> git.sesse.net Git - nageru/blobdiff - glwidget.cpp
Fix crashes on exit.
[nageru] / glwidget.cpp
index 3aa10fad1032b0e88b71f8b6e56294d1f9fc1139..fb5fe995719b36112edc8eef315a06ad05a31aa5 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "audio_mixer.h"
 #include "context.h"
+#include "context_menus.h"
 #include "flags.h"
 #include "mainwindow.h"
 #include "mixer.h"
@@ -39,12 +40,17 @@ GLWidget::GLWidget(QWidget *parent)
 {
 }
 
-void GLWidget::clean_context()
+GLWidget::~GLWidget()
+{
+}
+
+void GLWidget::shutdown()
 {
        if (resource_pool != nullptr) {
                makeCurrent();
                resource_pool->clean_context();
        }
+       global_mixer->remove_frame_ready_callback(output, this);
 }
 
 void GLWidget::initializeGL()
@@ -56,13 +62,16 @@ void GLWidget::initializeGL()
                global_mainwindow->mixer_created(global_mixer);
                global_mixer->start();
        });
-       global_mixer->set_frame_ready_callback(output, [this]{
+       global_mixer->add_frame_ready_callback(output, this, [this]{
                QMetaObject::invokeMethod(this, "update", Qt::AutoConnection);
        });
        if (output == Mixer::OUTPUT_LIVE) {
                global_mixer->set_transition_names_updated_callback(output, [this](const vector<string> &names){
                        emit transition_names_updated(names);
                });
+               setContextMenuPolicy(Qt::CustomContextMenu);
+               connect(this, &QWidget::customContextMenuRequested,
+                       bind(&GLWidget::show_live_context_menu, this, _1));
        }
        if (output >= Mixer::OUTPUT_INPUT0) {
                global_mixer->set_name_updated_callback(output, [this](const string &name){
@@ -76,7 +85,7 @@ void GLWidget::initializeGL()
                if (signal_num != -1) {
                        setContextMenuPolicy(Qt::CustomContextMenu);
                        connect(this, &QWidget::customContextMenuRequested,
-                               bind(&GLWidget::show_context_menu, this, signal_num, _1));
+                               bind(&GLWidget::show_preview_context_menu, this, signal_num, _1));
                }
        }
 
@@ -106,6 +115,8 @@ void GLWidget::paintGL()
        check_error();
        frame.setup_chain();
        check_error();
+       glDisable(GL_FRAMEBUFFER_SRGB);
+       check_error();
        frame.chain->render_to_screen();
        check_error();
 
@@ -121,7 +132,31 @@ void GLWidget::mousePressEvent(QMouseEvent *event)
        emit clicked();
 }
 
-void GLWidget::show_context_menu(unsigned signal_num, const QPoint &pos)
+void GLWidget::show_live_context_menu(const QPoint &pos)
+{
+       QPoint global_pos = mapToGlobal(pos);
+
+       QMenu menu;
+
+       // Add a submenu for selecting output card, with an action for each card.
+       QMenu card_submenu;
+       fill_hdmi_sdi_output_device_menu(&card_submenu);
+       card_submenu.setTitle("HDMI/SDI output device");
+       menu.addMenu(&card_submenu);
+
+       // Add a submenu for choosing the output resolution. Since this is
+       // card-dependent, it is disabled if we haven't chosen a card
+       // (but it's still there so that the user will know it exists).
+       QMenu resolution_submenu;
+       fill_hdmi_sdi_output_resolution_menu(&resolution_submenu);
+       resolution_submenu.setTitle("HDMI/SDI output resolution");
+       menu.addMenu(&resolution_submenu);
+
+       // Show the menu; if there's an action selected, it will deal with it itself.
+       menu.exec(global_pos);
+}
+
+void GLWidget::show_preview_context_menu(unsigned signal_num, const QPoint &pos)
 {
        QPoint global_pos = mapToGlobal(pos);
 
@@ -237,7 +272,10 @@ void GLWidget::show_context_menu(unsigned signal_num, const QPoint &pos)
        // And a master clock selector.
        QAction *master_clock_action = new QAction("Use as master clock", &menu);
        master_clock_action->setCheckable(true);
-       if (global_mixer->get_master_clock() == signal_num) {
+       if (global_mixer->get_output_card_index() != -1) {
+               master_clock_action->setChecked(false);
+               master_clock_action->setEnabled(false);
+       } else if (global_mixer->get_master_clock() == signal_num) {
                master_clock_action->setChecked(true);
                master_clock_action->setEnabled(false);
        }