diff options
| author | 2023-05-09 14:26:03 -0400 | |
|---|---|---|
| committer | 2023-07-21 10:56:07 -0400 | |
| commit | c1748b229a81390c3ee81a1b951455839204c572 (patch) | |
| tree | 8fa53fa4fb951cd42a2ecf7638b004cea4fb286d /src | |
| parent | configure_general: Hide reset button in custom configs (diff) | |
| download | yuzu-c1748b229a81390c3ee81a1b951455839204c572.tar.gz yuzu-c1748b229a81390c3ee81a1b951455839204c572.tar.xz yuzu-c1748b229a81390c3ee81a1b951455839204c572.zip | |
shared_widget: Make button creation static
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/shared_widget.cpp | 17 | ||||
| -rw-r--r-- | src/yuzu/configuration/shared_widget.h | 5 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/yuzu/configuration/shared_widget.cpp b/src/yuzu/configuration/shared_widget.cpp index 0676973a9..ba44d1973 100644 --- a/src/yuzu/configuration/shared_widget.cpp +++ b/src/yuzu/configuration/shared_widget.cpp | |||
| @@ -14,10 +14,10 @@ | |||
| 14 | 14 | ||
| 15 | namespace ConfigurationShared { | 15 | namespace ConfigurationShared { |
| 16 | 16 | ||
| 17 | void Widget::CreateRestoreGlobalButton() { | 17 | QPushButton* Widget::CreateRestoreGlobalButton(Settings::BasicSetting& setting, QWidget* parent) { |
| 18 | QStyle* style = this->style(); | 18 | QStyle* style = parent->style(); |
| 19 | QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton)); | 19 | QIcon* icon = new QIcon(style->standardIcon(QStyle::SP_DialogResetButton)); |
| 20 | restore_button = new QPushButton(*icon, QStringLiteral(""), this); | 20 | QPushButton* restore_button = new QPushButton(*icon, QStringLiteral(""), parent); |
| 21 | restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); | 21 | restore_button->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); |
| 22 | 22 | ||
| 23 | QSizePolicy sp_retain = restore_button->sizePolicy(); | 23 | QSizePolicy sp_retain = restore_button->sizePolicy(); |
| @@ -26,6 +26,8 @@ void Widget::CreateRestoreGlobalButton() { | |||
| 26 | 26 | ||
| 27 | restore_button->setEnabled(!setting.UsingGlobal()); | 27 | restore_button->setEnabled(!setting.UsingGlobal()); |
| 28 | restore_button->setVisible(!setting.UsingGlobal()); | 28 | restore_button->setVisible(!setting.UsingGlobal()); |
| 29 | |||
| 30 | return restore_button; | ||
| 29 | } | 31 | } |
| 30 | 32 | ||
| 31 | void Widget::CreateCheckBox(const QString& label, std::function<void()>& load_func) { | 33 | void Widget::CreateCheckBox(const QString& label, std::function<void()>& load_func) { |
| @@ -44,7 +46,7 @@ void Widget::CreateCheckBox(const QString& label, std::function<void()>& load_fu | |||
| 44 | setting.LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false"); | 46 | setting.LoadString(checkbox->checkState() == Qt::Checked ? "true" : "false"); |
| 45 | }; | 47 | }; |
| 46 | } else { | 48 | } else { |
| 47 | CreateRestoreGlobalButton(); | 49 | restore_button = CreateRestoreGlobalButton(setting, this); |
| 48 | layout->addWidget(restore_button); | 50 | layout->addWidget(restore_button); |
| 49 | 51 | ||
| 50 | QObject::connect(checkbox, &QCheckBox::stateChanged, [&](int) { | 52 | QObject::connect(checkbox, &QCheckBox::stateChanged, [&](int) { |
| @@ -97,7 +99,7 @@ void Widget::CreateCombobox(const QString& label, bool managed, std::function<vo | |||
| 97 | if (Settings::IsConfiguringGlobal() && managed) { | 99 | if (Settings::IsConfiguringGlobal() && managed) { |
| 98 | load_func = [=]() { setting.LoadString(std::to_string(combobox->currentIndex())); }; | 100 | load_func = [=]() { setting.LoadString(std::to_string(combobox->currentIndex())); }; |
| 99 | } else if (managed) { | 101 | } else if (managed) { |
| 100 | CreateRestoreGlobalButton(); | 102 | restore_button = CreateRestoreGlobalButton(setting, this); |
| 101 | layout->addWidget(restore_button); | 103 | layout->addWidget(restore_button); |
| 102 | 104 | ||
| 103 | QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { | 105 | QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { |
| @@ -144,7 +146,7 @@ void Widget::CreateLineEdit(const QString& label, bool managed, std::function<vo | |||
| 144 | setting.LoadString(load_text); | 146 | setting.LoadString(load_text); |
| 145 | }; | 147 | }; |
| 146 | } else if (!managed) { | 148 | } else if (!managed) { |
| 147 | CreateRestoreGlobalButton(); | 149 | restore_button = CreateRestoreGlobalButton(setting, this); |
| 148 | layout->addWidget(restore_button); | 150 | layout->addWidget(restore_button); |
| 149 | 151 | ||
| 150 | QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { | 152 | QObject::connect(restore_button, &QAbstractButton::clicked, [&](bool) { |
| @@ -207,7 +209,7 @@ void Widget::CreateSlider(const QString& name, bool reversed, float multiplier, | |||
| 207 | if (Settings::IsConfiguringGlobal()) { | 209 | if (Settings::IsConfiguringGlobal()) { |
| 208 | load_func = [=]() { setting.LoadString(std::to_string(slider->value())); }; | 210 | load_func = [=]() { setting.LoadString(std::to_string(slider->value())); }; |
| 209 | } else { | 211 | } else { |
| 210 | CreateRestoreGlobalButton(); | 212 | restore_button = CreateRestoreGlobalButton(setting, this); |
| 211 | layout->addWidget(restore_button); | 213 | layout->addWidget(restore_button); |
| 212 | 214 | ||
| 213 | QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { | 215 | QObject::connect(restore_button, &QAbstractButton::clicked, [=](bool) { |
| @@ -340,7 +342,6 @@ Widget::Widget(Settings::BasicSetting* setting_, const TranslationMap& translati | |||
| 340 | } | 342 | } |
| 341 | 343 | ||
| 342 | apply_funcs.push_front([load_func, setting_](bool powered_on) { | 344 | apply_funcs.push_front([load_func, setting_](bool powered_on) { |
| 343 | LOG_DEBUG(Frontend, "{}", setting_->GetLabel()); | ||
| 344 | if (setting_->RuntimeModfiable() || !powered_on) { | 345 | if (setting_->RuntimeModfiable() || !powered_on) { |
| 345 | load_func(); | 346 | load_func(); |
| 346 | } | 347 | } |
diff --git a/src/yuzu/configuration/shared_widget.h b/src/yuzu/configuration/shared_widget.h index 3d96805ed..8d2d7f269 100644 --- a/src/yuzu/configuration/shared_widget.h +++ b/src/yuzu/configuration/shared_widget.h | |||
| @@ -37,6 +37,9 @@ public: | |||
| 37 | 37 | ||
| 38 | bool Valid(); | 38 | bool Valid(); |
| 39 | 39 | ||
| 40 | [[nodiscard]] static QPushButton* CreateRestoreGlobalButton(Settings::BasicSetting& setting, | ||
| 41 | QWidget* parent); | ||
| 42 | |||
| 40 | QPushButton* restore_button{}; | 43 | QPushButton* restore_button{}; |
| 41 | QLineEdit* line_edit{}; | 44 | QLineEdit* line_edit{}; |
| 42 | QCheckBox* checkbox{}; | 45 | QCheckBox* checkbox{}; |
| @@ -54,8 +57,6 @@ private: | |||
| 54 | void CreateSlider(const QString& label, bool reversed, float multiplier, | 57 | void CreateSlider(const QString& label, bool reversed, float multiplier, |
| 55 | std::function<void()>& load_func); | 58 | std::function<void()>& load_func); |
| 56 | 59 | ||
| 57 | void CreateRestoreGlobalButton(); | ||
| 58 | |||
| 59 | QWidget* parent; | 60 | QWidget* parent; |
| 60 | const TranslationMap& translations; | 61 | const TranslationMap& translations; |
| 61 | Settings::BasicSetting& setting; | 62 | Settings::BasicSetting& setting; |