diff --git a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp index 7993925d25..eb906c9ed7 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.cpp +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.cpp @@ -2,7 +2,16 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include +#include +#include +#include +#include +#include +#include + #include "DolphinQt2/Config/SettingsWindow.h" +#include "DolphinQt2/Resources.h" #include "DolphinQt2/Settings.h" #include "DolphinQt2/Settings/GeneralPane.h" #include "DolphinQt2/Settings/InterfacePane.h" @@ -67,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); } @@ -87,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 6187ba5ab8..d83400791b 100644 --- a/Source/Core/DolphinQt2/Config/SettingsWindow.h +++ b/Source/Core/DolphinQt2/Config/SettingsWindow.h @@ -4,18 +4,14 @@ #pragma once +#include + #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 { @@ -29,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; 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); diff --git a/Source/Core/DolphinQt2/Settings.cpp b/Source/Core/DolphinQt2/Settings.cpp index 824c001b59..346b802237 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 8a8e79196a..d7ee40246b 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; @@ -111,6 +112,7 @@ public: void Save(); signals: + void ThemeChanged(); void PathAdded(const QString&); void PathRemoved(const QString&); void HideCursorChanged(); diff --git a/Source/Core/DolphinQt2/Settings/InterfacePane.cpp b/Source/Core/DolphinQt2/Settings/InterfacePane.cpp index 20f4e8dd1a..b34f66f1f6 100644 --- a/Source/Core/DolphinQt2/Settings/InterfacePane.cpp +++ b/Source/Core/DolphinQt2/Settings/InterfacePane.cpp @@ -108,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); @@ -143,7 +143,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(); 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();