Merge pull request #982 from Scrumplex/fix-theming-style

This commit is contained in:
DioEgizio 2023-04-08 19:26:43 +02:00 committed by GitHub
commit 1b8b044b52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 19 additions and 17 deletions

View File

@ -830,9 +830,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
}
});
{
applyCurrentlySelectedTheme();
}
applyCurrentlySelectedTheme(true);
updateCapabilities();
@ -1107,9 +1105,9 @@ QList<ITheme*> Application::getValidApplicationThemes()
return m_themeManager->getValidApplicationThemes();
}
void Application::applyCurrentlySelectedTheme()
void Application::applyCurrentlySelectedTheme(bool initial)
{
m_themeManager->applyCurrentlySelectedTheme();
m_themeManager->applyCurrentlySelectedTheme(initial);
}
void Application::setApplicationTheme(const QString& name)

View File

@ -120,7 +120,7 @@ public:
void setIconTheme(const QString& name);
void applyCurrentlySelectedTheme();
void applyCurrentlySelectedTheme(bool initial = false);
QList<ITheme*> getValidApplicationThemes();

View File

@ -38,7 +38,7 @@
#include <QDir>
#include "Application.h"
void ITheme::apply()
void ITheme::apply(bool)
{
APPLICATION->setStyleSheet(QString());
QApplication::setStyle(QStyleFactory::create(qtTheme()));

View File

@ -41,7 +41,7 @@ class QStyle;
class ITheme {
public:
virtual ~ITheme() {}
virtual void apply();
virtual void apply(bool initial);
virtual QString id() = 0;
virtual QString name() = 0;
virtual bool hasStyleSheet() = 0;

View File

@ -60,9 +60,13 @@ SystemTheme::SystemTheme()
themeDebugLog() << "System theme not found, defaulted to Fusion";
}
void SystemTheme::apply()
void SystemTheme::apply(bool initial)
{
ITheme::apply();
// See https://github.com/MultiMC/Launcher/issues/1790
// or https://github.com/PrismLauncher/PrismLauncher/issues/490
if (initial)
return;
ITheme::apply(initial);
}
QString SystemTheme::id()

View File

@ -40,7 +40,7 @@ class SystemTheme : public ITheme {
public:
SystemTheme();
virtual ~SystemTheme() {}
void apply() override;
void apply(bool initial) override;
QString id() override;
QString name() override;

View File

@ -116,22 +116,22 @@ void ThemeManager::setIconTheme(const QString& name)
QIcon::setThemeName(name);
}
void ThemeManager::applyCurrentlySelectedTheme()
void ThemeManager::applyCurrentlySelectedTheme(bool initial)
{
setIconTheme(APPLICATION->settings()->get("IconTheme").toString());
themeDebugLog() << "<> Icon theme set.";
setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString());
setApplicationTheme(APPLICATION->settings()->get("ApplicationTheme").toString(), initial);
themeDebugLog() << "<> Application theme set.";
}
void ThemeManager::setApplicationTheme(const QString& name)
void ThemeManager::setApplicationTheme(const QString& name, bool initial)
{
auto systemPalette = qApp->palette();
auto themeIter = m_themes.find(name);
if (themeIter != m_themes.end()) {
auto& theme = themeIter->second;
themeDebugLog() << "applying theme" << theme->name();
theme->apply();
theme->apply(initial);
} else {
themeWarningLog() << "Tried to set invalid theme:" << name;
}

View File

@ -37,8 +37,8 @@ class ThemeManager {
QList<ITheme*> getValidApplicationThemes();
void setIconTheme(const QString& name);
void applyCurrentlySelectedTheme();
void setApplicationTheme(const QString& name);
void applyCurrentlySelectedTheme(bool initial = false);
void setApplicationTheme(const QString& name, bool initial = false);
/// <summary>
/// Returns the cat based on selected cat and with events (Birthday, XMas, etc.)