summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar lat9nq2023-06-06 21:20:37 -0400
committerGravatar lat9nq2023-07-21 10:56:07 -0400
commit9a2a92673c8cae4589e0e801f49235a4890719f9 (patch)
tree1de0d04e5273e0ef0b6290a26eb75f56c63d8644 /src
parentshared_widget: Refactor again (diff)
downloadyuzu-9a2a92673c8cae4589e0e801f49235a4890719f9.tar.gz
yuzu-9a2a92673c8cae4589e0e801f49235a4890719f9.tar.xz
yuzu-9a2a92673c8cae4589e0e801f49235a4890719f9.zip
shared_widget: Complete refactoring
Reduces code bloat a good bit by moving code specific to each sub widget to their own functions.
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/configuration/shared_widget.cpp510
-rw-r--r--src/yuzu/configuration/shared_widget.h36
2 files changed, 168 insertions, 378 deletions
diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp
index 564c46e5e..096ec451d 100644
--- a/src/yuzu/configuration/shared_widget.cpp
+++ b/src/yuzu/configuration/shared_widget.cpp
@@ -59,12 +59,10 @@ QLabel* Widget::CreateLabel(const QString& text) {
59 return qt_label; 59 return qt_label;
60} 60}
61 61
62QHBoxLayout* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const QString& label, 62QWidget* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const QString& label,
63 std::function<void()>& load_func, bool managed) { 63 std::function<std::string()>& serializer,
64 created = true; 64 std::function<void()>& restore_func,
65 65 const std::function<void()>& touch) {
66 QHBoxLayout* layout = new QHBoxLayout(this);
67
68 checkbox = new QCheckBox(label, this); 66 checkbox = new QCheckBox(label, this);
69 checkbox->setCheckState(bool_setting->ToString() == "true" ? Qt::CheckState::Checked 67 checkbox->setCheckState(bool_setting->ToString() == "true" ? Qt::CheckState::Checked
70 : Qt::CheckState::Unchecked); 68 : Qt::CheckState::Unchecked);
@@ -74,60 +72,30 @@ QHBoxLayout* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const
74 checkbox->setEnabled(false); 72 checkbox->setEnabled(false);
75 } 73 }
76 74
77 layout->addWidget(checkbox); 75 serializer = [this]() {
78 76 return checkbox->checkState() == Qt::CheckState::Checked ? "true" : "false";
79 layout->setContentsMargins(0, 0, 0, 0); 77 };
80
81 if (!managed) {
82 return layout;
83 }
84
85 if (Settings::IsConfiguringGlobal()) {
86 load_func = [=]() {
87 bool_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
88 };
89 } else {
90 restore_button =
91 CreateRestoreGlobalButton(bool_setting->UsingGlobal() && setting.UsingGlobal(), this);
92 layout->addWidget(restore_button);
93
94 QObject::connect(checkbox, &QCheckBox::stateChanged, [=](int) {
95 restore_button->setVisible(true);
96 restore_button->setEnabled(true);
97 });
98 78
99 QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { 79 if (!Settings::IsConfiguringGlobal()) {
80 restore_func = [this, bool_setting]() {
100 checkbox->setCheckState(bool_setting->ToStringGlobal() == "true" ? Qt::Checked 81 checkbox->setCheckState(bool_setting->ToStringGlobal() == "true" ? Qt::Checked
101 : Qt::Unchecked); 82 : Qt::Unchecked);
102 restore_button->setEnabled(false);
103 restore_button->setVisible(false);
104 });
105
106 load_func = [=]() {
107 bool using_global = !restore_button->isEnabled();
108 bool_setting->SetGlobal(using_global);
109 if (!using_global) {
110 bool_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
111 }
112 }; 83 };
84
85 QObject::connect(checkbox, &QCheckBox::clicked, [touch]() { touch(); });
113 } 86 }
114 87
115 return layout; 88 return checkbox;
116} 89}
117 90
118QWidget* Widget::CreateCombobox(std::function<std::string()>& serializer, 91QWidget* Widget::CreateCombobox(std::function<std::string()>& serializer,
119 std::function<void()>& restore_func, 92 std::function<void()>& restore_func,
120 const std::function<void()>& touched) { 93 const std::function<void()>& touch) {
121 const auto type = setting.TypeId(); 94 const auto type = setting.TypeId();
122 95
123 combobox = new QComboBox(this); 96 combobox = new QComboBox(this);
124 combobox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 97 combobox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
125 98
126 if (!Settings::IsConfiguringGlobal()) {
127 QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated),
128 [touched]() { touched(); });
129 }
130
131 const ComboboxTranslations* enumeration{nullptr}; 99 const ComboboxTranslations* enumeration{nullptr};
132 if (combobox_enumerations.contains(type)) { 100 if (combobox_enumerations.contains(type)) {
133 enumeration = &combobox_enumerations.at(type); 101 enumeration = &combobox_enumerations.at(type);
@@ -155,98 +123,57 @@ QWidget* Widget::CreateCombobox(std::function<std::string()>& serializer,
155 return std::to_string(enumeration->at(current).first); 123 return std::to_string(enumeration->at(current).first);
156 }; 124 };
157 125
158 restore_func = [this, find_index]() { 126 if (!Settings::IsConfiguringGlobal()) {
159 const u32 global_value = std::stoi(setting.ToStringGlobal()); 127 restore_func = [this, find_index]() {
160 combobox->setCurrentIndex(find_index(global_value)); 128 const u32 global_value = std::stoi(setting.ToStringGlobal());
161 }; 129 combobox->setCurrentIndex(find_index(global_value));
162 130 };
163 return combobox;
164}
165 131
166void Widget::CreateLineEdit(const QString& label, std::function<void()>& load_func, bool managed, 132 QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated),
167 Settings::BasicSetting* other_setting) { 133 [touch]() { touch(); });
168 const bool has_checkbox = other_setting != nullptr;
169 if (has_checkbox && other_setting->TypeId() != typeid(bool)) {
170 LOG_WARNING(Frontend, "Extra setting requested but setting is not boolean");
171 return;
172 } 134 }
173 135
174 created = true; 136 return combobox;
175 137}
176 QHBoxLayout* layout{nullptr};
177 std::function<void()> checkbox_load_func = []() {};
178
179 if (has_checkbox) {
180 layout = CreateCheckBox(other_setting, label, checkbox_load_func, managed);
181 } else {
182 layout = new QHBoxLayout(this);
183 layout->setContentsMargins(0, 0, 0, 0);
184 QLabel* q_label = CreateLabel(label);
185 layout->addWidget(q_label);
186 }
187 138
139QWidget* Widget::CreateLineEdit(std::function<std::string()>& serializer,
140 std::function<void()>& restore_func,
141 const std::function<void()>& touch, bool managed) {
188 const QString text = QString::fromStdString(setting.ToString()); 142 const QString text = QString::fromStdString(setting.ToString());
189 line_edit = new QLineEdit(this); 143 line_edit = new QLineEdit(this);
190 line_edit->setText(text); 144 line_edit->setText(text);
191 145
192 layout->addWidget(line_edit); 146 serializer = [this]() { return line_edit->text().toStdString(); };
193 147
194 if (!managed) { 148 if (!managed) {
195 return; 149 return line_edit;
196 } 150 }
197 151
198 if (Settings::IsConfiguringGlobal()) { 152 if (!Settings::IsConfiguringGlobal()) {
199 load_func = [=]() { 153 restore_func = [this]() {
200 checkbox_load_func();
201
202 std::string load_text = line_edit->text().toStdString();
203 setting.LoadString(load_text);
204 };
205 } else {
206 if (!has_checkbox) {
207 restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this);
208 layout->addWidget(restore_button);
209 }
210
211 QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) {
212 restore_button->setEnabled(false);
213 restore_button->setVisible(false);
214
215 line_edit->setText(QString::fromStdString(setting.ToStringGlobal())); 154 line_edit->setText(QString::fromStdString(setting.ToStringGlobal()));
216 });
217
218 QObject::connect(line_edit, &QLineEdit::textChanged, [&](QString) {
219 restore_button->setEnabled(true);
220 restore_button->setVisible(true);
221 });
222
223 load_func = [=]() {
224 checkbox_load_func();
225
226 bool using_global = !restore_button->isEnabled();
227 setting.SetGlobal(using_global);
228 if (!using_global) {
229 setting.LoadString(line_edit->text().toStdString());
230 }
231 }; 155 };
156
157 QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
232 } 158 }
159
160 return line_edit;
233} 161}
234 162
235void Widget::CreateSlider(const QString& label, bool reversed, float multiplier, 163QWidget* Widget::CreateSlider(bool reversed, float multiplier, const QString& format,
236 std::function<void()>& load_func, bool managed, const QString& format, 164 std::function<std::string()>& serializer,
237 Settings::BasicSetting* const other_setting) { 165 std::function<void()>& restore_func,
238 created = true; 166 const std::function<void()>& touch) {
167 QWidget* container = new QWidget(this);
168 QHBoxLayout* layout = new QHBoxLayout(container);
239 169
240 QHBoxLayout* layout = new QHBoxLayout(this);
241 slider = new QSlider(Qt::Horizontal, this); 170 slider = new QSlider(Qt::Horizontal, this);
242 QLabel* qt_label = new QLabel(label, this);
243 QLabel* feedback = new QLabel(this); 171 QLabel* feedback = new QLabel(this);
244 172
245 layout->addWidget(qt_label);
246 layout->addWidget(slider); 173 layout->addWidget(slider);
247 layout->addWidget(feedback); 174 layout->addWidget(feedback);
248 175
249 qt_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 176 container->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
250 177
251 layout->setContentsMargins(0, 0, 0, 0); 178 layout->setContentsMargins(0, 0, 0, 0);
252 179
@@ -265,60 +192,20 @@ void Widget::CreateSlider(const QString& label, bool reversed, float multiplier,
265 192
266 slider->setInvertedAppearance(reversed); 193 slider->setInvertedAppearance(reversed);
267 194
268 if (!managed) { 195 serializer = [this]() { return std::to_string(slider->value()); };
269 return;
270 }
271
272 if (Settings::IsConfiguringGlobal()) {
273 load_func = [=]() { setting.LoadString(std::to_string(slider->value())); };
274 } else {
275 restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this);
276 layout->addWidget(restore_button);
277
278 QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
279 slider->setValue(std::stoi(setting.ToStringGlobal()));
280 196
281 restore_button->setEnabled(false); 197 if (!Settings::IsConfiguringGlobal()) {
282 restore_button->setVisible(false); 198 restore_func = [this]() { slider->setValue(std::stoi(setting.ToStringGlobal())); };
283 });
284
285 QObject::connect(slider, &QAbstractSlider::valueChanged, [=]() {
286 restore_button->setEnabled(true);
287 restore_button->setVisible(true);
288 });
289
290 load_func = [=]() {
291 bool using_global = !restore_button->isEnabled();
292 setting.SetGlobal(using_global);
293 if (!using_global) {
294 setting.LoadString(std::to_string(slider->value()));
295 }
296 };
297 }
298}
299 199
300void Widget::CreateSpinBox(const QString& label, std::function<void()>& load_func, bool managed, 200 QObject::connect(slider, &QAbstractSlider::sliderReleased, [touch]() { touch(); });
301 const QString& suffix, Settings::BasicSetting* other_setting) {
302 const bool has_checkbox = other_setting != nullptr;
303 if (has_checkbox && other_setting->TypeId() != typeid(bool)) {
304 LOG_WARNING(Frontend, "Extra setting requested but setting is not boolean");
305 return;
306 } 201 }
307 created = true;
308
309 QHBoxLayout* layout{nullptr};
310 std::function<void()> checkbox_load_func = []() {};
311 QLabel* q_label{nullptr};
312 202
313 if (has_checkbox) { 203 return container;
314 layout = CreateCheckBox(other_setting, label, checkbox_load_func, managed); 204}
315 } else {
316 layout = new QHBoxLayout(this);
317 layout->setContentsMargins(0, 0, 0, 0);
318 q_label = CreateLabel(label);
319 layout->addWidget(q_label);
320 }
321 205
206QWidget* Widget::CreateSpinBox(const QString& suffix, std::function<std::string()>& serializer,
207 std::function<void()>& restore_func,
208 const std::function<void()>& touch) {
322 const int min_val = std::stoi(setting.MinVal()); 209 const int min_val = std::stoi(setting.MinVal());
323 const int max_val = std::stoi(setting.MaxVal()); 210 const int max_val = std::stoi(setting.MaxVal());
324 const int default_val = std::stoi(setting.ToString()); 211 const int default_val = std::stoi(setting.ToString());
@@ -329,48 +216,29 @@ void Widget::CreateSpinBox(const QString& label, std::function<void()>& load_fun
329 spinbox->setSuffix(suffix); 216 spinbox->setSuffix(suffix);
330 spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 217 spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
331 218
332 layout->insertWidget(1, spinbox); 219 serializer = [this]() { return std::to_string(spinbox->value()); };
333
334 if (Settings::IsConfiguringGlobal()) {
335 load_func = [=]() {
336 checkbox_load_func();
337 setting.LoadString(std::to_string(spinbox->value()));
338 };
339 } else {
340 if (!has_checkbox) {
341 restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this);
342 layout->addWidget(restore_button);
343 }
344
345 QObject::connect(restore_button, &QAbstractButton::clicked,
346 [this](bool) { spinbox->setValue(std::stoi(setting.ToStringGlobal())); });
347
348 QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this](int) {
349 restore_button->setEnabled(true);
350 restore_button->setVisible(true);
351 });
352 220
353 load_func = [=]() { 221 if (!Settings::IsConfiguringGlobal()) {
354 checkbox_load_func(); 222 restore_func = [this]() { spinbox->setValue(std::stoi(setting.ToStringGlobal())); };
355 223
356 const bool using_global = !restore_button->isEnabled(); 224 QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this, touch]() {
357 setting.SetGlobal(using_global); 225 if (spinbox->value() != std::stoi(setting.ToStringGlobal())) {
358 if (!using_global) { 226 touch();
359 setting.LoadString(std::to_string(spinbox->value()));
360 } 227 }
361 }; 228 });
362 } 229 }
230
231 return spinbox;
363} 232}
364 233
365void Widget::CreateHexEdit(const QString& label, std::function<void()>& load_func, bool managed, 234QWidget* Widget::CreateHexEdit(std::function<std::string()>& serializer,
366 Settings::BasicSetting* const other_setting) { 235 std::function<void()>& restore_func,
367 CreateLineEdit(label, load_func, false, other_setting); 236 const std::function<void()>& touch) {
368 if (!created || !managed) { 237 auto* data_component = CreateLineEdit(serializer, restore_func, touch, false);
369 return; 238 if (data_component == nullptr) {
239 return nullptr;
370 } 240 }
371 241
372 QLayout* layout = this->layout();
373
374 auto to_hex = [=](const std::string& input) { 242 auto to_hex = [=](const std::string& input) {
375 return QString::fromStdString(fmt::format("{:08x}", std::stoi(input))); 243 return QString::fromStdString(fmt::format("{:08x}", std::stoi(input)));
376 }; 244 };
@@ -388,69 +256,21 @@ void Widget::CreateHexEdit(const QString& label, std::function<void()>& load_fun
388 return std::to_string(std::stoul(line_edit->text().toStdString(), nullptr, 16)); 256 return std::to_string(std::stoul(line_edit->text().toStdString(), nullptr, 16));
389 }; 257 };
390 258
391 if (Settings::IsConfiguringGlobal()) { 259 serializer = [hex_to_dec]() { return hex_to_dec(); };
392 load_func = [=]() {
393 other_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
394 setting.LoadString(hex_to_dec());
395 };
396 } else {
397 restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this);
398 layout->addWidget(restore_button);
399
400 QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) {
401 line_edit->setText(to_hex(setting.ToStringGlobal()));
402 checkbox->setCheckState(other_setting->ToStringGlobal() == "true" ? Qt::Checked
403 : Qt::Unchecked);
404
405 restore_button->setEnabled(false);
406 restore_button->setVisible(false);
407 });
408
409 QObject::connect(line_edit, &QLineEdit::textEdited, [&]() {
410 restore_button->setEnabled(true);
411 restore_button->setVisible(true);
412 });
413
414 QObject::connect(checkbox, &QAbstractButton::clicked, [&]() {
415 restore_button->setEnabled(true);
416 restore_button->setVisible(true);
417 });
418 260
419 load_func = [=]() { 261 if (!Settings::IsConfiguringGlobal()) {
420 const bool using_global = !restore_button->isEnabled(); 262 restore_func = [this, to_hex]() { line_edit->setText(to_hex(setting.ToStringGlobal())); };
421 other_setting->SetGlobal(using_global);
422 setting.SetGlobal(using_global);
423 263
424 if (!using_global) { 264 QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
425 other_setting->LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false");
426 setting.LoadString(hex_to_dec());
427 }
428 };
429 } 265 }
430}
431 266
432void Widget::CreateDateTimeEdit(const QString& label, std::function<void()>& load_func, 267 return line_edit;
433 bool managed, bool restrict, 268}
434 Settings::BasicSetting* const other_setting) {
435 const bool has_checkbox = other_setting != nullptr;
436 if ((restrict && !has_checkbox) || (has_checkbox && other_setting->TypeId() != typeid(bool))) {
437 LOG_WARNING(Frontend, "Extra setting or restrict requested but is not boolean");
438 return;
439 }
440 created = true;
441
442 QHBoxLayout* layout{nullptr};
443 std::function<void()> checkbox_load_func = []() {};
444
445 if (has_checkbox) {
446 layout = CreateCheckBox(other_setting, label, checkbox_load_func, managed);
447 } else {
448 layout = new QHBoxLayout(this);
449 QLabel* q_label = CreateLabel(label);
450 layout->addWidget(q_label);
451 }
452 269
453 const bool disabled = other_setting->ToString() != "true"; 270QWidget* Widget::CreateDateTimeEdit(bool disabled, bool restrict,
271 std::function<std::string()>& serializer,
272 std::function<void()>& restore_func,
273 const std::function<void()>& touch) {
454 const long long current_time = QDateTime::currentSecsSinceEpoch(); 274 const long long current_time = QDateTime::currentSecsSinceEpoch();
455 const s64 the_time = disabled ? current_time : std::stoll(setting.ToString()); 275 const s64 the_time = disabled ? current_time : std::stoll(setting.ToString());
456 const auto default_val = QDateTime::fromSecsSinceEpoch(the_time); 276 const auto default_val = QDateTime::fromSecsSinceEpoch(the_time);
@@ -460,27 +280,9 @@ void Widget::CreateDateTimeEdit(const QString& label, std::function<void()>& loa
460 date_time_edit->setMinimumDateTime(QDateTime::fromSecsSinceEpoch(0)); 280 date_time_edit->setMinimumDateTime(QDateTime::fromSecsSinceEpoch(0));
461 date_time_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 281 date_time_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
462 282
463 layout->insertWidget(1, date_time_edit); 283 serializer = [this]() { return std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()); };
464
465 if (!managed) {
466 return;
467 }
468
469 if (Settings::IsConfiguringGlobal()) {
470 load_func = [=]() {
471 checkbox_load_func();
472 if (restrict && checkbox->checkState() == Qt::Unchecked) {
473 return;
474 }
475
476 setting.LoadString(std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()));
477 };
478 } else {
479 if (!has_checkbox) {
480 restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this);
481 layout->addWidget(restore_button);
482 }
483 284
285 if (!Settings::IsConfiguringGlobal()) {
484 auto get_clear_val = [=]() { 286 auto get_clear_val = [=]() {
485 return QDateTime::fromSecsSinceEpoch([=]() { 287 return QDateTime::fromSecsSinceEpoch([=]() {
486 if (restrict && checkbox->checkState() == Qt::Checked) { 288 if (restrict && checkbox->checkState() == Qt::Checked) {
@@ -490,33 +292,21 @@ void Widget::CreateDateTimeEdit(const QString& label, std::function<void()>& loa
490 }()); 292 }());
491 }; 293 };
492 294
493 QObject::connect(restore_button, &QAbstractButton::clicked, 295 restore_func = [=]() { date_time_edit->setDateTime(get_clear_val()); };
494 [=](bool) { date_time_edit->setDateTime(get_clear_val()); });
495 296
496 QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished, [=]() { 297 QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished, [=]() {
497 if (date_time_edit->dateTime() != get_clear_val()) { 298 if (date_time_edit->dateTime() != get_clear_val()) {
498 restore_button->setEnabled(true); 299 touch();
499 restore_button->setVisible(true);
500 } 300 }
501 }); 301 });
502
503 load_func = [=]() {
504 checkbox_load_func();
505 if (restrict && checkbox->checkState() == Qt::Unchecked) {
506 return;
507 }
508
509 const bool using_global = !restore_button->isEnabled();
510 other_setting->SetGlobal(using_global);
511 if (!using_global) {
512 setting.LoadString(std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()));
513 }
514 };
515 } 302 }
303
304 return date_time_edit;
516} 305}
517 306
518void Widget::SetupComponent(const QString& label, std::function<void()>& load_func, bool managed, 307void Widget::SetupComponent(const QString& label, std::function<void()>& load_func, bool managed,
519 RequestType request, Settings::BasicSetting* other_setting) { 308 RequestType request, float multiplier,
309 Settings::BasicSetting* other_setting, const QString& string) {
520 created = true; 310 created = true;
521 const auto type = setting.TypeId(); 311 const auto type = setting.TypeId();
522 312
@@ -531,42 +321,74 @@ void Widget::SetupComponent(const QString& label, std::function<void()>& load_fu
531 "Extra setting specified but is not bool, refusing to create checkbox for it."); 321 "Extra setting specified but is not bool, refusing to create checkbox for it.");
532 } 322 }
533 323
534 if (require_checkbox) { 324 std::function<std::string()> checkbox_serializer = []() -> std::string { return {}; };
535 } else { 325 std::function<void()> checkbox_restore_func = []() {};
536 QLabel* qt_label = CreateLabel(label);
537 layout->addWidget(qt_label);
538 }
539 326
540 std::function<void()> touched = []() {}; 327 std::function<void()> touch = []() {};
541 std::function<std::string()> serializer = []() -> std::string { return {}; }; 328 std::function<std::string()> serializer = []() -> std::string { return {}; };
542 std::function<void()> restore_func = []() {}; 329 std::function<void()> restore_func = []() {};
543 330
544 QWidget* data_component{nullptr}; 331 QWidget* data_component{nullptr};
545 332
546 if (!Settings::IsConfiguringGlobal()) { 333 if (!Settings::IsConfiguringGlobal() && managed) {
547 restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this); 334 restore_button = CreateRestoreGlobalButton(setting.UsingGlobal(), this);
548 335
549 touched = [this]() { 336 touch = [this]() {
337 LOG_DEBUG(Frontend, "Setting custom setting for {}", setting.GetLabel());
550 restore_button->setEnabled(true); 338 restore_button->setEnabled(true);
551 restore_button->setVisible(true); 339 restore_button->setVisible(true);
552 }; 340 };
553 } 341 }
554 342
555 if (setting.IsEnum()) { 343 if (require_checkbox) {
556 data_component = CreateCombobox(serializer, restore_func, touched); 344 QWidget* lhs =
345 CreateCheckBox(other_setting, label, checkbox_serializer, checkbox_restore_func, touch);
346 layout->addWidget(lhs);
347 } else if (setting.TypeId() != typeid(bool)) {
348 QLabel* qt_label = CreateLabel(label);
349 layout->addWidget(qt_label);
350 }
351
352 if (setting.TypeId() == typeid(bool)) {
353 data_component = CreateCheckBox(&setting, label, serializer, restore_func, touch);
354 } else if (setting.IsEnum()) {
355 data_component = CreateCombobox(serializer, restore_func, touch);
557 } else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) || 356 } else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) ||
558 type == typeid(s64) || type == typeid(u8)) { 357 type == typeid(s64) || type == typeid(u8)) {
559 switch (request) { 358 switch (request) {
359 case RequestType::Slider:
360 case RequestType::ReverseSlider:
361 data_component = CreateSlider(request == RequestType::ReverseSlider, multiplier, string,
362 serializer, restore_func, touch);
363 break;
364 case RequestType::Default:
365 case RequestType::LineEdit:
366 data_component = CreateLineEdit(serializer, restore_func, touch);
367 break;
368 case RequestType::DateTimeEdit:
369 data_component = CreateDateTimeEdit(other_setting->ToString() != "true", true,
370 serializer, restore_func, touch);
371 break;
372 case RequestType::SpinBox:
373 data_component = CreateSpinBox(string, serializer, restore_func, touch);
374 break;
375 case RequestType::HexEdit:
376 data_component = CreateHexEdit(serializer, restore_func, touch);
377 break;
560 case RequestType::ComboBox: 378 case RequestType::ComboBox:
561 data_component = CreateCombobox(serializer, restore_func, touched); 379 data_component = CreateCombobox(serializer, restore_func, touch);
562 break; 380 break;
563 default: 381 default:
564 UNIMPLEMENTED(); 382 UNIMPLEMENTED();
565 } 383 }
566 } else if (type == typeid(std::string)) { 384 } else if (type == typeid(std::string)) {
567 switch (request) { 385 switch (request) {
386 case RequestType::Default:
387 case RequestType::LineEdit:
388 data_component = CreateLineEdit(serializer, restore_func, touch);
389 break;
568 case RequestType::ComboBox: 390 case RequestType::ComboBox:
569 data_component = CreateCombobox(serializer, restore_func, touched); 391 data_component = CreateCombobox(serializer, restore_func, touch);
570 break; 392 break;
571 default: 393 default:
572 UNIMPLEMENTED(); 394 UNIMPLEMENTED();
@@ -586,23 +408,36 @@ void Widget::SetupComponent(const QString& label, std::function<void()>& load_fu
586 } 408 }
587 409
588 if (Settings::IsConfiguringGlobal()) { 410 if (Settings::IsConfiguringGlobal()) {
589 load_func = [this, serializer]() { setting.LoadString(serializer()); }; 411 load_func = [this, serializer, checkbox_serializer, require_checkbox, other_setting]() {
412 if (require_checkbox) {
413 other_setting->LoadString(checkbox_serializer());
414 }
415 setting.LoadString(serializer());
416 };
590 } else { 417 } else {
591 layout->addWidget(restore_button); 418 layout->addWidget(restore_button);
592 419
593 QObject::connect(restore_button, &QAbstractButton::clicked, [this, restore_func](bool) { 420 QObject::connect(restore_button, &QAbstractButton::clicked,
594 restore_button->setEnabled(false); 421 [this, restore_func, checkbox_restore_func](bool) {
595 restore_button->setVisible(false); 422 restore_button->setEnabled(false);
423 restore_button->setVisible(false);
596 424
597 restore_func(); 425 checkbox_restore_func();
598 }); 426 restore_func();
427 });
599 428
600 load_func = [this, serializer]() { 429 load_func = [this, serializer, require_checkbox, checkbox_serializer, other_setting]() {
601 bool using_global = !restore_button->isEnabled(); 430 bool using_global = !restore_button->isEnabled();
602 setting.SetGlobal(using_global); 431 setting.SetGlobal(using_global);
603 if (!using_global) { 432 if (!using_global) {
604 setting.LoadString(serializer()); 433 setting.LoadString(serializer());
605 } 434 }
435 if (require_checkbox) {
436 other_setting->SetGlobal(using_global);
437 if (!using_global) {
438 other_setting->LoadString(checkbox_serializer());
439 }
440 }
606 }; 441 };
607 } 442 }
608} 443}
@@ -626,7 +461,6 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
626 return; 461 return;
627 } 462 }
628 463
629 const auto type = setting.TypeId();
630 const int id = setting.Id(); 464 const int id = setting.Id();
631 465
632 const auto [label, tooltip] = [&]() { 466 const auto [label, tooltip] = [&]() {
@@ -646,57 +480,7 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
646 480
647 std::function<void()> load_func = []() {}; 481 std::function<void()> load_func = []() {};
648 482
649 if (type == typeid(bool)) { 483 SetupComponent(label, load_func, managed, request, multiplier, other_setting, string);
650 CreateCheckBox(&setting, label, load_func, managed);
651 } else if (setting.IsEnum()) {
652 SetupComponent(label, load_func, managed, request, other_setting);
653 } else if (type == typeid(u32) || type == typeid(int) || type == typeid(u16) ||
654 type == typeid(s64) || type == typeid(u8)) {
655 switch (request) {
656 case RequestType::Slider:
657 case RequestType::ReverseSlider:
658 CreateSlider(label, request == RequestType::ReverseSlider, multiplier, load_func,
659 managed, string);
660 break;
661 case RequestType::LineEdit:
662 case RequestType::Default:
663 CreateLineEdit(label, load_func, managed);
664 break;
665 case RequestType::ComboBox:
666 SetupComponent(label, load_func, managed, request, other_setting);
667 break;
668 case RequestType::DateTimeEdit:
669 CreateDateTimeEdit(label, load_func, managed, true, other_setting);
670 break;
671 case RequestType::SpinBox:
672 CreateSpinBox(label, load_func, managed, string, other_setting);
673 break;
674 case RequestType::HexEdit:
675 CreateHexEdit(label, load_func, managed, other_setting);
676 break;
677 default:
678 LOG_WARNING(Frontend, "Requested widget is unimplemented.");
679 break;
680 }
681 } else if (type == typeid(std::string)) {
682 switch (request) {
683 case RequestType::Default:
684 case RequestType::LineEdit:
685 CreateLineEdit(label, load_func, managed);
686 break;
687 case RequestType::ComboBox:
688 SetupComponent(label, load_func, managed, request, other_setting);
689 break;
690 case RequestType::SpinBox:
691 case RequestType::Slider:
692 case RequestType::ReverseSlider:
693 case RequestType::HexEdit:
694 case RequestType::DateTimeEdit:
695 case RequestType::MaxEnum:
696 LOG_WARNING(Frontend, "Requested widget is unimplemented.");
697 break;
698 }
699 }
700 484
701 if (!created) { 485 if (!created) {
702 LOG_WARNING(Frontend, "No widget was created for \"{}\"", setting.GetLabel()); 486 LOG_WARNING(Frontend, "No widget was created for \"{}\"", setting.GetLabel());
diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h
index 2ed738a06..01348e442 100644
--- a/src/yuzu/configuration/shared_widget.h
+++ b/src/yuzu/configuration/shared_widget.h
@@ -57,26 +57,32 @@ public:
57 57
58private: 58private:
59 void SetupComponent(const QString& label, std::function<void()>& load_func, bool managed, 59 void SetupComponent(const QString& label, std::function<void()>& load_func, bool managed,
60 RequestType request, Settings::BasicSetting* other_setting); 60 RequestType request, float multiplier,
61 Settings::BasicSetting* other_setting, const QString& string);
61 62
62 QLabel* CreateLabel(const QString& text); 63 QLabel* CreateLabel(const QString& text);
63 QHBoxLayout* CreateCheckBox(Settings::BasicSetting* bool_setting, const QString& label, 64 QWidget* CreateCheckBox(Settings::BasicSetting* bool_setting, const QString& label,
64 std::function<void()>& load_func, bool managed); 65 std::function<std::string()>& serializer,
66 std::function<void()>& restore_func,
67 const std::function<void()>& touch);
65 68
66 QWidget* CreateCombobox(std::function<std::string()>& serializer, 69 QWidget* CreateCombobox(std::function<std::string()>& serializer,
67 std::function<void()>& restore_func, 70 std::function<void()>& restore_func,
68 const std::function<void()>& touched); 71 const std::function<void()>& touch);
69 void CreateLineEdit(const QString& label, std::function<void()>& load_func, bool managed, 72 QWidget* CreateLineEdit(std::function<std::string()>& serializer,
70 Settings::BasicSetting* const other_setting = nullptr); 73 std::function<void()>& restore_func, const std::function<void()>& touch,
71 void CreateHexEdit(const QString& label, std::function<void()>& load_func, bool managed, 74 bool managed = true);
72 Settings::BasicSetting* const other_setting = nullptr); 75 QWidget* CreateHexEdit(std::function<std::string()>& serializer,
73 void CreateSlider(const QString& label, bool reversed, float multiplier, 76 std::function<void()>& restore_func, const std::function<void()>& touch);
74 std::function<void()>& load_func, bool managed, const QString& format, 77 QWidget* CreateSlider(bool reversed, float multiplier, const QString& format,
75 Settings::BasicSetting* const other_setting = nullptr); 78 std::function<std::string()>& serializer,
76 void CreateDateTimeEdit(const QString& label, std::function<void()>& load_func, bool managed, 79 std::function<void()>& restore_func, const std::function<void()>& touch);
77 bool restrict, Settings::BasicSetting* const other_setting = nullptr); 80 QWidget* CreateDateTimeEdit(bool disabled, bool restrict,
78 void CreateSpinBox(const QString& label, std::function<void()>& load_func, bool managed, 81 std::function<std::string()>& serializer,
79 const QString& suffix, Settings::BasicSetting* other_setting = nullptr); 82 std::function<void()>& restore_func,
83 const std::function<void()>& touch);
84 QWidget* CreateSpinBox(const QString& suffix, std::function<std::string()>& serializer,
85 std::function<void()>& restore_func, const std::function<void()>& touch);
80 86
81 QWidget* parent; 87 QWidget* parent;
82 const TranslationMap& translations; 88 const TranslationMap& translations;