summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp
diff options
context:
space:
mode:
authorTryTwo <taolas@gmail.com>2024-10-21 14:47:42 -0700
committerTryTwo <taolas@gmail.com>2024-12-10 13:42:17 -0700
commitac129d318b02f6878352cb1c93d2ebf3542ace1c (patch)
tree68e4d8169b5eef2b8f11cd77e57827615261a2e7 /Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp
parent84a937ae651aa5296535e8feffe47aa1f2b219ab (diff)
EnhancementsWidget:: Move to using ConfigControls and add new control for ComboBoxes that set two settings at once.
Diffstat (limited to 'Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp')
-rw-r--r--Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp99
1 files changed, 99 insertions, 0 deletions
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<OptionVariant>(m_layer->Get(setting));
+
+ return static_cast<OptionVariant>(Config::Get(setting));
+ };
+
+ std::pair<OptionVariant, OptionVariant> 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<int>(std::distance(m_options.begin(), it));
+
+ const QSignalBlocker blocker(this);
+ setCurrentIndex(index);
+}
+
+const std::pair<Config::Location, Config::Location> 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);
+ }
+};