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>
2014-10-14 19:09:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 Thorben Kroeger <thorbenkroeger@gmail.com>.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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>
2014-10-14 19:09:48 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
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>
2014-10-14 19:09:48 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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>
2014-10-14 19:09:48 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "coreconstants.h"
|
2015-10-27 08:46:02 +01:00
|
|
|
#include "icore.h"
|
2016-01-11 23:06:44 +02:00
|
|
|
#include "manhattanstyle.h"
|
2016-01-20 22:20:59 +02:00
|
|
|
#include "themechooser.h"
|
2015-10-27 08:46:02 +01:00
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2016-01-11 23:06:44 +02:00
|
|
|
#include <utils/theme/theme.h>
|
|
|
|
|
#include <utils/theme/theme_p.h>
|
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>
2014-10-14 19:09:48 +02:00
|
|
|
|
2016-01-11 23:06:44 +02:00
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
#include <QComboBox>
|
2014-11-07 11:01:23 +02:00
|
|
|
#include <QCoreApplication>
|
2015-10-27 08:46:02 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDir>
|
2016-01-11 23:06:44 +02:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QMessageBox>
|
2015-10-27 08:46:02 +01:00
|
|
|
#include <QSettings>
|
2016-01-11 23:06:44 +02:00
|
|
|
#include <QSpacerItem>
|
|
|
|
|
|
|
|
|
|
using namespace Utils;
|
2015-10-27 08:46:02 +01:00
|
|
|
|
|
|
|
|
static const char themeNameKey[] = "ThemeName";
|
2014-11-07 11:01:23 +02:00
|
|
|
|
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>
2014-10-14 19:09:48 +02:00
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2016-01-11 17:53:18 +01:00
|
|
|
ThemeEntry::ThemeEntry(Id id, const QString &filePath)
|
|
|
|
|
: m_id(id)
|
|
|
|
|
, m_filePath(filePath)
|
2015-10-27 08:46:02 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Id ThemeEntry::id() const
|
|
|
|
|
{
|
|
|
|
|
return m_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ThemeEntry::displayName() const
|
|
|
|
|
{
|
|
|
|
|
if (m_displayName.isEmpty() && !m_filePath.isEmpty()) {
|
|
|
|
|
QSettings settings(m_filePath, QSettings::IniFormat);
|
|
|
|
|
m_displayName = settings.value(QLatin1String(themeNameKey),
|
|
|
|
|
QCoreApplication::tr("unnamed")).toString();
|
|
|
|
|
}
|
|
|
|
|
return m_displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString ThemeEntry::filePath() const
|
|
|
|
|
{
|
|
|
|
|
return m_filePath;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 23:06:44 +02:00
|
|
|
class ThemeListModel : public QAbstractListModel
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ThemeListModel(QObject *parent = 0):
|
|
|
|
|
QAbstractListModel(parent)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-17 10:49:34 +02:00
|
|
|
int rowCount(const QModelIndex &parent) const override
|
2016-01-11 23:06:44 +02:00
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : m_themes.size();
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-17 10:49:34 +02:00
|
|
|
QVariant data(const QModelIndex &index, int role) const override
|
2016-01-11 23:06:44 +02:00
|
|
|
{
|
|
|
|
|
if (role == Qt::DisplayRole)
|
|
|
|
|
return m_themes.at(index.row()).displayName();
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removeTheme(int index)
|
|
|
|
|
{
|
|
|
|
|
beginRemoveRows(QModelIndex(), index, index);
|
|
|
|
|
m_themes.removeAt(index);
|
|
|
|
|
endRemoveRows();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setThemes(const QList<ThemeEntry> &themes)
|
|
|
|
|
{
|
|
|
|
|
beginResetModel();
|
|
|
|
|
m_themes = themes;
|
|
|
|
|
endResetModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ThemeEntry &themeAt(int index) const
|
|
|
|
|
{
|
|
|
|
|
return m_themes.at(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
QList<ThemeEntry> m_themes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2016-01-20 22:20:59 +02:00
|
|
|
class ThemeChooserPrivate
|
2016-01-11 23:06:44 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2016-01-20 22:20:59 +02:00
|
|
|
ThemeChooserPrivate(QWidget *widget);
|
|
|
|
|
~ThemeChooserPrivate();
|
2016-01-11 23:06:44 +02:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ThemeListModel *m_themeListModel;
|
|
|
|
|
QComboBox *m_themeComboBox;
|
|
|
|
|
};
|
|
|
|
|
|
2016-01-20 22:20:59 +02:00
|
|
|
ThemeChooserPrivate::ThemeChooserPrivate(QWidget *widget)
|
2016-01-11 23:06:44 +02:00
|
|
|
: m_themeListModel(new ThemeListModel)
|
|
|
|
|
, m_themeComboBox(new QComboBox)
|
|
|
|
|
{
|
|
|
|
|
QHBoxLayout *layout = new QHBoxLayout(widget);
|
|
|
|
|
layout->addWidget(m_themeComboBox);
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
auto horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
|
layout->addSpacerItem(horizontalSpacer);
|
|
|
|
|
m_themeComboBox->setModel(m_themeListModel);
|
2016-01-20 22:24:42 +02:00
|
|
|
const QList<ThemeEntry> themes = ThemeEntry::availableThemes();
|
|
|
|
|
const Id activeTheme = Id::fromString(creatorTheme()->id());
|
|
|
|
|
const int selected = Utils::indexOf(themes, Utils::equal(&ThemeEntry::id, activeTheme));
|
|
|
|
|
m_themeListModel->setThemes(themes);
|
|
|
|
|
if (selected >= 0)
|
|
|
|
|
m_themeComboBox->setCurrentIndex(selected);
|
2016-01-11 23:06:44 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 22:20:59 +02:00
|
|
|
ThemeChooserPrivate::~ThemeChooserPrivate()
|
2016-01-11 23:06:44 +02:00
|
|
|
{
|
|
|
|
|
delete m_themeListModel;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-20 22:20:59 +02:00
|
|
|
ThemeChooser::ThemeChooser(QWidget *parent) :
|
2016-01-11 23:06:44 +02:00
|
|
|
QWidget(parent)
|
|
|
|
|
{
|
2016-01-20 22:20:59 +02:00
|
|
|
d = new ThemeChooserPrivate(this);
|
2016-01-11 23:06:44 +02:00
|
|
|
}
|
|
|
|
|
|
2016-01-20 22:20:59 +02:00
|
|
|
ThemeChooser::~ThemeChooser()
|
2016-01-11 23:06:44 +02:00
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-20 22:20:59 +02:00
|
|
|
void ThemeChooser::apply()
|
2016-01-11 23:06:44 +02:00
|
|
|
{
|
|
|
|
|
const int index = d->m_themeComboBox->currentIndex();
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return;
|
|
|
|
|
const QString themeId = d->m_themeListModel->themeAt(index).id().toString();
|
|
|
|
|
QSettings *settings = ICore::settings();
|
|
|
|
|
const QString currentThemeId = settings->value(QLatin1String(Constants::SETTINGS_THEME),
|
2016-03-18 11:15:20 +01:00
|
|
|
QLatin1String(Constants::DEFAULT_THEME)).toString();
|
2016-01-11 23:06:44 +02:00
|
|
|
if (currentThemeId != themeId) {
|
|
|
|
|
QMessageBox::information(ICore::mainWindow(), tr("Restart Required"),
|
|
|
|
|
tr("The theme change will take effect after a restart of Qt Creator."));
|
|
|
|
|
|
|
|
|
|
// save filename of selected theme in global config
|
|
|
|
|
settings->setValue(QLatin1String(Constants::SETTINGS_THEME), themeId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 17:53:18 +01:00
|
|
|
static void addThemesFromPath(const QString &path, QList<ThemeEntry> *themes)
|
2015-10-27 08:46:02 +01:00
|
|
|
{
|
2016-01-11 17:53:18 +01:00
|
|
|
static const QLatin1String extension("*.creatortheme");
|
2015-10-27 08:46:02 +01:00
|
|
|
QDir themeDir(path);
|
2016-01-11 17:53:18 +01:00
|
|
|
themeDir.setNameFilters(QStringList() << extension);
|
2015-10-27 08:46:02 +01:00
|
|
|
themeDir.setFilter(QDir::Files);
|
|
|
|
|
const QStringList themeList = themeDir.entryList();
|
|
|
|
|
foreach (const QString &fileName, themeList) {
|
|
|
|
|
QString id = QFileInfo(fileName).completeBaseName();
|
2016-01-11 17:53:18 +01:00
|
|
|
themes->append(ThemeEntry(Id::fromString(id), themeDir.absoluteFilePath(fileName)));
|
2015-10-27 08:46:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-11 22:56:00 +02:00
|
|
|
QList<ThemeEntry> ThemeEntry::availableThemes()
|
2015-10-27 08:46:02 +01:00
|
|
|
{
|
|
|
|
|
QList<ThemeEntry> themes;
|
|
|
|
|
|
|
|
|
|
static const QString installThemeDir = ICore::resourcePath() + QLatin1String("/themes");
|
|
|
|
|
static const QString userThemeDir = ICore::userResourcePath() + QLatin1String("/themes");
|
2016-01-11 17:53:18 +01:00
|
|
|
addThemesFromPath(installThemeDir, &themes);
|
2015-10-27 08:46:02 +01:00
|
|
|
if (themes.isEmpty())
|
|
|
|
|
qWarning() << "Warning: No themes found in installation: "
|
|
|
|
|
<< QDir::toNativeSeparators(installThemeDir);
|
|
|
|
|
// move default theme to front
|
2016-03-18 11:15:20 +01:00
|
|
|
int defaultIndex = Utils::indexOf(themes, Utils::equal(&ThemeEntry::id, Id(Constants::DEFAULT_THEME)));
|
2015-10-27 08:46:02 +01:00
|
|
|
if (defaultIndex > 0) { // == exists and not at front
|
|
|
|
|
ThemeEntry defaultEntry = themes.takeAt(defaultIndex);
|
|
|
|
|
themes.prepend(defaultEntry);
|
|
|
|
|
}
|
2016-01-11 17:53:18 +01:00
|
|
|
addThemesFromPath(userThemeDir, &themes);
|
2015-10-27 08:46:02 +01:00
|
|
|
return themes;
|
|
|
|
|
}
|
|
|
|
|
|
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>
2014-10-14 19:09:48 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|