Theming: allow to override base style

Change-Id: I48e2d03b83fccf3d6eb4b508bd77912dbdaea1d0
Reviewed-by: Thorben Kroeger <thorbenkroeger@gmail.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Thorben Kroeger
2014-10-20 22:32:55 +02:00
committed by Orgad Shaneh
parent 82bbc6f562
commit cf45c854e0
8 changed files with 27 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
[General]
ThemeName=dark
PreferredStyles=Fusion
[Palette]
shadowBackground=ff232323

View File

@@ -1,5 +1,6 @@
[General]
ThemeName=default
PreferredStyles=
[Palette]
brightText = ffffffff

View File

@@ -30,6 +30,7 @@
#include "theme.h"
#include "theme_p.h"
#include "../algorithm.h"
#include "../qtcassert.h"
#include <QApplication>
@@ -80,6 +81,11 @@ Theme::WidgetStyle Theme::widgetStyle() const
return d->widgetStyle;
}
QStringList Theme::preferredStyles() const
{
return d->preferredStyles;
}
bool Theme::flag(Theme::Flag f) const
{
return d->flags[f];
@@ -171,6 +177,7 @@ void Theme::writeSettings(const QString &filename) const
const QMetaObject &m = *metaObject();
{
settings.setValue(QLatin1String("ThemeName"), d->name);
settings.setValue(QLatin1String("PreferredStyles"), d->preferredStyles);
}
{
settings.beginGroup(QLatin1String("Palette"));
@@ -249,6 +256,7 @@ void Theme::readSettings(QSettings &settings)
{
d->name = settings.value(QLatin1String("ThemeName"), QLatin1String("unnamed")).toString();
d->preferredStyles = settings.value(QLatin1String("PreferredStyles")).toStringList();
}
{
settings.beginGroup(QLatin1String("Palette"));

View File

@@ -199,6 +199,7 @@ public:
QString imageFile(ImageFile imageFile, const QString &fallBack) const;
QGradientStops gradient(Gradient role) const;
QPalette palette(const QPalette &base) const;
QStringList preferredStyles() const;
QString fileName() const;
void setName(const QString &name);

View File

@@ -46,6 +46,7 @@ public:
QString fileName;
QString name;
QStringList preferredStyles;
QVector<QPair<QColor, QString> > colors;
QVector<QString> imageFiles;
QVector<QGradientStops> gradients;

View File

@@ -166,7 +166,18 @@ MainWindow::MainWindow() :
&& baseName == QLatin1String("windows")) {
baseName = QLatin1String("fusion");
}
qApp->setStyle(new ManhattanStyle(baseName));
// if the user has specified as base style in the theme settings,
// prefer that
const QStringList available = QStyleFactory::keys();
foreach (const QString &s, Utils::creatorTheme()->preferredStyles()) {
if (available.contains(s, Qt::CaseInsensitive)) {
baseName = s;
break;
}
}
QApplication::setStyle(new ManhattanStyle(baseName));
setDockNestingEnabled(true);

View File

@@ -236,6 +236,7 @@ void ThemeSettingsTableModel::initFrom(Theme *theme)
m_widgetStyle = theme->widgetStyle();
m_name = theme->d->name;
m_preferredStyles = theme->d->preferredStyles;
}
void ThemeSettingsTableModel::toTheme(Theme *t) const
@@ -265,6 +266,7 @@ void ThemeSettingsTableModel::toTheme(Theme *t) const
theme->widgetStyle = m_widgetStyle;
theme->name = m_name;
theme->preferredStyles = m_preferredStyles;
emit t->changed();
}

View File

@@ -78,6 +78,7 @@ public:
void toTheme(Utils::Theme *theme) const;
QString m_name;
QStringList m_preferredStyles;
public:
ThemeColors::Ptr m_colors;