2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
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
|
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.
|
2008-12-02 14:17:16 +01: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.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
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 "fancytabwidget.h"
|
2015-10-22 13:40:44 +02:00
|
|
|
#include "fancyactionbar.h"
|
|
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2009-07-15 12:38:45 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2009-07-16 17:34:04 +02:00
|
|
|
#include <utils/styledbar.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>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QColorDialog>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
#include <QMouseEvent>
|
2012-11-27 18:46:12 +01:00
|
|
|
#include <QStyleFactory>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPainter>
|
2015-10-19 18:03:10 +02:00
|
|
|
#include <QPixmapCache>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStackedLayout>
|
|
|
|
|
#include <QStatusBar>
|
|
|
|
|
#include <QToolTip>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Internal;
|
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
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
const int FancyTabBar::m_rounding = 22;
|
|
|
|
|
const int FancyTabBar::m_textPadding = 4;
|
|
|
|
|
|
2010-02-17 18:41:41 +01:00
|
|
|
void FancyTab::fadeIn()
|
|
|
|
|
{
|
2010-02-18 13:57:33 +01:00
|
|
|
animator.stop();
|
|
|
|
|
animator.setDuration(80);
|
2015-10-22 13:40:44 +02:00
|
|
|
animator.setEndValue(1);
|
2010-02-18 13:57:33 +01:00
|
|
|
animator.start();
|
2010-02-17 18:41:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTab::fadeOut()
|
|
|
|
|
{
|
2010-02-18 13:57:33 +01:00
|
|
|
animator.stop();
|
|
|
|
|
animator.setDuration(160);
|
|
|
|
|
animator.setEndValue(0);
|
|
|
|
|
animator.start();
|
2010-02-17 18:41:41 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-19 16:16:31 +01:00
|
|
|
void FancyTab::setFader(float value)
|
|
|
|
|
{
|
|
|
|
|
m_fader = value;
|
|
|
|
|
tabbar->update();
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
FancyTabBar::FancyTabBar(QWidget *parent)
|
2009-07-13 16:58:13 +02:00
|
|
|
: QWidget(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-13 16:58:13 +02:00
|
|
|
m_hoverIndex = -1;
|
2009-12-15 16:42:56 +01:00
|
|
|
m_currentIndex = -1;
|
2009-07-13 16:58:13 +02:00
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
2012-11-27 18:46:12 +01:00
|
|
|
setStyle(QStyleFactory::create(QLatin1String("windows")));
|
2008-12-02 12:01:29 +01:00
|
|
|
setMinimumWidth(qMax(2 * m_rounding, 40));
|
|
|
|
|
setAttribute(Qt::WA_Hover, true);
|
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
setMouseTracking(true); // Needed for hover events
|
2010-02-18 12:04:00 +01:00
|
|
|
m_triggerTimer.setSingleShot(true);
|
|
|
|
|
|
|
|
|
|
// We use a zerotimer to keep the sidebar responsive
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(&m_triggerTimer, &QTimer::timeout, this, &FancyTabBar::emitCurrentIndex);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FancyTabBar::~FancyTabBar()
|
|
|
|
|
{
|
|
|
|
|
delete style();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
QSize FancyTabBar::tabSizeHint(bool minimum) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
QFont boldFont(font());
|
2015-02-03 23:48:19 +02:00
|
|
|
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
2008-12-02 12:01:29 +01:00
|
|
|
boldFont.setBold(true);
|
|
|
|
|
QFontMetrics fm(boldFont);
|
2010-02-17 17:20:31 +01:00
|
|
|
int spacing = 8;
|
2008-12-02 12:01:29 +01:00
|
|
|
int width = 60 + spacing + 2;
|
2010-04-14 17:59:31 +02:00
|
|
|
int maxLabelwidth = 0;
|
|
|
|
|
for (int tab=0 ; tab<count() ;++tab) {
|
|
|
|
|
int width = fm.width(tabText(tab));
|
|
|
|
|
if (width > maxLabelwidth)
|
|
|
|
|
maxLabelwidth = width;
|
|
|
|
|
}
|
2009-07-14 11:03:48 +02:00
|
|
|
int iconHeight = minimum ? 0 : 32;
|
2010-04-14 17:59:31 +02:00
|
|
|
return QSize(qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabBar::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QPainter p(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) {
|
|
|
|
|
// draw background of upper part of left tab widget
|
|
|
|
|
// (Welcome, ... Help)
|
2016-02-16 21:06:44 +01:00
|
|
|
p.fillRect(event->rect(), StyleHelper::isBaseColorDefault()
|
|
|
|
|
? creatorTheme()->color(Theme::FancyTabBarBackgroundColor)
|
|
|
|
|
: StyleHelper::baseColor());
|
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
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
for (int i = 0; i < count(); ++i)
|
|
|
|
|
if (i != currentIndex())
|
|
|
|
|
paintTab(&p, i);
|
|
|
|
|
|
|
|
|
|
// paint active tab last, since it overlaps the neighbors
|
2010-02-16 15:58:02 +01:00
|
|
|
if (currentIndex() != -1)
|
|
|
|
|
paintTab(&p, currentIndex());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle hover events for mouse fade ins
|
|
|
|
|
void FancyTabBar::mouseMoveEvent(QMouseEvent *e)
|
|
|
|
|
{
|
2010-02-19 16:16:31 +01:00
|
|
|
int newHover = -1;
|
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
|
QRect area = tabRect(i);
|
|
|
|
|
if (area.contains(e->pos())) {
|
|
|
|
|
newHover = i;
|
|
|
|
|
break;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2010-02-19 16:16:31 +01:00
|
|
|
}
|
|
|
|
|
if (newHover == m_hoverIndex)
|
|
|
|
|
return;
|
2009-07-21 10:43:07 +02:00
|
|
|
|
2010-02-19 16:16:31 +01:00
|
|
|
if (validIndex(m_hoverIndex))
|
|
|
|
|
m_tabs[m_hoverIndex]->fadeOut();
|
2010-02-17 18:41:41 +01:00
|
|
|
|
2010-02-19 16:16:31 +01:00
|
|
|
m_hoverIndex = newHover;
|
2009-07-21 10:43:07 +02:00
|
|
|
|
2010-02-19 16:16:31 +01:00
|
|
|
if (validIndex(m_hoverIndex)) {
|
|
|
|
|
m_tabs[m_hoverIndex]->fadeIn();
|
|
|
|
|
m_hoverRect = tabRect(m_hoverIndex);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
bool FancyTabBar::event(QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::ToolTip) {
|
2010-02-17 18:41:41 +01:00
|
|
|
if (validIndex(m_hoverIndex)) {
|
2009-07-13 16:58:13 +02:00
|
|
|
QString tt = tabToolTip(m_hoverIndex);
|
|
|
|
|
if (!tt.isEmpty()) {
|
|
|
|
|
QToolTip::showText(static_cast<QHelpEvent*>(event)->globalPos(), tt, this);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Resets hover animation on mouse enter
|
|
|
|
|
void FancyTabBar::enterEvent(QEvent *e)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(e)
|
2008-12-02 12:01:29 +01:00
|
|
|
m_hoverRect = QRect();
|
2009-07-13 16:58:13 +02:00
|
|
|
m_hoverIndex = -1;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Resets hover animation on mouse enter
|
|
|
|
|
void FancyTabBar::leaveEvent(QEvent *e)
|
|
|
|
|
{
|
2009-07-13 17:35:17 +02:00
|
|
|
Q_UNUSED(e)
|
2010-02-18 13:57:33 +01:00
|
|
|
m_hoverIndex = -1;
|
|
|
|
|
m_hoverRect = QRect();
|
|
|
|
|
for (int i = 0 ; i < m_tabs.count() ; ++i) {
|
|
|
|
|
m_tabs[i]->fadeOut();
|
2009-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
QSize FancyTabBar::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
QSize sh = tabSizeHint();
|
|
|
|
|
return QSize(sh.width(), sh.height() * m_tabs.count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize FancyTabBar::minimumSizeHint() const
|
|
|
|
|
{
|
|
|
|
|
QSize sh = tabSizeHint(true);
|
|
|
|
|
return QSize(sh.width(), sh.height() * m_tabs.count());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QRect FancyTabBar::tabRect(int index) const
|
|
|
|
|
{
|
|
|
|
|
QSize sh = tabSizeHint();
|
|
|
|
|
|
|
|
|
|
if (sh.height() * m_tabs.count() > height())
|
|
|
|
|
sh.setHeight(height() / m_tabs.count());
|
|
|
|
|
|
|
|
|
|
return QRect(0, index * sh.height(), sh.width(), sh.height());
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-18 12:04:00 +01:00
|
|
|
// This keeps the sidebar responsive since
|
|
|
|
|
// we get a repaint before loading the
|
|
|
|
|
// mode itself
|
|
|
|
|
void FancyTabBar::emitCurrentIndex()
|
|
|
|
|
{
|
|
|
|
|
emit currentChanged(m_currentIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
void FancyTabBar::mousePressEvent(QMouseEvent *e)
|
|
|
|
|
{
|
|
|
|
|
e->accept();
|
2010-03-08 15:05:55 +01:00
|
|
|
for (int index = 0; index < m_tabs.count(); ++index) {
|
|
|
|
|
if (tabRect(index).contains(e->pos())) {
|
|
|
|
|
|
|
|
|
|
if (isTabEnabled(index)) {
|
|
|
|
|
m_currentIndex = index;
|
|
|
|
|
update();
|
|
|
|
|
m_triggerTimer.start(0);
|
|
|
|
|
}
|
2009-07-13 16:58:13 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-19 18:03:10 +02:00
|
|
|
static void paintSelectedTabBackground(QPainter *painter, const QRect &spanRect)
|
|
|
|
|
{
|
|
|
|
|
const int verticalOverlap = 2; // Grows up and down for the overlaps
|
|
|
|
|
const int dpr = painter->device()->devicePixelRatio();
|
|
|
|
|
const QString cacheKey = QLatin1String(Q_FUNC_INFO) + QString::number(spanRect.width())
|
|
|
|
|
+ QLatin1Char('x') + QString::number(spanRect.height())
|
|
|
|
|
+ QLatin1Char('@') + QString::number(dpr);
|
|
|
|
|
QPixmap selection;
|
|
|
|
|
if (!QPixmapCache::find(cacheKey, &selection)) {
|
|
|
|
|
selection = QPixmap(QSize(spanRect.width(), spanRect.height() + 2 * verticalOverlap) * dpr);
|
|
|
|
|
selection.fill(Qt::transparent);
|
|
|
|
|
selection.setDevicePixelRatio(dpr);
|
|
|
|
|
QPainter p(&selection);
|
|
|
|
|
p.translate(QPoint(0, verticalOverlap));
|
|
|
|
|
|
|
|
|
|
const QRect rect(QPoint(), spanRect.size());
|
|
|
|
|
const QRectF borderRect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
|
|
|
|
|
|
|
|
|
|
//background
|
|
|
|
|
p.save();
|
|
|
|
|
QLinearGradient grad(rect.topLeft(), rect.topRight());
|
|
|
|
|
grad.setColorAt(0, QColor(255, 255, 255, 140));
|
|
|
|
|
grad.setColorAt(1, QColor(255, 255, 255, 210));
|
|
|
|
|
p.fillRect(rect, grad);
|
|
|
|
|
p.restore();
|
|
|
|
|
|
|
|
|
|
//shadows
|
|
|
|
|
p.setPen(QColor(0, 0, 0, 110));
|
|
|
|
|
p.drawLine(borderRect.topLeft() + QPointF(1, -1), borderRect.topRight() - QPointF(0, 1));
|
|
|
|
|
p.drawLine(borderRect.bottomLeft(), borderRect.bottomRight());
|
|
|
|
|
p.setPen(QColor(0, 0, 0, 40));
|
|
|
|
|
p.drawLine(borderRect.topLeft(), borderRect.bottomLeft());
|
|
|
|
|
|
|
|
|
|
//highlights
|
|
|
|
|
p.setPen(QColor(255, 255, 255, 50));
|
|
|
|
|
p.drawLine(borderRect.topLeft() + QPointF(0, -2), borderRect.topRight() - QPointF(0, 2));
|
|
|
|
|
p.drawLine(borderRect.bottomLeft() + QPointF(0, 1), borderRect.bottomRight() + QPointF(0, 1));
|
|
|
|
|
p.setPen(QColor(255, 255, 255, 40));
|
|
|
|
|
p.drawLine(borderRect.topLeft() + QPointF(0, 0), borderRect.topRight());
|
|
|
|
|
p.drawLine(borderRect.topRight() + QPointF(0, 1), borderRect.bottomRight() - QPointF(0, 1));
|
|
|
|
|
p.drawLine(borderRect.bottomLeft() + QPointF(0, -1), borderRect.bottomRight() - QPointF(0, 1));
|
|
|
|
|
|
|
|
|
|
QPixmapCache::insert(cacheKey, selection);
|
|
|
|
|
}
|
|
|
|
|
painter->drawPixmap(spanRect.topLeft() + QPoint(0, -verticalOverlap), selection);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
|
|
|
|
{
|
2010-02-17 18:41:41 +01:00
|
|
|
if (!validIndex(tabIndex)) {
|
|
|
|
|
qWarning("invalid index");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
painter->save();
|
|
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
QRect rect = tabRect(tabIndex);
|
|
|
|
|
bool selected = (tabIndex == m_currentIndex);
|
2010-02-16 15:36:56 +01:00
|
|
|
bool enabled = isTabEnabled(tabIndex);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (selected) {
|
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) {
|
|
|
|
|
// background color of a fancy tab that is active
|
|
|
|
|
painter->fillRect(rect.adjusted(0, 0, 0, -1),
|
|
|
|
|
creatorTheme()->color(Theme::BackgroundColorSelected));
|
|
|
|
|
} else {
|
2015-10-19 18:03:10 +02:00
|
|
|
paintSelectedTabBackground(painter, rect);
|
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
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
QString tabText(this->tabText(tabIndex));
|
2012-09-13 14:49:14 +02:00
|
|
|
QRect tabTextRect(rect);
|
|
|
|
|
const bool drawIcon = rect.height() > 36;
|
2009-07-13 16:58:13 +02:00
|
|
|
QRect tabIconRect(tabTextRect);
|
2012-09-13 14:49:14 +02:00
|
|
|
tabTextRect.translate(0, drawIcon ? -2 : 1);
|
2008-12-02 12:01:29 +01:00
|
|
|
QFont boldFont(painter->font());
|
2015-02-03 23:48:19 +02:00
|
|
|
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
2008-12-02 12:01:29 +01:00
|
|
|
boldFont.setBold(true);
|
|
|
|
|
painter->setFont(boldFont);
|
2010-02-26 16:12:10 +01:00
|
|
|
painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
|
2012-09-13 14:49:14 +02:00
|
|
|
const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter) | Qt::TextWordWrap;
|
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
|
|
|
|
2015-10-22 13:40:44 +02:00
|
|
|
const float fader = m_tabs[tabIndex]->fader();
|
|
|
|
|
if (fader > 0 && !HostOsInfo::isMacHost() && !selected && enabled) {
|
2010-02-18 12:50:26 +01:00
|
|
|
painter->save();
|
2016-02-16 21:06:44 +01:00
|
|
|
painter->setOpacity(fader);
|
|
|
|
|
if (creatorTheme()->widgetStyle() == Theme::StyleFlat)
|
|
|
|
|
painter->fillRect(rect, creatorTheme()->color(Theme::BackgroundColorHover));
|
|
|
|
|
else
|
2015-10-22 13:40:44 +02:00
|
|
|
FancyToolButton::hoverOverlay(painter, rect);
|
2010-02-18 12:50:26 +01:00
|
|
|
painter->restore();
|
|
|
|
|
}
|
2010-02-24 19:23:40 +01:00
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
|
painter->setOpacity(0.7);
|
|
|
|
|
|
2012-09-13 14:49:14 +02:00
|
|
|
if (drawIcon) {
|
|
|
|
|
int textHeight = painter->fontMetrics().boundingRect(QRect(0, 0, width(), height()), Qt::TextWordWrap, tabText).height();
|
|
|
|
|
tabIconRect.adjust(0, 4, 0, -textHeight);
|
2015-11-11 19:26:58 +01:00
|
|
|
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
|
|
|
|
: QIcon::Disabled;
|
|
|
|
|
StyleHelper::drawIconWithShadow(tabIcon(tabIndex), tabIconRect, painter, iconMode);
|
2012-09-13 14:49:14 +02:00
|
|
|
}
|
2010-03-23 15:47:43 +01: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
|
|
|
painter->setOpacity(1.0); //FIXME: was 0.7 before?
|
|
|
|
|
if (enabled) {
|
|
|
|
|
painter->setPen(selected
|
|
|
|
|
? creatorTheme()->color(Theme::FancyTabWidgetEnabledSelectedTextColor)
|
|
|
|
|
: creatorTheme()->color(Theme::FancyTabWidgetEnabledUnselectedTextColor));
|
|
|
|
|
} else {
|
|
|
|
|
painter->setPen(selected
|
|
|
|
|
? creatorTheme()->color(Theme::FancyTabWidgetDisabledSelectedTextColor)
|
|
|
|
|
: creatorTheme()->color(Theme::FancyTabWidgetDisabledUnselectedTextColor));
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
painter->translate(0, -1);
|
|
|
|
|
painter->drawText(tabTextRect, textFlags, tabText);
|
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
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
painter->restore();
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
void FancyTabBar::setCurrentIndex(int index) {
|
2010-02-16 15:36:56 +01:00
|
|
|
if (isTabEnabled(index)) {
|
|
|
|
|
m_currentIndex = index;
|
|
|
|
|
update();
|
2010-03-08 15:05:55 +01:00
|
|
|
emit currentChanged(m_currentIndex);
|
2010-02-16 15:36:56 +01:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-16 15:36:56 +01:00
|
|
|
void FancyTabBar::setTabEnabled(int index, bool enable)
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(index < m_tabs.size());
|
|
|
|
|
Q_ASSERT(index >= 0);
|
|
|
|
|
|
|
|
|
|
if (index < m_tabs.size() && index >= 0) {
|
2010-02-17 18:41:41 +01:00
|
|
|
m_tabs[index]->enabled = enable;
|
2010-02-16 15:36:56 +01:00
|
|
|
update(tabRect(index));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FancyTabBar::isTabEnabled(int index) const
|
|
|
|
|
{
|
|
|
|
|
Q_ASSERT(index < m_tabs.size());
|
|
|
|
|
Q_ASSERT(index >= 0);
|
|
|
|
|
|
|
|
|
|
if (index < m_tabs.size() && index >= 0)
|
2010-02-17 18:41:41 +01:00
|
|
|
return m_tabs[index]->enabled;
|
2010-02-16 15:36:56 +01:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
//////
|
|
|
|
|
// FancyColorButton
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
|
|
class FancyColorButton : public QWidget
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FancyColorButton(QWidget *parent)
|
|
|
|
|
: m_parent(parent)
|
|
|
|
|
{
|
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent *ev)
|
|
|
|
|
{
|
2011-05-19 23:14:28 +02:00
|
|
|
if (ev->modifiers() & Qt::ShiftModifier) {
|
2015-02-03 23:48:19 +02:00
|
|
|
QColor color = QColorDialog::getColor(StyleHelper::requestedBaseColor(), m_parent);
|
2011-05-19 23:14:28 +02:00
|
|
|
if (color.isValid())
|
2015-02-03 23:48:19 +02:00
|
|
|
StyleHelper::setBaseColor(color);
|
2011-05-19 23:14:28 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
QWidget *m_parent;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
// FancyTabWidget
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
|
|
FancyTabWidget::FancyTabWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
m_tabBar = new FancyTabBar(this);
|
|
|
|
|
|
|
|
|
|
m_selectionWidget = new QWidget(this);
|
|
|
|
|
QVBoxLayout *selectionLayout = new QVBoxLayout;
|
|
|
|
|
selectionLayout->setSpacing(0);
|
|
|
|
|
selectionLayout->setMargin(0);
|
|
|
|
|
|
2015-02-03 23:48:19 +02:00
|
|
|
StyledBar *bar = new StyledBar;
|
2009-07-16 17:34:04 +02:00
|
|
|
QHBoxLayout *layout = new QHBoxLayout(bar);
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
layout->setSpacing(0);
|
|
|
|
|
layout->addWidget(new FancyColorButton(this));
|
2008-12-02 12:01:29 +01:00
|
|
|
selectionLayout->addWidget(bar);
|
|
|
|
|
|
2009-07-13 18:04:08 +02:00
|
|
|
selectionLayout->addWidget(m_tabBar, 1);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_selectionWidget->setLayout(selectionLayout);
|
2009-07-13 16:58:13 +02:00
|
|
|
m_selectionWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_cornerWidgetContainer = new QWidget(this);
|
2009-07-13 18:04:08 +02:00
|
|
|
m_cornerWidgetContainer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_cornerWidgetContainer->setAutoFillBackground(false);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *cornerWidgetLayout = new QVBoxLayout;
|
|
|
|
|
cornerWidgetLayout->setSpacing(0);
|
|
|
|
|
cornerWidgetLayout->setMargin(0);
|
|
|
|
|
cornerWidgetLayout->addStretch();
|
|
|
|
|
m_cornerWidgetContainer->setLayout(cornerWidgetLayout);
|
|
|
|
|
|
|
|
|
|
selectionLayout->addWidget(m_cornerWidgetContainer, 0);
|
|
|
|
|
|
|
|
|
|
m_modesStack = new QStackedLayout;
|
|
|
|
|
m_statusBar = new QStatusBar;
|
|
|
|
|
m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
|
|
QVBoxLayout *vlayout = new QVBoxLayout;
|
|
|
|
|
vlayout->setMargin(0);
|
|
|
|
|
vlayout->setSpacing(0);
|
|
|
|
|
vlayout->addLayout(m_modesStack);
|
|
|
|
|
vlayout->addWidget(m_statusBar);
|
|
|
|
|
|
2009-07-16 17:34:04 +02:00
|
|
|
QHBoxLayout *mainLayout = new QHBoxLayout;
|
|
|
|
|
mainLayout->setMargin(0);
|
|
|
|
|
mainLayout->setSpacing(1);
|
|
|
|
|
mainLayout->addWidget(m_selectionWidget);
|
|
|
|
|
mainLayout->addLayout(vlayout);
|
|
|
|
|
setLayout(mainLayout);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(m_tabBar, &FancyTabBar::currentChanged, this, &FancyTabWidget::showWidget);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-11 12:22:10 +02:00
|
|
|
void FancyTabWidget::setSelectionWidgetVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
m_selectionWidget->setVisible(visible);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FancyTabWidget::isSelectionWidgetVisible() const
|
|
|
|
|
{
|
|
|
|
|
return m_selectionWidget->isVisible();
|
2010-11-11 16:49:17 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label)
|
|
|
|
|
{
|
|
|
|
|
m_modesStack->insertWidget(index, tab);
|
|
|
|
|
m_tabBar->insertTab(index, icon, label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::removeTab(int index)
|
|
|
|
|
{
|
|
|
|
|
m_modesStack->removeWidget(m_modesStack->widget(index));
|
|
|
|
|
m_tabBar->removeTab(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::setBackgroundBrush(const QBrush &brush)
|
|
|
|
|
{
|
2014-01-07 20:38:32 +01:00
|
|
|
QPalette pal;
|
2008-12-02 12:01:29 +01:00
|
|
|
pal.setBrush(QPalette::Mid, brush);
|
|
|
|
|
m_tabBar->setPalette(pal);
|
|
|
|
|
m_cornerWidgetContainer->setPalette(pal);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(event)
|
2013-04-11 12:22:10 +02:00
|
|
|
if (m_selectionWidget->isVisible()) {
|
|
|
|
|
QPainter painter(this);
|
|
|
|
|
|
|
|
|
|
QRect rect = m_selectionWidget->rect().adjusted(0, 0, 1, 0);
|
|
|
|
|
rect = style()->visualRect(layoutDirection(), geometry(), rect);
|
2015-10-19 18:03:10 +02:00
|
|
|
const QRectF boderRect = QRectF(rect).adjusted(0.5, 0.5, -0.5, -0.5);
|
2015-02-03 23:48:19 +02:00
|
|
|
StyleHelper::verticalGradient(&painter, rect, rect);
|
|
|
|
|
painter.setPen(StyleHelper::borderColor());
|
2015-10-19 18:03:10 +02:00
|
|
|
painter.drawLine(boderRect.topRight(), boderRect.bottomRight());
|
2013-04-11 12:22:10 +02:00
|
|
|
|
2015-02-03 23:48:19 +02:00
|
|
|
QColor light = StyleHelper::sidebarHighlight();
|
2013-04-11 12:22:10 +02:00
|
|
|
painter.setPen(light);
|
2015-10-19 18:03:10 +02:00
|
|
|
painter.drawLine(boderRect.bottomLeft(), boderRect.bottomRight());
|
2013-04-11 12:22:10 +02:00
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::insertCornerWidget(int pos, QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
QVBoxLayout *layout = static_cast<QVBoxLayout *>(m_cornerWidgetContainer->layout());
|
|
|
|
|
layout->insertWidget(pos, widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FancyTabWidget::cornerWidgetCount() const
|
|
|
|
|
{
|
|
|
|
|
return m_cornerWidgetContainer->layout()->count();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::addCornerWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
m_cornerWidgetContainer->layout()->addWidget(widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FancyTabWidget::currentIndex() const
|
|
|
|
|
{
|
|
|
|
|
return m_tabBar->currentIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStatusBar *FancyTabWidget::statusBar() const
|
|
|
|
|
{
|
|
|
|
|
return m_statusBar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::setCurrentIndex(int index)
|
|
|
|
|
{
|
2010-02-16 15:36:56 +01:00
|
|
|
if (m_tabBar->isTabEnabled(index))
|
|
|
|
|
m_tabBar->setCurrentIndex(index);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::showWidget(int index)
|
|
|
|
|
{
|
|
|
|
|
emit currentAboutToShow(index);
|
|
|
|
|
m_modesStack->setCurrentIndex(index);
|
|
|
|
|
emit currentChanged(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::setTabToolTip(int index, const QString &toolTip)
|
|
|
|
|
{
|
|
|
|
|
m_tabBar->setTabToolTip(index, toolTip);
|
|
|
|
|
}
|
2010-02-16 15:36:56 +01:00
|
|
|
|
|
|
|
|
void FancyTabWidget::setTabEnabled(int index, bool enable)
|
|
|
|
|
{
|
|
|
|
|
m_tabBar->setTabEnabled(index, enable);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FancyTabWidget::isTabEnabled(int index) const
|
|
|
|
|
{
|
|
|
|
|
return m_tabBar->isTabEnabled(index);
|
|
|
|
|
}
|