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