X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=glwidget.cpp;h=5a1325803a283fad20cf8be86478d94945b66ca5;hb=1202ad9167357a461366dab9cbbaa6c578423253;hp=3d5b0f97abe86a494bedda4ee5607e14499a2be2;hpb=9b9f5c84113b8a818f296467fd2150ce6a095fbe;p=nageru diff --git a/glwidget.cpp b/glwidget.cpp index 3d5b0f9..5a13258 100644 --- a/glwidget.cpp +++ b/glwidget.cpp @@ -6,17 +6,19 @@ #include // Needs to come before egl.h. #include #include +#include +#include #include -#include #include "glwidget.h" #include #include #include +#include +#include #include "context.h" -#include "effect_chain.h" #include "flags.h" #include "mainwindow.h" #include "mixer.h" @@ -31,6 +33,7 @@ class QWidget; #include using namespace std; +using namespace std::placeholders; GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent, global_share_widget) @@ -59,6 +62,15 @@ void GLWidget::initializeGL() emit resolution_updated(output); }); + if (output >= Mixer::OUTPUT_INPUT0) { + int signal_num = global_mixer->get_channel_signal(output); + if (signal_num != -1) { + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, &QWidget::customContextMenuRequested, + bind(&GLWidget::show_context_menu, this, signal_num, _1)); + } + } + glDisable(GL_BLEND); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); @@ -99,3 +111,94 @@ void GLWidget::mousePressEvent(QMouseEvent *event) { emit clicked(); } + +void GLWidget::show_context_menu(unsigned signal_num, const QPoint &pos) +{ + QPoint global_pos = mapToGlobal(pos); + + QMenu menu; + + // Add a submenu for selecting input card, with an action for each card. + QMenu card_submenu; + QActionGroup card_group(&card_submenu); + + unsigned num_cards = global_mixer->get_num_cards(); + unsigned current_card = global_mixer->map_signal(signal_num); + for (unsigned card_index = 0; card_index < num_cards; ++card_index) { + QString description(QString::fromStdString(global_mixer->get_card_description(card_index))); + QAction *action = new QAction(description, &card_group); + action->setCheckable(true); + if (current_card == card_index) { + action->setChecked(true); + } + action->setData(QList{"card", card_index}); + card_submenu.addAction(action); + } + + card_submenu.setTitle("Input source"); + menu.addMenu(&card_submenu); + + // Add a submenu for selecting resolution, with an action for each resolution. + // Note that the choice depends a lot on which card is active. + QMenu mode_submenu; + QActionGroup mode_group(&mode_submenu); + std::map video_modes = global_mixer->get_available_video_modes(current_card); + uint32_t current_video_mode = global_mixer->get_current_video_mode(current_card); + bool has_auto_mode = false; + for (const auto &mode : video_modes) { + QString description(QString::fromStdString(mode.second.name)); + QAction *action = new QAction(description, &mode_group); + action->setCheckable(true); + if (mode.first == current_video_mode) { + action->setChecked(true); + } + action->setData(QList{"video_mode", mode.first}); + mode_submenu.addAction(action); + + // TODO: Relying on the 0 value here (from bmusb.h) is ugly, it should be a named constant. + if (mode.first == 0) { + has_auto_mode = true; + } + } + + // Add a “scan” menu if there's no “auto” mode. + if (!has_auto_mode) { + QAction *action = new QAction("Scan", &mode_group); + action->setData(QList{"video_mode", 0}); + mode_submenu.addSeparator(); + mode_submenu.addAction(action); + } + + mode_submenu.setTitle("Input mode"); + menu.addMenu(&mode_submenu); + + // Add an audio source selector. + QAction *audio_source_action = new QAction("Use as audio source", &menu); + audio_source_action->setCheckable(true); + if (global_mixer->get_audio_source() == signal_num) { + audio_source_action->setChecked(true); + audio_source_action->setEnabled(false); + } + menu.addAction(audio_source_action); + + // Show the menu and look at the result. + QAction *selected_item = menu.exec(global_pos); + if (selected_item == audio_source_action) { + global_mixer->set_audio_source(signal_num); + } else if (selected_item != nullptr) { + QList selected = selected_item->data().toList(); + if (selected[0].toString() == "video_mode") { + uint32_t mode = selected[1].toUInt(nullptr); + if (mode == 0 && !has_auto_mode) { + global_mixer->start_mode_scanning(current_card); + } else { + global_mixer->set_video_mode(current_card, mode); + } + } else if (selected[0].toString() == "card") { + unsigned card_index = selected[1].toUInt(nullptr); + global_mixer->set_signal_mapping(signal_num, card_index); + } else { + assert(false); + } + } +}