Implement theming for QtCreator

Adds a 'Theme' tab to the environment settings and a '-theme' command
line option.
A theme is a combination of colors, gradients, flags and style
information.

There are two themes:
- 'default': preserves the current default look
- 'dark': uses a more flat for many widgets, dark color theme
  for everything

This does not use a stylesheet (too limited), but rather sets
the palette via C++ and modifies drawing behavior.
Overall, the look is more flat (removed some gradients and bevels).

Tested on Ubuntu 14.04 using Qt 5.4 and running on a KDE
Desktop (Oxygen base style).

For a screenshot, see
https://gist.github.com/thorbenk/5ab06bea726de0aa7473

Changes:
- Introduce class Theme, defining the interface how to access theme
  specific settings. The class reads a .creatortheme file (INI file, via
  QSettings)

  - Define named colors in the [Palette] section
    (see dark.creatortheme for example usage)

  - Use either named colors of AARRGGBB (hex) in the [Colors]
    section

  - A file ending with .creatortheme may be supplied
    to the '-theme' command line option

- A global Theme instance can be accessed via creatorTheme()

- Query colors, gradients, icons and flags from the theme
  were possible (TODO: use this in more places...)

- There are very many color roles. It seems better to me
  to describe the role clearly, and then to consolidate later
  in the actual theme by assigning the same color.
  For example, one can set the text color of the output pane button
  individualy.

- Many elements are also drawn differently.
  For the dark theme, I wanted to have a flatter look.
  - Introduce Theme::WidgetStyle enum, for now {Original, Flat}.
  - The theme specifies which kind of widget style it wants.
  - The drawing code queries the theme's style flag and
    switches between the original, gradient based look and
    the new, flat look.

- Create some custom icons which look better on dark background
  (wip, currently folder/file icons)

- Let ManhattanStyle draw some elements for non-panelwidgets, too
  (open/close arrows in QTreeView, custom folder/file icons)

- For the welcomescreen, pass the WelcomeTheme class.
  WelcomeTheme exposes theme colors as Q_PROPERTY accessible from
  .qml

- Themes can be modified via the 'Themes' tab in the environment
  settings.

TODO:
* Unify image handling
* Avoid style name references
* Fix gradients

Change-Id: I92c2050ab0fb327649ea1eff4adec973d2073944
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Thorben Kroeger
2014-10-14 19:09:48 +02:00
committed by hjk
parent fd8fcd29a1
commit 84f5585b5d
94 changed files with 4135 additions and 359 deletions

View File

@@ -42,23 +42,30 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/find/findplugin.h>
#include <coreplugin/locator/locator.h>
#include <coreplugin/coreconstants.h>
#include <utils/macroexpander.h>
#include <utils/savefile.h>
#include <utils/stringutils.h>
#include <utils/theme/theme.h>
#include <QtPlugin>
#include <QDebug>
#include <QDateTime>
#include <QDir>
using namespace Core;
using namespace Core::Internal;
using namespace Utils;
CorePlugin::CorePlugin() : m_editMode(0), m_designMode(0)
CorePlugin::CorePlugin()
: m_mainWindow(0)
, m_editMode(0)
, m_designMode(0)
, m_findPlugin(0)
, m_locator(0)
{
qRegisterMetaType<Core::Id>();
m_mainWindow = new MainWindow;
m_findPlugin = new FindPlugin;
m_locator = new Locator;
}
CorePlugin::~CorePlugin()
@@ -84,15 +91,55 @@ CorePlugin::~CorePlugin()
void CorePlugin::parseArguments(const QStringList &arguments)
{
QString themeName = QLatin1String("default");
QColor overrideColor;
bool overrideTheme = false;
for (int i = 0; i < arguments.size(); ++i) {
if (arguments.at(i) == QLatin1String("-color")) {
const QString colorcode(arguments.at(i + 1));
m_mainWindow->setOverrideColor(QColor(colorcode));
overrideColor = QColor(colorcode);
i++; // skip the argument
}
if (arguments.at(i) == QLatin1String("-presentationMode"))
ActionManager::setPresentationModeEnabled(true);
if (arguments.at(i) == QLatin1String("-theme")) {
overrideTheme = true;
themeName = arguments.at(i + 1);
i++;
}
}
QSettings *settings = Core::ICore::settings();
QString themeURI = settings->value(QLatin1String(Core::Constants::SETTINGS_THEME)).toString();
if (!QFileInfo::exists(themeURI) || overrideTheme) {
const QString builtInTheme = QStringLiteral("%1/themes/%2.creatortheme")
.arg(ICore::resourcePath()).arg(themeName);
if (QFile::exists(builtInTheme)) {
themeURI = builtInTheme;
} else if (themeName.endsWith(QLatin1String(".creatortheme"))) {
themeURI = themeName;
} else { // TODO: Fallback to default theme
qCritical("%s", qPrintable(QCoreApplication::translate("Application", "No valid theme '%1'")
.arg(themeName)));
}
}
QSettings themeSettings(themeURI, QSettings::IniFormat);
Theme *theme = new Theme(qApp);
theme->readSettings(themeSettings);
setCreatorTheme(theme);
qApp->setPalette(creatorTheme()->palette(qApp->palette()));
// defer creation of these widgets until here,
// because they need a valid theme set
m_mainWindow = new MainWindow;
m_findPlugin = new FindPlugin;
m_locator = new Locator;
if (overrideColor.isValid())
m_mainWindow->setOverrideColor(overrideColor);
}
bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)