more system themes initial changes

Signed-off-by: Tayou <git@tayou.org>
This commit is contained in:
Tayou 2024-06-30 21:35:03 +02:00
parent fc445078cd
commit 046e3588af
5 changed files with 58 additions and 17 deletions

View File

@ -1073,8 +1073,8 @@ bool Application::createSetupWizard()
// set default theme after going into theme wizard // set default theme after going into theme wizard
if (!validIcons) if (!validIcons)
settings()->set("IconTheme", QString("pe_colored")); settings()->set("IconTheme", QString("pe_colored"));
if (!validWidgets) //if (!validWidgets)
settings()->set("ApplicationTheme", QString("system")); //settings()->set("ApplicationTheme", QString("system"));
m_themeManager->applyCurrentlySelectedTheme(true); m_themeManager->applyCurrentlySelectedTheme(true);

View File

@ -43,25 +43,33 @@
SystemTheme::SystemTheme() SystemTheme::SystemTheme()
{ {
themeName = QObject::tr("System");
themeDebugLog() << "Determining System Theme..."; themeDebugLog() << "Determining System Theme...";
const auto& style = QApplication::style(); const auto& style = QApplication::style();
systemPalette = QApplication::palette(); colorPalette = QApplication::palette();
QString lowerThemeName = style->objectName(); QString lowerThemeName = style->name();
themeDebugLog() << "System theme seems to be:" << lowerThemeName; themeDebugLog() << "System theme seems to be:" << lowerThemeName;
QStringList styles = QStyleFactory::keys(); QStringList styles = QStyleFactory::keys();
for (auto& st : styles) { for (auto& st : styles) {
themeDebugLog() << "Considering theme from theme factory:" << st.toLower(); themeDebugLog() << "Considering theme from theme factory:" << st.toLower();
if (st.toLower() == lowerThemeName) { if (st.toLower() == lowerThemeName) {
systemTheme = st; widgetTheme = st;
themeDebugLog() << "System theme has been determined to be:" << systemTheme; themeDebugLog() << "System theme has been determined to be:" << widgetTheme;
return; return;
} }
} }
// fall back to fusion if we can't find the current theme. // fall back to fusion if we can't find the current theme.
systemTheme = "Fusion"; widgetTheme = "Fusion";
themeDebugLog() << "System theme not found, defaulted to 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) void SystemTheme::apply(bool initial)
{ {
// See https://github.com/MultiMC/Launcher/issues/1790 // See https://github.com/MultiMC/Launcher/issues/1790
@ -76,22 +84,30 @@ void SystemTheme::apply(bool initial)
QString SystemTheme::id() QString SystemTheme::id()
{ {
return "system"; return themeName;
} }
QString SystemTheme::name() 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() QString SystemTheme::qtTheme()
{ {
return systemTheme; return widgetTheme;
} }
QPalette SystemTheme::colorScheme() QPalette SystemTheme::colorScheme()
{ {
return systemPalette; return colorPalette;
} }
QString SystemTheme::appStyleSheet() QString SystemTheme::appStyleSheet()

View File

@ -39,6 +39,7 @@
class SystemTheme : public ITheme { class SystemTheme : public ITheme {
public: public:
SystemTheme(); SystemTheme();
explicit SystemTheme(QString& themeName);
virtual ~SystemTheme() {} virtual ~SystemTheme() {}
void apply(bool initial) override; void apply(bool initial) override;
@ -53,6 +54,7 @@ class SystemTheme : public ITheme {
QColor fadeColor() override; QColor fadeColor() override;
private: private:
QPalette systemPalette; QPalette colorPalette;
QString systemTheme; QString widgetTheme;
QString themeName;
}; };

View File

@ -23,6 +23,8 @@
#include <QDirIterator> #include <QDirIterator>
#include <QIcon> #include <QIcon>
#include <QImageReader> #include <QImageReader>
#include <QStyleFactory>
#include <QStyle>
#include "Exception.h" #include "Exception.h"
#include "ui/themes/BrightTheme.h" #include "ui/themes/BrightTheme.h"
#include "ui/themes/CatPack.h" #include "ui/themes/CatPack.h"
@ -119,14 +121,30 @@ void ThemeManager::initializeIcons()
void ThemeManager::initializeWidgets() 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() << "<> Initializing Widget Themes";
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>()); //themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
auto darkThemeId = addTheme(std::make_unique<DarkTheme>()); auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId; themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>()); themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<BrightTheme>());
// TODO: need some way to differentiate same name themes in different subdirectories (maybe smaller grey text next to theme name in themeDebugLog() << "<> Initializing System Themes";
// dropdown?) 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<SystemTheme>(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(".")) if (!m_applicationThemeFolder.mkpath("."))
themeWarningLog() << "Couldn't create theme folder"; themeWarningLog() << "Couldn't create theme folder";
@ -238,7 +256,11 @@ void ThemeManager::applyCurrentlySelectedTheme(bool initial)
auto settings = APPLICATION->settings(); auto settings = APPLICATION->settings();
setIconTheme(settings->get("IconTheme").toString()); setIconTheme(settings->get("IconTheme").toString());
themeDebugLog() << "<> Icon theme set."; 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."; themeDebugLog() << "<> Application theme set.";
} }

View File

@ -64,6 +64,7 @@ class ThemeManager {
QDir m_applicationThemeFolder{ "themes" }; QDir m_applicationThemeFolder{ "themes" };
QDir m_catPacksFolder{ "catpacks" }; QDir m_catPacksFolder{ "catpacks" };
std::map<QString, std::unique_ptr<CatPack>> m_cat_packs; std::map<QString, std::unique_ptr<CatPack>> m_cat_packs;
QString currentlySelectedSystemTheme;
void initializeThemes(); void initializeThemes();
void initializeCatPacks(); void initializeCatPacks();