GH-903 force Dark theme to use Fusion Qt style

Themes now include Qt styles.
This commit is contained in:
Petr Mrázek 2016-10-22 01:43:36 +02:00
parent 872cfe036d
commit bbe139dce5
6 changed files with 32 additions and 2 deletions

View File

@ -22,6 +22,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QStringList> #include <QStringList>
#include <QDebug> #include <QDebug>
#include <QStyleFactory>
#include "InstanceList.h" #include "InstanceList.h"
#include <minecraft/auth/MojangAccountList.h> #include <minecraft/auth/MojangAccountList.h>
@ -982,9 +983,9 @@ void MultiMC::setApplicationTheme(const QString& name)
if(themeIter != m_themes.end()) if(themeIter != m_themes.end())
{ {
auto & theme = (*themeIter).second; auto & theme = (*themeIter).second;
setStyle(QStyleFactory::create(theme->qtTheme()));
setPalette(theme->colorScheme()); setPalette(theme->colorScheme());
setStyleSheet(theme->appStyleSheet()); setStyleSheet(theme->appStyleSheet());
//setStyle(QStyleFactory::create("Fusion"));
} }
else else
{ {

View File

@ -10,6 +10,11 @@ QString DarkTheme::name()
return QObject::tr("Dark"); return QObject::tr("Dark");
} }
QString DarkTheme::qtTheme()
{
return "Fusion";
}
QPalette DarkTheme::colorScheme() QPalette DarkTheme::colorScheme()
{ {
QPalette darkPalette; QPalette darkPalette;

View File

@ -7,6 +7,7 @@ class DarkTheme: public ITheme
public: public:
virtual ~DarkTheme() {} virtual ~DarkTheme() {}
QString qtTheme() override;
QString id() override; QString id() override;
QString name() override; QString name() override;
QString appStyleSheet() override; QString appStyleSheet() override;

View File

@ -9,5 +9,6 @@ public:
virtual QString id() = 0; virtual QString id() = 0;
virtual QString name() = 0; virtual QString name() = 0;
virtual QString appStyleSheet() = 0; virtual QString appStyleSheet() = 0;
virtual QString qtTheme() = 0;
virtual QPalette colorScheme() = 0; virtual QPalette colorScheme() = 0;
}; };

View File

@ -1,10 +1,26 @@
#include "SystemTheme.h" #include "SystemTheme.h"
#include <QApplication> #include <QApplication>
#include <QStyle> #include <QStyle>
#include <QStyleFactory>
#include <QDebug>
SystemTheme::SystemTheme() SystemTheme::SystemTheme()
{ {
systemPalette = QApplication::style()->standardPalette(); const auto & style = QApplication::style();
systemPalette = style->standardPalette();
QString lowerThemeName = style->objectName();
qWarning() << systemTheme;
QStringList styles = QStyleFactory::keys();
for(auto &st: styles)
{
if(st.toLower() == lowerThemeName)
{
systemTheme = st;
return;
}
}
// fall back to fusion if we can't find the current theme.
systemTheme = "Fusion";
} }
QString SystemTheme::id() QString SystemTheme::id()
@ -17,6 +33,11 @@ QString SystemTheme::name()
return QObject::tr("System"); return QObject::tr("System");
} }
QString SystemTheme::qtTheme()
{
return systemTheme;
}
QPalette SystemTheme::colorScheme() QPalette SystemTheme::colorScheme()
{ {
return systemPalette; return systemPalette;

View File

@ -10,6 +10,7 @@ public:
QString id() override; QString id() override;
QString name() override; QString name() override;
QString qtTheme() override;
QString appStyleSheet() override; QString appStyleSheet() override;
QPalette colorScheme() override; QPalette colorScheme() override;
private: private: