From 9bdbd02efc5ed0800739801e697dc21da54a1ed1 Mon Sep 17 00:00:00 2001 From: Michael Maltese Date: Wed, 31 May 2017 16:49:32 -0700 Subject: [PATCH] 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);