]> git.sesse.net Git - nageru/blob - nageru/context_menus.cpp
When previewing the playlist time, use compute_time_left().
[nageru] / nageru / context_menus.cpp
1 #include <QActionGroup>
2 #include <QMenu>
3 #include <QObject>
4
5 #include <map>
6
7 #include "mixer.h"
8
9 using namespace std;
10
11 void fill_hdmi_sdi_output_device_menu(QMenu *menu)
12 {
13         menu->clear();
14         QActionGroup *card_group = new QActionGroup(menu);
15         int current_card = global_mixer->get_output_card_index();
16
17         QAction *none_action = new QAction("None", card_group);
18         none_action->setCheckable(true);
19         if (current_card == -1) {
20                 none_action->setChecked(true);
21         }
22         QObject::connect(none_action, &QAction::triggered, []{ global_mixer->set_output_card(-1); });
23         menu->addAction(none_action);
24
25         unsigned num_cards = global_mixer->get_num_cards();
26         for (unsigned card_index = 0; card_index < num_cards; ++card_index) {
27                 if (!global_mixer->card_can_be_used_as_output(card_index)) {
28                         continue;
29                 }
30
31                 QString description(QString::fromStdString(global_mixer->get_output_card_description(card_index)));
32                 QAction *action = new QAction(description, card_group);
33                 action->setCheckable(true);
34                 if (current_card == int(card_index)) {
35                         action->setChecked(true);
36                 }
37                 QObject::connect(action, &QAction::triggered, [card_index]{ global_mixer->set_output_card(card_index); });
38                 menu->addAction(action);
39         }
40 }
41
42 void fill_hdmi_sdi_output_resolution_menu(QMenu *menu)
43 {
44         menu->clear();
45         int current_card = global_mixer->get_output_card_index();
46         if (current_card == -1) {
47                 menu->setEnabled(false);
48                 return;
49         }
50
51         menu->setEnabled(true);
52         QActionGroup *resolution_group = new QActionGroup(menu);
53         uint32_t current_mode = global_mixer->get_output_video_mode();
54         map<uint32_t, bmusb::VideoMode> video_modes = global_mixer->get_available_output_video_modes();
55         for (const auto &mode : video_modes) {
56                 QString description(QString::fromStdString(mode.second.name));
57                 QAction *action = new QAction(description, resolution_group);
58                 action->setCheckable(true);
59                 if (current_mode == mode.first) {
60                         action->setChecked(true);
61                 }
62                 const uint32_t mode_id = mode.first;
63                 QObject::connect(action, &QAction::triggered, [mode_id]{ global_mixer->set_output_video_mode(mode_id); });
64                 menu->addAction(action);
65         }
66 }