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()));
setIconTheme(settings()->get("IconTheme").toString());
setApplicationTheme(settings()->get("ApplicationTheme").toString());
setApplicationTheme(settings()->get("ApplicationTheme").toString(), true);
initAnalytics();
@ -868,27 +868,14 @@ void MultiMC::initThemes()
insertTheme(new CustomTheme(darkTheme, "custom"));
}
void MultiMC::setApplicationTheme(const QString& name)
void MultiMC::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;
setStyle(QStyleFactory::create(theme->qtTheme()));
if(theme->hasColorScheme())
{
setPalette(theme->colorScheme());
}
if(theme->hasStyleSheet())
{
setStyleSheet(theme->appStyleSheet());
}
else
{
setStyleSheet(QString());
}
QDir::setSearchPaths("theme", theme->searchPaths());
theme->apply(initial);
}
else
{

View File

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

View File

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

View File

@ -1,5 +1,26 @@
#include "ITheme.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)
{

View File

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

View File

@ -24,6 +24,16 @@ SystemTheme::SystemTheme()
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()
{
return "system";
@ -66,10 +76,5 @@ bool SystemTheme::hasStyleSheet()
bool SystemTheme::hasColorScheme()
{
// FIXME: horrible hack to work around Qt's sketchy theming APIs
#if defined(Q_OS_LINUX)
return true;
#else
return false;
#endif
}

View File

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