Merge pull request #4532 from lioncash/object-name

configuration_shared: Simplify name lookup in highlighting functions
This commit is contained in:
bunnei 2020-08-18 00:45:02 -04:00 committed by GitHub
commit 00573fb2c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 90 deletions

View file

@ -72,18 +72,18 @@ void ConfigurationShared::SetPerGameSetting(
ConfigurationShared::USE_GLOBAL_OFFSET); ConfigurationShared::USE_GLOBAL_OFFSET);
} }
void ConfigurationShared::SetHighlight(QWidget* widget, const std::string& name, bool highlighted) { void ConfigurationShared::SetHighlight(QWidget* widget, bool highlighted) {
if (highlighted) { if (highlighted) {
widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }") widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,203,255,0.5) }")
.arg(QString::fromStdString(name))); .arg(widget->objectName()));
} else { } else {
widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,0,0,0) }") widget->setStyleSheet(QStringLiteral("QWidget#%1 { background-color:rgba(0,0,0,0) }")
.arg(QString::fromStdString(name))); .arg(widget->objectName()));
} }
widget->show(); widget->show();
} }
void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name, void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox,
const Settings::Setting<bool>& setting, const Settings::Setting<bool>& setting,
CheckState& tracker) { CheckState& tracker) {
if (setting.UsingGlobal()) { if (setting.UsingGlobal()) {
@ -91,45 +91,39 @@ void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::str
} else { } else {
tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off; tracker = (setting.GetValue() == setting.GetValue(true)) ? CheckState::On : CheckState::Off;
} }
SetHighlight(checkbox, name, tracker != CheckState::Global); SetHighlight(checkbox, tracker != CheckState::Global);
QObject::connect(checkbox, &QCheckBox::clicked, checkbox, QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, setting, &tracker] {
[checkbox, name, setting, &tracker]() {
tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) % tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
static_cast<int>(CheckState::Count)); static_cast<int>(CheckState::Count));
if (tracker == CheckState::Global) { if (tracker == CheckState::Global) {
checkbox->setChecked(setting.GetValue(true)); checkbox->setChecked(setting.GetValue(true));
} }
SetHighlight(checkbox, name, tracker != CheckState::Global); SetHighlight(checkbox, tracker != CheckState::Global);
}); });
} }
void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, const std::string& name, void ConfigurationShared::SetColoredTristate(QCheckBox* checkbox, bool global, bool state,
bool global, bool state, bool global_state, bool global_state, CheckState& tracker) {
CheckState& tracker) {
if (global) { if (global) {
tracker = CheckState::Global; tracker = CheckState::Global;
} else { } else {
tracker = (state == global_state) ? CheckState::On : CheckState::Off; tracker = (state == global_state) ? CheckState::On : CheckState::Off;
} }
SetHighlight(checkbox, name, tracker != CheckState::Global); SetHighlight(checkbox, tracker != CheckState::Global);
QObject::connect(checkbox, &QCheckBox::clicked, checkbox, QObject::connect(checkbox, &QCheckBox::clicked, checkbox, [checkbox, global_state, &tracker] {
[checkbox, name, global_state, &tracker]() {
tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) % tracker = static_cast<CheckState>((static_cast<int>(tracker) + 1) %
static_cast<int>(CheckState::Count)); static_cast<int>(CheckState::Count));
if (tracker == CheckState::Global) { if (tracker == CheckState::Global) {
checkbox->setChecked(global_state); checkbox->setChecked(global_state);
} }
SetHighlight(checkbox, name, tracker != CheckState::Global); SetHighlight(checkbox, tracker != CheckState::Global);
}); });
} }
void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target, void ConfigurationShared::SetColoredComboBox(QComboBox* combobox, QWidget* target, int global) {
const std::string& target_name, int global) {
InsertGlobalItem(combobox, global); InsertGlobalItem(combobox, global);
QObject::connect(combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), target, QObject::connect(combobox, qOverload<int>(&QComboBox::activated), target,
[target, target_name](int index) { [target](int index) { SetHighlight(target, index != 0); });
ConfigurationShared::SetHighlight(target, target_name, index != 0);
});
} }
void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) { void ConfigurationShared::InsertGlobalItem(QComboBox* combobox, int global_index) {

View file

@ -39,13 +39,12 @@ void SetPerGameSetting(QComboBox* combobox,
void SetPerGameSetting(QComboBox* combobox, void SetPerGameSetting(QComboBox* combobox,
const Settings::Setting<Settings::GPUAccuracy>* setting); const Settings::Setting<Settings::GPUAccuracy>* setting);
void SetHighlight(QWidget* widget, const std::string& name, bool highlighted); void SetHighlight(QWidget* widget, bool highlighted);
void SetColoredTristate(QCheckBox* checkbox, const std::string& name, void SetColoredTristate(QCheckBox* checkbox, const Settings::Setting<bool>& setting,
const Settings::Setting<bool>& setting, CheckState& tracker); CheckState& tracker);
void SetColoredTristate(QCheckBox* checkbox, const std::string& name, bool global, bool state, void SetColoredTristate(QCheckBox* checkbox, bool global, bool state, bool global_state,
bool global_state, CheckState& tracker); CheckState& tracker);
void SetColoredComboBox(QComboBox* combobox, QWidget* target, const std::string& target_name, void SetColoredComboBox(QComboBox* combobox, QWidget* target, int global);
int global);
void InsertGlobalItem(QComboBox* combobox, int global_index); void InsertGlobalItem(QComboBox* combobox, int global_index);

View file

@ -59,7 +59,7 @@ void ConfigureAudio::SetConfiguration() {
ui->volume_combo_box->setCurrentIndex(1); ui->volume_combo_box->setCurrentIndex(1);
ui->volume_slider->setEnabled(true); ui->volume_slider->setEnabled(true);
} }
ConfigurationShared::SetHighlight(ui->volume_layout, "volume_layout", ConfigurationShared::SetHighlight(ui->volume_layout,
!Settings::values.volume.UsingGlobal()); !Settings::values.volume.UsingGlobal());
} }
SetVolumeIndicatorText(ui->volume_slider->sliderPosition()); SetVolumeIndicatorText(ui->volume_slider->sliderPosition());
@ -173,13 +173,12 @@ void ConfigureAudio::SetupPerGameUI() {
return; return;
} }
ConfigurationShared::SetColoredTristate(ui->toggle_audio_stretching, "toggle_audio_stretching", ConfigurationShared::SetColoredTristate(ui->toggle_audio_stretching,
Settings::values.enable_audio_stretching, Settings::values.enable_audio_stretching,
enable_audio_stretching); enable_audio_stretching);
connect(ui->volume_combo_box, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), connect(ui->volume_combo_box, qOverload<int>(&QComboBox::activated), this, [this](int index) {
this, [this](int index) {
ui->volume_slider->setEnabled(index == 1); ui->volume_slider->setEnabled(index == 1);
ConfigurationShared::SetHighlight(ui->volume_layout, "volume_layout", index == 1); ConfigurationShared::SetHighlight(ui->volume_layout, index == 1);
}); });
ui->output_sink_combo_box->setVisible(false); ui->output_sink_combo_box->setVisible(false);

