From 5a4ee87d6a271a24200d7b599fbdb019cd45ac04 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 31 May 2017 16:15:48 -0700 Subject: [PATCH 1/5] DolphinQt2: Settings: emit ThemeChanged signal --- Source/Core/DolphinQt2/Settings.cpp | 6 ++++++ Source/Core/DolphinQt2/Settings.h | 2 ++ Source/Core/DolphinQt2/Settings/InterfacePane.cpp | 5 +++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index a1ec7d7b94..cc19bcdd7b 100644 --- a/Source/Core/DolphinQt2/Settings.cpp +++ b/Source/Core/DolphinQt2/Settings.cpp @@ -27,6 +27,12 @@ Settings& Settings::Instance() return settings; } +void Settings::SetThemeName(const QString& theme_name) +{ + SConfig::GetInstance().theme_name = theme_name.toStdString(); + emit ThemeChanged(); +} + QString Settings::GetThemeDir() const { return QString::fromStdString(File::GetThemeDir(SConfig::GetInstance().theme_name)); diff --git a/Source/Core/DolphinQt2/Settings.h b/Source/Core/DolphinQt2/Settings.h index d7f3dae319..47b9a9656f 100644 --- a/Source/Core/DolphinQt2/Settings.h +++ b/Source/Core/DolphinQt2/Settings.h @@ -26,6 +26,7 @@ public: static Settings& Instance(); // UI + void SetThemeName(const QString& theme_name); QString GetThemeDir() const; QString GetResourcesDir() const; QString GetProfilesDir() const; @@ -109,6 +110,7 @@ public: void Save(); signals: + void ThemeChanged(); void PathAdded(const QString&); void PathRemoved(const QString&); diff --git a/Source/Core/DolphinQt2/Settings/InterfacePane.cpp b/Source/Core/DolphinQt2/Settings/InterfacePane.cpp index fd404fb83c..b6d4bd11f1 100644 --- a/Source/Core/DolphinQt2/Settings/InterfacePane.cpp +++ b/Source/Core/DolphinQt2/Settings/InterfacePane.cpp @@ -17,6 +17,8 @@ #include "Common/StringUtil.h" #include "Core/ConfigManager.h" +#include "DolphinQt2/Settings.h" + InterfacePane::InterfacePane(QWidget* parent) : QWidget(parent) { CreateLayout(); @@ -106,7 +108,7 @@ void InterfacePane::ConnectLayout() connect(m_checkbox_top_window, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig); connect(m_checkbox_render_to_window, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig); connect(m_combobox_theme, static_cast(&QComboBox::activated), - [this](const QString& text) { OnSaveConfig(); }); + &Settings::Instance(), &Settings::SetThemeName); connect(m_combobox_language, static_cast(&QComboBox::activated), [this](int index) { OnSaveConfig(); }); connect(m_checkbox_confirm_on_stop, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig); @@ -140,7 +142,6 @@ void InterfacePane::OnSaveConfig() settings.bRenderWindowAutoSize = m_checkbox_auto_window->isChecked(); settings.bKeepWindowOnTop = m_checkbox_top_window->isChecked(); settings.bRenderToMain = m_checkbox_render_to_window->isChecked(); - settings.theme_name = m_combobox_theme->currentText().toStdString(); // In Game Options settings.bConfirmStop = m_checkbox_confirm_on_stop->isChecked(); From 9bdbd02efc5ed0800739801e697dc21da54a1ed1 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 31 May 2017 16:49:32 -0700 Subject: [PATCH 2/5] GameListModel: update icons when theme changes --- Source/Core/DolphinQt2/GameList/GameListModel.cpp | 8 ++++++++ Source/Core/DolphinQt2/Resources.cpp | 12 ++++++++++-- Source/Core/DolphinQt2/Resources.h | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt2/GameList/GameListModel.cpp b/Source/Core/DolphinQt2/GameList/GameListModel.cpp index ad2a291908..07f23c1b94 100644 --- a/Source/Core/DolphinQt2/GameList/GameListModel.cpp +++ b/Source/Core/DolphinQt2/GameList/GameListModel.cpp @@ -4,6 +4,7 @@ #include "DolphinQt2/GameList/GameListModel.h" #include "DolphinQt2/Resources.h" +#include "DolphinQt2/Settings.h" const QSize GAMECUBE_BANNER_SIZE(96, 32); @@ -13,6 +14,13 @@ GameListModel::GameListModel(QObject* parent) : QAbstractTableModel(parent) connect(&m_tracker, &GameTracker::GameRemoved, this, &GameListModel::RemoveGame); connect(this, &GameListModel::DirectoryAdded, &m_tracker, &GameTracker::AddDirectory); connect(this, &GameListModel::DirectoryRemoved, &m_tracker, &GameTracker::RemoveDirectory); + + connect(&Settings::Instance(), &Settings::ThemeChanged, [this] { + // Tell the view to repaint. The signal 'dataChanged' also seems like it would work here, but + // unfortunately it won't cause a repaint until the view is focused. + emit layoutAboutToBeChanged(); + emit layoutChanged(); + }); } QVariant GameListModel::data(const QModelIndex& index, int role) const diff --git a/Source/Core/DolphinQt2/Resources.cpp b/Source/Core/DolphinQt2/Resources.cpp index 69b1b22515..d0435fe74b 100644 --- a/Source/Core/DolphinQt2/Resources.cpp +++ b/Source/Core/DolphinQt2/Resources.cpp @@ -82,12 +82,20 @@ void Resources::Init() { m_countries.append(GetScaledPixmap(country)); } - for (int stars = 0; stars <= 5; stars++) - m_ratings.append(GetScaledThemePixmap("rating" + std::to_string(stars))); m_misc.append(GetScaledPixmap("nobanner")); m_misc.append(GetScaledPixmap("dolphin_logo")); m_misc.append(GetScaledPixmap("Dolphin")); + + QObject::connect(&Settings::Instance(), &Settings::ThemeChanged, Resources::InitThemeIcons); + InitThemeIcons(); +} + +void Resources::InitThemeIcons() +{ + m_ratings = {GetScaledThemePixmap("rating0"), GetScaledThemePixmap("rating1"), + GetScaledThemePixmap("rating2"), GetScaledThemePixmap("rating3"), + GetScaledThemePixmap("rating4"), GetScaledThemePixmap("rating5")}; } QPixmap Resources::GetPlatform(int platform) diff --git a/Source/Core/DolphinQt2/Resources.h b/Source/Core/DolphinQt2/Resources.h index 3a9027e3f4..0d2909441b 100644 --- a/Source/Core/DolphinQt2/Resources.h +++ b/Source/Core/DolphinQt2/Resources.h @@ -33,6 +33,7 @@ public: private: Resources() {} + static void InitThemeIcons(); static QIcon GetIcon(const QString& name, const QString& dir); static QPixmap GetPixmap(const QString& name, const QString& dir); From 4be07b4eb2a43a14a0126fb4c70b78c95f882039 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 31 May 2017 16:49:47 -0700 Subject: [PATCH 3/5] ToolBar: update icons when theme changes --- Source/Core/DolphinQt2/ToolBar.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/DolphinQt2/ToolBar.cpp b/Source/Core/DolphinQt2/ToolBar.cpp index d1e075e500..0cea6f151f 100644 --- a/Source/Core/DolphinQt2/ToolBar.cpp +++ b/Source/Core/DolphinQt2/ToolBar.cpp @@ -18,6 +18,7 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent) setIconSize(ICON_SIZE); MakeActions(); + connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons); UpdateIcons(); EmulationStopped(); From d6db5151655f42298c1c9a8587489954e718a22f Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 31 May 2017 16:53:46 -0700 Subject: [PATCH 4/5] SettingsWindow: cleanup includes --- Source/Core/DolphinQt2/Config/SettingsWindow.cpp | 8 ++++++++ Source/Core/DolphinQt2/Config/SettingsWindow.h | 16 +++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp index 7993925d25..8cfc1d0d5c 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp @@ -2,6 +2,14 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include +#include +#include +#include +#include +#include +#include + #include "DolphinQt2/Config/SettingsWindow.h" #include "DolphinQt2/Settings.h" #include "DolphinQt2/Settings/GeneralPane.h" diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.h b/Source/Core/DolphinQt2/Config/SettingsWindow.h index 6187ba5ab8..00c1c227c1 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.h +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.h @@ -5,17 +5,11 @@ #pragma once #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + +class QGroupBox; +class QListWidget; +class QListWidgetItem; +class QStackedWidget; class SettingsWindow final : public QDialog { From 6b084e21dc5aa25f8e5cea5bc54e477dd0b4a561 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Mon, 5 Jun 2017 00:15:15 -0700 Subject: [PATCH 5/5] SettingsWindow: update icons when theme changes --- Source/Core/DolphinQt2/Config/SettingsWindow.cpp | 14 +++++++++----- Source/Core/DolphinQt2/Config/SettingsWindow.h | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp index 8cfc1d0d5c..eb906c9ed7 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp @@ -11,6 +11,7 @@ #include #include "DolphinQt2/Config/SettingsWindow.h" +#include "DolphinQt2/Resources.h" #include "DolphinQt2/Settings.h" #include "DolphinQt2/Settings/GeneralPane.h" #include "DolphinQt2/Settings/InterfacePane.h" @@ -75,15 +76,18 @@ void SettingsWindow::MakeUnfinishedWarning() m_warning_group->setLayout(m_warning_group_layout); } -void SettingsWindow::AddCategoryToList(const QString& title, const QString& icon) +void SettingsWindow::AddCategoryToList(const QString& title, const std::string& icon_name) { QString dir = Settings::Instance().GetThemeDir(); QListWidgetItem* button = new QListWidgetItem(); - button->setIcon(QIcon(dir.append(icon))); button->setText(title); button->setTextAlignment(Qt::AlignVCenter); button->setSizeHint(QSize(28, 28)); button->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled); + + auto set_icon = [=] { button->setIcon(Resources::GetScaledThemeIcon(icon_name)); }; + QObject::connect(&Settings::Instance(), &Settings::ThemeChanged, set_icon); + set_icon(); m_categories->addItem(button); } @@ -95,9 +99,9 @@ void SettingsWindow::MakeCategoryList() m_categories->setMovement(QListView::Static); m_categories->setSpacing(0); - AddCategoryToList(tr("General"), QStringLiteral("config.png")); - AddCategoryToList(tr("Interface"), QStringLiteral("browse.png")); - AddCategoryToList(tr("Paths"), QStringLiteral("browse.png")); + AddCategoryToList(tr("General"), "config"); + AddCategoryToList(tr("Interface"), "browse"); + AddCategoryToList(tr("Paths"), "browse"); connect(m_categories, &QListWidget::currentItemChanged, this, &SettingsWindow::changePage); } diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.h b/Source/Core/DolphinQt2/Config/SettingsWindow.h index 00c1c227c1..d83400791b 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.h +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.h @@ -4,6 +4,8 @@ #pragma once +#include + #include class QGroupBox; @@ -23,7 +25,7 @@ public slots: private: void MakeCategoryList(); void MakeUnfinishedWarning(); - void AddCategoryToList(const QString& title, const QString& icon); + void AddCategoryToList(const QString& title, const std::string& icon_name); void SetupSettingsWidget(); QStackedWidget* m_settings_outer; QListWidget* m_categories;