Skip to content

Commit

Permalink
Merge pull request #5546 from ligfx/qtdynamicthemes
Browse files Browse the repository at this point in the history
DolphinQt2: live updates to UI theme
  • Loading branch information
shuffle2 committed Jun 6, 2017
2 parents 9994bee + 6b084e2 commit b8f2e24
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 21 deletions.
22 changes: 17 additions & 5 deletions Source/Core/DolphinQt2/Config/SettingsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QListWidget>
#include <QStackedWidget>
#include <QVBoxLayout>

#include "DolphinQt2/Config/SettingsWindow.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/Settings/GeneralPane.h"
#include "DolphinQt2/Settings/InterfacePane.h"
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
20 changes: 8 additions & 12 deletions Source/Core/DolphinQt2/Config/SettingsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

#pragma once

#include <string>

#include <QDialog>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QListView>
#include <QListWidget>
#include <QListWidgetItem>
#include <QStackedWidget>
#include <QString>
#include <QVBoxLayout>
#include <QWidget>

class QGroupBox;
class QListWidget;
class QListWidgetItem;
class QStackedWidget;

class SettingsWindow final : public QDialog
{
Expand All @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions Source/Core/DolphinQt2/GameList/GameListModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "DolphinQt2/GameList/GameListModel.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/Settings.h"

const QSize GAMECUBE_BANNER_SIZE(96, 32);

Expand All @@ -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
Expand Down
12 changes: 10 additions & 2 deletions Source/Core/DolphinQt2/Resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt2/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Resources final

private:
Resources() {}
static void InitThemeIcons();
static QIcon GetIcon(const QString& name, const QString& dir);
static QPixmap GetPixmap(const QString& name, const QString& dir);

Expand Down
6 changes: 6 additions & 0 deletions Source/Core/DolphinQt2/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DolphinQt2/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Settings final : public QSettings, NonCopyable
static Settings& Instance();

// UI
void SetThemeName(const QString& theme_name);
QString GetThemeDir() const;
QString GetResourcesDir() const;
QString GetProfilesDir() const;
Expand Down Expand Up @@ -111,6 +112,7 @@ class Settings final : public QSettings, NonCopyable
void Save();

signals:
void ThemeChanged();
void PathAdded(const QString&);
void PathRemoved(const QString&);
void HideCursorChanged();
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/DolphinQt2/Settings/InterfacePane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void (QComboBox::*)(const QString&)>(&QComboBox::activated),
[this](const QString& text) { OnSaveConfig(); });
&Settings::Instance(), &Settings::SetThemeName);
connect(m_combobox_language, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated),
[this](int index) { OnSaveConfig(); });
connect(m_checkbox_confirm_on_stop, &QCheckBox::clicked, this, &InterfacePane::OnSaveConfig);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt2/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ToolBar::ToolBar(QWidget* parent) : QToolBar(parent)
setIconSize(ICON_SIZE);

MakeActions();
connect(&Settings::Instance(), &Settings::ThemeChanged, this, &ToolBar::UpdateIcons);
UpdateIcons();

EmulationStopped();
Expand Down

0 comments on commit b8f2e24

Please sign in to comment.