2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fancyactionbar.h"
|
2010-02-09 19:05:15 +01:00
|
|
|
#include "coreconstants.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-03-14 10:44:46 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2010-01-21 21:12:40 +01:00
|
|
|
#include <utils/stylehelper.h>
|
2011-11-14 17:33:28 +01:00
|
|
|
#include <utils/stringutils.h>
|
2013-01-10 15:12:39 +01:00
|
|
|
#include <utils/tooltip/tooltip.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
|
|
|
#include <utils/theme/theme.h>
|
2010-01-21 21:12:40 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QAction>
|
|
|
|
|
#include <QStyle>
|
|
|
|
|
#include <QStyleOption>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QEvent>
|
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
|
#include <QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-09-11 17:11:15 +02:00
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
FancyToolButton::FancyToolButton(QWidget *parent)
|
2010-02-17 17:20:31 +01:00
|
|
|
: QToolButton(parent), m_fader(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setAttribute(Qt::WA_Hover, true);
|
2009-07-13 18:04:08 +02:00
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-17 17:09:00 +01:00
|
|
|
bool FancyToolButton::event(QEvent *e)
|
|
|
|
|
{
|
2012-11-28 20:44:03 +02:00
|
|
|
switch (e->type()) {
|
2010-02-17 17:09:00 +01:00
|
|
|
case QEvent::Enter:
|
|
|
|
|
{
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
|
2010-02-17 17:20:31 +01:00
|
|
|
animation->setDuration(125);
|
2010-02-17 17:09:00 +01:00
|
|
|
animation->setEndValue(1.0);
|
|
|
|
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case QEvent::Leave:
|
|
|
|
|
{
|
|
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation(this, "fader");
|
2010-02-17 17:20:31 +01:00
|
|
|
animation->setDuration(125);
|
2010-02-17 17:09:00 +01:00
|
|
|
animation->setEndValue(0.0);
|
|
|
|
|
animation->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2013-01-10 15:12:39 +01:00
|
|
|
case QEvent::ToolTip:
|
|
|
|
|
{
|
|
|
|
|
QHelpEvent *he = static_cast<QHelpEvent *>(e);
|
2014-12-08 10:57:05 +01:00
|
|
|
ToolTip::show(mapToGlobal(he->pos()), toolTip(), this);
|
2013-01-10 15:12:39 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2010-02-17 17:09:00 +01:00
|
|
|
default:
|
|
|
|
|
return QToolButton::event(e);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-14 17:33:28 +01:00
|
|
|
static QVector<QString> splitInTwoLines(const QString &text, const QFontMetrics &fontMetrics,
|
|
|
|
|
qreal availableWidth)
|
|
|
|
|
{
|
|
|
|
|
// split in two lines.
|
|
|
|
|
// this looks if full words can be split off at the end of the string,
|
|
|
|
|
// to put them in the second line. First line is drawn with ellipsis,
|
|
|
|
|
// second line gets ellipsis if it couldn't split off full words.
|
|
|
|
|
QVector<QString> splitLines(2);
|
|
|
|
|
QRegExp rx(QLatin1String("\\s+"));
|
|
|
|
|
int splitPos = -1;
|
|
|
|
|
int nextSplitPos = text.length();
|
|
|
|
|
do {
|
|
|
|
|
nextSplitPos = rx.lastIndexIn(text,
|
|
|
|
|
nextSplitPos - text.length() - 1);
|
|
|
|
|
if (nextSplitPos != -1) {
|
|
|
|
|
int splitCandidate = nextSplitPos + rx.matchedLength();
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (fontMetrics.width(text.mid(splitCandidate)) <= availableWidth)
|
2011-11-14 17:33:28 +01:00
|
|
|
splitPos = splitCandidate;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-11-14 17:33:28 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (nextSplitPos > 0 && fontMetrics.width(text.left(nextSplitPos)) > availableWidth);
|
|
|
|
|
// check if we could split at white space at all
|
|
|
|
|
if (splitPos < 0) {
|
|
|
|
|
splitLines[0] = fontMetrics.elidedText(text, Qt::ElideRight,
|
|
|
|
|
availableWidth);
|
|
|
|
|
QString common = Utils::commonPrefix(QStringList()
|
|
|
|
|
<< splitLines[0] << text);
|
|
|
|
|
splitLines[1] = text.mid(common.length());
|
|
|
|
|
// elide the second line even if it fits, since it is cut off in mid-word
|
|
|
|
|
while (fontMetrics.width(QChar(0x2026) /*'...'*/ + splitLines[1]) > availableWidth
|
|
|
|
|
&& splitLines[1].length() > 3
|
|
|
|
|
/*keep at least three original characters (should not happen)*/) {
|
|
|
|
|
splitLines[1].remove(0, 1);
|
|
|
|
|
}
|
|
|
|
|
splitLines[1] = QChar(0x2026) /*'...'*/ + splitLines[1];
|
|
|
|
|
} else {
|
|
|
|
|
splitLines[0] = fontMetrics.elidedText(text.left(splitPos).trimmed(), Qt::ElideRight, availableWidth);
|
|
|
|
|
splitLines[1] = text.mid(splitPos);
|
|
|
|
|
}
|
|
|
|
|
return splitLines;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FancyToolButton::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
2010-01-22 18:04:24 +01:00
|
|
|
QPainter painter(this);
|
2010-01-21 21:12:40 +01:00
|
|
|
|
2010-01-22 18:04:24 +01:00
|
|
|
// draw borders
|
2010-01-21 21:12:40 +01:00
|
|
|
bool isTitledAction = defaultAction()->property("titledAction").toBool();
|
|
|
|
|
|
2013-03-14 10:44:46 +01:00
|
|
|
|
|
|
|
|
if (!Utils::HostOsInfo::isMacHost() // Mac UIs usually don't hover
|
|
|
|
|
&& m_fader > 0 && isEnabled() && !isDown() && !isChecked()) {
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.save();
|
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
|
|
|
const QColor hoverColor = creatorTheme()->color(Theme::FancyToolButtonHoverColor);
|
|
|
|
|
QColor fadedHoverColor = hoverColor;
|
|
|
|
|
fadedHoverColor.setAlpha(int(m_fader * hoverColor.alpha()));
|
|
|
|
|
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
|
|
|
|
|
QLinearGradient grad(rect().topLeft(), rect().topRight());
|
|
|
|
|
grad.setColorAt(0, Qt::transparent);
|
|
|
|
|
grad.setColorAt(0.5, fadedHoverColor);
|
|
|
|
|
grad.setColorAt(1, Qt::transparent);
|
|
|
|
|
painter.fillRect(rect(), grad);
|
|
|
|
|
painter.setPen(QPen(grad, 1.0));
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
|
|
|
|
|
} else {
|
|
|
|
|
painter.fillRect(rect(), fadedHoverColor);
|
|
|
|
|
}
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.restore();
|
2013-03-14 10:44:46 +01:00
|
|
|
} else if (isDown() || isChecked()) {
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.save();
|
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
|
|
|
const QColor selectedColor = creatorTheme()->color(Theme::FancyToolButtonSelectedColor);
|
|
|
|
|
if (creatorTheme()->widgetStyle() == Theme::StyleDefault) {
|
|
|
|
|
QLinearGradient grad(rect().topLeft(), rect().topRight());
|
|
|
|
|
grad.setColorAt(0, Qt::transparent);
|
|
|
|
|
grad.setColorAt(0.5, selectedColor);
|
|
|
|
|
grad.setColorAt(1, Qt::transparent);
|
|
|
|
|
painter.fillRect(rect(), grad);
|
|
|
|
|
painter.setPen(QPen(grad, 1.0));
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.drawLine(rect().topLeft() + QPoint(0,1), rect().topRight() + QPoint(0,1));
|
|
|
|
|
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
|
|
|
|
|
painter.drawLine(rect().bottomLeft(), rect().bottomRight());
|
|
|
|
|
painter.drawLine(rect().topLeft() - QPoint(0,1), rect().topRight() - QPoint(0,1));
|
|
|
|
|
} else {
|
|
|
|
|
painter.fillRect(rect(), selectedColor);
|
|
|
|
|
}
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.restore();
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
|
|
|
|
|
2014-11-16 10:52:41 +02:00
|
|
|
QRect iconRect(0, 0, Constants::TARGET_ICON_SIZE, Constants::TARGET_ICON_SIZE);
|
2010-01-22 18:04:24 +01:00
|
|
|
// draw popup texts
|
2010-01-21 21:12:40 +01:00
|
|
|
if (isTitledAction) {
|
2010-03-12 18:46:25 +01:00
|
|
|
|
2010-01-22 18:04:24 +01:00
|
|
|
QFont normalFont(painter.font());
|
2010-03-23 15:47:43 +01:00
|
|
|
QRect centerRect = rect();
|
2010-01-22 18:04:24 +01:00
|
|
|
normalFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
|
|
|
|
|
QFont boldFont(normalFont);
|
|
|
|
|
boldFont.setBold(true);
|
|
|
|
|
QFontMetrics fm(normalFont);
|
|
|
|
|
QFontMetrics boldFm(boldFont);
|
|
|
|
|
int lineHeight = boldFm.height();
|
|
|
|
|
int textFlags = Qt::AlignVCenter|Qt::AlignHCenter;
|
|
|
|
|
|
2010-03-12 18:46:25 +01:00
|
|
|
const QString projectName = defaultAction()->property("heading").toString();
|
|
|
|
|
if (!projectName.isNull())
|
2010-03-23 15:47:43 +01:00
|
|
|
centerRect.adjust(0, lineHeight + 4, 0, 0);
|
2010-03-12 18:46:25 +01:00
|
|
|
|
2012-01-26 13:06:30 +01:00
|
|
|
centerRect.adjust(0, 0, 0, -lineHeight*2 - 4);
|
2010-03-12 18:46:25 +01:00
|
|
|
|
2010-03-23 15:47:43 +01:00
|
|
|
iconRect.moveCenter(centerRect.center());
|
|
|
|
|
Utils::StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, isEnabled() ? QIcon::Normal : QIcon::Disabled);
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.setFont(normalFont);
|
|
|
|
|
|
2010-03-23 15:47:43 +01:00
|
|
|
QPoint textOffset = centerRect.center() - QPoint(iconRect.width()/2, iconRect.height()/2);
|
|
|
|
|
textOffset = textOffset - QPoint(0, lineHeight + 4);
|
2010-01-22 18:04:24 +01:00
|
|
|
QRectF r(0, textOffset.y(), rect().width(), lineHeight);
|
2010-01-21 21:12:40 +01:00
|
|
|
QColor penColor;
|
|
|
|
|
if (isEnabled())
|
|
|
|
|
penColor = Qt::white;
|
|
|
|
|
else
|
|
|
|
|
penColor = Qt::gray;
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.setPen(penColor);
|
2010-03-12 18:46:25 +01:00
|
|
|
|
2011-11-14 17:33:28 +01:00
|
|
|
// draw project name
|
2010-04-14 17:59:31 +02:00
|
|
|
const int margin = 6;
|
2011-11-14 17:33:28 +01:00
|
|
|
const qreal availableWidth = r.width() - margin;
|
|
|
|
|
QString ellidedProjectName = fm.elidedText(projectName, Qt::ElideMiddle, availableWidth);
|
2010-01-21 21:12:40 +01:00
|
|
|
if (isEnabled()) {
|
2010-01-22 18:04:24 +01:00
|
|
|
const QRectF shadowR = r.translated(0, 1);
|
|
|
|
|
painter.setPen(QColor(30, 30, 30, 80));
|
|
|
|
|
painter.drawText(shadowR, textFlags, ellidedProjectName);
|
|
|
|
|
painter.setPen(penColor);
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.drawText(r, textFlags, ellidedProjectName);
|
2011-11-14 17:33:28 +01:00
|
|
|
|
|
|
|
|
// draw build configuration name
|
2010-03-23 15:47:43 +01:00
|
|
|
textOffset = iconRect.center() + QPoint(iconRect.width()/2, iconRect.height()/2);
|
2011-11-14 17:33:28 +01:00
|
|
|
QRectF buildConfigRect[2];
|
|
|
|
|
buildConfigRect[0] = QRectF(0, textOffset.y() + 5, rect().width(), lineHeight);
|
|
|
|
|
buildConfigRect[1] = QRectF(0, textOffset.y() + 5 + lineHeight, rect().width(), lineHeight);
|
2010-01-22 18:04:24 +01:00
|
|
|
painter.setFont(boldFont);
|
2011-11-14 17:33:28 +01:00
|
|
|
QVector<QString> splitBuildConfiguration(2);
|
2012-01-26 13:06:30 +01:00
|
|
|
const QString buildConfiguration = defaultAction()->property("subtitle").toString();
|
2011-11-14 17:33:28 +01:00
|
|
|
if (boldFm.width(buildConfiguration) <= availableWidth) {
|
|
|
|
|
// text fits in one line
|
|
|
|
|
splitBuildConfiguration[0] = buildConfiguration;
|
|
|
|
|
} else {
|
|
|
|
|
splitBuildConfiguration = splitInTwoLines(buildConfiguration, boldFm, availableWidth);
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
2011-11-14 17:33:28 +01:00
|
|
|
// draw the two lines for the build configuration
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
|
if (splitBuildConfiguration[i].isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
if (isEnabled()) {
|
|
|
|
|
const QRectF shadowR = buildConfigRect[i].translated(0, 1);
|
|
|
|
|
painter.setPen(QColor(30, 30, 30, 80));
|
|
|
|
|
painter.drawText(shadowR, textFlags, splitBuildConfiguration[i]);
|
|
|
|
|
painter.setPen(penColor);
|
|
|
|
|
}
|
|
|
|
|
painter.drawText(buildConfigRect[i], textFlags, splitBuildConfiguration[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pop up arrow next to icon
|
2010-03-12 18:46:25 +01:00
|
|
|
if (!icon().isNull()) {
|
|
|
|
|
QStyleOption opt;
|
|
|
|
|
opt.initFrom(this);
|
2010-03-23 15:47:43 +01:00
|
|
|
opt.rect = rect().adjusted(rect().width() - 16, 0, -8, 0);
|
2010-03-12 18:46:25 +01:00
|
|
|
Utils::StyleHelper::drawArrow(QStyle::PE_IndicatorArrowRight, &painter, &opt);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-03-23 15:47:43 +01:00
|
|
|
iconRect.moveCenter(rect().center());
|
|
|
|
|
Utils::StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, isEnabled() ? QIcon::Normal : QIcon::Disabled);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyActionBar::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
2010-02-17 17:09:00 +01:00
|
|
|
QPainter painter(this);
|
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
|
|
|
|
|
|
|
|
if (creatorTheme()->widgetStyle () == Theme::StyleFlat) {
|
|
|
|
|
// this paints the background of the bottom portion of the
|
|
|
|
|
// left tab bar
|
|
|
|
|
painter.fillRect(event->rect(), creatorTheme()->color(Theme::FancyTabBarBackgroundColor));
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 11:41:58 +01:00
|
|
|
QColor light = Utils::StyleHelper::sidebarHighlight();
|
|
|
|
|
QColor dark = Utils::StyleHelper::sidebarShadow();
|
2010-02-17 17:09:00 +01:00
|
|
|
painter.setPen(dark);
|
|
|
|
|
painter.drawLine(rect().topLeft(), rect().topRight());
|
|
|
|
|
painter.setPen(light);
|
2010-02-19 18:05:42 +01:00
|
|
|
painter.drawLine(rect().topLeft() + QPoint(1,1), rect().topRight() + QPoint(0,1));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-02-17 17:09:00 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QSize FancyToolButton::sizeHint() const
|
|
|
|
|
{
|
2010-03-11 18:05:29 +01:00
|
|
|
QSizeF buttonSize = iconSize().expandedTo(QSize(64, 38));
|
2010-01-21 21:12:40 +01:00
|
|
|
if (defaultAction()->property("titledAction").toBool()) {
|
2010-01-22 18:04:24 +01:00
|
|
|
QFont boldFont(font());
|
|
|
|
|
boldFont.setPointSizeF(Utils::StyleHelper::sidebarFontSize());
|
|
|
|
|
boldFont.setBold(true);
|
|
|
|
|
QFontMetrics fm(boldFont);
|
|
|
|
|
qreal lineHeight = fm.height();
|
2010-03-12 18:46:25 +01:00
|
|
|
const QString projectName = defaultAction()->property("heading").toString();
|
2010-03-19 18:40:00 +01:00
|
|
|
buttonSize += QSizeF(0, 10);
|
2010-03-12 18:46:25 +01:00
|
|
|
if (!projectName.isEmpty())
|
2010-03-19 18:40:00 +01:00
|
|
|
buttonSize += QSizeF(0, lineHeight + 2);
|
2010-03-12 18:46:25 +01:00
|
|
|
|
2012-01-26 13:06:30 +01:00
|
|
|
buttonSize += QSizeF(0, lineHeight*2 + 2);
|
2010-01-21 21:12:40 +01:00
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
return buttonSize.toSize();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-13 18:04:08 +02:00
|
|
|
QSize FancyToolButton::minimumSizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return QSize(8, 8);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-16 15:50:52 +02:00
|
|
|
void FancyToolButton::actionChanged()
|
|
|
|
|
{
|
|
|
|
|
// the default action changed in some way, e.g. it might got hidden
|
|
|
|
|
// since we inherit a tool button we won't get invisible, so do this here
|
2013-06-19 12:54:53 +02:00
|
|
|
if (QAction* action = defaultAction())
|
|
|
|
|
setVisible(action->isVisible());
|
2009-10-16 15:50:52 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
FancyActionBar::FancyActionBar(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
2012-01-30 16:39:10 +02:00
|
|
|
setObjectName(QLatin1String("actionbar"));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_actionsLayout = new QVBoxLayout;
|
2010-01-21 21:12:40 +01:00
|
|
|
QVBoxLayout *spacerLayout = new QVBoxLayout;
|
|
|
|
|
spacerLayout->addLayout(m_actionsLayout);
|
2010-03-31 18:51:06 +02:00
|
|
|
int sbh = 8;
|
2010-01-21 21:12:40 +01:00
|
|
|
spacerLayout->addSpacing(sbh);
|
|
|
|
|
spacerLayout->setMargin(0);
|
|
|
|
|
spacerLayout->setSpacing(0);
|
2010-02-17 17:09:00 +01:00
|
|
|
setLayout(spacerLayout);
|
|
|
|
|
setContentsMargins(0,2,0,0);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-21 21:12:40 +01:00
|
|
|
void FancyActionBar::addProjectSelector(QAction *action)
|
|
|
|
|
{
|
|
|
|
|
FancyToolButton* toolButton = new FancyToolButton(this);
|
|
|
|
|
toolButton->setDefaultAction(action);
|
|
|
|
|
connect(action, SIGNAL(changed()), toolButton, SLOT(actionChanged()));
|
|
|
|
|
m_actionsLayout->insertWidget(0, toolButton);
|
|
|
|
|
|
|
|
|
|
}
|
2010-01-22 18:04:24 +01:00
|
|
|
void FancyActionBar::insertAction(int index, QAction *action)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
FancyToolButton *toolButton = new FancyToolButton(this);
|
|
|
|
|
toolButton->setDefaultAction(action);
|
2009-10-16 15:50:52 +02:00
|
|
|
connect(action, SIGNAL(changed()), toolButton, SLOT(actionChanged()));
|
2008-12-02 12:01:29 +01:00
|
|
|
m_actionsLayout->insertWidget(index, toolButton);
|
|
|
|
|
}
|
2009-08-20 18:44:02 +02:00
|
|
|
|
2010-01-21 21:12:40 +01:00
|
|
|
QLayout *FancyActionBar::actionsLayout() const
|
|
|
|
|
{
|
|
|
|
|
return m_actionsLayout;
|
|
|
|
|
}
|
2010-03-31 18:51:06 +02:00
|
|
|
|
|
|
|
|
QSize FancyActionBar::minimumSizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return sizeHint();
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 17:11:15 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Core
|