2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "fancytabwidget.h"
|
2018-02-20 18:11:23 +01:00
|
|
|
|
2017-09-12 18:55:14 +02:00
|
|
|
#include "coreconstants.h"
|
2018-02-20 18:11:23 +01:00
|
|
|
#include "fancyactionbar.h"
|
2015-10-22 13:40:44 +02:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2018-06-25 23:56:41 +03:00
|
|
|
#include <utils/qtcassert.h>
|
2009-07-16 17:34:04 +02:00
|
|
|
#include <utils/styledbar.h>
|
2018-02-20 18:11:23 +01:00
|
|
|
#include <utils/stylehelper.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>
|
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
|
#include <QMouseEvent>
|
|
|
|
|
#include <QPainter>
|
2015-10-19 18:03:10 +02:00
|
|
|
#include <QPixmapCache>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QStackedLayout>
|
|
|
|
|
#include <QStatusBar>
|
2018-02-20 18:11:23 +01:00
|
|
|
#include <QStyleFactory>
|
2016-05-19 11:50:45 +02:00
|
|
|
#include <QStyleOption>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QToolTip>
|
2018-02-20 18:11:23 +01:00
|
|
|
#include <QVBoxLayout>
|
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
|
|
|
|
2016-05-19 11:50:45 +02:00
|
|
|
static const int kMenuButtonWidth = 16;
|
|
|
|
|
|
2010-02-17 18:41:41 +01:00
|
|
|
void FancyTab::fadeIn()
|
|
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
m_animator.stop();
|
|
|
|
|
m_animator.setDuration(80);
|
|
|
|
|
m_animator.setEndValue(1);
|
|
|
|
|
m_animator.start();
|
2010-02-17 18:41:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTab::fadeOut()
|
|
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
m_animator.stop();
|
|
|
|
|
m_animator.setDuration(160);
|
|
|
|
|
m_animator.setEndValue(0);
|
|
|
|
|
m_animator.start();
|
2010-02-17 18:41:41 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void FancyTab::setFader(qreal value)
|
2010-02-19 16:16:31 +01:00
|
|
|
{
|
|
|
|
|
m_fader = value;
|
2018-02-20 18:11:23 +01:00
|
|
|
m_tabbar->update();
|
2010-02-19 16:16:31 +01:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
2008-12-02 12:01:29 +01:00
|
|
|
setAttribute(Qt::WA_Hover, true);
|
|
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
setMouseTracking(true); // Needed for hover events
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-13 16:58:13 +02:00
|
|
|
QSize FancyTabBar::tabSizeHint(bool minimum) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-04-26 16:09:16 +02:00
|
|
|
if (m_iconsOnly) {
|
|
|
|
|
return {Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE,
|
|
|
|
|
Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE / (minimum ? 3 : 1)};
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2018-02-20 18:11:23 +01:00
|
|
|
const QFontMetrics fm(boldFont);
|
|
|
|
|
const int spacing = 8;
|
|
|
|
|
const int width = 60 + spacing + 2;
|
2010-04-14 17:59:31 +02:00
|
|
|
int maxLabelwidth = 0;
|
2022-10-07 14:46:06 +02:00
|
|
|
for (auto tab : std::as_const(m_tabs)) {
|
2019-02-11 10:32:46 +01:00
|
|
|
const int width = fm.horizontalAdvance(tab->text);
|
2010-04-14 17:59:31 +02:00
|
|
|
if (width > maxLabelwidth)
|
|
|
|
|
maxLabelwidth = width;
|
|
|
|
|
}
|
2018-02-20 18:11:23 +01:00
|
|
|
const int iconHeight = minimum ? 0 : 32;
|
|
|
|
|
return {qMax(width, maxLabelwidth + 4), iconHeight + spacing + fm.height()};
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabBar::paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QPainter p(this);
|
2016-06-15 17:41:33 +02:00
|
|
|
if (creatorTheme()->flag(Theme::FlatToolBars)) {
|
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
|
|
|
// draw background of upper part of left tab widget
|
|
|
|
|
// (Welcome, ... Help)
|
2016-03-21 12:48:06 +01:00
|
|
|
p.fillRect(event->rect(), 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
|
2018-02-20 18:11:23 +01:00
|
|
|
void FancyTabBar::mouseMoveEvent(QMouseEvent *event)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2010-02-19 16:16:31 +01:00
|
|
|
int newHover = -1;
|
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
2018-02-20 18:11:23 +01:00
|
|
|
const QRect area = tabRect(i);
|
|
|
|
|
if (area.contains(event->pos())) {
|
2010-02-19 16:16:31 +01:00
|
|
|
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)) {
|
2018-02-20 18:11:23 +01:00
|
|
|
const QString tt = tabToolTip(m_hoverIndex);
|
2009-07-13 16:58:13 +02:00
|
|
|
if (!tt.isEmpty()) {
|
2018-02-20 18:11:23 +01:00
|
|
|
QToolTip::showText(static_cast<QHelpEvent *>(event)->globalPos(), tt, this);
|
2009-07-13 16:58:13 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return QWidget::event(event);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// Resets hover animation on mouse enter
|
2022-07-13 09:27:18 +02:00
|
|
|
void FancyTabBar::enterEvent(QEnterEvent *event)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
Q_UNUSED(event)
|
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
|
2018-02-20 18:11:23 +01:00
|
|
|
void FancyTabBar::leaveEvent(QEvent *event)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
Q_UNUSED(event)
|
2010-02-18 13:57:33 +01:00
|
|
|
m_hoverIndex = -1;
|
|
|
|
|
m_hoverRect = QRect();
|
2022-10-07 14:46:06 +02:00
|
|
|
for (auto tab : std::as_const(m_tabs))
|
2018-02-20 18:11:23 +01:00
|
|
|
tab->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
|
|
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
const QSize sh = tabSizeHint();
|
2020-07-21 15:47:35 +02:00
|
|
|
return {sh.width(), sh.height() * int(m_tabs.count())};
|
2009-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize FancyTabBar::minimumSizeHint() const
|
|
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
const QSize sh = tabSizeHint(true);
|
2020-07-21 15:47:35 +02:00
|
|
|
return {sh.width(), sh.height() * int(m_tabs.count())};
|
2009-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QRect FancyTabBar::tabRect(int index) const
|
|
|
|
|
{
|
|
|
|
|
QSize sh = tabSizeHint();
|
|
|
|
|
|
|
|
|
|
if (sh.height() * m_tabs.count() > height())
|
|
|
|
|
sh.setHeight(height() / m_tabs.count());
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
return {0, index * sh.height(), sh.width(), sh.height()};
|
2009-07-13 16:58:13 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void FancyTabBar::mousePressEvent(QMouseEvent *event)
|
2009-07-13 16:58:13 +02:00
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
event->accept();
|
2010-03-08 15:05:55 +01:00
|
|
|
for (int index = 0; index < m_tabs.count(); ++index) {
|
2016-05-19 11:50:45 +02:00
|
|
|
const QRect rect = tabRect(index);
|
2018-02-20 18:11:23 +01:00
|
|
|
if (rect.contains(event->pos())) {
|
2010-03-08 15:05:55 +01:00
|
|
|
if (isTabEnabled(index)) {
|
2018-02-20 18:11:23 +01:00
|
|
|
if (m_tabs.at(index)->hasMenu
|
2020-06-16 15:56:47 +02:00
|
|
|
&& ((!m_iconsOnly && rect.right() - event->pos().x() <= kMenuButtonWidth)
|
|
|
|
|
|| event->button() == Qt::RightButton)) {
|
|
|
|
|
// menu arrow clicked or right-click
|
2018-02-20 18:11:23 +01:00
|
|
|
emit menuTriggered(index, event);
|
2016-05-19 11:50:45 +02:00
|
|
|
} else {
|
2019-04-05 09:31:16 +02:00
|
|
|
if (index != m_currentIndex) {
|
|
|
|
|
emit currentAboutToChange(index);
|
|
|
|
|
m_currentIndex = index;
|
|
|
|
|
update();
|
|
|
|
|
// update tab bar before showing widget
|
2022-07-19 22:37:03 +02:00
|
|
|
QMetaObject::invokeMethod(this, [this] {
|
2021-01-28 11:29:14 +01:00
|
|
|
emit currentChanged(m_currentIndex);
|
|
|
|
|
}, Qt::QueuedConnection);
|
2019-04-05 09:31:16 +02:00
|
|
|
}
|
2016-05-19 11:50:45 +02:00
|
|
|
}
|
2010-03-08 15:05:55 +01:00
|
|
|
}
|
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())
|
2018-02-20 18:11:23 +01:00
|
|
|
+ QLatin1Char('x') + QString::number(spanRect.height())
|
|
|
|
|
+ QLatin1Char('@') + QString::number(dpr);
|
2015-10-19 18:03:10 +02:00
|
|
|
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));
|
2018-02-20 18:11:23 +01:00
|
|
|
p.drawLine(borderRect.bottomLeft() + QPointF(0, 1),
|
|
|
|
|
borderRect.bottomRight() + QPointF(0, 1));
|
2015-10-19 18:03:10 +02:00
|
|
|
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));
|
2018-02-20 18:11:23 +01:00
|
|
|
p.drawLine(borderRect.bottomLeft() + QPointF(0, -1),
|
|
|
|
|
borderRect.bottomRight() - QPointF(0, 1));
|
2017-02-06 12:25:15 +01:00
|
|
|
p.end();
|
2015-10-19 18:03:10 +02:00
|
|
|
|
|
|
|
|
QPixmapCache::insert(cacheKey, selection);
|
|
|
|
|
}
|
|
|
|
|
painter->drawPixmap(spanRect.topLeft() + QPoint(0, -verticalOverlap), selection);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 16:09:16 +02:00
|
|
|
static void paintIcon(QPainter *painter, const QRect &rect,
|
|
|
|
|
const QIcon &icon,
|
|
|
|
|
bool enabled, bool selected)
|
|
|
|
|
{
|
|
|
|
|
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
|
|
|
|
: QIcon::Disabled;
|
|
|
|
|
QRect iconRect(0, 0, Core::Constants::MODEBAR_ICON_SIZE, Core::Constants::MODEBAR_ICON_SIZE);
|
|
|
|
|
iconRect.moveCenter(rect.center());
|
|
|
|
|
iconRect = iconRect.intersected(rect);
|
|
|
|
|
if (!enabled && !creatorTheme()->flag(Theme::FlatToolBars))
|
|
|
|
|
painter->setOpacity(0.7);
|
|
|
|
|
StyleHelper::drawIconWithShadow(icon, iconRect, painter, iconMode);
|
2019-01-12 01:52:56 -08:00
|
|
|
|
|
|
|
|
if (selected && creatorTheme()->flag(Theme::FlatToolBars)) {
|
|
|
|
|
painter->setOpacity(1.0);
|
|
|
|
|
QRect accentRect = rect;
|
|
|
|
|
accentRect.setWidth(2);
|
|
|
|
|
painter->fillRect(accentRect, creatorTheme()->color(Theme::IconsBaseColor));
|
|
|
|
|
}
|
2018-04-26 16:09:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void paintIconAndText(QPainter *painter, const QRect &rect,
|
|
|
|
|
const QIcon &icon, const QString &text,
|
|
|
|
|
bool enabled, bool selected)
|
|
|
|
|
{
|
2018-05-29 13:27:19 +02:00
|
|
|
QFont boldFont(painter->font());
|
|
|
|
|
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
|
|
|
|
boldFont.setBold(true);
|
|
|
|
|
painter->setFont(boldFont);
|
|
|
|
|
|
2018-04-26 16:09:16 +02:00
|
|
|
const bool drawIcon = rect.height() > 36;
|
|
|
|
|
if (drawIcon) {
|
|
|
|
|
const int textHeight =
|
|
|
|
|
painter->fontMetrics().boundingRect(rect, Qt::TextWordWrap, text).height();
|
|
|
|
|
const QRect tabIconRect(rect.adjusted(0, 4, 0, -textHeight));
|
|
|
|
|
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
|
|
|
|
: QIcon::Disabled;
|
|
|
|
|
QRect iconRect(0, 0, Core::Constants::MODEBAR_ICON_SIZE, Core::Constants::MODEBAR_ICON_SIZE);
|
|
|
|
|
iconRect.moveCenter(tabIconRect.center());
|
|
|
|
|
iconRect = iconRect.intersected(tabIconRect);
|
|
|
|
|
if (!enabled && !creatorTheme()->flag(Theme::FlatToolBars))
|
|
|
|
|
painter->setOpacity(0.7);
|
|
|
|
|
StyleHelper::drawIconWithShadow(icon, iconRect, painter, iconMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->setOpacity(1.0); //FIXME: was 0.7 before?
|
2019-01-12 01:32:52 +01:00
|
|
|
if (selected && creatorTheme()->flag(Theme::FlatToolBars)) {
|
|
|
|
|
QRect accentRect = rect;
|
|
|
|
|
accentRect.setWidth(2);
|
|
|
|
|
painter->fillRect(accentRect, creatorTheme()->color(Theme::IconsBaseColor));
|
|
|
|
|
}
|
2018-04-26 16:09:16 +02:00
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
painter->translate(0, -1);
|
|
|
|
|
QRect tabTextRect(rect);
|
|
|
|
|
tabTextRect.translate(0, drawIcon ? -2 : 1);
|
|
|
|
|
const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter)
|
|
|
|
|
| Qt::TextWordWrap;
|
|
|
|
|
painter->drawText(tabTextRect, textFlags, text);
|
|
|
|
|
}
|
|
|
|
|
|
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();
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
const FancyTab *tab = m_tabs.at(tabIndex);
|
|
|
|
|
const QRect rect = tabRect(tabIndex);
|
|
|
|
|
const bool selected = (tabIndex == m_currentIndex);
|
|
|
|
|
const bool enabled = isTabEnabled(tabIndex);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
if (selected) {
|
2016-06-15 17:41:33 +02:00
|
|
|
if (creatorTheme()->flag(Theme::FlatToolBars)) {
|
2018-02-20 18:11:23 +01:00
|
|
|
// background color of a fancy tab that is active
|
2018-12-01 01:42:38 -08:00
|
|
|
painter->fillRect(rect, creatorTheme()->color(Theme::FancyTabBarSelectedBackgroundColor));
|
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
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
const qreal fader = tab->fader();
|
2015-10-22 13:40:44 +02:00
|
|
|
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);
|
2016-06-15 17:41:33 +02:00
|
|
|
if (creatorTheme()->flag(Theme::FlatToolBars))
|
2016-02-26 12:30:14 +01:00
|
|
|
painter->fillRect(rect, creatorTheme()->color(Theme::FancyToolButtonHoverColor));
|
2016-02-16 21:06:44 +01:00
|
|
|
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
|
|
|
|
2018-04-26 16:09:16 +02:00
|
|
|
if (m_iconsOnly)
|
|
|
|
|
paintIcon(painter, rect, tab->icon, enabled, selected);
|
|
|
|
|
else
|
|
|
|
|
paintIconAndText(painter, rect, tab->icon, tab->text, enabled, 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
|
|
|
|
2016-05-19 11:50:45 +02:00
|
|
|
// menu arrow
|
2020-06-16 15:56:47 +02:00
|
|
|
if (tab->hasMenu && !m_iconsOnly) {
|
2016-05-19 11:50:45 +02:00
|
|
|
QStyleOption opt;
|
|
|
|
|
opt.initFrom(this);
|
|
|
|
|
opt.rect = rect.adjusted(rect.width() - kMenuButtonWidth, 0, -8, 0);
|
|
|
|
|
StyleHelper::drawArrow(QStyle::PE_IndicatorArrowRight, painter, &opt);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
painter->restore();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void FancyTabBar::setCurrentIndex(int index)
|
|
|
|
|
{
|
2016-08-23 09:26:12 +02:00
|
|
|
if (isTabEnabled(index) && index != m_currentIndex) {
|
2019-04-02 16:24:32 +02:00
|
|
|
emit currentAboutToChange(index);
|
2010-02-16 15:36:56 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-04-26 16:09:16 +02:00
|
|
|
void FancyTabBar::setIconsOnly(bool iconsOnly)
|
|
|
|
|
{
|
|
|
|
|
m_iconsOnly = iconsOnly;
|
|
|
|
|
updateGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
class FancyColorButton : public QWidget
|
|
|
|
|
{
|
2016-03-16 12:28:31 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
public:
|
2018-02-20 18:11:23 +01:00
|
|
|
explicit FancyColorButton(QWidget *parent = nullptr)
|
|
|
|
|
: QWidget(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void mousePressEvent(QMouseEvent *ev) override { emit clicked(ev->button(), ev->modifiers()); }
|
2016-03-16 12:28:31 +01:00
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void paintEvent(QPaintEvent *event) override
|
2016-04-09 23:49:11 +02:00
|
|
|
{
|
|
|
|
|
QWidget::paintEvent(event);
|
|
|
|
|
|
2016-07-19 17:27:23 +02:00
|
|
|
// Some Themes do not want highlights, shadows and borders in the toolbars.
|
2016-04-09 23:49:11 +02:00
|
|
|
// But we definitely want a separator between FancyColorButton and FancyTabBar
|
2016-07-19 17:27:23 +02:00
|
|
|
if (!creatorTheme()->flag(Theme::DrawToolBarHighlights)
|
2018-02-20 18:11:23 +01:00
|
|
|
&& !creatorTheme()->flag(Theme::DrawToolBarBorders)) {
|
2016-04-09 23:49:11 +02:00
|
|
|
QPainter p(this);
|
2016-07-19 18:24:25 +02:00
|
|
|
p.setPen(StyleHelper::toolBarBorderColor());
|
2016-04-09 23:49:11 +02:00
|
|
|
const QRectF innerRect = QRectF(rect()).adjusted(0.5, 0.5, -0.5, -0.5);
|
|
|
|
|
p.drawLine(innerRect.bottomLeft(), innerRect.bottomRight());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 12:28:31 +01:00
|
|
|
signals:
|
|
|
|
|
void clicked(Qt::MouseButton button, Qt::KeyboardModifiers modifiers);
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
// FancyTabWidget
|
|
|
|
|
//////
|
|
|
|
|
|
|
|
|
|
FancyTabWidget::FancyTabWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
m_tabBar = new FancyTabBar(this);
|
2018-12-10 17:10:17 +01:00
|
|
|
m_tabBar->setObjectName("ModeSelector"); // used for UI introduction
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
m_selectionWidget = new QWidget(this);
|
2018-02-20 18:11:23 +01:00
|
|
|
auto selectionLayout = new QVBoxLayout;
|
2008-12-02 12:01:29 +01:00
|
|
|
selectionLayout->setSpacing(0);
|
2019-08-29 10:36:01 +02:00
|
|
|
selectionLayout->setContentsMargins(0, 0, 0, 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
auto bar = new StyledBar;
|
|
|
|
|
auto layout = new QHBoxLayout(bar);
|
2019-08-29 10:36:01 +02:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2009-07-16 17:34:04 +02:00
|
|
|
layout->setSpacing(0);
|
2016-03-16 12:28:31 +01:00
|
|
|
auto fancyButton = new FancyColorButton(this);
|
|
|
|
|
connect(fancyButton, &FancyColorButton::clicked, this, &FancyTabWidget::topAreaClicked);
|
|
|
|
|
layout->addWidget(fancyButton);
|
2008-12-02 12:01:29 +01:00
|
|
|
selectionLayout->addWidget(bar);
|
|
|
|
|
|
2018-12-10 17:10:17 +01:00
|
|
|
selectionLayout->addWidget(m_tabBar);
|
|
|
|
|
selectionLayout->addStretch(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);
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
auto cornerWidgetLayout = new QVBoxLayout;
|
2008-12-02 12:01:29 +01:00
|
|
|
cornerWidgetLayout->setSpacing(0);
|
2019-08-29 10:36:01 +02:00
|
|
|
cornerWidgetLayout->setContentsMargins(0, 0, 0, 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
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);
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
auto vlayout = new QVBoxLayout;
|
2019-08-29 10:36:01 +02:00
|
|
|
vlayout->setContentsMargins(0, 0, 0, 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
vlayout->setSpacing(0);
|
|
|
|
|
vlayout->addLayout(m_modesStack);
|
|
|
|
|
vlayout->addWidget(m_statusBar);
|
|
|
|
|
|
2019-08-07 12:44:40 +02:00
|
|
|
m_infoBarDisplay.setTarget(vlayout, 1);
|
2020-10-08 23:48:34 +02:00
|
|
|
m_infoBarDisplay.setEdge(Qt::BottomEdge);
|
2019-08-07 12:44:40 +02:00
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
auto mainLayout = new QHBoxLayout;
|
2019-08-29 10:36:01 +02:00
|
|
|
mainLayout->setContentsMargins(0, 0, 0, 0);
|
2009-07-16 17:34:04 +02:00
|
|
|
mainLayout->setSpacing(1);
|
|
|
|
|
mainLayout->addWidget(m_selectionWidget);
|
|
|
|
|
mainLayout->addLayout(vlayout);
|
|
|
|
|
setLayout(mainLayout);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2019-04-02 16:24:32 +02:00
|
|
|
connect(m_tabBar, &FancyTabBar::currentAboutToChange, this, &FancyTabWidget::currentAboutToShow);
|
2016-02-02 09:10:54 +02:00
|
|
|
connect(m_tabBar, &FancyTabBar::currentChanged, this, &FancyTabWidget::showWidget);
|
2016-05-19 11:50:45 +02:00
|
|
|
connect(m_tabBar, &FancyTabBar::menuTriggered, this, &FancyTabWidget::menuTriggered);
|
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
|
|
|
}
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
m_modesStack->insertWidget(index, tab);
|
2016-05-19 11:50:45 +02:00
|
|
|
m_tabBar->insertTab(index, icon, label, hasMenu);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2021-09-22 11:33:01 +02:00
|
|
|
void FancyTabWidget::removeTab(int index)
|
|
|
|
|
{
|
|
|
|
|
m_modesStack->removeWidget(m_modesStack->widget(index));
|
|
|
|
|
m_tabBar->removeTab(index);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
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);
|
2020-11-27 13:12:23 +01:00
|
|
|
rect = QStyle::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);
|
2013-04-11 12:22:10 +02:00
|
|
|
|
2016-07-19 18:24:25 +02:00
|
|
|
if (creatorTheme()->flag(Theme::FlatToolBars)) {
|
2018-12-20 14:19:59 +01:00
|
|
|
painter.fillRect(rect, StyleHelper::baseColor());
|
2016-07-19 18:24:25 +02:00
|
|
|
painter.setPen(StyleHelper::toolBarBorderColor());
|
|
|
|
|
painter.drawLine(boderRect.topRight(), boderRect.bottomRight());
|
|
|
|
|
} else {
|
|
|
|
|
StyleHelper::verticalGradient(&painter, rect, rect);
|
|
|
|
|
painter.setPen(StyleHelper::borderColor());
|
|
|
|
|
painter.drawLine(boderRect.topRight(), boderRect.bottomRight());
|
|
|
|
|
|
2018-02-20 18:11:23 +01:00
|
|
|
const QColor light = StyleHelper::sidebarHighlight();
|
2016-07-19 18:24:25 +02:00
|
|
|
painter.setPen(light);
|
|
|
|
|
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)
|
|
|
|
|
{
|
2018-02-20 18:11:23 +01:00
|
|
|
auto layout = static_cast<QVBoxLayout *>(m_cornerWidgetContainer->layout());
|
2008-12-02 12:01:29 +01:00
|
|
|
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
|
|
|
|
|
{
|
2019-04-02 16:24:32 +02:00
|
|
|
return m_tabBar->currentIndex();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStatusBar *FancyTabWidget::statusBar() const
|
|
|
|
|
{
|
|
|
|
|
return m_statusBar;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-07 12:44:40 +02:00
|
|
|
InfoBar *FancyTabWidget::infoBar()
|
|
|
|
|
{
|
|
|
|
|
if (!m_infoBarDisplay.infoBar())
|
|
|
|
|
m_infoBarDisplay.setInfoBar(&m_infoBar);
|
|
|
|
|
return &m_infoBar;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void FancyTabWidget::setCurrentIndex(int index)
|
|
|
|
|
{
|
2016-08-23 09:26:12 +02:00
|
|
|
m_tabBar->setCurrentIndex(index);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FancyTabWidget::showWidget(int index)
|
|
|
|
|
{
|
|
|
|
|
m_modesStack->setCurrentIndex(index);
|
2018-06-25 23:56:41 +03:00
|
|
|
QWidget *w = m_modesStack->currentWidget();
|
|
|
|
|
if (QTC_GUARD(w)) {
|
|
|
|
|
if (QWidget *focusWidget = w->focusWidget())
|
|
|
|
|
w = focusWidget;
|
|
|
|
|
w->setFocus();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
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);
|
|
|
|
|
}
|
2016-03-16 12:28:31 +01:00
|
|
|
|
2018-04-26 16:09:16 +02:00
|
|
|
void FancyTabWidget::setIconsOnly(bool iconsOnly)
|
|
|
|
|
{
|
|
|
|
|
m_tabBar->setIconsOnly(iconsOnly);
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-16 12:28:31 +01:00
|
|
|
#include "fancytabwidget.moc"
|