Skip to content

Commit 879a174

Browse files
committed
Collapse overlay checkboxes into a dropdown to save space.
1 parent da2ee4a commit 879a174

File tree

3 files changed

+143
-58
lines changed

3 files changed

+143
-58
lines changed

Common/Qt/CheckboxDropdown.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/* Command Row
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_CheckboxDropdown_H
8+
#define PokemonAutomation_CheckboxDropdown_H
9+
10+
#include <QEvent>
11+
#include <QAbstractItemView>
12+
#include <QStandardItemModel>
13+
#include <QComboBox>
14+
15+
namespace PokemonAutomation{
16+
17+
class CheckboxDropdownItem : public QObject, public QStandardItem{
18+
Q_OBJECT
19+
public:
20+
using QStandardItem::QStandardItem;
21+
22+
void setChecked(bool checked){
23+
if (checked){
24+
this->setCheckState(Qt::Checked);
25+
}else{
26+
this->setCheckState(Qt::Unchecked);
27+
}
28+
}
29+
30+
signals:
31+
void checkStateChanged(Qt::CheckState state);
32+
};
33+
34+
35+
36+
37+
class CheckboxDropdown : public QComboBox{
38+
Q_OBJECT
39+
public:
40+
CheckboxDropdown(QWidget* parent, const QString& label)
41+
: QComboBox(parent)
42+
{
43+
m_model = new QStandardItemModel(this);
44+
this->setModel(m_model);
45+
46+
QComboBox::addItem(label);
47+
48+
this->view()->viewport()->installEventFilter(this);
49+
}
50+
51+
CheckboxDropdownItem* addItem(const QString& text, Qt::CheckState = Qt::Unchecked){
52+
CheckboxDropdownItem* item = new CheckboxDropdownItem(text);
53+
item->setCheckable(true);
54+
item->setCheckState(Qt::Unchecked);
55+
m_model->appendRow(item);
56+
m_items.emplace_back(item);
57+
return item;
58+
}
59+
60+
virtual bool eventFilter(QObject* obj, QEvent* event) override{
61+
// cout << "eventFilter()" << endl;
62+
if (event->type() != QEvent::MouseButtonRelease){
63+
return QComboBox::eventFilter(obj, event);
64+
}
65+
int index = view()->currentIndex().row();
66+
if (index <= 0){
67+
return QComboBox::eventFilter(obj, event);
68+
}
69+
if (itemData(index, Qt::CheckStateRole) == Qt::Checked){
70+
setItemData(index, Qt::Unchecked, Qt::CheckStateRole);
71+
emit m_items[index - 1]->checkStateChanged(Qt::Unchecked);
72+
}else{
73+
setItemData(index, Qt::Checked, Qt::CheckStateRole);
74+
emit m_items[index - 1]->checkStateChanged(Qt::Checked);
75+
}
76+
return true;
77+
}
78+
79+
private:
80+
QStandardItemModel* m_model;
81+
std::vector<CheckboxDropdownItem*> m_items;
82+
};
83+
84+
85+
}
86+
#endif

SerialPrograms/Source/NintendoSwitch/Framework/UI/NintendoSwitch_CommandRow.cpp

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace PokemonAutomation{
1919
namespace NintendoSwitch{
2020

2121

22+
23+
2224
CommandRow::~CommandRow(){
2325
m_controller.remove_listener(*this);
2426
m_session.remove_listener(*this);
@@ -65,29 +67,28 @@ CommandRow::CommandRow(
6567

6668
// row->addWidget(new QLabel("<b>Overlays:<b>", this));
6769

68-
m_overlay_boxes = new QCheckBox("Boxes", this);
69-
m_overlay_boxes->setChecked(session.enabled_boxes());
70-
row->addWidget(m_overlay_boxes);
71-
72-
m_overlay_text = new QCheckBox("Text", this);
73-
m_overlay_text->setHidden(true); // Nothing uses text overlay yet.
74-
m_overlay_text->setChecked(session.enabled_text());
75-
row->addWidget(m_overlay_text);
76-
77-
m_overlay_images = new QCheckBox("Masks", this);
78-
m_overlay_images->setChecked(session.enabled_images());
79-
row->addWidget(m_overlay_images);
80-
if (!PreloadSettings::instance().DEVELOPER_MODE){
81-
m_overlay_images->setVisible(false);
70+
CheckboxDropdown* overlays = new CheckboxDropdown(this, "Overlays");
71+
{
72+
m_overlay_boxes = overlays->addItem("Boxes");
73+
m_overlay_boxes->setChecked(session.enabled_boxes());
8274
}
83-
84-
m_overlay_log = new QCheckBox("Log", this);
85-
m_overlay_log->setChecked(session.enabled_log());
86-
row->addWidget(m_overlay_log);
87-
88-
m_overlay_stats = new QCheckBox("Stats", this);
89-
m_overlay_stats->setChecked(session.enabled_stats());
90-
row->addWidget(m_overlay_stats);
75+
if (PreloadSettings::instance().DEVELOPER_MODE){
76+
m_overlay_text = overlays->addItem("Text"); // Nothing uses text overlay yet.
77+
m_overlay_text->setChecked(session.enabled_text());
78+
}
79+
if (PreloadSettings::instance().DEVELOPER_MODE){
80+
m_overlay_images = overlays->addItem("Masks");
81+
m_overlay_images->setChecked(session.enabled_images());
82+
}
83+
{
84+
m_overlay_log = overlays->addItem("Log");
85+
m_overlay_log->setChecked(session.enabled_log());
86+
}
87+
{
88+
m_overlay_stats = overlays->addItem("Stats");
89+
m_overlay_stats->setChecked(session.enabled_stats());
90+
}
91+
row->addWidget(overlays);
9192

9293
row->addSpacing(5);
9394

@@ -107,47 +108,44 @@ CommandRow::CommandRow(
107108

108109
update_ui();
109110

111+
#if 1
110112
connect(
111-
m_overlay_boxes, &QCheckBox::clicked,
112-
this, [this](bool checked){ m_session.set_enabled_boxes(checked); }
113-
);
114-
#if QT_VERSION < 0x060700
115-
connect(
116-
m_overlay_text, &QCheckBox::stateChanged,
117-
this, [this](bool checked){ m_session.set_enabled_text(checked); }
118-
);
119-
connect(
120-
m_overlay_images, &QCheckBox::stateChanged,
121-
this, [this](bool checked){ m_session.set_enabled_images(checked); }
122-
);
123-
connect(
124-
m_overlay_log, &QCheckBox::stateChanged,
125-
this, [this](bool checked){ m_session.set_enabled_log(checked); }
126-
);
127-
connect(
128-
m_overlay_stats, &QCheckBox::stateChanged,
129-
this, [this](bool checked){ m_session.set_enabled_stats(checked); }
130-
);
131-
#else
132-
connect(
133-
m_overlay_text, &QCheckBox::checkStateChanged,
134-
this, [this](Qt::CheckState state){ m_session.set_enabled_text(state == Qt::Checked); }
113+
m_overlay_boxes, &CheckboxDropdownItem::checkStateChanged,
114+
this, [this](Qt::CheckState state){
115+
116+
m_session.set_enabled_boxes(state == Qt::Checked);
117+
}
135118
);
136-
if (PreloadSettings::instance().DEVELOPER_MODE){
119+
if (m_overlay_text){
120+
connect(
121+
m_overlay_text, &CheckboxDropdownItem::checkStateChanged,
122+
this, [this](Qt::CheckState state){
123+
m_session.set_enabled_text(state == Qt::Checked);
124+
}
125+
);
126+
}
127+
if (m_overlay_images){
137128
connect(
138-
m_overlay_images, &QCheckBox::checkStateChanged,
139-
this, [this](Qt::CheckState state){ m_session.set_enabled_images(state == Qt::Checked); }
129+
m_overlay_images, &CheckboxDropdownItem::checkStateChanged,
130+
this, [this](Qt::CheckState state){
131+
m_session.set_enabled_images(state == Qt::Checked);
132+
}
140133
);
141134
}
142135
connect(
143-
m_overlay_log, &QCheckBox::checkStateChanged,
144-
this, [this](Qt::CheckState state){ m_session.set_enabled_log(state == Qt::Checked); }
136+
m_overlay_log, &CheckboxDropdownItem::checkStateChanged,
137+
this, [this](Qt::CheckState state){
138+
m_session.set_enabled_log(state == Qt::Checked);
139+
}
145140
);
146141
connect(
147-
m_overlay_stats, &QCheckBox::checkStateChanged,
148-
this, [this](Qt::CheckState state){ m_session.set_enabled_stats(state == Qt::Checked); }
142+
m_overlay_stats, &CheckboxDropdownItem::checkStateChanged,
143+
this, [this](Qt::CheckState state){
144+
m_session.set_enabled_stats(state == Qt::Checked);
145+
}
149146
);
150147
#endif
148+
151149
connect(
152150
m_load_profile_button, &QPushButton::clicked,
153151
this, [this](bool) { emit load_profile(); }

SerialPrograms/Source/NintendoSwitch/Framework/UI/NintendoSwitch_CommandRow.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <QLabel>
1212
#include <QPushButton>
1313
#include <QCheckBox>
14+
#include "Common/Qt/CheckboxDropdown.h"
1415
#include "CommonFramework/Globals.h"
1516
#include "CommonFramework/VideoPipeline/VideoOverlaySession.h"
1617
#include "Controllers/ControllerSession.h"
@@ -68,11 +69,11 @@ class CommandRow :
6869
QComboBox* m_command_box = nullptr;
6970
QLabel* m_status = nullptr;
7071

71-
QCheckBox* m_overlay_log = nullptr;
72-
QCheckBox* m_overlay_text = nullptr;
73-
QCheckBox* m_overlay_images = nullptr;
74-
QCheckBox* m_overlay_boxes = nullptr;
75-
QCheckBox* m_overlay_stats = nullptr;
72+
CheckboxDropdownItem* m_overlay_boxes = nullptr;
73+
CheckboxDropdownItem* m_overlay_text = nullptr;
74+
CheckboxDropdownItem* m_overlay_images = nullptr;
75+
CheckboxDropdownItem* m_overlay_log = nullptr;
76+
CheckboxDropdownItem* m_overlay_stats = nullptr;
7677

7778
QPushButton* m_load_profile_button = nullptr;
7879
QPushButton* m_save_profile_button = nullptr;

0 commit comments

Comments
 (0)