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
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);

View File

@ -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()

View File

@ -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;
};

View File

@ -23,6 +23,8 @@
#include <QDirIterator>
#include <QIcon>
#include <QImageReader>
#include <QStyleFactory>
#include <QStyle>
#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<SystemTheme>());
//themeDebugLog() << "Loading Built-in Theme:" << addTheme(std::make_unique<SystemTheme>());
auto darkThemeId = addTheme(std::make_unique<DarkTheme>());
themeDebugLog() << "Loading Built-in Theme:" << darkThemeId;
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
// 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<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("."))
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.";
}

View File

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