diff options
| author | 2020-07-13 23:00:56 -0400 | |
|---|---|---|
| committer | 2020-07-19 13:26:55 -0400 | |
| commit | 6316a3d8d9db432eb810c554385837c96037cba5 (patch) | |
| tree | adb209ad049d79cb3e29229e6acf45749aa64a20 /src | |
| parent | configuration_shared: Use an int instead of a QString (diff) | |
| download | yuzu-6316a3d8d9db432eb810c554385837c96037cba5.tar.gz yuzu-6316a3d8d9db432eb810c554385837c96037cba5.tar.xz yuzu-6316a3d8d9db432eb810c554385837c96037cba5.zip | |
configuration_shared: Add default combobox setup function
Not a catch-all, but helps clean up the code for when I do this a lot. Also fixes some bugs caught in configure_graphics.
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/configuration/configuration_shared.cpp | 42 | ||||
| -rw-r--r-- | src/yuzu/configuration/configuration_shared.h | 7 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_graphics.cpp | 24 |
3 files changed, 52 insertions, 21 deletions
diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp index a648d339b..0c7caf8b5 100644 --- a/src/yuzu/configuration/configuration_shared.cpp +++ b/src/yuzu/configuration/configuration_shared.cpp | |||
| @@ -88,13 +88,11 @@ void ConfigurationShared::SetPerGameSetting( | |||
| 88 | 88 | ||
| 89 | void ConfigurationShared::SetHighlight(QWidget* widget, const std::string& name, bool highlighted) { | 89 | void ConfigurationShared::SetHighlight(QWidget* widget, const std::string& name, bool highlighted) { |
| 90 | if (highlighted) { | 90 | if (highlighted) { |
| 91 | widget->setStyleSheet( | 91 | widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }") |
| 92 | QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }") | 92 | .arg(QString::fromStdString(name))); |
| 93 | .arg(QString::fromStdString(name))); | ||
| 94 | } else { | 93 | } else { |
| 95 | widget->setStyleSheet( | 94 | widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,0,0,0) }") |
| 96 | QStringLiteral("QWidget#%1 { background-color:rgba(0,0,0,0) }") | 95 | .arg(QString::fromStdString(name))); |
| 97 | .arg(QString::fromStdString(name))); | ||
| 98 | } | 96 | } |
| 99 | widget->show(); | 97 | widget->show(); |
| 100 | } | 98 | } |
| @@ -119,6 +117,35 @@ void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::str | |||
| 119 | }); | 117 | }); |
| 120 | } | 118 | } |
| 121 | 119 | ||
| 120 | void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name, | ||
| 121 | bool global, bool state, bool global_state, | ||
| 122 | ConfigurationShared::CheckState& tracker) { | ||
| 123 | if (global) { | ||
| 124 | tracker = CheckState::Global; | ||
| 125 | } else { | ||
| 126 | tracker = (state == global_state) ? CheckState::On : CheckState::Off; | ||
| 127 | } | ||
| 128 | SetHighlight(checkbox, name, tracker != CheckState::Global); | ||
| 129 | QObject::connect( | ||
| 130 | checkbox, &QCheckBox::clicked, checkbox, [checkbox, name, global_state, &tracker]() { | ||
| 131 | tracker = | ||
| 132 | static_cast<ConfigurationShared::CheckState>((tracker + 1) % CheckState::Count); | ||
| 133 | if (tracker == CheckState::Global) { | ||
| 134 | checkbox->setChecked(global_state); | ||
| 135 | } | ||
| 136 | SetHighlight(checkbox, name, tracker != CheckState::Global); | ||
| 137 | }); | ||
| 138 | } | ||
| 139 | |||
| 140 | void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target, | ||
| 141 | const std::string& target_name, int global) { | ||
| 142 | InsertGlobalItem(combobox, global); | ||
| 143 | QObject::connect(combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), | ||
| 144 | target, [target, target_name](int index) { | ||
| 145 | ConfigurationShared::SetHighlight(target, target_name, index != 0); | ||
| 146 | }); | ||
| 147 | } | ||
| 148 | |||
| 122 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) { | 149 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) { |
| 123 | const QString use_global_text = ConfigurePerGame::tr("Use global configuration"); | 150 | const QString use_global_text = ConfigurePerGame::tr("Use global configuration"); |
| 124 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); | 151 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); |
| @@ -126,7 +153,8 @@ void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) { | |||
| 126 | } | 153 | } |
| 127 | 154 | ||
| 128 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) { | 155 | void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) { |
| 129 | const QString use_global_text = ConfigurePerGame::tr("Use global configuration (%1)").arg(combobox->itemText(global_index)); | 156 | const QString use_global_text = |
| 157 | ConfigurePerGame::tr("Use global configuration (%1)").arg(combobox->itemText(global_index)); | ||
| 130 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); | 158 | combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); |
| 131 | combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX); | 159 | combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX); |
| 132 | } | 160 | } |
diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h index f3676bd3a..b5d6ea8c8 100644 --- a/src/yuzu/configuration/configuration_shared.h +++ b/src/yuzu/configuration/configuration_shared.h | |||
| @@ -57,8 +57,13 @@ void SetPerGameSetting(QComboBox* combobox, | |||
| 57 | const Settings::Setting<Settings::GPUAccuracy>* setting); | 57 | const Settings::Setting<Settings::GPUAccuracy>* setting); |
| 58 | 58 | ||
| 59 | void SetHighlight(QWidget* widget, const std::string& name, bool highlighted); | 59 | void SetHighlight(QWidget* widget, const std::string& name, bool highlighted); |
| 60 | void SetColoredTristate(QCheckBox* checkbox, const std::string& name, const Settings::Setting<bool>& setting, | 60 | void SetColoredTristate(QCheckBox* checkbox, const std::string& name, |
| 61 | const Settings::Setting<bool>& setting, | ||
| 61 | ConfigurationShared::CheckState& tracker); | 62 | ConfigurationShared::CheckState& tracker); |
| 63 | void SetColoredTristate(QCheckBox* checkbox, const std::string& name, bool global, bool state, | ||
| 64 | bool global_state, ConfigurationShared::CheckState& tracker); | ||
| 65 | void SetColoredComboBox(QComboBox* combobox, QWidget* target, const std::string& target_name, | ||
| 66 | int global); | ||
| 62 | 67 | ||
| 63 | void InsertGlobalItem(QComboBox* combobox); | 68 | void InsertGlobalItem(QComboBox* combobox); |
| 64 | void InsertGlobalItem(QComboBox* combobox, int global_index); | 69 | void InsertGlobalItem(QComboBox* combobox, int global_index); |
diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index c1b38728d..c79b256f9 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp | |||
| @@ -80,6 +80,8 @@ void ConfigureGraphics::SetConfiguration() { | |||
| 80 | ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); | 80 | ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); |
| 81 | } else { | 81 | } else { |
| 82 | ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); | 82 | ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); |
| 83 | ConfigurationShared::SetHighlight(ui->api_layout, "api_layout", | ||
| 84 | !Settings::values.renderer_backend.UsingGlobal()); | ||
| 83 | ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, | 85 | ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, |
| 84 | &Settings::values.aspect_ratio); | 86 | &Settings::values.aspect_ratio); |
| 85 | 87 | ||
| @@ -89,8 +91,6 @@ void ConfigureGraphics::SetConfiguration() { | |||
| 89 | !Settings::values.aspect_ratio.UsingGlobal()); | 91 | !Settings::values.aspect_ratio.UsingGlobal()); |
| 90 | ConfigurationShared::SetHighlight(ui->bg_layout, "bg_layout", | 92 | ConfigurationShared::SetHighlight(ui->bg_layout, "bg_layout", |
| 91 | !Settings::values.bg_red.UsingGlobal()); | 93 | !Settings::values.bg_red.UsingGlobal()); |
| 92 | // FIXME: ConfigurationShared::SetHighlight(ui->api_layout, "api_layout", | ||
| 93 | // !Settings::values.renderer_backend.UsingGlobal()); | ||
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red.GetValue(), | 96 | UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red.GetValue(), |
| @@ -141,10 +141,12 @@ void ConfigureGraphics::ApplyConfiguration() { | |||
| 141 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio, | 141 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio, |
| 142 | ui->aspect_ratio_combobox); | 142 | ui->aspect_ratio_combobox); |
| 143 | 143 | ||
| 144 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache, | 144 | ConfigurationShared::ApplyPerGameSetting( |
| 145 | ui->use_disk_shader_cache); | 145 | &Settings::values.use_disk_shader_cache, ui->use_disk_shader_cache, |
| 146 | ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, | 146 | ConfigurationShared::trackers.use_disk_shader_cache); |
| 147 | ui->use_asynchronous_gpu_emulation); | 147 | ConfigurationShared::ApplyPerGameSetting( |
| 148 | &Settings::values.use_asynchronous_gpu_emulation, ui->use_asynchronous_gpu_emulation, | ||
| 149 | ConfigurationShared::trackers.use_asynchronous_gpu_emulation); | ||
| 148 | 150 | ||
| 149 | if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { | 151 | if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { |
| 150 | Settings::values.bg_red.SetGlobal(true); | 152 | Settings::values.bg_red.SetGlobal(true); |
| @@ -247,11 +249,6 @@ void ConfigureGraphics::SetupPerGameUI() { | |||
| 247 | return; | 249 | return; |
| 248 | } | 250 | } |
| 249 | 251 | ||
| 250 | connect(ui->aspect_ratio_combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), | ||
| 251 | this, [this](int index) { | ||
| 252 | ConfigurationShared::SetHighlight(ui->aspect_ratio_layout, "aspect_ratio_layout", | ||
| 253 | index != 0); | ||
| 254 | }); | ||
| 255 | connect(ui->bg_combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, | 252 | connect(ui->bg_combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, |
| 256 | [this](int index) { | 253 | [this](int index) { |
| 257 | ui->bg_button->setEnabled(index == 1); | 254 | ui->bg_button->setEnabled(index == 1); |
| @@ -266,8 +263,9 @@ void ConfigureGraphics::SetupPerGameUI() { | |||
| 266 | Settings::values.use_asynchronous_gpu_emulation, | 263 | Settings::values.use_asynchronous_gpu_emulation, |
| 267 | ConfigurationShared::trackers.use_asynchronous_gpu_emulation); | 264 | ConfigurationShared::trackers.use_asynchronous_gpu_emulation); |
| 268 | 265 | ||
| 269 | ConfigurationShared::InsertGlobalItem(ui->aspect_ratio_combobox, | 266 | ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->aspect_ratio_layout, |
| 270 | Settings::values.aspect_ratio.GetValue(true)); | 267 | "aspect_ratio_layout", |
| 268 | Settings::values.aspect_ratio.GetValue(true)); | ||
| 271 | ConfigurationShared::InsertGlobalItem( | 269 | ConfigurationShared::InsertGlobalItem( |
| 272 | ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true))); | 270 | ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true))); |
| 273 | } | 271 | } |