summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/configuration/configure_graphics.cpp19
-rw-r--r--src/yuzu/configuration/shared_widget.cpp87
-rw-r--r--src/yuzu/configuration/shared_widget.h8
3 files changed, 66 insertions, 48 deletions
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp
index d1ec2bae3..ae3cf269f 100644
--- a/src/yuzu/configuration/configure_graphics.cpp
+++ b/src/yuzu/configuration/configure_graphics.cpp
@@ -273,25 +273,6 @@ void ConfigureGraphics::Setup() {
273 hold_api.push_front(widget); 273 hold_api.push_front(widget);
274 shader_backend_combobox = widget->combobox; 274 shader_backend_combobox = widget->combobox;
275 shader_backend_widget = widget; 275 shader_backend_widget = widget;
276 } else if (setting->Id() == Settings::values.use_speed_limit.Id()) {
277 apply_funcs.push_front([setting, widget](bool powered_on) {
278 if (!setting->RuntimeModfiable() && powered_on) {
279 return;
280 }
281
282 u16 value = QVariant(widget->line_edit->text()).value<u16>();
283 auto& speed_limit = Settings::values.speed_limit;
284 if (Settings::IsConfiguringGlobal()) {
285 speed_limit.SetValue(value);
286 } else {
287 bool using_global = !widget->restore_button->isVisible();
288 speed_limit.SetGlobal(using_global);
289 if (!using_global) {
290 speed_limit.SetValue(value);
291 }
292 }
293 });
294 hold_graphics[setting->IsEnum()][setting_label] = widget;
295 } else if (setting->Id() == Settings::values.vsync_mode.Id()) { 276 } else if (setting->Id() == Settings::values.vsync_mode.Id()) {
296 vsync_mode_combobox = widget->combobox; 277 vsync_mode_combobox = widget->combobox;
297 hold_graphics[setting->IsEnum()][setting_label] = widget; 278 hold_graphics[setting->IsEnum()][setting_label] = widget;
diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp
index 841524b9c..d1113f793 100644
--- a/src/yuzu/configuration/shared_widget.cpp
+++ b/src/yuzu/configuration/shared_widget.cpp
@@ -9,12 +9,18 @@
9#include <QSpinBox> 9#include <QSpinBox>
10#include <QWidget> 10#include <QWidget>
11#include <qabstractbutton.h> 11#include <qabstractbutton.h>
12#include "common/common_types.h"
12#include "common/settings.h" 13#include "common/settings.h"
14#include "yuzu/configuration/configuration_shared.h"
13#include "yuzu/configuration/shared_translation.h" 15#include "yuzu/configuration/shared_translation.h"
14#include "yuzu/configuration/shared_widget.h" 16#include "yuzu/configuration/shared_widget.h"
15 17
16namespace ConfigurationShared { 18namespace ConfigurationShared {
17 19
20static bool IsInt(const std::type_index& type) {
21 return type == typeid(u32) || type == typeid(s32) || type == typeid(u16) || type == typeid(s16);
22}
23
18QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) { 24QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) {
19 QStyle* style = parent->style(); 25 QStyle* style = parent->style();
20 QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton)); 26 QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton));
@@ -235,43 +241,63 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier,
235 } 241 }
236} 242}
237 243
238void Widget::CreateCheckBoxWithLineEdit(const QString& label, 244void Widget::CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSetting* other_setting,
239 const Settings::BasicSetting* other_setting,
240 std::function<void()>& load_func) { 245 std::function<void()>& load_func) {
246 if (other_setting == nullptr) {
247 LOG_WARNING(Frontend, "Extra setting is null or not an integer");
248 return;
249 }
241 created = true; 250 created = true;
242 251
243 CreateCheckBox(label, load_func); 252 std::function<void()> checkbox_load_func;
253 CreateCheckBox(label, checkbox_load_func);
244 254
245 QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout()); 255 QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
256 const QString default_val = QString::fromStdString(other_setting->ToString());
246 257
247 line_edit = new QLineEdit(this); 258 line_edit = new QLineEdit(this);
248 line_edit->setText(QString::fromStdString(other_setting->ToString())); 259 line_edit->setText(default_val);
249 260
250 checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 261 checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
251 262
252 layout->insertWidget(1, line_edit); 263 layout->insertWidget(1, line_edit);
253 264
254 QObject::connect(line_edit, &QLineEdit::textEdited, 265 if (Settings::IsConfiguringGlobal()) {
255 [=](const QString&) { checkbox->setCheckState(Qt::Checked); }); 266 load_func = [=]() {
256 267 checkbox_load_func();
257 if (!Settings::IsConfiguringGlobal()) { 268 other_setting->LoadString(line_edit->text().toStdString());
258 QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { 269 };
259 line_edit->setText(QString::fromStdString(other_setting->ToString())); 270 } else {
260 }); 271 QObject::connect(restore_button, &QAbstractButton::clicked,
272 [=](bool) { line_edit->setText(default_val); });
261 273
262 QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) { 274 QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) {
263 restore_button->setEnabled(true); 275 restore_button->setEnabled(true);
264 restore_button->setVisible(true); 276 restore_button->setVisible(true);
265 }); 277 });
278
279 load_func = [=]() {
280 checkbox_load_func();
281
282 const bool using_global = !restore_button->isVisible();
283 other_setting->SetGlobal(using_global);
284 if (!using_global) {
285 other_setting->LoadString(line_edit->text().toStdString());
286 }
287 };
266 } 288 }
267} 289}
268 290
269void Widget::CreateCheckBoxWithSpinBox(const QString& label, 291void Widget::CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSetting* other_setting,
270 const Settings::BasicSetting* other_setting,
271 std::function<void()>& load_func, const QString& suffix) { 292 std::function<void()>& load_func, const QString& suffix) {
293 if (other_setting == nullptr && IsInt(other_setting->TypeId())) {
294 LOG_WARNING(Frontend, "Extra setting is null or not an integer");
295 return;
296 }
272 created = true; 297 created = true;
273 298
274 CreateCheckBox(label, load_func); 299 std::function<void()> checkbox_load_func;
300 CreateCheckBox(label, checkbox_load_func);
275 checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 301 checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
276 302
277 QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout()); 303 QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout());
@@ -279,17 +305,20 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label,
279 spinbox = new QSpinBox(this); 305 spinbox = new QSpinBox(this);
280 const int min_val = std::stoi(other_setting->MinVal()); 306 const int min_val = std::stoi(other_setting->MinVal());
281 const int max_val = std::stoi(other_setting->MaxVal()); 307 const int max_val = std::stoi(other_setting->MaxVal());
308 const int default_val = std::stoi(other_setting->ToString());
282 spinbox->setRange(min_val, max_val); 309 spinbox->setRange(min_val, max_val);
283 spinbox->setValue(std::stoi(other_setting->ToString())); 310 spinbox->setValue(default_val);
284 spinbox->setSuffix(suffix); 311 spinbox->setSuffix(suffix);
285 spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); 312 spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
286 313
287 layout->insertWidget(1, spinbox); 314 layout->insertWidget(1, spinbox);
288 315
289 QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), 316 if (Settings::IsConfiguringGlobal()) {
290 [this](int) { checkbox->setCheckState(Qt::Checked); }); 317 load_func = [=]() {
291 318 checkbox_load_func();
292 if (!Settings::IsConfiguringGlobal()) { 319 other_setting->LoadString(std::to_string(spinbox->value()));
320 };
321 } else {
293 QObject::connect(restore_button, &QAbstractButton::clicked, [this, other_setting](bool) { 322 QObject::connect(restore_button, &QAbstractButton::clicked, [this, other_setting](bool) {
294 spinbox->setValue(std::stoi(other_setting->ToString())); 323 spinbox->setValue(std::stoi(other_setting->ToString()));
295 }); 324 });
@@ -298,6 +327,16 @@ void Widget::CreateCheckBoxWithSpinBox(const QString& label,
298 restore_button->setEnabled(true); 327 restore_button->setEnabled(true);
299 restore_button->setVisible(true); 328 restore_button->setVisible(true);
300 }); 329 });
330
331 load_func = [=]() {
332 checkbox_load_func();
333
334 const bool using_global = !restore_button->isVisible();
335 other_setting->SetGlobal(using_global);
336 if (!using_global) {
337 other_setting->LoadString(std::to_string(spinbox->value()));
338 }
339 };
301 } 340 }
302} 341}
303 342
@@ -310,7 +349,7 @@ Widget::~Widget() = default;
310Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, 349Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_,
311 QWidget* parent_, bool runtime_lock, 350 QWidget* parent_, bool runtime_lock,
312 std::forward_list<std::function<void(bool)>>& apply_funcs, RequestType request, 351 std::forward_list<std::function<void(bool)>>& apply_funcs, RequestType request,
313 bool managed, float multiplier, const Settings::BasicSetting* other_setting, 352 bool managed, float multiplier, Settings::BasicSetting* other_setting,
314 const QString& format) 353 const QString& format)
315 : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} { 354 : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} {
316 if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) { 355 if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) {
@@ -340,15 +379,15 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
340 379
341 if (type == typeid(bool)) { 380 if (type == typeid(bool)) {
342 switch (request) { 381 switch (request) {
382 case RequestType::SpinBox:
383 CreateCheckBoxWithSpinBox(label, other_setting, load_func, format);
384 break;
343 case RequestType::Default: 385 case RequestType::Default:
344 CreateCheckBox(label, load_func); 386 CreateCheckBox(label, load_func);
345 break; 387 break;
346 case RequestType::LineEdit: 388 case RequestType::LineEdit:
347 CreateCheckBoxWithLineEdit(label, other_setting, load_func); 389 CreateCheckBoxWithLineEdit(label, other_setting, load_func);
348 break; 390 break;
349 case RequestType::SpinBox:
350 CreateCheckBoxWithSpinBox(label, other_setting, load_func, format);
351 break;
352 case RequestType::ComboBox: 391 case RequestType::ComboBox:
353 case RequestType::Slider: 392 case RequestType::Slider:
354 case RequestType::ReverseSlider: 393 case RequestType::ReverseSlider:
@@ -377,7 +416,7 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati
377 } 416 }
378 417
379 if (!created) { 418 if (!created) {
380 LOG_ERROR(Frontend, "No widget was created for \"{}\"", setting.GetLabel()); 419 LOG_WARNING(Frontend, "No widget was created for \"{}\"", setting.GetLabel());
381 return; 420 return;
382 } 421 }
383 422
diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h
index c25d819f0..88a864b42 100644
--- a/src/yuzu/configuration/shared_widget.h
+++ b/src/yuzu/configuration/shared_widget.h
@@ -33,7 +33,7 @@ public:
33 Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent, 33 Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent,
34 bool runtime_lock, std::forward_list<std::function<void(bool)>>& apply_funcs, 34 bool runtime_lock, std::forward_list<std::function<void(bool)>>& apply_funcs,
35 RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f, 35 RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f,
36 const Settings::BasicSetting* other_setting = nullptr, 36 Settings::BasicSetting* other_setting = nullptr,
37 const QString& format = QStringLiteral("")); 37 const QString& format = QStringLiteral(""));
38 virtual ~Widget(); 38 virtual ~Widget();
39 39
@@ -51,11 +51,9 @@ public:
51 51
52private: 52private:
53 void CreateCheckBox(const QString& label, std::function<void()>& load_func); 53 void CreateCheckBox(const QString& label, std::function<void()>& load_func);
54 void CreateCheckBoxWithLineEdit(const QString& label, 54 void CreateCheckBoxWithLineEdit(const QString& label, Settings::BasicSetting* other_setting,
55 const Settings::BasicSetting* other_setting,
56 std::function<void()>& load_func); 55 std::function<void()>& load_func);
57 void CreateCheckBoxWithSpinBox(const QString& label, 56 void CreateCheckBoxWithSpinBox(const QString& label, Settings::BasicSetting* other_setting,
58 const Settings::BasicSetting* other_setting,
59 std::function<void()>& load_func, const QString& suffix); 57 std::function<void()>& load_func, const QString& suffix);
60 void CreateCombobox(const QString& label, bool managed, std::function<void()>& load_func); 58 void CreateCombobox(const QString& label, bool managed, std::function<void()>& load_func);
61 void CreateLineEdit(const QString& label, bool managed, std::function<void()>& load_func); 59 void CreateLineEdit(const QString& label, bool managed, std::function<void()>& load_func);