From dbcfefca1b0e537aaec2bfe0ddc091c5f994317d Mon Sep 17 00:00:00 2001 From: Tayou Date: Mon, 1 Jul 2024 23:05:54 +0200 Subject: [PATCH] fix system theme Signed-off-by: Tayou --- launcher/Application.cpp | 4 ++-- launcher/ui/themes/SystemTheme.cpp | 30 +++++------------------------ launcher/ui/themes/SystemTheme.h | 3 +-- launcher/ui/themes/ThemeManager.cpp | 2 +- 4 files changed, 9 insertions(+), 30 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 6254e38fe..7ae66e13a 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1073,8 +1073,8 @@ bool Application::createSetupWizard() // set default theme after going into theme wizard if (!validIcons) settings()->set("IconTheme", QString("pe_colored")); - // if (!validWidgets) - // settings()->set("ApplicationTheme", QString("system")); + if (!validWidgets) + settings()->set("ApplicationTheme", QString("system")); m_themeManager->applyCurrentlySelectedTheme(true); diff --git a/launcher/ui/themes/SystemTheme.cpp b/launcher/ui/themes/SystemTheme.cpp index a46b2002a..70de21894 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -40,31 +40,9 @@ #include "HintOverrideProxyStyle.h" #include "ThemeManager.h" -SystemTheme::SystemTheme() +SystemTheme::SystemTheme(QString& styleName, bool isSystemTheme) { - themeName = QObject::tr("System"); - themeDebugLog() << "Determining System Theme..."; - const auto& style = QApplication::style(); - colorPalette = QApplication::palette(); - QString lowerThemeName = style->objectName(); - themeDebugLog() << "System theme seems to be:" << lowerThemeName; - QStringList styles = QStyleFactory::keys(); - for (auto& st : styles) { - themeDebugLog() << "Considering theme from theme factory:" << st.toLower(); - if (st.toLower() == lowerThemeName) { - widgetTheme = st; - themeDebugLog() << "System theme has been determined to be:" << widgetTheme; - return; - } - } - // fall back to fusion if we can't find the current theme. - widgetTheme = "Fusion"; - themeDebugLog() << "System theme not found, defaulted to Fusion"; -} - -SystemTheme::SystemTheme(QString& styleName) -{ - themeName = styleName; + themeName = isSystemTheme ? "system" : styleName; widgetTheme = styleName; colorPalette = QApplication::palette(); } @@ -94,6 +72,8 @@ QString SystemTheme::name() return QObject::tr("Windows 9x"); } else if (themeName.toLower() == "windows11") { return QObject::tr("Windows 11"); + } else if (themeName.toLower() == "system") { + return QObject::tr("System"); } else { return themeName; } @@ -110,7 +90,7 @@ QString SystemTheme::tooltip() } else if (themeName.toLower() == "fusion") { return QObject::tr("The default Qt widget style"); } else if (themeName.toLower() == "system") { - return QObject::tr("Your current system theme") + " (" + widgetTheme + ")"; + return QObject::tr("Your current system theme"); } else { return ""; } diff --git a/launcher/ui/themes/SystemTheme.h b/launcher/ui/themes/SystemTheme.h index bcfe34288..5c58856cb 100644 --- a/launcher/ui/themes/SystemTheme.h +++ b/launcher/ui/themes/SystemTheme.h @@ -38,8 +38,7 @@ class SystemTheme : public ITheme { public: - SystemTheme(); - explicit SystemTheme(QString& themeName); + SystemTheme(QString& themeName, bool isSystemTheme = false); virtual ~SystemTheme() {} void apply(bool initial) override; diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index ac2bf26dc..d57e166f4 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -127,7 +127,7 @@ void ThemeManager::initializeWidgets() themeDebugLog() << "System theme seems to be:" << currentlySelectedSystemTheme; themeDebugLog() << "<> Initializing Widget Themes"; - themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); + themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique(currentlySelectedSystemTheme, true)); auto darkThemeId = addTheme(std::make_unique()); themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique());