diff options
| author | 2020-07-13 17:08:24 -0400 | |
|---|---|---|
| committer | 2020-07-19 13:26:55 -0400 | |
| commit | e26e82d8d5f9a3907b3623bd50dffd1c9b84969e (patch) | |
| tree | 7dcd7e9dc01a56cecfded796479c63b1b330befd | |
| parent | Merge pull request #4376 from ogniK5377/dark-wait-tree (diff) | |
| download | yuzu-e26e82d8d5f9a3907b3623bd50dffd1c9b84969e.tar.gz yuzu-e26e82d8d5f9a3907b3623bd50dffd1c9b84969e.tar.xz yuzu-e26e82d8d5f9a3907b3623bd50dffd1c9b84969e.zip | |
configuration_shared: Initial functions and data for manual tristate
Sets up initial support for implementing colored tristate functions. These functions color a QWidget blue when it's overriding a global setting, and discolor it when not. The lack of color indicates it uses the global state, replacing the Qt::CheckState::PartiallyChecked state with the global state.
| -rw-r--r-- | src/yuzu/configuration/configuration_shared.cpp | 42 | ||||
| -rw-r--r-- | src/yuzu/configuration/configuration_shared.h | 16 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp index bb47c3933..f32fcf3b7 100644 --- a/src/yuzu/configuration/configuration_shared.cpp +++ b/src/yuzu/configuration/configuration_shared.cpp | |||
| @@ -4,10 +4,15 @@ | |||
| 4 | 4 | ||
| 5 | #include <QCheckBox> | 5 | #include <QCheckBox> |
| 6 | #include <QComboBox> | 6 | #include <QComboBox> |
| 7 | #include <QObject> | ||
| 7 | #include "core/settings.h" | 8 | #include "core/settings.h" |
| 8 | #include "yuzu/configuration/configuration_shared.h" | 9 | #include "yuzu/configuration/configuration_shared.h" |
| 9 | #include "yuzu/configuration/configure_per_game.h" | 10 | #include "yuzu/configuration/configure_per_game.h" |
| 10 | 11 | ||
| 12 | namespace ConfigurationShared { | ||
| 13 | Trackers trackers = {}; | ||
| 14 | } | ||
| 15 | |||
| 11 | void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting, | 16 | void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting, |
| 12 | const QCheckBox* checkbox) { | 17 | const QCheckBox* checkbox) { |
| 13 | if (checkbox->checkState() == Qt::PartiallyChecked) { | 18 | if (checkbox->checkState() == Qt::PartiallyChecked) { |
| @@ -18,6 +23,17 @@ void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting, | |||
| 18 | } | 23 | } |
| 19 | } | 24 | } |
| 20 | 25 | ||
| 26 | void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<bool>* setting, | ||
| 27 | const QCheckBox* checkbox, | ||
| 28 | const CheckState& tracker) { | ||
| 29 | if (tracker == CheckState::Global) { | ||
| 30 | setting->SetGlobal(true); | ||
| 31 | } else { | ||
| 32 | setting->SetGlobal(false); | ||
| 33 | setting->SetValue(checkbox->checkState()); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 21 | void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<int>* setting, | 37 | void ConfigurationShared::ApplyPerGameSetting(Settings::Setting<int>* setting, |
| 22 | const QComboBox* combobox) { | 38 | const QComboBox* combobox) { |
| 23 | if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { | 39 | if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { |
| @@ -69,6 +85,32 @@ void ConfigurationShared::SetPerGameSetting( | |||
| 69 | ConfigurationShared::USE_GLOBAL_OFFSET); | 85 | ConfigurationShared::USE_GLOBAL_OFFSET); |
| 70 | } | 86 | } |
| 71 | 87 | ||
| 88 | void ConfigurationShared::SetBGColor(QWidget* widget, bool highlighted) { | ||
| 89 | if (highlighted) { | ||
| 90 | widget->setStyleSheet(QStringLiteral("background-color:rgba(0,203,255,0.5);")); | ||
| 91 | } else { | ||
| 92 | widget->setStyleSheet(QStringLiteral("background-color:rgba(0,0,0,0);")); | ||
| 93 | } | ||
| 94 | widget->show(); | ||
| 95 | } | ||
| 96 | |||
| 97 | void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, Settings::Setting<bool>& setting, | ||
| 98 | ConfigurationShared::CheckState& tracker) { | ||
| 99 | if (setting.UsingGlobal()) { | ||
| 100 | tracker = CheckState::Global; | ||
| 101 | } else { | ||
| 102 | tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off; | ||
| 103 | } | ||
| 104 | SetBGColor(checkbox, tracker != CheckState::Global); | ||
| 105 | QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, setting, &tracker]() { | ||
| 106 | tracker = static_cast<ConfigurationShared::CheckState>((tracker + 1) % CheckState::Count); | ||
| 107 | if (tracker == CheckState::Global) { | ||
| 108 | checkbox->setChecked(setting.GetValue(true)); | ||
| 109 | } | ||
| 110 | SetBGColor(checkbox, tracker != CheckState::Global); | ||
| 111 | }); | ||
| 112 | } | ||
| 113 | |||
| 72 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) { | 114 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) { |
| 73 | const QString use_global_text = ConfigurePerGame::tr("Use global configuration"); | 115 | const QString use_global_text = ConfigurePerGame::tr("Use global configuration"); |
| 74 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); | 116 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); |
diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h index b11b1b950..1163604bf 100644 --- a/src/yuzu/configuration/configuration_shared.h +++ b/src/yuzu/configuration/configuration_shared.h | |||
| @@ -15,8 +15,20 @@ constexpr int USE_GLOBAL_INDEX = 0; | |||
| 15 | constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1; | 15 | constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1; |
| 16 | constexpr int USE_GLOBAL_OFFSET = 2; | 16 | constexpr int USE_GLOBAL_OFFSET = 2; |
| 17 | 17 | ||
| 18 | enum CheckState { | ||
| 19 | Off, | ||
| 20 | On, | ||
| 21 | Global, | ||
| 22 | Count, | ||
| 23 | }; | ||
| 24 | |||
| 25 | struct Trackers { | ||
| 26 | } extern trackers; | ||
| 27 | |||
| 18 | // Global-aware apply and set functions | 28 | // Global-aware apply and set functions |
| 19 | 29 | ||
| 30 | void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox, | ||
| 31 | const CheckState& tracker); | ||
| 20 | void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox); | 32 | void ApplyPerGameSetting(Settings::Setting<bool>* setting, const QCheckBox* checkbox); |
| 21 | void ApplyPerGameSetting(Settings::Setting<int>* setting, const QComboBox* combobox); | 33 | void ApplyPerGameSetting(Settings::Setting<int>* setting, const QComboBox* combobox); |
| 22 | void ApplyPerGameSetting(Settings::Setting<Settings::RendererBackend>* setting, | 34 | void ApplyPerGameSetting(Settings::Setting<Settings::RendererBackend>* setting, |
| @@ -31,6 +43,10 @@ void SetPerGameSetting(QComboBox* combobox, | |||
| 31 | void SetPerGameSetting(QComboBox* combobox, | 43 | void SetPerGameSetting(QComboBox* combobox, |
| 32 | const Settings::Setting<Settings::GPUAccuracy>* setting); | 44 | const Settings::Setting<Settings::GPUAccuracy>* setting); |
| 33 | 45 | ||
| 46 | void SetBGColor(QWidget* widget, bool highlighted); | ||
| 47 | void SetColoredTristate(QCheckBox* checkbox, Settings::Setting<bool>& setting, | ||
| 48 | ConfigurationShared::CheckState& tracker); | ||
| 49 | |||
| 34 | void InsertGlobalItem(QComboBox* combobox); | 50 | void InsertGlobalItem(QComboBox* combobox); |
| 35 | 51 | ||
| 36 | } // namespace ConfigurationShared | 52 | } // namespace ConfigurationShared |