diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 7ae66e13a..327b63b02 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 cefe664db..d927d2207 100644 --- a/launcher/ui/themes/SystemTheme.cpp +++ b/launcher/ui/themes/SystemTheme.cpp @@ -43,25 +43,33 @@ SystemTheme::SystemTheme() { + themeName = QObject::tr("System"); themeDebugLog() << "Determining System Theme..."; const auto& style = QApplication::style(); - systemPalette = QApplication::palette(); - QString lowerThemeName = style->objectName(); + colorPalette = QApplication::palette(); + QString lowerThemeName = style->name(); 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) { - systemTheme = st; - themeDebugLog() << "System theme has been determined to be:" << systemTheme; + widgetTheme = st; + themeDebugLog() << "System theme has been determined to be:" << widgetTheme; return; } } // fall back to fusion if we can't find the current theme. - systemTheme = "Fusion"; + widgetTheme = "Fusion"; themeDebugLog() << "System theme not found, defaulted to Fusion"; } +SystemTheme::SystemTheme(QString& styleName) +{ + themeName = styleName; + widgetTheme = styleName; + colorPalette = QApplication::palette(); +} + void SystemTheme::apply(bool initial) { // See https://github.com/MultiMC/Launcher/issues/1790 @@ -76,22 +84,30 @@ void SystemTheme::apply(bool initial) QString SystemTheme::id() { - return "system"; + return themeName; } QString SystemTheme::name() { - return QObject::tr("System"); + if (themeName.toLower() == "windowsvista") { + return QObject::tr("Windows Vista"); + } else if (themeName.toLower() == "windows") { + return QObject::tr("Windows 9x"); + } else if (themeName.toLower() == "windows11") { + return QObject::tr("Windows 11"); + } else { + return themeName; + } } QString SystemTheme::qtTheme() { - return systemTheme; + return widgetTheme; } QPalette SystemTheme::colorScheme() { - return systemPalette; + return colorPalette; } QString SystemTheme::appStyleSheet() diff --git a/launcher/ui/themes/SystemTheme.h b/launcher/ui/themes/SystemTheme.h index 4f7d83e57..a0e77fae1 100644 --- a/launcher/ui/themes/SystemTheme.h +++ b/launcher/ui/themes/SystemTheme.h @@ -39,6 +39,7 @@ class SystemTheme : public ITheme { public: SystemTheme(); + explicit SystemTheme(QString& themeName); virtual ~SystemTheme() {} void apply(bool initial) override; @@ -53,6 +54,7 @@ class SystemTheme : public ITheme { QColor fadeColor() override; private: - QPalette systemPalette; - QString systemTheme; + QPalette colorPalette; + QString widgetTheme; + QString themeName; }; diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index 1cb83ca26..601bc66c2 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include "Exception.h" #include "ui/themes/BrightTheme.h" #include "ui/themes/CatPack.h" @@ -119,14 +121,30 @@ void ThemeManager::initializeIcons() void ThemeManager::initializeWidgets() { + themeDebugLog() << "Determining System Widget Theme..."; + const auto& style = QApplication::style(); + currentlySelectedSystemTheme = style->name(); + 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()); auto darkThemeId = addTheme(std::make_unique()); themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique()); - // TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in - // dropdown?) + themeDebugLog() << "<> Initializing System Themes"; + QStringList styles = QStyleFactory::keys(); + for (auto& st : styles) { +#if Q_OS_WINDOWS + if (QSysInfo::productVersion() != "11" && st == "windows11") { + continue; + } +#endif + themeDebugLog() << "Loading System Theme:" << addTheme(std::make_unique(st)); + } + + // TODO: need some way to differentiate same name themes in different subdirectories + // (maybe smaller grey text next to theme name in dropdown?) if (!m_applicationThemeFolder.mkpath(".")) themeWarningLog() << "Couldn't create theme folder"; @@ -238,7 +256,11 @@ void ThemeManager::applyCurrentlySelectedTheme(bool initial) auto settings = APPLICATION->settings(); setIconTheme(settings->get("IconTheme").toString()); themeDebugLog() << "<> Icon theme set."; - setApplicationTheme(settings->get("ApplicationTheme").toString(), initial); + auto applicationTheme = settings->get("ApplicationTheme").toString(); + if (applicationTheme == "") { + applicationTheme = currentlySelectedSystemTheme; + } + setApplicationTheme(applicationTheme, initial); themeDebugLog() << "<> Application theme set."; } diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index 47b9589e3..ddf619a80 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -64,6 +64,7 @@ class ThemeManager { QDir m_applicationThemeFolder{ "themes" }; QDir m_catPacksFolder{ "catpacks" }; std::map> m_cat_packs; + QString currentlySelectedSystemTheme; void initializeThemes(); void initializeCatPacks();