diff options
| author | 2023-05-09 15:46:07 -0400 | |
|---|---|---|
| committer | 2023-07-21 10:56:07 -0400 | |
| commit | 97674bc88821b202aa7309208b71f2ab042fc5aa (patch) | |
| tree | abdbd2840381fab4e49d749941e4d870e1d7f2ac /src | |
| parent | configure_debug: Reorganize (diff) | |
| download | yuzu-97674bc88821b202aa7309208b71f2ab042fc5aa.tar.gz yuzu-97674bc88821b202aa7309208b71f2ab042fc5aa.tar.xz yuzu-97674bc88821b202aa7309208b71f2ab042fc5aa.zip | |
shared_widget: Support checkbox + spinbox
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configure_graphics.cpp | 2 | ||||
| -rw-r--r-- | src/yuzu/configuration/shared_widget.cpp | 50 | ||||
| -rw-r--r-- | src/yuzu/configuration/shared_widget.h | 13 |
3 files changed, 55 insertions, 10 deletions
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 4c6d69703..5132c4796 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp | |||
| @@ -240,7 +240,7 @@ void ConfigureGraphics::Setup() { | |||
| 240 | return new ConfigurationShared::Widget( | 240 | return new ConfigurationShared::Widget( |
| 241 | setting, translations, this, runtime_lock, apply_funcs, | 241 | setting, translations, this, runtime_lock, apply_funcs, |
| 242 | ConfigurationShared::RequestType::LineEdit, true, 1.0f, | 242 | ConfigurationShared::RequestType::LineEdit, true, 1.0f, |
| 243 | Settings::values.speed_limit.ToString()); | 243 | &Settings::values.speed_limit, QString::fromStdString("%")); |
| 244 | } else { | 244 | } else { |
| 245 | return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, | 245 | return new ConfigurationShared::Widget(setting, translations, this, runtime_lock, |
| 246 | apply_funcs); | 246 | apply_funcs); |
diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index ba44d1973..841524b9c 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <QLineEdit> | 6 | #include <QLineEdit> |
| 7 | #include <QPushButton> | 7 | #include <QPushButton> |
| 8 | #include <QSizePolicy> | 8 | #include <QSizePolicy> |
| 9 | #include <QSpinBox> | ||
| 9 | #include <QWidget> | 10 | #include <QWidget> |
| 10 | #include <qabstractbutton.h> | 11 | #include <qabstractbutton.h> |
| 11 | #include "common/settings.h" | 12 | #include "common/settings.h" |
| @@ -234,7 +235,8 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier, | |||
| 234 | } | 235 | } |
| 235 | } | 236 | } |
| 236 | 237 | ||
| 237 | void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string& text_box_default, | 238 | void Widget::CreateCheckBoxWithLineEdit(const QString& label, |
| 239 | const Settings::BasicSetting* other_setting, | ||
| 238 | std::function<void()>& load_func) { | 240 | std::function<void()>& load_func) { |
| 239 | created = true; | 241 | created = true; |
| 240 | 242 | ||
| @@ -243,7 +245,7 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string& | |||
| 243 | QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout()); | 245 | QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout()); |
| 244 | 246 | ||
| 245 | line_edit = new QLineEdit(this); | 247 | line_edit = new QLineEdit(this); |
| 246 | line_edit->setText(QString::fromStdString(text_box_default)); | 248 | line_edit->setText(QString::fromStdString(other_setting->ToString())); |
| 247 | 249 | ||
| 248 | checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | 250 | checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
| 249 | 251 | ||
| @@ -254,7 +256,7 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string& | |||
| 254 | 256 | ||
| 255 | if (!Settings::IsConfiguringGlobal()) { | 257 | if (!Settings::IsConfiguringGlobal()) { |
| 256 | QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { | 258 | QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { |
| 257 | line_edit->setText(QString::fromStdString(text_box_default)); | 259 | line_edit->setText(QString::fromStdString(other_setting->ToString())); |
| 258 | }); | 260 | }); |
| 259 | 261 | ||
| 260 | QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) { | 262 | QObject::connect(line_edit, &QLineEdit::textEdited, [=](const QString&) { |
| @@ -264,6 +266,41 @@ void Widget::CreateCheckBoxWithLineEdit(const QString& label, const std::string& | |||
| 264 | } | 266 | } |
| 265 | } | 267 | } |
| 266 | 268 | ||
| 269 | void Widget::CreateCheckBoxWithSpinBox(const QString& label, | ||
| 270 | const Settings::BasicSetting* other_setting, | ||
| 271 | std::function<void()>& load_func, const QString& suffix) { | ||
| 272 | created = true; | ||
| 273 | |||
| 274 | CreateCheckBox(label, load_func); | ||
| 275 | checkbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | ||
| 276 | |||
| 277 | QHBoxLayout* layout = reinterpret_cast<QHBoxLayout*>(this->layout()); | ||
| 278 | |||
| 279 | spinbox = new QSpinBox(this); | ||
| 280 | const int min_val = std::stoi(other_setting->MinVal()); | ||
| 281 | const int max_val = std::stoi(other_setting->MaxVal()); | ||
| 282 | spinbox->setRange(min_val, max_val); | ||
| 283 | spinbox->setValue(std::stoi(other_setting->ToString())); | ||
| 284 | spinbox->setSuffix(suffix); | ||
| 285 | spinbox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); | ||
| 286 | |||
| 287 | layout->insertWidget(1, spinbox); | ||
| 288 | |||
| 289 | QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), | ||
| 290 | [this](int) { checkbox->setCheckState(Qt::Checked); }); | ||
| 291 | |||
| 292 | if (!Settings::IsConfiguringGlobal()) { | ||
| 293 | QObject::connect(restore_button, &QAbstractButton::clicked, [this, other_setting](bool) { | ||
| 294 | spinbox->setValue(std::stoi(other_setting->ToString())); | ||
| 295 | }); | ||
| 296 | |||
| 297 | QObject::connect(spinbox, QOverload<int>::of(&QSpinBox::valueChanged), [this](int) { | ||
| 298 | restore_button->setEnabled(true); | ||
| 299 | restore_button->setVisible(true); | ||
| 300 | }); | ||
| 301 | } | ||
| 302 | } | ||
| 303 | |||
| 267 | bool Widget::Valid() { | 304 | bool Widget::Valid() { |
| 268 | return created; | 305 | return created; |
| 269 | } | 306 | } |
| @@ -273,7 +310,8 @@ Widget::~Widget() = default; | |||
| 273 | Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, | 310 | Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translations_, |
| 274 | QWidget* parent_, bool runtime_lock, | 311 | QWidget* parent_, bool runtime_lock, |
| 275 | std::forward_list<std::function<void(bool)>>& apply_funcs, RequestType request, | 312 | std::forward_list<std::function<void(bool)>>& apply_funcs, RequestType request, |
| 276 | bool managed, float multiplier, const std::string& text_box_default) | 313 | bool managed, float multiplier, const Settings::BasicSetting* other_setting, |
| 314 | const QString& format) | ||
| 277 | : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} { | 315 | : QWidget(parent_), parent{parent_}, translations{translations_}, setting{*setting_} { |
| 278 | if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) { | 316 | if (!Settings::IsConfiguringGlobal() && !setting.Switchable()) { |
| 279 | LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel()); | 317 | LOG_DEBUG(Frontend, "\"{}\" is not switchable, skipping...", setting.GetLabel()); |
| @@ -306,8 +344,10 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati | |||
| 306 | CreateCheckBox(label, load_func); | 344 | CreateCheckBox(label, load_func); |
| 307 | break; | 345 | break; |
| 308 | case RequestType::LineEdit: | 346 | case RequestType::LineEdit: |
| 347 | CreateCheckBoxWithLineEdit(label, other_setting, load_func); | ||
| 348 | break; | ||
| 309 | case RequestType::SpinBox: | 349 | case RequestType::SpinBox: |
| 310 | CreateCheckBoxWithLineEdit(label, text_box_default, load_func); | 350 | CreateCheckBoxWithSpinBox(label, other_setting, load_func, format); |
| 311 | break; | 351 | break; |
| 312 | case RequestType::ComboBox: | 352 | case RequestType::ComboBox: |
| 313 | case RequestType::Slider: | 353 | case RequestType::Slider: |
diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 8d2d7f269..c25d819f0 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include "yuzu/configuration/shared_translation.h" | 4 | #include "yuzu/configuration/shared_translation.h" |
| 5 | 5 | ||
| 6 | class QPushButton; | 6 | class QPushButton; |
| 7 | class QSpinBox; | ||
| 7 | class QComboBox; | 8 | class QComboBox; |
| 8 | class QLineEdit; | 9 | class QLineEdit; |
| 9 | class QSlider; | 10 | class QSlider; |
| @@ -32,7 +33,8 @@ public: | |||
| 32 | Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent, | 33 | Widget(Settings::BasicSetting* setting, const TranslationMap& translations, QWidget* parent, |
| 33 | 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, |
| 34 | RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f, | 35 | RequestType request = RequestType::Default, bool managed = true, float multiplier = 1.0f, |
| 35 | const std::string& text_box_default = ""); | 36 | const Settings::BasicSetting* other_setting = nullptr, |
| 37 | const QString& format = QStringLiteral("")); | ||
| 36 | virtual ~Widget(); | 38 | virtual ~Widget(); |
| 37 | 39 | ||
| 38 | bool Valid(); | 40 | bool Valid(); |
| @@ -42,16 +44,19 @@ public: | |||
| 42 | 44 | ||
| 43 | QPushButton* restore_button{}; | 45 | QPushButton* restore_button{}; |
| 44 | QLineEdit* line_edit{}; | 46 | QLineEdit* line_edit{}; |
| 47 | QSpinBox* spinbox{}; | ||
| 45 | QCheckBox* checkbox{}; | 48 | QCheckBox* checkbox{}; |
| 46 | QSlider* slider{}; | 49 | QSlider* slider{}; |
| 47 | QComboBox* combobox{}; | 50 | QComboBox* combobox{}; |
| 48 | 51 | ||
| 49 | private: | 52 | private: |
| 50 | void CreateCheckBox(const QString& label, std::function<void()>& load_func); | 53 | void CreateCheckBox(const QString& label, std::function<void()>& load_func); |
| 51 | void CreateCheckBoxWithLineEdit(const QString& label, const std::string& text_box_default, | 54 | void CreateCheckBoxWithLineEdit(const QString& label, |
| 55 | const Settings::BasicSetting* other_setting, | ||
| 52 | std::function<void()>& load_func); | 56 | std::function<void()>& load_func); |
| 53 | void CreateCheckBoxWithSpinBox(const QString& label, const std::string& text_box_default, | 57 | void CreateCheckBoxWithSpinBox(const QString& label, |
| 54 | std::function<void()>& load_func); | 58 | const Settings::BasicSetting* other_setting, |
| 59 | std::function<void()>& load_func, const QString& suffix); | ||
| 55 | void CreateCombobox(const QString& label, bool managed, std::function<void()>& load_func); | 60 | void CreateCombobox(const QString& label, bool managed, std::function<void()>& load_func); |
| 56 | void CreateLineEdit(const QString& label, bool managed, std::function<void()>& load_func); | 61 | void CreateLineEdit(const QString& label, bool managed, std::function<void()>& load_func); |
| 57 | void CreateSlider(const QString& label, bool reversed, float multiplier, | 62 | void CreateSlider(const QString& label, bool reversed, float multiplier, |