summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar lat9nq2023-06-21 04:04:48 -0400
committerGravatar lat9nq2023-07-21 10:56:55 -0400
commitd1de1c3bedcd2526eb78c7eaa21f2eef6041a590 (patch)
tree0142d6346997b86881c37e700219969c8e1b6a79
parentconfiguration: Use specialization of settings (diff)
downloadyuzu-d1de1c3bedcd2526eb78c7eaa21f2eef6041a590.tar.gz
yuzu-d1de1c3bedcd2526eb78c7eaa21f2eef6041a590.tar.xz
yuzu-d1de1c3bedcd2526eb78c7eaa21f2eef6041a590.zip
shared_widget: Internalize component restoring
Diffstat (limited to '')
-rw-r--r--src/yuzu/configuration/configure_system.cpp28
-rw-r--r--src/yuzu/configuration/configure_system.h4
-rw-r--r--src/yuzu/configuration/shared_widget.cpp78
3 files changed, 49 insertions, 61 deletions
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
index 796ebc44f..ef26fb6ce 100644
--- a/src/yuzu/configuration/configure_system.cpp
+++ b/src/yuzu/configuration/configure_system.cpp
@@ -52,20 +52,6 @@ ConfigureSystem::ConfigureSystem(
52 52
53 Setup(builder); 53 Setup(builder);
54 54
55 connect(rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
56 rng_seed_edit->setEnabled(state == Qt::Checked);
57 if (state != Qt::Checked) {
58 rng_seed_edit->setText(QStringLiteral("00000000"));
59 }
60 });
61
62 connect(custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](int state) {
63 custom_rtc_edit->setEnabled(state == Qt::Checked);
64 if (state != Qt::Checked) {
65 custom_rtc_edit->setDateTime(QDateTime::currentDateTime());
66 }
67 });
68
69 const auto locale_check = [this]() { 55 const auto locale_check = [this]() {
70 const auto region_index = combo_region->currentIndex(); 56 const auto region_index = combo_region->currentIndex();
71 const auto language_index = combo_language->currentIndex(); 57 const auto language_index = combo_language->currentIndex();
@@ -149,19 +135,7 @@ void ConfigureSystem::Setup(const ConfigurationShared::Builder& builder) {
149 continue; 135 continue;
150 } 136 }
151 137
152 if (setting->Id() == Settings::values.rng_seed.Id()) { 138 if (setting->Id() == Settings::values.region_index.Id()) {
153 // Keep track of rng_seed's widgets to reset it with the checkbox state
154 rng_seed_checkbox = widget->checkbox;
155 rng_seed_edit = widget->line_edit;
156
157 rng_seed_edit->setEnabled(Settings::values.rng_seed_enabled.GetValue());
158 } else if (setting->Id() == Settings::values.custom_rtc.Id()) {
159 // Keep track of custom_rtc's widgets to reset it with the checkbox state
160 custom_rtc_checkbox = widget->checkbox;
161 custom_rtc_edit = widget->date_time_edit;
162
163 custom_rtc_edit->setEnabled(Settings::values.custom_rtc_enabled.GetValue());
164 } else if (setting->Id() == Settings::values.region_index.Id()) {
165 // Keep track of the region_index (and langauge_index) combobox to validate the selected 139 // Keep track of the region_index (and langauge_index) combobox to validate the selected
166 // settings 140 // settings
167 combo_region = widget->combobox; 141 combo_region = widget->combobox;
diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h
index 7f4259698..f63aedda0 100644
--- a/src/yuzu/configuration/configure_system.h
+++ b/src/yuzu/configuration/configure_system.h
@@ -50,10 +50,6 @@ private:
50 50
51 Core::System& system; 51 Core::System& system;
52 52
53 QCheckBox* rng_seed_checkbox;
54 QLineEdit* rng_seed_edit;
55 QCheckBox* custom_rtc_checkbox;
56 QDateTimeEdit* custom_rtc_edit;
57 QComboBox* combo_region; 53 QComboBox* combo_region;
58 QComboBox* combo_language; 54 QComboBox* combo_language;
59}; 55};
diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp
index 807d1d668..7670475be 100644
--- a/src/yuzu/configuration/shared_widget.cpp
+++ b/src/yuzu/configuration/shared_widget.cpp
@@ -46,6 +46,10 @@ namespace ConfigurationShared {
46 46
47static int restore_button_count = 0; 47static int restore_button_count = 0;
48 48
49static std::string RelevantDefault(const Settings::BasicSetting& setting) {
50 return Settings::IsConfiguringGlobal() ? setting.DefaultToString() : setting.ToStringGlobal();
51}
52
49QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* parent) { 53QPushButton* Widget::CreateRestoreGlobalButton(bool using_global, QWidget* parent) {
50 restore_button_count++; 54 restore_button_count++;
51 55
@@ -92,12 +96,12 @@ QWidget* Widget::CreateCheckBox(Settings::BasicSetting* bool_setting, const QStr
92 return checkbox->checkState() == Qt::CheckState::Checked ? "true" : "false"; 96 return checkbox->checkState() == Qt::CheckState::Checked ? "true" : "false";
93 }; 97 };
94 98
95 if (!Settings::IsConfiguringGlobal()) { 99 restore_func = [this, bool_setting]() {
96 restore_func = [this, bool_setting]() { 100 checkbox->setCheckState(RelevantDefault(*bool_setting) == "true" ? Qt::Checked
97 checkbox->setCheckState(bool_setting->ToStringGlobal() == "true" ? Qt::Checked 101 : Qt::Unchecked);
98 : Qt::Unchecked); 102 };
99 };
100 103
104 if (!Settings::IsConfiguringGlobal()) {
101 QObject::connect(checkbox, &QCheckBox::clicked, [touch]() { touch(); }); 105 QObject::connect(checkbox, &QCheckBox::clicked, [touch]() { touch(); });
102 } 106 }
103 107
@@ -139,12 +143,12 @@ QWidget* Widget::CreateCombobox(std::function<std::string()>& serializer,
139 return std::to_string(enumeration->at(current).first); 143 return std::to_string(enumeration->at(current).first);
140 }; 144 };
141 145
142 if (!Settings::IsConfiguringGlobal()) { 146 restore_func = [this, find_index]() {
143 restore_func = [this, find_index]() { 147 const u32 global_value = std::stoi(RelevantDefault(setting));
144 const u32 global_value = std::stoi(setting.ToStringGlobal()); 148 combobox->setCurrentIndex(find_index(global_value));
145 combobox->setCurrentIndex(find_index(global_value)); 149 };
146 };
147 150
151 if (!Settings::IsConfiguringGlobal()) {
148 QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated), 152 QObject::connect(combobox, QOverload<int>::of(&QComboBox::activated),
149 [touch]() { touch(); }); 153 [touch]() { touch(); });
150 } 154 }
@@ -165,11 +169,11 @@ QWidget* Widget::CreateLineEdit(std::function<std::string()>& serializer,
165 return line_edit; 169 return line_edit;
166 } 170 }
167 171
168 if (!Settings::IsConfiguringGlobal()) { 172 restore_func = [this]() {
169 restore_func = [this]() { 173 line_edit->setText(QString::fromStdString(RelevantDefault(setting)));
170 line_edit->setText(QString::fromStdString(setting.ToStringGlobal())); 174 };
171 };
172 175
176 if (!Settings::IsConfiguringGlobal()) {
173 QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); }); 177 QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
174 } 178 }
175 179
@@ -215,10 +219,9 @@ QWidget* Widget::CreateSlider(bool reversed, float multiplier, const QString& fo
215 slider->setInvertedAppearance(reversed); 219 slider->setInvertedAppearance(reversed);
216 220
217 serializer = [this]() { return std::to_string(slider->value()); }; 221 serializer = [this]() { return std::to_string(slider->value()); };
222 restore_func = [this]() { slider->setValue(std::stoi(RelevantDefault(setting))); };
218 223
219 if (!Settings::IsConfiguringGlobal()) { 224 if (!Settings::IsConfiguringGlobal()) {
220 restore_func = [this]() { slider->setValue(std::stoi(setting.ToStringGlobal())); };
221
222 QObject::connect(slider, &QAbstractSlider::actionTriggered, [touch]() { touch(); }); 225 QObject::connect(slider, &QAbstractSlider::actionTriggered, [touch]() { touch(); });
223 } 226 }
224 227
@@ -242,9 +245,12 @@ QWidget* Widget::CreateSpinBox(const QString& suffix, std::function<std::string(
242 245
243 serializer = [this]() { return std::to_string(spinbox->value()); }; 246 serializer = [this]() { return std::to_string(spinbox->value()); };
244 247
245 if (!Settings::IsConfiguringGlobal()) { 248 restore_func = [this]() {
246 restore_func = [this]() { spinbox->setValue(std::stoi(setting.ToStringGlobal())); }; 249 auto value{std::stol(RelevantDefault(setting))};
250 spinbox->setValue(value);
251 };
247 252
253 if (!Settings::IsConfiguringGlobal()) {
248 QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this, touch]() { 254 QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this, touch]() {
249 if (spinbox->value() != std::stoi(setting.ToStringGlobal())) { 255 if (spinbox->value() != std::stoi(setting.ToStringGlobal())) {
250 touch(); 256 touch();
@@ -264,7 +270,7 @@ QWidget* Widget::CreateHexEdit(std::function<std::string()>& serializer,
264 } 270 }
265 271
266 auto to_hex = [=](const std::string& input) { 272 auto to_hex = [=](const std::string& input) {
267 return QString::fromStdString(fmt::format("{:08x}", std::stoi(input))); 273 return QString::fromStdString(fmt::format("{:08x}", std::stoul(input)));
268 }; 274 };
269 275
270 QRegExpValidator* regex = 276 QRegExpValidator* regex =
@@ -282,8 +288,9 @@ QWidget* Widget::CreateHexEdit(std::function<std::string()>& serializer,
282 288
283 serializer = [hex_to_dec]() { return hex_to_dec(); }; 289 serializer = [hex_to_dec]() { return hex_to_dec(); };
284 290
291 restore_func = [this, to_hex]() { line_edit->setText(to_hex(RelevantDefault(setting))); };
292
285 if (!Settings::IsConfiguringGlobal()) { 293 if (!Settings::IsConfiguringGlobal()) {
286 restore_func = [this, to_hex]() { line_edit->setText(to_hex(setting.ToStringGlobal())); };
287 294
288 QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); }); 295 QObject::connect(line_edit, &QLineEdit::textChanged, [touch]() { touch(); });
289 } 296 }
@@ -306,18 +313,18 @@ QWidget* Widget::CreateDateTimeEdit(bool disabled, bool restrict,
306 313
307 serializer = [this]() { return std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()); }; 314 serializer = [this]() { return std::to_string(date_time_edit->dateTime().toSecsSinceEpoch()); };
308 315
309 if (!Settings::IsConfiguringGlobal()) { 316 auto get_clear_val = [this, restrict, current_time]() {
310 auto get_clear_val = [this, restrict, current_time]() { 317 return QDateTime::fromSecsSinceEpoch([this, restrict, current_time]() {
311 return QDateTime::fromSecsSinceEpoch([this, restrict, current_time]() { 318 if (restrict && checkbox->checkState() == Qt::Checked) {
312 if (restrict && checkbox->checkState() == Qt::Checked) { 319 return std::stoll(RelevantDefault(setting));
313 return std::stoll(setting.ToStringGlobal()); 320 }
314 } 321 return current_time;
315 return current_time; 322 }());
316 }()); 323 };
317 };
318 324
319 restore_func = [this, get_clear_val]() { date_time_edit->setDateTime(get_clear_val()); }; 325 restore_func = [this, get_clear_val]() { date_time_edit->setDateTime(get_clear_val()); };
320 326
327 if (!Settings::IsConfiguringGlobal()) {
321 QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished, 328 QObject::connect(date_time_edit, &QDateTimeEdit::editingFinished,
322 [this, get_clear_val, touch]() { 329 [this, get_clear_val, touch]() {
323 if (date_time_edit->dateTime() != get_clear_val()) { 330 if (date_time_edit->dateTime() != get_clear_val()) {
@@ -493,6 +500,17 @@ void Widget::SetupComponent(const QString& label, std::function<void()>& load_fu
493 } 500 }
494 }; 501 };
495 } 502 }
503
504 if (other_setting != nullptr) {
505 const auto reset = [restore_func, data_component](int state) {
506 data_component->setEnabled(state == Qt::Checked);
507 if (state != Qt::Checked) {
508 restore_func();
509 }
510 };
511 connect(checkbox, &QCheckBox::stateChanged, reset);
512 reset(checkbox->checkState());
513 }
496} 514}
497 515
498bool Widget::Valid() const { 516bool Widget::Valid() const {