-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathPanelLists.cpp
More file actions
151 lines (123 loc) · 4.91 KB
/
PanelLists.cpp
File metadata and controls
151 lines (123 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* Left-Side Panel
*
* From: https://github.com/PokemonAutomation/
*
*/
#include <QStandardItemModel>
#include <QVBoxLayout>
#include <QLabel>
#include "Common/Qt/NoWheelComboBox.h"
#include "CommonFramework/PersistentSettings.h"
#include "CommonFramework/Windows/DpiScaler.h"
#include "CommonFramework/Panels/UI/PanelListWidget.h"
#include "CommonFramework/GlobalSettingsPanel.h"
#include "ML/ML_Panels.h"
#include "NintendoSwitch/NintendoSwitch_Panels.h"
#include "PokemonSwSh/PokemonSwSh_Panels.h"
#include "PokemonHome/PokemonHome_Panels.h"
#include "PokemonBDSP/PokemonBDSP_Panels.h"
#include "PokemonFRLG/PokemonFRLG_Panels.h"
#include "PokemonLA/PokemonLA_Panels.h"
#include "PokemonLGPE/PokemonLGPE_Panels.h"
#include "PokemonRSE/PokemonRSE_Panels.h"
#include "PokemonSV/PokemonSV_Panels.h"
#include "PokemonLZA/PokemonLZA_Panels.h"
#include "PokemonPokopia/PokemonPokopia_Panels.h"
#include "ZeldaTotK/ZeldaTotK_Panels.h"
#include "PanelLists.h"
//#include <iostream>
//using std::cout;
//using std::endl;
namespace PokemonAutomation{
ProgramSelect::ProgramSelect(QWidget& parent, PanelHolder& holder)
: QGroupBox("Program Select", &parent)
, m_holder(holder)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setAlignment(Qt::AlignTop);
m_dropdown = new NoWheelCompactComboBox(this);
m_dropdown->setMaxVisibleItems(20);
layout->addWidget(m_dropdown);
add(std::make_unique<NintendoSwitch::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonHome::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonLGPE::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonSwSh::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonBDSP::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonLA::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonSV::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonLZA::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonFRLG::PanelListFactory>());
add(std::make_unique<NintendoSwitch::PokemonPokopia::PanelListFactory>());
if (PreloadSettings::instance().DEVELOPER_MODE){
add(std::make_unique<NintendoSwitch::PokemonRSE::PanelListFactory>());
}
add(std::make_unique<NintendoSwitch::ZeldaTotK::PanelListFactory>());
if (PreloadSettings::instance().DEVELOPER_MODE){
add(std::make_unique<ML::PanelListFactory>());
}
// Load the 1st list by default.
m_dropdown->setCurrentIndex(0);
m_active_index = 0;
m_active_list = m_lists[0]->make_QWidget(*this, m_holder);
layout->addWidget(m_active_list);
connect(
m_dropdown, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
this, [this](int index){
change_list(index);
}
);
}
void ProgramSelect::add(std::unique_ptr<PanelListDescriptor> list){
int index = m_dropdown->count();
m_dropdown->addItem(QString::fromStdString(list->name()));
m_lists.emplace_back(std::move(list));
const PanelListDescriptor& back = *m_lists.back();
if (!m_tab_map.emplace(back.name(), index).second){
m_lists.pop_back();
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Duplicate Category Name: " + back.name());
}
if (!back.enabled()){
auto* model = qobject_cast<QStandardItemModel*>(m_dropdown->model());
if (model != nullptr){
QStandardItem* line_handle = model->item(index);
if (line_handle != nullptr){
line_handle->setEnabled(false);
}
}
}
}
void ProgramSelect::load_persistent_panel(){
const std::string* str = PERSISTENT_SETTINGS().panels.get_string("ProgramCategory");
if (str == nullptr){
return;
}
auto iter = m_tab_map.find(*str);
if (iter == m_tab_map.end()){
return;
}
m_dropdown->setCurrentIndex(iter->second);
change_list(iter->second);
str = PERSISTENT_SETTINGS().panels.get_string(PanelListWidget::JSON_PROGRAM_PANEL);
if (str != nullptr){
m_active_list->set_panel(*str);
}
}
void ProgramSelect::change_list(int index){
if (m_active_index == index && m_active_list != nullptr){
return;
}
m_dropdown->setCurrentIndex(index);
m_active_index = index;
PERSISTENT_SETTINGS().panels["ProgramCategory"] = m_lists[index]->name();
delete m_active_list;
m_active_list = m_lists[index]->make_QWidget(*this, m_holder);
layout()->addWidget(m_active_list);
}
QSize ProgramSelect::sizeHint() const{
QSize size = QGroupBox::sizeHint();
// cout << size.width() << " x " << size.height() << endl;
// cout << this->size().width() << " x " << this->size().height() << endl;
size.setWidth(scale_dpi_width(size.width() + 10));
return size;
}
}