GH-1790 do not apply system theme on launch if it is selected

This prevents some ugly colors to show up on macOS in most cases.
It still looks ugly right after you switch to the it though.
This commit is contained in:
Petr Mrázek 2017-01-18 02:45:04 +01:00
parent 201d4ac317
commit ceb5fc6d75
7 changed files with 44 additions and 29 deletions

View File

@ -355,7 +355,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv)
connect(this, SIGNAL(aboutToQuit()), SLOT(onExit())); connect(this, SIGNAL(aboutToQuit()), SLOT(onExit()));
setIconTheme(settings()->get("IconTheme").toString()); setIconTheme(settings()->get("IconTheme").toString());
setApplicationTheme(settings()->get("ApplicationTheme").toString()); setApplicationTheme(settings()->get("ApplicationTheme").toString(), true);
initAnalytics(); initAnalytics();
@ -868,27 +868,14 @@ void MultiMC::initThemes()
insertTheme(new CustomTheme(darkTheme, "custom")); insertTheme(new CustomTheme(darkTheme, "custom"));
} }
void MultiMC::setApplicationTheme(const QString& name) void MultiMC::setApplicationTheme(const QString& name, bool initial)
{ {
auto systemPalette = qApp->palette(); auto systemPalette = qApp->palette();
auto themeIter = m_themes.find(name); auto themeIter = m_themes.find(name);
if(themeIter != m_themes.end()) if(themeIter != m_themes.end())
{ {
auto & theme = (*themeIter).second; auto & theme = (*themeIter).second;
setStyle(QStyleFactory::create(theme->qtTheme())); theme->apply(initial);
if(theme->hasColorScheme())
{
setPalette(theme->colorScheme());
}
if(theme->hasStyleSheet())
{
setStyleSheet(theme->appStyleSheet());
}
else
{
setStyleSheet(QString());
}
QDir::setSearchPaths("theme", theme->searchPaths());
} }
else else
{ {

View File

@ -87,7 +87,7 @@ public:
std::vector<ITheme *> getValidApplicationThemes(); std::vector<ITheme *> getValidApplicationThemes();
void setApplicationTheme(const QString& name); void setApplicationTheme(const QString& name, bool initial);
// DownloadUpdateTask // DownloadUpdateTask
std::shared_ptr<UpdateChecker> updateChecker() std::shared_ptr<UpdateChecker> updateChecker()

View File

@ -330,7 +330,7 @@ void MultiMCPage::applySettings()
if(originalAppTheme != newAppTheme) if(originalAppTheme != newAppTheme)
{ {
s->set("ApplicationTheme", newAppTheme); s->set("ApplicationTheme", newAppTheme);
MMC->setApplicationTheme(newAppTheme); MMC->setApplicationTheme(newAppTheme, false);
} }
// Console settings // Console settings

View File

@ -1,5 +1,26 @@
#include "ITheme.h" #include "ITheme.h"
#include "rainbow.h" #include "rainbow.h"
#include <QStyleFactory>
#include <QDir>
#include "MultiMC.h"
void ITheme::apply(bool)
{
QApplication::setStyle(QStyleFactory::create(qtTheme()));
if(hasColorScheme())
{
QApplication::setPalette(colorScheme());
}
if(hasStyleSheet())
{
MMC->setStyleSheet(appStyleSheet());
}
else
{
MMC->setStyleSheet(QString());
}
QDir::setSearchPaths("theme", searchPaths());
}
QPalette ITheme::fadeInactive(QPalette in, qreal bias, QColor color) QPalette ITheme::fadeInactive(QPalette in, qreal bias, QColor color)
{ {

View File

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

View File

@ -24,6 +24,16 @@ SystemTheme::SystemTheme()
qWarning() << "System theme not found, defaulted to Fusion"; qWarning() << "System theme not found, defaulted to Fusion";
} }
void SystemTheme::apply(bool initial)
{
// if we are applying the system theme as the first theme, just don't touch anything. it's for the better...
if(initial)
{
return;
}
ITheme::apply(initial);
}
QString SystemTheme::id() QString SystemTheme::id()
{ {
return "system"; return "system";
@ -50,14 +60,14 @@ QString SystemTheme::appStyleSheet()
} }
double SystemTheme::fadeAmount() double SystemTheme::fadeAmount()
{ {
return 0.5; return 0.5;
} }
QColor SystemTheme::fadeColor() QColor SystemTheme::fadeColor()
{ {
return QColor(128,128,128); return QColor(128,128,128);
} }
bool SystemTheme::hasStyleSheet() bool SystemTheme::hasStyleSheet()
{ {
@ -66,10 +76,5 @@ bool SystemTheme::hasStyleSheet()
bool SystemTheme::hasColorScheme() bool SystemTheme::hasColorScheme()
{ {
// FIXME: horrible hack to work around Qt's sketchy theming APIs
#if defined(Q_OS_LINUX)
return true; return true;
#else
return false;
#endif
} }

View File

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