From 55aaa323ec6c42b065009eb5e272946372177070 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Sat, 4 Nov 2023 15:33:19 -0700 Subject: [PATCH] InterfacePane: Add BalloonTip to theme combobox --- .../Config/ConfigControls/ConfigChoice.cpp | 36 +++++++++++++++++++ .../Config/ConfigControls/ConfigChoice.h | 18 ++++++++++ Source/Core/DolphinQt/Settings.cpp | 3 +- Source/Core/DolphinQt/Settings.h | 2 +- .../Core/DolphinQt/Settings/InterfacePane.cpp | 34 +++++++++--------- .../Core/DolphinQt/Settings/InterfacePane.h | 3 +- 6 files changed, 76 insertions(+), 20 deletions(-) diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp index 205fd25898..060678f161 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.cpp @@ -30,3 +30,39 @@ void ConfigChoice::Update(int choice) { Config::SetBaseOrCurrent(m_setting, choice); } + +ConfigStringChoice::ConfigStringChoice(const std::vector& options, + const Config::Info& setting) + : m_setting(setting) +{ + for (const auto& op : options) + addItem(QString::fromStdString(op)); + + 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); +} + +void ConfigStringChoice::Update(int index) +{ + Config::SetBaseOrCurrent(m_setting, itemText(index).toStdString()); +} + +void ConfigStringChoice::Load() +{ + const QSignalBlocker blocker(this); + setCurrentIndex(findText(QString::fromStdString(Config::Get(m_setting)))); +} diff --git a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h index 04d619ac4e..548ff515c9 100644 --- a/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h +++ b/Source/Core/DolphinQt/Config/ConfigControls/ConfigChoice.h @@ -3,6 +3,9 @@ #pragma once +#include +#include + #include "DolphinQt/Config/ToolTipControls/ToolTipComboBox.h" #include "Common/Config/Config.h" @@ -18,3 +21,18 @@ private: Config::Info m_setting; }; + +class ConfigStringChoice : public ToolTipComboBox +{ + Q_OBJECT +public: + ConfigStringChoice(const std::vector& options, + const Config::Info& setting); + +private: + void Connect(); + void Update(int index); + void Load(); + + Config::Info m_setting; +}; diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index fca24370b7..2afb243855 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -118,9 +118,8 @@ QSettings& Settings::GetQSettings() return settings; } -void Settings::SetThemeName(const QString& theme_name) +void Settings::TriggerThemeChanged() { - Config::SetBaseOrCurrent(Config::MAIN_THEME_NAME, theme_name.toStdString()); emit ThemeChanged(); } diff --git a/Source/Core/DolphinQt/Settings.h b/Source/Core/DolphinQt/Settings.h index 27325b141b..0f9519163a 100644 --- a/Source/Core/DolphinQt/Settings.h +++ b/Source/Core/DolphinQt/Settings.h @@ -51,7 +51,7 @@ public: static QSettings& GetQSettings(); // UI - void SetThemeName(const QString& theme_name); + void TriggerThemeChanged(); void InitDefaultPalette(); void UpdateSystemDark(); void SetSystemDark(bool dark); diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.cpp b/Source/Core/DolphinQt/Settings/InterfacePane.cpp index 50f1bb80bd..14b61ad56a 100644 --- a/Source/Core/DolphinQt/Settings/InterfacePane.cpp +++ b/Source/Core/DolphinQt/Settings/InterfacePane.cpp @@ -24,6 +24,7 @@ #include "Core/Config/UISettings.h" #include "DolphinQt/Config/ConfigControls/ConfigBool.h" +#include "DolphinQt/Config/ConfigControls/ConfigChoice.h" #include "DolphinQt/Config/ToolTipControls/ToolTipCheckBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/SignalBlocking.h" @@ -120,18 +121,17 @@ void InterfacePane::CreateUI() m_combobox_language = MakeLanguageComboBox(); combobox_layout->addRow(tr("&Language:"), m_combobox_language); - // Theme Combobox - m_combobox_theme = new QComboBox; - combobox_layout->addRow(tr("&Theme:"), m_combobox_theme); - // List avalable themes - auto theme_search_results = + auto theme_paths = Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR}); - for (const std::string& path : theme_search_results) - { - const QString qt_name = QString::fromStdString(PathToFileName(path)); - m_combobox_theme->addItem(qt_name); - } + std::vector theme_names; + theme_names.reserve(theme_paths.size()); + std::transform(theme_paths.cbegin(), theme_paths.cend(), std::back_inserter(theme_names), + PathToFileName); + + // Theme Combobox + m_combobox_theme = new ConfigStringChoice(theme_names, Config::MAIN_THEME_NAME); + combobox_layout->addRow(tr("&Theme:"), m_combobox_theme); // User Style Combobox m_combobox_userstyle = new QComboBox; @@ -229,9 +229,8 @@ void InterfacePane::ConnectLayout() connect(m_checkbox_disable_screensaver, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig); connect(m_checkbox_show_debugging_ui, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig); connect(m_checkbox_focused_hotkeys, &QCheckBox::toggled, this, &InterfacePane::OnSaveConfig); - connect(m_combobox_theme, &QComboBox::currentIndexChanged, this, [this](int index) { - Settings::Instance().SetThemeName(m_combobox_theme->itemText(index)); - }); + connect(m_combobox_theme, &QComboBox::currentIndexChanged, this, + [this](int index) { Settings::Instance().TriggerThemeChanged(); }); connect(m_combobox_userstyle, &QComboBox::currentIndexChanged, this, &InterfacePane::OnSaveConfig); connect(m_combobox_language, &QComboBox::currentIndexChanged, this, &InterfacePane::OnSaveConfig); @@ -273,9 +272,6 @@ void InterfacePane::LoadConfig() SignalBlocking(m_combobox_language) ->setCurrentIndex(m_combobox_language->findData( QString::fromStdString(Config::Get(Config::MAIN_INTERFACE_LANGUAGE)))); - SignalBlocking(m_combobox_theme) - ->setCurrentIndex( - m_combobox_theme->findText(QString::fromStdString(Config::Get(Config::MAIN_THEME_NAME)))); const Settings::StyleType style_type = Settings::Instance().GetStyleType(); const QString userstyle = Settings::Instance().GetUserStyleName(); @@ -375,6 +371,12 @@ void InterfacePane::AddDescriptions() static constexpr char TR_TITLE_DATABASE_DESCRIPTION[] = QT_TR_NOOP( "Uses Dolphin's database of properly formatted names in the Game List Title column." "

If unsure, leave this checked."); + static constexpr char TR_THEME_DESCRIPTION[] = + QT_TR_NOOP("Changes the appearance and color of Dolphin's buttons." + "

If unsure, select Clean."); m_checkbox_use_builtin_title_database->SetDescription(tr(TR_TITLE_DATABASE_DESCRIPTION)); + + m_combobox_theme->SetTitle(tr("Theme")); + m_combobox_theme->SetDescription(tr(TR_THEME_DESCRIPTION)); } diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.h b/Source/Core/DolphinQt/Settings/InterfacePane.h index ece9406bd0..8363c56800 100644 --- a/Source/Core/DolphinQt/Settings/InterfacePane.h +++ b/Source/Core/DolphinQt/Settings/InterfacePane.h @@ -6,6 +6,7 @@ #include class ConfigBool; +class ConfigStringChoice; class QCheckBox; class QComboBox; class QLabel; @@ -34,7 +35,7 @@ private: QVBoxLayout* m_main_layout; QComboBox* m_combobox_language; - QComboBox* m_combobox_theme; + ConfigStringChoice* m_combobox_theme; QComboBox* m_combobox_userstyle; QLabel* m_label_userstyle; QCheckBox* m_checkbox_top_window;