From f2909b447ba0c4f82fec6f0f8ba751fa39a1f5a5 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 15 Aug 2021 14:28:48 +1000 Subject: [PATCH] Qt: Split icon theme and style init --- src/duckstation-qt/mainwindow.cpp | 43 ++++++++++++++++--------------- src/duckstation-qt/mainwindow.h | 3 ++- src/duckstation-qt/mainwindow.ui | 4 +-- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index d44043bcc..f47583221 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -89,12 +89,12 @@ MainWindow::~MainWindow() void MainWindow::initializeAndShow() { + setIconThemeFromSettings(); + m_ui.setupUi(this); + setStyleFromSettings(); setupAdditionalUi(); connectSignals(); - setThemeFromSettings(); - - resize(800, 700); restoreStateFromConfig(); switchToGameListView(); @@ -1304,16 +1304,16 @@ void MainWindow::addThemeToMenu(const QString& name, const QString& key) void MainWindow::setTheme(const QString& theme) { m_host_interface->SetStringSettingValue("UI", "Theme", theme.toUtf8().constData()); - setThemeFromSettings(); + setStyleFromSettings(); + setIconThemeFromSettings(); updateMenuSelectedTheme(); } -void MainWindow::setThemeFromSettings() +void MainWindow::setStyleFromSettings() { - QString theme = QString::fromStdString(m_host_interface->GetStringSettingValue("UI", "Theme", DEFAULT_THEME_NAME)); - QString icon_theme; + const std::string theme(m_host_interface->GetStringSettingValue("UI", "Theme", DEFAULT_THEME_NAME)); - if (theme == QStringLiteral("qdarkstyle")) + if (theme == "qdarkstyle") { qApp->setStyle(m_unthemed_style_name); qApp->setPalette(QApplication::style()->standardPalette()); @@ -1321,18 +1321,14 @@ void MainWindow::setThemeFromSettings() QFile f(QStringLiteral(":qdarkstyle/style.qss")); if (f.open(QFile::ReadOnly | QFile::Text)) qApp->setStyleSheet(f.readAll()); - - icon_theme = QStringLiteral("white"); } - else if (theme == QStringLiteral("fusion")) + else if (theme == "fusion") { qApp->setPalette(QApplication::style()->standardPalette()); qApp->setStyleSheet(QString()); qApp->setStyle(QStyleFactory::create("Fusion")); - - icon_theme = QStringLiteral("black"); } - else if (theme == QStringLiteral("darkfusion")) + else if (theme == "darkfusion") { // adapted from https://gist.github.com/QuantumCD/6245215 qApp->setStyle(QStyleFactory::create("Fusion")); @@ -1366,10 +1362,8 @@ void MainWindow::setThemeFromSettings() qApp->setPalette(darkPalette); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); - - icon_theme = QStringLiteral("white"); } - else if (theme == QStringLiteral("darkfusionblue")) + else if (theme == "darkfusionblue") { // adapted from https://gist.github.com/QuantumCD/6245215 qApp->setStyle(QStyleFactory::create("Fusion")); @@ -1404,17 +1398,24 @@ void MainWindow::setThemeFromSettings() qApp->setPalette(darkPalette); qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 1px solid white; }"); - - icon_theme = QStringLiteral("white"); } else { qApp->setPalette(QApplication::style()->standardPalette()); qApp->setStyleSheet(QString()); qApp->setStyle(m_unthemed_style_name); - - icon_theme = QStringLiteral("black"); } +} + +void MainWindow::setIconThemeFromSettings() +{ + const std::string theme(m_host_interface->GetStringSettingValue("UI", "Theme", DEFAULT_THEME_NAME)); + QString icon_theme; + + if (theme == "qdarkstyle" || theme == "darkfusion" || theme == "darkfusionblue") + icon_theme = QStringLiteral("white"); + else + icon_theme = QStringLiteral("black"); QIcon::setThemeName(icon_theme); } diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index b8a849fa4..389fa72f3 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -125,7 +125,8 @@ private: } void setTheme(const QString& theme); - void setThemeFromSettings(); + void setStyleFromSettings(); + void setIconThemeFromSettings(); void setupAdditionalUi(); void connectSignals(); void addThemeToMenu(const QString& name, const QString& key); diff --git a/src/duckstation-qt/mainwindow.ui b/src/duckstation-qt/mainwindow.ui index ae1fbc735..e6fa7269a 100644 --- a/src/duckstation-qt/mainwindow.ui +++ b/src/duckstation-qt/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 754 - 600 + 800 + 700