From 96086d57fab96cd8add5607736bd893666f4ccc3 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 6 Apr 2020 20:08:02 +0200 Subject: [PATCH] Qt: implement EnhanceRadioButton --- rpcs3/rpcs3qt/emu_settings.cpp | 64 ++++++++++++++++++++++++- rpcs3/rpcs3qt/emu_settings.h | 10 ++-- rpcs3/rpcs3qt/settings_dialog.cpp | 79 ++----------------------------- rpcs3/rpcs3qt/settings_dialog.ui | 28 +++++------ 4 files changed, 89 insertions(+), 92 deletions(-) diff --git a/rpcs3/rpcs3qt/emu_settings.cpp b/rpcs3/rpcs3qt/emu_settings.cpp index 2fc04241c1..587c2804eb 100644 --- a/rpcs3/rpcs3qt/emu_settings.cpp +++ b/rpcs3/rpcs3qt/emu_settings.cpp @@ -366,7 +366,7 @@ void emu_settings::EnhanceComboBox(QComboBox* combobox, SettingsType type, bool } else { - QStringList settings = GetSettingOptions(type); + const QStringList settings = GetSettingOptions(type); for (const QString& setting : settings) { @@ -580,6 +580,41 @@ void emu_settings::EnhanceEdit(QLineEdit* edit, SettingsType type) }); } +void emu_settings::EnhanceRadioButton(QButtonGroup* button_group, SettingsType type) +{ + if (!button_group) + { + cfg_log.fatal("EnhanceRadioButton '%s' was used with an invalid object", GetSettingName(type)); + return; + } + + const QString selected = qstr(GetSetting(type)); + const QStringList options = GetSettingOptions(type); + + if (button_group->buttons().count() < options.size()) + { + cfg_log.fatal("EnhanceRadioButton '%s': wrong button count", GetSettingName(type)); + return; + } + + for (int i = 0; i < options.count(); i++) + { + const QString localized_setting = GetLocalizedSetting(options[i], type, i); + + button_group->button(i)->setText(localized_setting); + + if (options[i] == selected) + { + button_group->button(i)->setChecked(true); + } + + connect(button_group->button(i), &QAbstractButton::clicked, [=, this]() + { + SetSetting(type, sstr(options[i])); + }); + } +} + std::vector emu_settings::GetLoadedLibraries() { return m_currentSettings["Core"]["Load libraries"].as, std::initializer_list>({}); @@ -795,6 +830,33 @@ QString emu_settings::GetLocalizedSetting(const QString& original, SettingsType case screen_quadrant::bottom_right: return tr("Bottom Right"); } break; + case emu_settings::LibLoadOptions: + switch (static_cast(index)) + { + case lib_loading_type::manual: return tr("Manually load selected libraries"); + case lib_loading_type::hybrid: return tr("Load automatic and manual selection"); + case lib_loading_type::liblv2only: return tr("Load liblv2.sprx only"); + case lib_loading_type::liblv2both: return tr("Load liblv2.sprx and manual selection"); + case lib_loading_type::liblv2list: return tr("Load liblv2.sprx and strict selection"); + } + break; + case emu_settings::PPUDecoder: + switch (static_cast(index)) + { + case ppu_decoder_type::precise: return tr("Interpreter (precise)"); + case ppu_decoder_type::fast: return tr("Interpreter (fast)"); + case ppu_decoder_type::llvm: return tr("Recompiler (LLVM)"); + } + break; + case emu_settings::SPUDecoder: + switch (static_cast(index)) + { + case spu_decoder_type::precise: return tr("Interpreter (precise)"); + case spu_decoder_type::fast: return tr("Interpreter (fast)"); + case spu_decoder_type::asmjit: return tr("Recompiler (ASMJIT)"); + case spu_decoder_type::llvm: return tr("Recompiler (LLVM)"); + } + break; default: break; } diff --git a/rpcs3/rpcs3qt/emu_settings.h b/rpcs3/rpcs3qt/emu_settings.h index 0d7b42214d..21b97e2159 100644 --- a/rpcs3/rpcs3qt/emu_settings.h +++ b/rpcs3/rpcs3qt/emu_settings.h @@ -4,6 +4,7 @@ #include "stdafx.h" +#include #include #include #include @@ -236,6 +237,9 @@ public: /** Connects a line edit with the target settings type*/ void EnhanceEdit(QLineEdit* edit, SettingsType type); + /** Connects a button group with the target settings type*/ + void EnhanceRadioButton(QButtonGroup* button_group, SettingsType type); + std::vector GetLoadedLibraries(); void SaveSelectedLibraries(const std::vector& libs); @@ -266,13 +270,13 @@ public: /** Fixes all registered invalid settings after asking the user for permission.*/ void OpenCorrectionDialog(QWidget* parent = Q_NULLPTR); + /** Get a localized and therefore freely adjustable version of the string used in config.yml.*/ + QString GetLocalizedSetting(const QString& original, SettingsType type, int index) const; + public Q_SLOTS: /** Writes the unsaved settings to file. Used in settings dialog on accept.*/ void SaveSettings(); private: - /** Get a localized and therefore freely adjustable version of the string used in config.yml.*/ - QString GetLocalizedSetting(const QString& original, SettingsType type, int index) const; - /** A helper map that keeps track of where a given setting type is located*/ const QMap m_settings_location = { diff --git a/rpcs3/rpcs3qt/settings_dialog.cpp b/rpcs3/rpcs3qt/settings_dialog.cpp index 33b22b996f..5fa11da26d 100644 --- a/rpcs3/rpcs3qt/settings_dialog.cpp +++ b/rpcs3/rpcs3qt/settings_dialog.cpp @@ -241,23 +241,7 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std ppu_bg->addButton(ui->ppu_fast, static_cast(ppu_decoder_type::fast)); ppu_bg->addButton(ui->ppu_llvm, static_cast(ppu_decoder_type::llvm)); - { // PPU Stuff - const QString selected_ppu = qstr(m_emu_settings->GetSetting(emu_settings::PPUDecoder)); - QStringList ppu_list = m_emu_settings->GetSettingOptions(emu_settings::PPUDecoder); - - for (int i = 0; i < ppu_list.count(); i++) - { - if (ppu_list[i] == selected_ppu) - { - ppu_bg->button(i)->setChecked(true); - } - - connect(ppu_bg->button(i), &QAbstractButton::clicked, [=, this]() - { - m_emu_settings->SetSetting(emu_settings::PPUDecoder, sstr(ppu_list[i])); - }); - } - } + m_emu_settings->EnhanceRadioButton(ppu_bg, emu_settings::PPUDecoder); // SPU tool tips SubscribeTooltip(ui->spu_precise, tooltips.settings.spu_precise); @@ -271,23 +255,7 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std spu_bg->addButton(ui->spu_asmjit, static_cast(spu_decoder_type::asmjit)); spu_bg->addButton(ui->spu_llvm, static_cast(spu_decoder_type::llvm)); - { // Spu stuff - const QString selected_spu = qstr(m_emu_settings->GetSetting(emu_settings::SPUDecoder)); - QStringList spu_list = m_emu_settings->GetSettingOptions(emu_settings::SPUDecoder); - - for (int i = 0; i < spu_list.count(); i++) - { - if (spu_list[i] == selected_spu) - { - spu_bg->button(i)->setChecked(true); - } - - connect(spu_bg->button(i), &QAbstractButton::clicked, [=, this]() - { - m_emu_settings->SetSetting(emu_settings::SPUDecoder, sstr(spu_list[i])); - }); - } - } + m_emu_settings->EnhanceRadioButton(spu_bg, emu_settings::SPUDecoder); connect(ui->spu_llvm, &QAbstractButton::toggled, [this](bool checked) { @@ -863,32 +831,13 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std // Radio Buttons - SubscribeTooltip(ui->gb_enterButtonAssignment, tooltips.settings.enter_button_assignment); - // creating this in ui file keeps scrambling the order... QButtonGroup *enter_button_assignment_bg = new QButtonGroup(this); enter_button_assignment_bg->addButton(ui->enterButtonAssignCircle, 0); enter_button_assignment_bg->addButton(ui->enterButtonAssignCross, 1); - { // EnterButtonAssignment options - const QString assigned_button = qstr(m_emu_settings->GetSetting(emu_settings::EnterButtonAssignment)); - QStringList assignable_buttons = m_emu_settings->GetSettingOptions(emu_settings::EnterButtonAssignment); - - for (int i = 0; i < assignable_buttons.count(); i++) - { - enter_button_assignment_bg->button(i)->setText(assignable_buttons[i]); - - if (assignable_buttons[i] == assigned_button) - { - enter_button_assignment_bg->button(i)->setChecked(true); - } - - connect(enter_button_assignment_bg->button(i), &QAbstractButton::clicked, [=, this]() - { - m_emu_settings->SetSetting(emu_settings::EnterButtonAssignment, sstr(assignable_buttons[i])); - }); - } - } + m_emu_settings->EnhanceRadioButton(enter_button_assignment_bg, emu_settings::EnterButtonAssignment); + SubscribeTooltip(ui->gb_enterButtonAssignment, tooltips.settings.enter_button_assignment); // _ _ _ _ _______ _ // | \ | | | | | | |__ __| | | @@ -1051,25 +1000,7 @@ settings_dialog::settings_dialog(std::shared_ptr gui_settings, std lib_mode_bg->addButton(ui->lib_lv2b, static_cast(lib_loading_type::liblv2both)); lib_mode_bg->addButton(ui->lib_lv2l, static_cast(lib_loading_type::liblv2list)); - {// Handle lib loading options - const QString selected_lib = qstr(m_emu_settings->GetSetting(emu_settings::LibLoadOptions)); - QStringList libmode_list = m_emu_settings->GetSettingOptions(emu_settings::LibLoadOptions); - - for (int i = 0; i < libmode_list.count(); i++) - { - lib_mode_bg->button(i)->setText(libmode_list[i]); - - if (libmode_list[i] == selected_lib) - { - lib_mode_bg->button(i)->setChecked(true); - } - - connect(lib_mode_bg->button(i), &QAbstractButton::clicked, [=, this]() - { - m_emu_settings->SetSetting(emu_settings::LibLoadOptions, sstr(libmode_list[i])); - }); - } - } + m_emu_settings->EnhanceRadioButton(lib_mode_bg, emu_settings::LibLoadOptions); // Sort string vector alphabetically static const auto sort_string_vector = [](std::vector& vec) diff --git a/rpcs3/rpcs3qt/settings_dialog.ui b/rpcs3/rpcs3qt/settings_dialog.ui index 4f12503af6..a5bc51326f 100644 --- a/rpcs3/rpcs3qt/settings_dialog.ui +++ b/rpcs3/rpcs3qt/settings_dialog.ui @@ -56,21 +56,21 @@ - Interpreter (precise) + Interpreter (precise) - Interpreter (fast) + Interpreter (fast) - LLVM Recompiler (fastest) + LLVM Recompiler (fastest) @@ -86,28 +86,28 @@ - Interpreter (precise) + Interpreter (precise) - Interpreter (fast) + Interpreter (fast) - ASMJIT Recompiler (faster) + ASMJIT Recompiler (faster) - LLVM Recompiler (fastest) + LLVM Recompiler (fastest) @@ -1378,14 +1378,14 @@ - Enter with circle + Enter with circle - Enter with cross + Enter with cross @@ -1791,7 +1791,7 @@ - Manually load selected libraries + Manually load selected libraries @@ -1804,7 +1804,7 @@ - Load automatic and manual selection + Load automatic and manual selection @@ -1817,7 +1817,7 @@ - Load liblv2.sprx only + Load liblv2.sprx only @@ -1830,7 +1830,7 @@ - Load liblv2.sprx and manual selection + Load liblv2.sprx and manual selection @@ -1843,7 +1843,7 @@ - Load liblv2.sprx and strict selection + Load liblv2.sprx and strict selection