From 08df9a66e03acb614dca6d1c118818f84f1cbcfd Mon Sep 17 00:00:00 2001 From: TryTwo Date: Tue, 17 Sep 2024 23:29:13 -0700 Subject: DolphinQt: Refactor, add ConfigControl class This reduces code duplication in the different ConfigControls. This is helpful for the next commit, which will modify the now deduplicated code. --- .../Config/ConfigControls/ConfigChoice.cpp | 62 ++++++++-------------- 1 file changed, 21 insertions(+), 41 deletions(-) (limited to 'Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp') diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp index ad65f0c96b..a26b87b46e 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp @@ -5,85 +5,65 @@ #include -#include "Common/Config/Config.h" - -#include "DolphinQt/Settings.h" - ConfigChoice::ConfigChoice(const QStringList& options, const Config::Info& setting) - : m_setting(setting) + : ConfigControl(setting.GetLocation()), m_setting(setting) { addItems(options); - connect(this, &QComboBox::currentIndexChanged, this, &ConfigChoice::Update); - setCurrentIndex(Config::Get(m_setting)); + setCurrentIndex(ReadValue(setting)); - connect(&Settings::Instance(), &Settings::ConfigChanged, this, [this] { - QFont bf = font(); - bf.setBold(Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base); - setFont(bf); - - const QSignalBlocker blocker(this); - setCurrentIndex(Config::Get(m_setting)); - }); + connect(this, &QComboBox::currentIndexChanged, this, &ConfigChoice::Update); } void ConfigChoice::Update(int choice) { - Config::SetBaseOrCurrent(m_setting, choice); + SaveValue(m_setting, choice); +} + +void ConfigChoice::OnConfigChanged() +{ + setCurrentIndex(ReadValue(m_setting)); } ConfigStringChoice::ConfigStringChoice(const std::vector& options, const Config::Info& setting) - : m_setting(setting), m_text_is_data(true) + : ConfigControl(setting.GetLocation()), m_setting(setting), m_text_is_data(true) { for (const auto& op : options) addItem(QString::fromStdString(op)); - Connect(); Load(); + connect(this, &QComboBox::currentIndexChanged, this, &ConfigStringChoice::Update); } ConfigStringChoice::ConfigStringChoice(const std::vector>& options, const Config::Info& setting) - : m_setting(setting), m_text_is_data(false) + : ConfigControl(setting.GetLocation()), m_setting(setting), m_text_is_data(false) { for (const auto& [option_text, option_data] : options) addItem(option_text, option_data); - Connect(); - Load(); -} - -void ConfigStringChoice::Connect() -{ - const auto on_config_changed = [this]() { - QFont bf = font(); - bf.setBold(Config::GetActiveLayerForConfig(m_setting) != Config::LayerType::Base); - setFont(bf); - - Load(); - }; - - connect(&Settings::Instance(), &Settings::ConfigChanged, this, on_config_changed); connect(this, &QComboBox::currentIndexChanged, this, &ConfigStringChoice::Update); + Load(); } void ConfigStringChoice::Update(int index) { if (m_text_is_data) - { - Config::SetBaseOrCurrent(m_setting, itemText(index).toStdString()); - } + SaveValue(m_setting, itemText(index).toStdString()); else - { - Config::SetBaseOrCurrent(m_setting, itemData(index).toString().toStdString()); - } + SaveValue(m_setting, itemData(index).toString().toStdString()); } void ConfigStringChoice::Load() { - const QString setting_value = QString::fromStdString(Config::Get(m_setting)); + const QString setting_value = QString::fromStdString(ReadValue(m_setting)); const int index = m_text_is_data ? findText(setting_value) : findData(setting_value); const QSignalBlocker blocker(this); setCurrentIndex(index); } + +void ConfigStringChoice::OnConfigChanged() +{ + Load(); +} -- cgit v1.2.3 From 84a937ae651aa5296535e8feffe47aa1f2b219ab Mon Sep 17 00:00:00 2001 From: TryTwo Date: Tue, 17 Sep 2024 23:29:13 -0700 Subject: Add GFX property tabs to game properties window, allowing them to be set to the user game ini. Additionally, refactor ConfigWidgets to reduce duplication. Refactor GameConfigWidget to use config system. Creates a layer outside the game config layer system and passes it to the created gfx widows, so as to not interfere with the global config system. Supports multiple game properties being open at once. Supports editing while a game is playing, but the options only save and update the active game when the window is closed. Right-clicking will remove a property from the game ini. --- .../DolphinQt/Config/ConfigControls/ConfigChoice.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp') diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp index a26b87b46e..c2652563d1 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp @@ -5,8 +5,9 @@ #include -ConfigChoice::ConfigChoice(const QStringList& options, const Config::Info& setting) - : ConfigControl(setting.GetLocation()), m_setting(setting) +ConfigChoice::ConfigChoice(const QStringList& options, const Config::Info& setting, + Config::Layer* layer) + : ConfigControl(setting.GetLocation(), layer), m_setting(setting) { addItems(options); setCurrentIndex(ReadValue(setting)); @@ -25,8 +26,9 @@ void ConfigChoice::OnConfigChanged() } ConfigStringChoice::ConfigStringChoice(const std::vector& options, - const Config::Info& setting) - : ConfigControl(setting.GetLocation()), m_setting(setting), m_text_is_data(true) + const Config::Info& setting, + Config::Layer* layer) + : ConfigControl(setting.GetLocation(), layer), m_setting(setting), m_text_is_data(true) { for (const auto& op : options) addItem(QString::fromStdString(op)); @@ -36,8 +38,9 @@ ConfigStringChoice::ConfigStringChoice(const std::vector& options, } ConfigStringChoice::ConfigStringChoice(const std::vector>& options, - const Config::Info& setting) - : ConfigControl(setting.GetLocation()), m_setting(setting), m_text_is_data(false) + const Config::Info& setting, + Config::Layer* layer) + : ConfigControl(setting.GetLocation(), layer), m_setting(setting), m_text_is_data(false) { for (const auto& [option_text, option_data] : options) addItem(option_text, option_data); @@ -57,9 +60,10 @@ void ConfigStringChoice::Update(int index) void ConfigStringChoice::Load() { const QString setting_value = QString::fromStdString(ReadValue(m_setting)); - const int index = m_text_is_data ? findText(setting_value) : findData(setting_value); - const QSignalBlocker blocker(this); + + // This can be called publicly. + const QSignalBlocker block(this); setCurrentIndex(index); } -- cgit v1.2.3 From ac129d318b02f6878352cb1c93d2ebf3542ace1c Mon Sep 17 00:00:00 2001 From: TryTwo Date: Mon, 21 Oct 2024 14:47:42 -0700 Subject: EnhancementsWidget:: Move to using ConfigControls and add new control for ComboBoxes that set two settings at once. --- .../Config/ConfigControls/ConfigChoice.cpp | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) (limited to 'Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp') diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp index c2652563d1..b1c12a4172 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp @@ -71,3 +71,102 @@ void ConfigStringChoice::OnConfigChanged() { Load(); } + +ConfigComplexChoice::ConfigComplexChoice(const InfoVariant setting1, const InfoVariant setting2, + Config::Layer* layer) + : m_setting1(setting1), m_setting2(setting2), m_layer(layer) +{ + connect(&Settings::Instance(), &Settings::ConfigChanged, this, &ConfigComplexChoice::Refresh); + connect(this, &QComboBox::currentIndexChanged, this, &ConfigComplexChoice::SaveValue); +} + +void ConfigComplexChoice::Refresh() +{ + auto& location = GetLocation(); + + QFont bf = font(); + if (m_layer != nullptr) + { + bf.setBold(m_layer->Exists(location.first) || m_layer->Exists(location.second)); + } + else + { + bf.setBold(Config::GetActiveLayerForConfig(location.first) != Config::LayerType::Base || + Config::GetActiveLayerForConfig(location.second) != Config::LayerType::Base); + } + + setFont(bf); + UpdateComboIndex(); +} + +void ConfigComplexChoice::Add(const QString& name, const OptionVariant option1, + const OptionVariant option2) +{ + const QSignalBlocker blocker(this); + addItem(name); + m_options.push_back(std::make_pair(option1, option2)); +} + +void ConfigComplexChoice::Reset() +{ + clear(); + m_options.clear(); +} + +void ConfigComplexChoice::SaveValue(int choice) +{ + auto Set = [this, choice](auto& setting, auto& value) { + if (m_layer != nullptr) + { + m_layer->Set(setting.GetLocation(), value); + Config::OnConfigChanged(); + return; + } + + Config::SetBaseOrCurrent(setting, value); + }; + + std::visit(Set, m_setting1, m_options[choice].first); + std::visit(Set, m_setting2, m_options[choice].second); +} + +void ConfigComplexChoice::UpdateComboIndex() +{ + auto Get = [this](auto& setting) { + if (m_layer != nullptr) + return static_cast(m_layer->Get(setting)); + + return static_cast(Config::Get(setting)); + }; + + std::pair values = + std::make_pair(std::visit(Get, m_setting1), std::visit(Get, m_setting2)); + + auto it = std::find(m_options.begin(), m_options.end(), values); + int index = static_cast(std::distance(m_options.begin(), it)); + + const QSignalBlocker blocker(this); + setCurrentIndex(index); +} + +const std::pair ConfigComplexChoice::GetLocation() const +{ + auto visit = [](auto& v) { return v.GetLocation(); }; + + return {std::visit(visit, m_setting1), std::visit(visit, m_setting2)}; +} + +void ConfigComplexChoice::mousePressEvent(QMouseEvent* event) +{ + if (event->button() == Qt::RightButton && m_layer != nullptr) + { + auto& location = GetLocation(); + m_layer->DeleteKey(location.first); + m_layer->DeleteKey(location.second); + Config::OnConfigChanged(); + } + else + { + QComboBox::mousePressEvent(event); + } +}; -- cgit v1.2.3