View file

@ -105,10 +105,10 @@ void ConfigureGeneral::SetupPerGameUI() {
ui->toggle_background_pause->setVisible(false); ui->toggle_background_pause->setVisible(false);
ui->toggle_hide_mouse->setVisible(false); ui->toggle_hide_mouse->setVisible(false);
ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit, "toggle_frame_limit", ConfigurationShared::SetColoredTristate(ui->toggle_frame_limit,
Settings::values.use_frame_limit, use_frame_limit); Settings::values.use_frame_limit, use_frame_limit);
ConfigurationShared::SetColoredTristate(ui->use_multi_core, "use_multi_core", ConfigurationShared::SetColoredTristate(ui->use_multi_core, Settings::values.use_multi_core,
Settings::values.use_multi_core, use_multi_core); use_multi_core);
connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, [this]() { connect(ui->toggle_frame_limit, &QCheckBox::clicked, ui->frame_limit, [this]() {
ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked() && ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked() &&

View file

@ -34,9 +34,8 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent)
connect(ui->api, qOverload<int>(&QComboBox::currentIndexChanged), this, [this] { connect(ui->api, qOverload<int>(&QComboBox::currentIndexChanged), this, [this] {
UpdateDeviceComboBox(); UpdateDeviceComboBox();
if (!Settings::configuring_global) { if (!Settings::configuring_global) {
ConfigurationShared::SetHighlight(ui->api_layout, "api_layout", ConfigurationShared::SetHighlight(
ui->api->currentIndex() != ui->api_layout, ui->api->currentIndex() != ConfigurationShared::USE_GLOBAL_INDEX);
ConfigurationShared::USE_GLOBAL_INDEX);
} }
}); });
connect(ui->device, qOverload<int>(&QComboBox::activated), this, connect(ui->device, qOverload<int>(&QComboBox::activated), this,
@ -80,17 +79,16 @@ void ConfigureGraphics::SetConfiguration() {
ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue());
} else { } else {
ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend);
ConfigurationShared::SetHighlight(ui->api_layout, "api_layout", ConfigurationShared::SetHighlight(ui->api_layout,
!Settings::values.renderer_backend.UsingGlobal()); !Settings::values.renderer_backend.UsingGlobal());
ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox,
&Settings::values.aspect_ratio); &Settings::values.aspect_ratio);
ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1);
ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal());
ConfigurationShared::SetHighlight(ui->ar_label, "ar_label", ConfigurationShared::SetHighlight(ui->ar_label,
!Settings::values.aspect_ratio.UsingGlobal()); !Settings::values.aspect_ratio.UsingGlobal());
ConfigurationShared::SetHighlight(ui->bg_layout, "bg_layout", ConfigurationShared::SetHighlight(ui->bg_layout, !Settings::values.bg_red.UsingGlobal());
!Settings::values.bg_red.UsingGlobal());
} }
UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red.GetValue(), UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red.GetValue(),
@ -248,20 +246,18 @@ void ConfigureGraphics::SetupPerGameUI() {
return; return;
} }
connect(ui->bg_combobox, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, connect(ui->bg_combobox, qOverload<int>(&QComboBox::activated), this, [this](int index) {
[this](int index) {
ui->bg_button->setEnabled(index == 1); ui->bg_button->setEnabled(index == 1);
ConfigurationShared::SetHighlight(ui->bg_layout, "bg_layout", index == 1); ConfigurationShared::SetHighlight(ui->bg_layout, index == 1);
}); });
ConfigurationShared::SetColoredTristate(ui->use_disk_shader_cache, "use_disk_shader_cache",
Settings::values.use_disk_shader_cache,
use_disk_shader_cache);
ConfigurationShared::SetColoredTristate( ConfigurationShared::SetColoredTristate(
ui->use_asynchronous_gpu_emulation, "use_asynchronous_gpu_emulation", ui->use_disk_shader_cache, Settings::values.use_disk_shader_cache, use_disk_shader_cache);
Settings::values.use_asynchronous_gpu_emulation, use_asynchronous_gpu_emulation); ConfigurationShared::SetColoredTristate(ui->use_asynchronous_gpu_emulation,
Settings::values.use_asynchronous_gpu_emulation,
use_asynchronous_gpu_emulation);
ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->ar_label, "ar_label", ConfigurationShared::SetColoredComboBox(ui->aspect_ratio_combobox, ui->ar_label,
Settings::values.aspect_ratio.GetValue(true)); Settings::values.aspect_ratio.GetValue(true));
ConfigurationShared::InsertGlobalItem( ConfigurationShared::InsertGlobalItem(
ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true))); ui->api, static_cast<int>(Settings::values.renderer_backend.GetValue(true)));

