summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/configuration/shared_widget.cpp68
-rw-r--r--src/yuzu/configuration/shared_widget.h6
2 files changed, 73 insertions, 1 deletions
diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp
index bdb38c8ea..36d8da5a5 100644
--- a/src/yuzu/configuration/shared_widget.cpp
+++ b/src/yuzu/configuration/shared_widget.cpp
@@ -23,6 +23,7 @@
23#include <QLineEdit> 23#include <QLineEdit>
24#include <QObject> 24#include <QObject>
25#include <QPushButton> 25#include <QPushButton>
26#include <QRadioButton>
26#include <QRegularExpression> 27#include <QRegularExpression>
27#include <QSizePolicy> 28#include <QSizePolicy>
28#include <QSlider> 29#include <QSlider>
@@ -171,6 +172,65 @@ QWidget* Widget::CreateCombobox(std::function<std::string()>& serializer,
171 return combobox; 172 return combobox;
172} 173}
173 174
175QWidget* Widget::CreateRadioGroup(std::function<std::string()>& serializer,
176 std::function<void()>& restore_func,
177 const std::function<void()>& touch) {
178 const auto type = setting.EnumIndex();
179
180 QWidget* group = new QWidget(this);
181 QHBoxLayout* layout = new QHBoxLayout(group);
182 layout->setContentsMargins(0, 0, 0, 0);
183 group->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
184
185 const ComboboxTranslations* enumeration{nullptr};
186 if (combobox_enumerations.contains(type)) {
187 enumeration = &combobox_enumerations.at(type);
188 for (const auto& [id, name] : *enumeration) {
189 QRadioButton* radio_button = new QRadioButton(name, group);
190 layout->addWidget(radio_button);
191 radio_buttons.push_back({id, radio_button});
192 }
193 } else {
194 return group;
195 }
196
197 const auto get_selected = [=]() -> u32 {
198 for (const auto& [id, button] : radio_buttons) {
199 if (button->isChecked()) {
200 return id;
201 }
202 }
203 return -1;
204 };
205
206 const auto set_index = [=](u32 value) {
207 for (const auto& [id, button] : radio_buttons) {
208 button->setChecked(id == value);
209 }
210 };
211
212 const u32 setting_value = std::stoi(setting.ToString());
213 set_index(setting_value);
214
215 serializer = [get_selected]() {
216 int current = get_selected();
217 return std::to_string(current);
218 };
219
220 restore_func = [this, set_index]() {
221 const u32 global_value = std::stoi(RelevantDefault(setting));
222 set_index(global_value);
223 };
224
225 if (!Settings::IsConfiguringGlobal()) {
226 for (const auto& [id, button] : radio_buttons) {
227 QObject::connect(button, &QAbstractButton::clicked, [touch]() { touch(); });
228 }
229 }
230
231 return group;
232}
233
174QWidget* Widget::CreateLineEdit(std::function<std::string()>& serializer, 234QWidget* Widget::CreateLineEdit(std::function<std::string()>& serializer,
175 std::function<void()>& restore_func, 235 std::function<void()>& restore_func,
176 const std::function<void()>& touch, bool managed) { 236 const std::function<void()>& touch, bool managed) {
@@ -410,6 +470,8 @@ void Widget::SetupComponent(const QString& label, std::function<void()>& load_fu
410 return RequestType::Slider; 470 return RequestType::Slider;
411 case Settings::Specialization::Countable: 471 case Settings::Specialization::Countable:
412 return RequestType::SpinBox; 472 return RequestType::SpinBox;
473 case Settings::Specialization::Radio:
474 return RequestType::RadioGroup;
413 default: 475 default:
414 break; 476 break;
415 } 477 }
@@ -438,7 +500,11 @@ void Widget::SetupComponent(const QString& label, std::function<void()>& load_fu
438 if (setting.TypeId() == typeid(bool)) { 500 if (setting.TypeId() == typeid(bool)) {
439 data_component = CreateCheckBox(&setting, label, serializer, restore_func, touch); 501 data_component = CreateCheckBox(&setting, label, serializer, restore_func, touch);
440 } else if (setting.IsEnum()) { 502 } else if (setting.IsEnum()) {
441 data_component = CreateCombobox(serializer, restore_func, touch); 503 if (request == RequestType::RadioGroup) {
504 data_component = CreateRadioGroup(serializer, restore_func, touch);
505 } else {
506 data_component = CreateCombobox(serializer, restore_func, touch);
507 }
442 } else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) || 508 } else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) ||
443 type == typeid(s64) || type == typeid(u8)) { 509 type == typeid(s64) || type == typeid(u8)) {
444 switch (request) { 510 switch (request) {
diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h
index e64693bab..5303dd898 100644
--- a/src/yuzu/configuration/shared_widget.h
+++ b/src/yuzu/configuration/shared_widget.h
@@ -22,6 +22,7 @@ class QObject;
22class QPushButton; 22class QPushButton;
23class QSlider; 23class QSlider;
24class QSpinBox; 24class QSpinBox;
25class QRadioButton;
25 26
26namespace Settings { 27namespace Settings {
27class BasicSetting; 28class BasicSetting;
@@ -38,6 +39,7 @@ enum class RequestType {
38 LineEdit, 39 LineEdit,
39 HexEdit, 40 HexEdit,
40 DateTimeEdit, 41 DateTimeEdit,
42 RadioGroup,
41 MaxEnum, 43 MaxEnum,
42}; 44};
43 45
@@ -91,6 +93,7 @@ public:
91 QSlider* slider{}; 93 QSlider* slider{};
92 QComboBox* combobox{}; 94 QComboBox* combobox{};
93 QDateTimeEdit* date_time_edit{}; 95 QDateTimeEdit* date_time_edit{};
96 std::vector<std::pair<u32, QRadioButton*>> radio_buttons{};
94 97
95private: 98private:
96 void SetupComponent(const QString& label, std::function<void()>& load_func, bool managed, 99 void SetupComponent(const QString& label, std::function<void()>& load_func, bool managed,
@@ -106,6 +109,9 @@ private:
106 QWidget* CreateCombobox(std::function<std::string()>& serializer, 109 QWidget* CreateCombobox(std::function<std::string()>& serializer,
107 std::function<void()>& restore_func, 110 std::function<void()>& restore_func,
108 const std::function<void()>& touch); 111 const std::function<void()>& touch);
112 QWidget* CreateRadioGroup(std::function<std::string()>& serializer,
113 std::function<void()>& restore_func,
114 const std::function<void()>& touch);
109 QWidget* CreateLineEdit(std::function<std::string()>& serializer, 115 QWidget* CreateLineEdit(std::function<std::string()>& serializer,
110 std::function<void()>& restore_func, const std::function<void()>& touch, 116 std::function<void()>& restore_func, const std::function<void()>& touch,
111 bool managed = true); 117 bool managed = true);