Theming: Store initial palette

Change-Id: Iea8b74534a59d8410814f9dd41225b88e1e81f75
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2014-11-17 08:07:28 +02:00
committed by Orgad Shaneh
parent ab83c30f87
commit 3ec16fe4d8
4 changed files with 18 additions and 7 deletions

View File

@@ -324,14 +324,20 @@ void Theme::readSettings(QSettings &settings)
} }
} }
QPalette Theme::palette(const QPalette &base) const QPalette Theme::initialPalette()
{ {
static QPalette palette = QApplication::palette();
return palette;
}
QPalette Theme::palette() const
{
QPalette pal = initialPalette();
if (!flag(DerivePaletteFromTheme)) if (!flag(DerivePaletteFromTheme))
return base; return pal;
// FIXME: introduce some more color roles for this // FIXME: introduce some more color roles for this
QPalette pal = base;
pal.setColor(QPalette::All, QPalette::Window, color(Theme::BackgroundColorNormal)); pal.setColor(QPalette::All, QPalette::Window, color(Theme::BackgroundColorNormal));
pal.setBrush(QPalette::All, QPalette::WindowText, color(Theme::TextColorNormal)); pal.setBrush(QPalette::All, QPalette::WindowText, color(Theme::TextColorNormal));
pal.setColor(QPalette::All, QPalette::Base, color(Theme::BackgroundColorNormal)); pal.setColor(QPalette::All, QPalette::Base, color(Theme::BackgroundColorNormal));

View File

@@ -33,8 +33,9 @@
#include "../utils_global.h" #include "../utils_global.h"
#include <QStyle>
#include <QFlags> #include <QFlags>
#include <QPalette>
#include <QStyle>
QT_FORWARD_DECLARE_CLASS(QSettings) QT_FORWARD_DECLARE_CLASS(QSettings)
@@ -199,7 +200,7 @@ public:
QColor color(Color role) const; QColor color(Color role) const;
QString imageFile(ImageFile imageFile, const QString &fallBack) const; QString imageFile(ImageFile imageFile, const QString &fallBack) const;
QGradientStops gradient(Gradient role) const; QGradientStops gradient(Gradient role) const;
QPalette palette(const QPalette &base) const; QPalette palette() const;
QStringList preferredStyles() const; QStringList preferredStyles() const;
QString fileName() const; QString fileName() const;
@@ -209,6 +210,9 @@ public:
void writeSettings(const QString &filename) const; void writeSettings(const QString &filename) const;
void readSettings(QSettings &settings); void readSettings(QSettings &settings);
static QPalette initialPalette();
ThemePrivate *d; ThemePrivate *d;
signals: signals:

View File

@@ -133,7 +133,7 @@ void CorePlugin::parseArguments(const QStringList &arguments)
theme->readSettings(themeSettings); theme->readSettings(themeSettings);
setCreatorTheme(theme); setCreatorTheme(theme);
if (theme->flag(Theme::ApplyThemePaletteGlobally)) if (theme->flag(Theme::ApplyThemePaletteGlobally))
QApplication::setPalette(creatorTheme()->palette(QApplication::palette())); QApplication::setPalette(creatorTheme()->palette());
// defer creation of these widgets until here, // defer creation of these widgets until here,
// because they need a valid theme set // because they need a valid theme set
@@ -148,6 +148,7 @@ void CorePlugin::parseArguments(const QStringList &arguments)
bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
{ {
Theme::initialPalette(); // Initialize palette before setting it
qsrand(QDateTime::currentDateTime().toTime_t()); qsrand(QDateTime::currentDateTime().toTime_t());
parseArguments(arguments); parseArguments(arguments);
const bool success = m_mainWindow->init(errorMessage); const bool success = m_mainWindow->init(errorMessage);

View File

@@ -419,7 +419,7 @@ void ThemeSettingsWidget::apply()
{ {
d->m_ui->editor->model()->toTheme(creatorTheme()); d->m_ui->editor->model()->toTheme(creatorTheme());
if (creatorTheme()->flag(Theme::ApplyThemePaletteGlobally)) if (creatorTheme()->flag(Theme::ApplyThemePaletteGlobally))
QApplication::setPalette(creatorTheme()->palette(QApplication::palette())); QApplication::setPalette(creatorTheme()->palette());
foreach (QWidget *w, QApplication::topLevelWidgets()) foreach (QWidget *w, QApplication::topLevelWidgets())
w->update(); w->update();
} }