From 143c466165c0f15abfba9801318e15841bef767b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Tue, 21 Jul 2026 01:23:47 +0200 Subject: [PATCH] [ThemeManager] Capture app palette before theme is applied for reverting --- cockatrice/src/interface/theme_manager.cpp | 8 +++++++- cockatrice/src/interface/theme_manager.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cockatrice/src/interface/theme_manager.cpp b/cockatrice/src/interface/theme_manager.cpp index b23f461aa..7b771d14f 100644 --- a/cockatrice/src/interface/theme_manager.cpp +++ b/cockatrice/src/interface/theme_manager.cpp @@ -99,6 +99,8 @@ ThemeManager::ThemeManager(QObject *parent) : QObject(parent) QStyleFactory::keys().contains("windows11", Qt::CaseInsensitive)) { defaultStyleName = "windows11"; } + // Capture the untouched application palette before any theme is applied. + defaultPalette = qApp->palette(); ensureThemeDirectoryExists(); #if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)) connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, &ThemeManager::themeChangedSlot); @@ -332,7 +334,11 @@ void ThemeManager::applyStyleAndPalette(const QString &themeName, } #endif } else { - base = qApp->palette(); + // Use the pristine startup palette rather than qApp->palette(): the + // latter may already carry a previously-applied custom (e.g. dark) + // palette, which would otherwise persist when switching to a scheme + // that supplies no palette of its own. + base = defaultPalette; } // Overlay custom palette colours diff --git a/cockatrice/src/interface/theme_manager.h b/cockatrice/src/interface/theme_manager.h index 32056f30e..861ab838b 100644 --- a/cockatrice/src/interface/theme_manager.h +++ b/cockatrice/src/interface/theme_manager.h @@ -43,6 +43,10 @@ public: private: QString defaultStyleName; + // Pristine application palette captured at startup, before any custom theme + // palette is applied. Used as the base when a theme supplies no palette, so + // switching away from a custom palette restores the original colours. + QPalette defaultPalette; QString currentThemePath; std::array brushes; QStringMap availableThemes;