View file

@ -41,9 +41,9 @@ void ConfigureGraphicsAdvanced::SetConfiguration() {
ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy); ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy);
ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox, ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox,
&Settings::values.max_anisotropy); &Settings::values.max_anisotropy);
ConfigurationShared::SetHighlight(ui->label_gpu_accuracy, "label_gpu_accuracy", ConfigurationShared::SetHighlight(ui->label_gpu_accuracy,
!Settings::values.gpu_accuracy.UsingGlobal()); !Settings::values.gpu_accuracy.UsingGlobal());
ConfigurationShared::SetHighlight(ui->af_label, "af_label", ConfigurationShared::SetHighlight(ui->af_label,
!Settings::values.max_anisotropy.UsingGlobal()); !Settings::values.max_anisotropy.UsingGlobal());
} }
} }
@ -131,20 +131,18 @@ void ConfigureGraphicsAdvanced::SetupPerGameUI() {
return; return;
} }
ConfigurationShared::SetColoredTristate(ui->use_vsync, "use_vsync", Settings::values.use_vsync, ConfigurationShared::SetColoredTristate(ui->use_vsync, Settings::values.use_vsync, use_vsync);
use_vsync);
ConfigurationShared::SetColoredTristate(ui->use_assembly_shaders, "use_assembly_shaders",
Settings::values.use_assembly_shaders,
use_assembly_shaders);
ConfigurationShared::SetColoredTristate( ConfigurationShared::SetColoredTristate(
ui->use_asynchronous_shaders, "use_asynchronous_shaders", ui->use_assembly_shaders, Settings::values.use_assembly_shaders, use_assembly_shaders);
Settings::values.use_asynchronous_shaders, use_asynchronous_shaders); ConfigurationShared::SetColoredTristate(ui->use_asynchronous_shaders,
ConfigurationShared::SetColoredTristate(ui->use_fast_gpu_time, "use_fast_gpu_time", Settings::values.use_asynchronous_shaders,
use_asynchronous_shaders);
ConfigurationShared::SetColoredTristate(ui->use_fast_gpu_time,
Settings::values.use_fast_gpu_time, use_fast_gpu_time); Settings::values.use_fast_gpu_time, use_fast_gpu_time);
ConfigurationShared::SetColoredComboBox( ConfigurationShared::SetColoredComboBox(
ui->gpu_accuracy, ui->label_gpu_accuracy, "label_gpu_accuracy", ui->gpu_accuracy, ui->label_gpu_accuracy,
static_cast<int>(Settings::values.gpu_accuracy.GetValue(true))); static_cast<int>(Settings::values.gpu_accuracy.GetValue(true)));
ConfigurationShared::SetColoredComboBox( ConfigurationShared::SetColoredComboBox(
ui->anisotropic_filtering_combobox, ui->af_label, "af_label", ui->anisotropic_filtering_combobox, ui->af_label,
static_cast<int>(Settings::values.max_anisotropy.GetValue(true))); static_cast<int>(Settings::values.max_anisotropy.GetValue(true)));
} }

