From 6f9e8efee54e25a57cc17d41bc9ccc10aff6a001 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 18 Aug 2024 13:22:58 +1000 Subject: [PATCH] Qt: Fix a couple of theme switching glitches --- src/duckstation-qt/CMakeLists.txt | 1 + src/duckstation-qt/duckstation-qt.vcxproj | 1 + .../duckstation-qt.vcxproj.filters | 1 + src/duckstation-qt/mainwindow.cpp | 261 +--------------- src/duckstation-qt/mainwindow.h | 6 - src/duckstation-qt/qthost.cpp | 2 +- src/duckstation-qt/qthost.h | 15 + src/duckstation-qt/qtthemes.cpp | 291 ++++++++++++++++++ src/duckstation-qt/setupwizarddialog.cpp | 6 +- src/duckstation-qt/setupwizarddialog.h | 1 + src/duckstation-qt/setupwizarddialog.ui | 2 +- 11 files changed, 319 insertions(+), 268 deletions(-) create mode 100644 src/duckstation-qt/qtthemes.cpp diff --git a/src/duckstation-qt/CMakeLists.txt b/src/duckstation-qt/CMakeLists.txt index 2e3ae8724..f50e31514 100644 --- a/src/duckstation-qt/CMakeLists.txt +++ b/src/duckstation-qt/CMakeLists.txt @@ -130,6 +130,7 @@ set(SRCS qtkeycodes.cpp qtprogresscallback.cpp qtprogresscallback.h + qtthemes.cpp qttranslations.cpp qtutils.cpp qtutils.h diff --git a/src/duckstation-qt/duckstation-qt.vcxproj b/src/duckstation-qt/duckstation-qt.vcxproj index 6e1d5a3f7..af91a4dd4 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj +++ b/src/duckstation-qt/duckstation-qt.vcxproj @@ -43,6 +43,7 @@ Create + diff --git a/src/duckstation-qt/duckstation-qt.vcxproj.filters b/src/duckstation-qt/duckstation-qt.vcxproj.filters index 5c9708a41..3f57a9749 100644 --- a/src/duckstation-qt/duckstation-qt.vcxproj.filters +++ b/src/duckstation-qt/duckstation-qt.vcxproj.filters @@ -178,6 +178,7 @@ moc + diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index eac232cc1..2c3c0442d 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -73,8 +73,6 @@ static constexpr char DISC_IMAGE_FILTER[] = QT_TRANSLATE_NOOP( "*.psexe *.ps-exe);;Portable Sound Format Files (*.psf *.minipsf);;Playlists (*.m3u)"); MainWindow* g_main_window = nullptr; -static QString s_unthemed_style_name; -static bool s_unthemed_style_name_set; #if defined(_WIN32) || defined(__APPLE__) static const bool s_use_central_widget = false; @@ -149,18 +147,6 @@ MainWindow::~MainWindow() #endif } -void MainWindow::updateApplicationTheme() -{ - if (!s_unthemed_style_name_set) - { - s_unthemed_style_name_set = true; - s_unthemed_style_name = QApplication::style()->objectName(); - } - - setStyleFromSettings(); - setIconThemeFromSettings(); -} - void MainWindow::initialize() { m_ui.setupUi(this); @@ -2241,7 +2227,7 @@ void MainWindow::setTheme(const QString& theme) void MainWindow::updateTheme() { - updateApplicationTheme(); + QtHost::UpdateApplicationTheme(); updateMenuSelectedTheme(); reloadThemeSpecificImages(); } @@ -2251,249 +2237,6 @@ void MainWindow::reloadThemeSpecificImages() m_game_list_widget->reloadThemeSpecificImages(); } -void MainWindow::setStyleFromSettings() -{ - const std::string theme(Host::GetBaseStringSettingValue("UI", "Theme", InterfaceSettingsWidget::DEFAULT_THEME_NAME)); - - // setPalette() shouldn't be necessary, as the documentation claims that setStyle() resets the palette, but it - // is here, to work around a bug in 6.4.x and 6.5.x where the palette doesn't restore after changing themes. - qApp->setPalette(QPalette()); - - if (theme == "qdarkstyle") - { - qApp->setStyle(s_unthemed_style_name); - qApp->setStyleSheet(QString()); - - QFile f(QStringLiteral(":qdarkstyle/style.qss")); - if (f.open(QFile::ReadOnly | QFile::Text)) - qApp->setStyleSheet(f.readAll()); - } - else if (theme == "fusion") - { - qApp->setStyle(QStyleFactory::create("Fusion")); - qApp->setStyleSheet(QString()); - } - else if (theme == "darkfusion") - { - // adapted from https://gist.github.com/QuantumCD/6245215 - qApp->setStyle(QStyleFactory::create("Fusion")); - - const QColor lighterGray(75, 75, 75); - const QColor darkGray(53, 53, 53); - const QColor gray(128, 128, 128); - const QColor black(25, 25, 25); - const QColor blue(198, 238, 255); - - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, darkGray); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, black); - darkPalette.setColor(QPalette::AlternateBase, darkGray); - darkPalette.setColor(QPalette::ToolTipBase, darkGray); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, darkGray); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Link, blue); - darkPalette.setColor(QPalette::Highlight, lighterGray); - darkPalette.setColor(QPalette::HighlightedText, Qt::white); - darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); - - darkPalette.setColor(QPalette::Active, QPalette::Button, gray.darker()); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); - - qApp->setPalette(darkPalette); - } - else if (theme == "darkfusionblue") - { - // adapted from https://gist.github.com/QuantumCD/6245215 - qApp->setStyle(QStyleFactory::create("Fusion")); - - // const QColor lighterGray(75, 75, 75); - const QColor darkGray(53, 53, 53); - const QColor gray(128, 128, 128); - const QColor black(25, 25, 25); - const QColor blue(198, 238, 255); - const QColor blue2(0, 88, 208); - - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, darkGray); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, black); - darkPalette.setColor(QPalette::AlternateBase, darkGray); - darkPalette.setColor(QPalette::ToolTipBase, blue2); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, darkGray); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Link, blue); - darkPalette.setColor(QPalette::Highlight, blue2); - darkPalette.setColor(QPalette::HighlightedText, Qt::white); - darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); - - darkPalette.setColor(QPalette::Active, QPalette::Button, gray.darker()); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); - - qApp->setPalette(darkPalette); - } - else if (theme == "cobaltsky") - { - // Custom palette by KamFretoZ, A soothing deep royal blue - // that are meant to be easy on the eyes as the main color. - // Alternative dark theme. - qApp->setStyle(QStyleFactory::create("Fusion")); - - const QColor gray(150, 150, 150); - const QColor royalBlue(29, 41, 81); - const QColor darkishBlue(17, 30, 108); - const QColor lighterBlue(25, 32, 130); - const QColor highlight(36, 93, 218); - const QColor link(0, 202, 255); - - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, royalBlue); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, royalBlue.lighter()); - darkPalette.setColor(QPalette::AlternateBase, darkishBlue); - darkPalette.setColor(QPalette::ToolTipBase, darkishBlue); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, lighterBlue); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Link, link); - darkPalette.setColor(QPalette::Highlight, highlight); - darkPalette.setColor(QPalette::HighlightedText, Qt::white); - - darkPalette.setColor(QPalette::Active, QPalette::Button, lighterBlue); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Light, gray); - - qApp->setPalette(darkPalette); - } - else if (theme == "greymatter") - { - qApp->setStyle(QStyleFactory::create("Fusion")); - - const QColor darkGray(46, 52, 64); - const QColor lighterGray(59, 66, 82); - const QColor gray(111, 111, 111); - const QColor blue(198, 238, 255); - - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, darkGray); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, lighterGray); - darkPalette.setColor(QPalette::AlternateBase, darkGray); - darkPalette.setColor(QPalette::ToolTipBase, darkGray); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, lighterGray); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Link, blue); - darkPalette.setColor(QPalette::Highlight, lighterGray.darker()); - darkPalette.setColor(QPalette::HighlightedText, Qt::white); - darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); - - darkPalette.setColor(QPalette::Active, QPalette::Button, lighterGray); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray.lighter()); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray.lighter()); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray.lighter()); - darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); - - qApp->setPalette(darkPalette); - } - else if (theme == "darkruby") - { - qApp->setStyle(QStyleFactory::create("Fusion")); - - const QColor gray(128, 128, 128); - const QColor slate(18, 18, 18); - const QColor rubyish(172, 21, 31); - - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, slate); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, slate.lighter()); - darkPalette.setColor(QPalette::AlternateBase, slate.lighter()); - darkPalette.setColor(QPalette::ToolTipBase, slate); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, slate); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Link, Qt::white); - darkPalette.setColor(QPalette::Highlight, rubyish); - darkPalette.setColor(QPalette::HighlightedText, Qt::white); - - darkPalette.setColor(QPalette::Active, QPalette::Button, slate); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); - darkPalette.setColor(QPalette::Disabled, QPalette::Light, slate.lighter()); - - qApp->setPalette(darkPalette); - } - else if (theme == "purplerain") - { - qApp->setStyle(QStyleFactory::create("Fusion")); - - const QColor darkPurple(73, 41, 121); - const QColor darkerPurple(53, 29, 87); - const QColor gold(250, 207, 0); - - QPalette darkPalette; - darkPalette.setColor(QPalette::Window, darkPurple); - darkPalette.setColor(QPalette::WindowText, Qt::white); - darkPalette.setColor(QPalette::Base, darkerPurple); - darkPalette.setColor(QPalette::AlternateBase, darkPurple); - darkPalette.setColor(QPalette::ToolTipBase, darkPurple); - darkPalette.setColor(QPalette::ToolTipText, Qt::white); - darkPalette.setColor(QPalette::Text, Qt::white); - darkPalette.setColor(QPalette::Button, darkerPurple); - darkPalette.setColor(QPalette::ButtonText, Qt::white); - darkPalette.setColor(QPalette::Link, gold); - darkPalette.setColor(QPalette::Highlight, gold); - darkPalette.setColor(QPalette::HighlightedText, Qt::black); - darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); - - darkPalette.setColor(QPalette::Active, QPalette::Button, darkerPurple); - darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, darkPurple.lighter()); - darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, darkPurple.lighter()); - darkPalette.setColor(QPalette::Disabled, QPalette::Text, darkPurple.lighter()); - darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkPurple); - - qApp->setPalette(darkPalette); - - qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #505a70; border: 1px solid white; }"); - } -#ifdef _WIN32 - else if (theme == "windowsvista") - { - qApp->setStyle(QStyleFactory::create("windowsvista")); - qApp->setStyleSheet(QString()); - } -#endif - else - { - qApp->setStyle(s_unthemed_style_name); - qApp->setStyleSheet(QString()); - } -} - -void MainWindow::setIconThemeFromSettings() -{ - const QPalette palette(qApp->palette()); - const bool dark = palette.windowText().color().value() > palette.window().color().value(); - QIcon::setThemeName(dark ? QStringLiteral("white") : QStringLiteral("black")); -} - void MainWindow::onSettingsResetToDefault(bool system, bool controller) { if (system && m_settings_window) @@ -2770,7 +2513,7 @@ void MainWindow::changeEvent(QEvent* event) if (event->type() == QEvent::StyleChange) { - setIconThemeFromSettings(); + QtHost::SetIconThemeFromStyle(); reloadThemeSpecificImages(); } diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 252a9c4f9..d42966a39 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -78,9 +78,6 @@ public: explicit MainWindow(); ~MainWindow(); - /// Sets application theme according to settings. - static void updateApplicationTheme(); - /// Performs update check if enabled in settings. void startupUpdateCheck(); @@ -205,9 +202,6 @@ protected: #endif private: - static void setStyleFromSettings(); - static void setIconThemeFromSettings(); - /// Initializes the window. Call once at startup. void initialize(); diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 1781badda..fab3fb24f 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -2555,7 +2555,7 @@ int main(int argc, char* argv[]) AutoUpdaterDialog::cleanupAfterUpdate(); // Set theme before creating any windows. - MainWindow::updateApplicationTheme(); + QtHost::UpdateApplicationTheme(); // Start logging early. LogWindow::updateSettings(); diff --git a/src/duckstation-qt/qthost.h b/src/duckstation-qt/qthost.h index 80730c9de..d03e56497 100644 --- a/src/duckstation-qt/qthost.h +++ b/src/duckstation-qt/qthost.h @@ -250,6 +250,21 @@ private: extern EmuThread* g_emu_thread; namespace QtHost { +/// Default theme name for the platform. +const char* GetDefaultThemeName(); + +/// Default language for the platform. +const char* GetDefaultLanguage(); + +/// Sets application theme according to settings. +void UpdateApplicationTheme(); + +/// Returns true if the application theme is using dark colours. +bool IsDarkApplicationTheme(); + +/// Sets the icon theme, based on the current style (light/dark). +void SetIconThemeFromStyle(); + /// Sets batch mode (exit after game shutdown). bool InBatchMode(); diff --git a/src/duckstation-qt/qtthemes.cpp b/src/duckstation-qt/qtthemes.cpp new file mode 100644 index 000000000..9e5b4f827 --- /dev/null +++ b/src/duckstation-qt/qtthemes.cpp @@ -0,0 +1,291 @@ +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) + +#include "interfacesettingswidget.h" +#include "qthost.h" + +#include "common/path.h" + +#include +#include +#include +#include +#include + +namespace QtHost { +static void SetStyleFromSettings(); +} // namespace QtHost + +static QString s_unthemed_style_name; +static QPalette s_unthemed_palette; +static bool s_unthemed_style_name_set; + +const char* QtHost::GetDefaultThemeName() +{ + return "darkfusion"; +} + +void QtHost::UpdateApplicationTheme() +{ + if (!s_unthemed_style_name_set) + { + s_unthemed_style_name_set = true; + s_unthemed_style_name = QApplication::style()->objectName(); + s_unthemed_palette = QApplication::palette(); + } + + SetStyleFromSettings(); + SetIconThemeFromStyle(); +} + +void QtHost::SetStyleFromSettings() +{ + const std::string theme = Host::GetBaseStringSettingValue("UI", "Theme", InterfaceSettingsWidget::DEFAULT_THEME_NAME); + + // setPalette() shouldn't be necessary, as the documentation claims that setStyle() resets the palette, but it + // is here, to work around a bug in 6.4.x and 6.5.x where the palette doesn't restore after changing themes. + qApp->setPalette(s_unthemed_palette); + + if (theme == "qdarkstyle") + { + qApp->setStyle(s_unthemed_style_name); + qApp->setStyleSheet(QString()); + + QFile f(QStringLiteral(":qdarkstyle/style.qss")); + if (f.open(QFile::ReadOnly | QFile::Text)) + qApp->setStyleSheet(f.readAll()); + } + else if (theme == "fusion") + { + qApp->setStyle(QStyleFactory::create("Fusion")); + qApp->setStyleSheet(QString()); + } + else if (theme == "darkfusion") + { + // adapted from https://gist.github.com/QuantumCD/6245215 + qApp->setStyle(QStyleFactory::create("Fusion")); + qApp->setStyleSheet(QString()); + + const QColor lighterGray(75, 75, 75); + const QColor darkGray(53, 53, 53); + const QColor gray(128, 128, 128); + const QColor black(25, 25, 25); + const QColor blue(198, 238, 255); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, darkGray); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, black); + darkPalette.setColor(QPalette::AlternateBase, darkGray); + darkPalette.setColor(QPalette::ToolTipBase, darkGray); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, darkGray); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Link, blue); + darkPalette.setColor(QPalette::Highlight, lighterGray); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); + + darkPalette.setColor(QPalette::Active, QPalette::Button, darkGray); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); + + qApp->setPalette(darkPalette); + } + else if (theme == "darkfusionblue") + { + // adapted from https://gist.github.com/QuantumCD/6245215 + qApp->setStyle(QStyleFactory::create("Fusion")); + qApp->setStyleSheet(QString()); + + // const QColor lighterGray(75, 75, 75); + const QColor darkGray(53, 53, 53); + const QColor gray(128, 128, 128); + const QColor black(25, 25, 25); + const QColor blue(198, 238, 255); + const QColor blue2(0, 88, 208); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, darkGray); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, black); + darkPalette.setColor(QPalette::AlternateBase, darkGray); + darkPalette.setColor(QPalette::ToolTipBase, blue2); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, darkGray); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Link, blue); + darkPalette.setColor(QPalette::Highlight, blue2); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); + + darkPalette.setColor(QPalette::Active, QPalette::Button, gray.darker()); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); + + qApp->setPalette(darkPalette); + } + else if (theme == "cobaltsky") + { + // Custom palette by KamFretoZ, A soothing deep royal blue + // that are meant to be easy on the eyes as the main color. + // Alternative dark theme. + qApp->setStyle(QStyleFactory::create("Fusion")); + qApp->setStyleSheet(QString()); + + const QColor gray(150, 150, 150); + const QColor royalBlue(29, 41, 81); + const QColor darkishBlue(17, 30, 108); + const QColor lighterBlue(25, 32, 130); + const QColor highlight(36, 93, 218); + const QColor link(0, 202, 255); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, royalBlue); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, royalBlue.lighter()); + darkPalette.setColor(QPalette::AlternateBase, darkishBlue); + darkPalette.setColor(QPalette::ToolTipBase, darkishBlue); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, lighterBlue); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Link, link); + darkPalette.setColor(QPalette::Highlight, highlight); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + + darkPalette.setColor(QPalette::Active, QPalette::Button, lighterBlue); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Light, gray); + + qApp->setPalette(darkPalette); + } + else if (theme == "greymatter") + { + qApp->setStyle(QStyleFactory::create("Fusion")); + qApp->setStyleSheet(QString()); + + const QColor darkGray(46, 52, 64); + const QColor lighterGray(59, 66, 82); + const QColor gray(111, 111, 111); + const QColor blue(198, 238, 255); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, darkGray); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, lighterGray); + darkPalette.setColor(QPalette::AlternateBase, darkGray); + darkPalette.setColor(QPalette::ToolTipBase, darkGray); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, lighterGray); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Link, blue); + darkPalette.setColor(QPalette::Highlight, lighterGray.darker()); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); + + darkPalette.setColor(QPalette::Active, QPalette::Button, lighterGray); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray.lighter()); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray.lighter()); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray.lighter()); + darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkGray); + + qApp->setPalette(darkPalette); + } + else if (theme == "darkruby") + { + qApp->setStyle(QStyleFactory::create("Fusion")); + qApp->setStyleSheet(QString()); + + const QColor gray(128, 128, 128); + const QColor slate(18, 18, 18); + const QColor rubyish(172, 21, 31); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, slate); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, slate.lighter()); + darkPalette.setColor(QPalette::AlternateBase, slate.lighter()); + darkPalette.setColor(QPalette::ToolTipBase, slate); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, slate); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Link, Qt::white); + darkPalette.setColor(QPalette::Highlight, rubyish); + darkPalette.setColor(QPalette::HighlightedText, Qt::white); + + darkPalette.setColor(QPalette::Active, QPalette::Button, slate); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray); + darkPalette.setColor(QPalette::Disabled, QPalette::Light, slate.lighter()); + + qApp->setPalette(darkPalette); + } + else if (theme == "purplerain") + { + qApp->setStyle(QStyleFactory::create("Fusion")); + qApp->setStyleSheet("QToolTip { color: #ffffff; background-color: #505a70; border: 1px solid white; }"); + + const QColor darkPurple(73, 41, 121); + const QColor darkerPurple(53, 29, 87); + const QColor gold(250, 207, 0); + + QPalette darkPalette; + darkPalette.setColor(QPalette::Window, darkPurple); + darkPalette.setColor(QPalette::WindowText, Qt::white); + darkPalette.setColor(QPalette::Base, darkerPurple); + darkPalette.setColor(QPalette::AlternateBase, darkPurple); + darkPalette.setColor(QPalette::ToolTipBase, darkPurple); + darkPalette.setColor(QPalette::ToolTipText, Qt::white); + darkPalette.setColor(QPalette::Text, Qt::white); + darkPalette.setColor(QPalette::Button, darkerPurple); + darkPalette.setColor(QPalette::ButtonText, Qt::white); + darkPalette.setColor(QPalette::Link, gold); + darkPalette.setColor(QPalette::Highlight, gold); + darkPalette.setColor(QPalette::HighlightedText, Qt::black); + darkPalette.setColor(QPalette::PlaceholderText, QColor(Qt::white).darker()); + + darkPalette.setColor(QPalette::Active, QPalette::Button, darkerPurple); + darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, darkPurple.lighter()); + darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, darkPurple.lighter()); + darkPalette.setColor(QPalette::Disabled, QPalette::Text, darkPurple.lighter()); + darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkPurple); + + qApp->setPalette(darkPalette); + } +#ifdef _WIN32 + else if (theme == "windowsvista") + { + qApp->setStyle(QStyleFactory::create("windowsvista")); + qApp->setStyleSheet(QString()); + } +#endif + else + { + qApp->setStyle(s_unthemed_style_name); + qApp->setStyleSheet(QString()); + } +} + +bool QtHost::IsDarkApplicationTheme() +{ + QPalette palette = qApp->palette(); + return (palette.windowText().color().value() > palette.window().color().value()); +} + +void QtHost::SetIconThemeFromStyle() +{ + const bool dark = IsDarkApplicationTheme(); + QIcon::setThemeName(dark ? QStringLiteral("white") : QStringLiteral("black")); +} diff --git a/src/duckstation-qt/setupwizarddialog.cpp b/src/duckstation-qt/setupwizarddialog.cpp index 9c210ea11..95cc1ccf6 100644 --- a/src/duckstation-qt/setupwizarddialog.cpp +++ b/src/duckstation-qt/setupwizarddialog.cpp @@ -198,7 +198,7 @@ void SetupWizardDialog::setupLanguagePage() void SetupWizardDialog::themeChanged() { // Main window gets recreated at the end here anyway, so it's fine to just yolo it. - MainWindow::updateApplicationTheme(); + QtHost::UpdateApplicationTheme(); } void SetupWizardDialog::languageChanged() @@ -441,6 +441,10 @@ void SetupWizardDialog::setupControllerPage(bool initial) } } +void SetupWizardDialog::updateStylesheets() +{ +} + void SetupWizardDialog::openAutomaticMappingMenu(u32 port, QLabel* update_label) { QMenu menu(this); diff --git a/src/duckstation-qt/setupwizarddialog.h b/src/duckstation-qt/setupwizarddialog.h index eead20f2a..ad5bad941 100644 --- a/src/duckstation-qt/setupwizarddialog.h +++ b/src/duckstation-qt/setupwizarddialog.h @@ -68,6 +68,7 @@ private: void setupBIOSPage(); void setupGameListPage(); void setupControllerPage(bool initial); + void updateStylesheets(); void pageChangedTo(int page); void updatePageLabels(int prev_page); diff --git a/src/duckstation-qt/setupwizarddialog.ui b/src/duckstation-qt/setupwizarddialog.ui index 0208178da..780c844f2 100644 --- a/src/duckstation-qt/setupwizarddialog.ui +++ b/src/duckstation-qt/setupwizarddialog.ui @@ -45,7 +45,7 @@ 0 - + <html><head/><body><h1 style=" margin-top:18px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:xx-large; font-weight:700;">Welcome to DuckStation!</span></h1><p>This wizard will help guide you through the configuration steps required to use the application. It is recommended if this is your first time installing DuckStation that you view the setup guide at <a href="https://github.com/stenzek/duckstation#downloading-and-running"><span style=" text-decoration: underline; color:#0000ff;">https://github.com/stenzek/duckstation#downloading-and-running</span></a>.</p><p>By default, DuckStation will connect to the server at <a href="https://github.com/"><span style=" text-decoration: underline; color:#0000ff;">github.com</span></a> to check for updates, and if available and confirmed, download update packages from <a href="https://github.com/"><span style=" text-decoration: underline; color:#0000ff;">github.com</span></a>. If you do not wish for DuckStation to make any network connections on startup, you should uncheck the Automatic Updates option now. The Automatic Update setting can be changed later at any time in Interface Settings.</p><p>Please choose a language and theme to begin.</p></body></html>