From cf45c854e00dfc7f620d4e6ba5474464a59e0b27 Mon Sep 17 00:00:00 2001
From: Thorben Kroeger <thorbenkroeger@gmail.com>
Date: Mon, 20 Oct 2014 22:32:55 +0200
Subject: [PATCH] Theming: allow to override base style

Change-Id: I48e2d03b83fccf3d6eb4b508bd77912dbdaea1d0
Reviewed-by: Thorben Kroeger <thorbenkroeger@gmail.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
---
 share/qtcreator/themes/dark.creatortheme            |  1 +
 share/qtcreator/themes/default.creatortheme         |  1 +
 src/libs/utils/theme/theme.cpp                      |  8 ++++++++
 src/libs/utils/theme/theme.h                        |  1 +
 src/libs/utils/theme/theme_p.h                      |  1 +
 src/plugins/coreplugin/mainwindow.cpp               | 13 ++++++++++++-
 .../themeeditor/themesettingstablemodel.cpp         |  2 ++
 .../themeeditor/themesettingstablemodel.h           |  1 +
 8 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/share/qtcreator/themes/dark.creatortheme b/share/qtcreator/themes/dark.creatortheme
index 0853182f6e5..3eb1628fd1c 100644
--- a/share/qtcreator/themes/dark.creatortheme
+++ b/share/qtcreator/themes/dark.creatortheme
@@ -1,5 +1,6 @@
 [General]
 ThemeName=dark
+PreferredStyles=Fusion
 
 [Palette]
 shadowBackground=ff232323
diff --git a/share/qtcreator/themes/default.creatortheme b/share/qtcreator/themes/default.creatortheme
index fd3a6372c24..5149e83162e 100644
--- a/share/qtcreator/themes/default.creatortheme
+++ b/share/qtcreator/themes/default.creatortheme
@@ -1,5 +1,6 @@
 [General]
 ThemeName=default
+PreferredStyles=
 
 [Palette]
 brightText = ffffffff
diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp
index 09f699ff217..95b03c9c86f 100644
--- a/src/libs/utils/theme/theme.cpp
+++ b/src/libs/utils/theme/theme.cpp
@@ -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"));
diff --git a/src/libs/utils/theme/theme.h b/src/libs/utils/theme/theme.h
index ef1ac85b7c9..a8d5bfcbc3a 100644
--- a/src/libs/utils/theme/theme.h
+++ b/src/libs/utils/theme/theme.h
@@ -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);
diff --git a/src/libs/utils/theme/theme_p.h b/src/libs/utils/theme/theme_p.h
index e1493a17e33..bf78904e7ed 100644
--- a/src/libs/utils/theme/theme_p.h
+++ b/src/libs/utils/theme/theme_p.h
@@ -46,6 +46,7 @@ public:
 
     QString fileName;
     QString name;
+    QStringList preferredStyles;
     QVector<QPair<QColor, QString> > colors;
     QVector<QString> imageFiles;
     QVector<QGradientStops> gradients;
diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp
index f5edf4f7056..cd149b60aba 100644
--- a/src/plugins/coreplugin/mainwindow.cpp
+++ b/src/plugins/coreplugin/mainwindow.cpp
@@ -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);
 
diff --git a/src/plugins/coreplugin/themeeditor/themesettingstablemodel.cpp b/src/plugins/coreplugin/themeeditor/themesettingstablemodel.cpp
index 20a607dba84..87826f87bb4 100644
--- a/src/plugins/coreplugin/themeeditor/themesettingstablemodel.cpp
+++ b/src/plugins/coreplugin/themeeditor/themesettingstablemodel.cpp
@@ -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();
 }
 
diff --git a/src/plugins/coreplugin/themeeditor/themesettingstablemodel.h b/src/plugins/coreplugin/themeeditor/themesettingstablemodel.h
index 720c07e4e71..ea7cf4db394 100644
--- a/src/plugins/coreplugin/themeeditor/themesettingstablemodel.h
+++ b/src/plugins/coreplugin/themeeditor/themesettingstablemodel.h
@@ -78,6 +78,7 @@ public:
     void toTheme(Utils::Theme *theme) const;
 
     QString m_name;
+    QStringList m_preferredStyles;
 
 public:
     ThemeColors::Ptr m_colors;
-- 
GitLab