View file

@ -90,13 +90,13 @@ void ConfigureSystem::SetConfiguration() {
&Settings::values.time_zone_index); &Settings::values.time_zone_index);
ConfigurationShared::SetPerGameSetting(ui->combo_sound, &Settings::values.sound_index); ConfigurationShared::SetPerGameSetting(ui->combo_sound, &Settings::values.sound_index);
ConfigurationShared::SetHighlight(ui->label_language, "label_language", ConfigurationShared::SetHighlight(ui->label_language,
!Settings::values.language_index.UsingGlobal()); !Settings::values.language_index.UsingGlobal());
ConfigurationShared::SetHighlight(ui->label_region, "label_region", ConfigurationShared::SetHighlight(ui->label_region,
!Settings::values.region_index.UsingGlobal()); !Settings::values.region_index.UsingGlobal());
ConfigurationShared::SetHighlight(ui->label_timezone, "label_timezone", ConfigurationShared::SetHighlight(ui->label_timezone,
!Settings::values.time_zone_index.UsingGlobal()); !Settings::values.time_zone_index.UsingGlobal());
ConfigurationShared::SetHighlight(ui->label_sound, "label_sound", ConfigurationShared::SetHighlight(ui->label_sound,
!Settings::values.sound_index.UsingGlobal()); !Settings::values.sound_index.UsingGlobal());
} }
} }
@ -224,22 +224,20 @@ void ConfigureSystem::SetupPerGameUI() {
} }
ConfigurationShared::SetColoredComboBox(ui->combo_language, ui->label_language, ConfigurationShared::SetColoredComboBox(ui->combo_language, ui->label_language,
"label_language",
Settings::values.language_index.GetValue(true)); Settings::values.language_index.GetValue(true));
ConfigurationShared::SetColoredComboBox(ui->combo_region, ui->label_region, "label_region", ConfigurationShared::SetColoredComboBox(ui->combo_region, ui->label_region,
Settings::values.region_index.GetValue(true)); Settings::values.region_index.GetValue(true));
ConfigurationShared::SetColoredComboBox(ui->combo_time_zone, ui->label_timezone, ConfigurationShared::SetColoredComboBox(ui->combo_time_zone, ui->label_timezone,
"label_timezone",
Settings::values.time_zone_index.GetValue(true)); Settings::values.time_zone_index.GetValue(true));
ConfigurationShared::SetColoredComboBox(ui->combo_sound, ui->label_sound, "label_sound", ConfigurationShared::SetColoredComboBox(ui->combo_sound, ui->label_sound,
Settings::values.sound_index.GetValue(true)); Settings::values.sound_index.GetValue(true));
ConfigurationShared::SetColoredTristate( ConfigurationShared::SetColoredTristate(
ui->rng_seed_checkbox, "rng_seed_checkbox", Settings::values.rng_seed.UsingGlobal(), ui->rng_seed_checkbox, Settings::values.rng_seed.UsingGlobal(),
Settings::values.rng_seed.GetValue().has_value(), Settings::values.rng_seed.GetValue().has_value(),
Settings::values.rng_seed.GetValue(true).has_value(), use_rng_seed); Settings::values.rng_seed.GetValue(true).has_value(), use_rng_seed);
ConfigurationShared::SetColoredTristate( ConfigurationShared::SetColoredTristate(
ui->custom_rtc_checkbox, "custom_rtc_checkbox", Settings::values.custom_rtc.UsingGlobal(), ui->custom_rtc_checkbox, Settings::values.custom_rtc.UsingGlobal(),
Settings::values.custom_rtc.GetValue().has_value(), Settings::values.custom_rtc.GetValue().has_value(),
Settings::values.custom_rtc.GetValue(true).has_value(), use_custom_rtc); Settings::values.custom_rtc.GetValue(true).has_value(), use_custom_rtc);
} }