From d725aaa5bcb6760522997a3ba43676c88b341d63 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Tue, 1 Aug 2023 19:52:36 +0200 Subject: [PATCH] DolphinQt: Set the application palette to a matching one when the Windows dark theme is in use. --- Source/Core/DolphinQt/Main.cpp | 1 + Source/Core/DolphinQt/Settings.cpp | 34 ++++++++++++++++++++++++++++-- Source/Core/DolphinQt/Settings.h | 1 + 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/Source/Core/DolphinQt/Main.cpp b/Source/Core/DolphinQt/Main.cpp index aa1697c6a7..3cf943b17b 100644 --- a/Source/Core/DolphinQt/Main.cpp +++ b/Source/Core/DolphinQt/Main.cpp @@ -246,6 +246,7 @@ int main(int argc, char* argv[]) DolphinAnalytics::Instance().ReportDolphinStart("qt"); MainWindow win{std::move(boot), static_cast(options.get("movie"))}; + Settings::Instance().InitDefaultPalette(); Settings::Instance().UpdateSystemDark(); Settings::Instance().SetCurrentUserStyle(Settings::Instance().GetCurrentUserStyle()); win.Show(); diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index e35be9a8ba..3c4461db1c 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -4,19 +4,21 @@ #include "DolphinQt/Settings.h" #include +#include #include +#include #include #include #include #include +#include #include #include +#include #include #ifdef _WIN32 -#include - #include #include @@ -50,6 +52,7 @@ #include "VideoCommon/NetPlayGolfUI.h" static bool s_system_dark = false; +static std::unique_ptr s_default_palette; Settings::Settings() { @@ -129,6 +132,11 @@ QString Settings::GetCurrentUserStyle() const return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName(); } +void Settings::InitDefaultPalette() +{ + s_default_palette = std::make_unique(qApp->palette()); +} + void Settings::UpdateSystemDark() { #ifdef _WIN32 @@ -183,6 +191,28 @@ void Settings::SetCurrentUserStyle(const QString& stylesheet_name) QFile file(QStringLiteral(":/dolphin_dark_win/dark.qss")); if (file.open(QFile::ReadOnly)) stylesheet_contents = QString::fromUtf8(file.readAll().data()); + + QPalette palette = qApp->style()->standardPalette(); + palette.setColor(QPalette::Window, QColor(32, 32, 32)); + palette.setColor(QPalette::WindowText, QColor(220, 220, 220)); + palette.setColor(QPalette::Base, QColor(32, 32, 32)); + palette.setColor(QPalette::AlternateBase, QColor(48, 48, 48)); + palette.setColor(QPalette::PlaceholderText, QColor(126, 126, 126)); + palette.setColor(QPalette::Text, QColor(220, 220, 220)); + palette.setColor(QPalette::Button, QColor(48, 48, 48)); + palette.setColor(QPalette::ButtonText, QColor(220, 220, 220)); + palette.setColor(QPalette::BrightText, QColor(255, 255, 255)); + palette.setColor(QPalette::Highlight, QColor(0, 120, 215)); + palette.setColor(QPalette::HighlightedText, QColor(255, 255, 255)); + palette.setColor(QPalette::Link, QColor(100, 160, 220)); + palette.setColor(QPalette::LinkVisited, QColor(100, 160, 220)); + qApp->setPalette(palette); + } + else + { + // reset any palette changes that may exist from a previously set dark mode + if (s_default_palette) + qApp->setPalette(*s_default_palette); } } #endif diff --git a/Source/Core/DolphinQt/Settings.h b/Source/Core/DolphinQt/Settings.h index 1e1e4b1d7e..b95b768250 100644 --- a/Source/Core/DolphinQt/Settings.h +++ b/Source/Core/DolphinQt/Settings.h @@ -52,6 +52,7 @@ public: // UI void SetThemeName(const QString& theme_name); + void InitDefaultPalette(); void UpdateSystemDark(); void SetSystemDark(bool dark); bool IsSystemDark();