2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-12-07 15:14:08 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2009-12-07 15:14:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-12-07 15:14:08 +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:58:39 +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.
|
2009-12-07 15:14:08 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +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
|
|
|
****************************************************************************/
|
2009-12-07 15:14:08 +01:00
|
|
|
|
2009-10-01 14:39:31 +02:00
|
|
|
#include "detailswidget.h"
|
|
|
|
|
#include "detailsbutton.h"
|
2012-08-23 15:53:58 +02:00
|
|
|
#include "hostosinfo.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 "theme/theme.h"
|
2009-10-01 14:39:31 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QGridLayout>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QCheckBox>
|
|
|
|
|
#include <QPainter>
|
|
|
|
|
#include <QScrollArea>
|
|
|
|
|
#include <QApplication>
|
2013-10-02 13:53:47 +02:00
|
|
|
#include <QStyle>
|
2009-10-01 14:39:31 +02:00
|
|
|
|
2011-03-02 17:13:33 +01:00
|
|
|
/*!
|
|
|
|
|
\class Utils::DetailsWidget
|
|
|
|
|
|
2013-06-05 14:29:24 +02:00
|
|
|
\brief The DetailsWidget class implements a button to expand a \e Details
|
|
|
|
|
area.
|
2011-03-02 17:13:33 +01:00
|
|
|
|
|
|
|
|
This widget is using a grid layout and places the items
|
|
|
|
|
in the following way:
|
|
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
+------------+-------------------------+---------------+
|
|
|
|
|
+summaryLabel| toolwidget | detailsButton |
|
|
|
|
|
+------------+-------------------------+---------------+
|
2011-03-14 14:33:48 +01:00
|
|
|
+ additional summary |
|
|
|
|
|
+------------+-------------------------+---------------+
|
2011-03-02 17:13:33 +01:00
|
|
|
| widget |
|
|
|
|
|
+------------+-------------------------+---------------+
|
|
|
|
|
\endcode
|
|
|
|
|
*/
|
|
|
|
|
|
2010-02-02 09:59:55 +01:00
|
|
|
namespace Utils {
|
2009-10-01 14:39:31 +02:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
static const int MARGIN = 8;
|
|
|
|
|
|
|
|
|
|
class DetailsWidgetPrivate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
DetailsWidgetPrivate(QWidget *parent);
|
|
|
|
|
|
|
|
|
|
void updateControls();
|
|
|
|
|
void changeHoverState(bool hovered);
|
|
|
|
|
|
|
|
|
|
QWidget *q;
|
|
|
|
|
DetailsButton *m_detailsButton;
|
|
|
|
|
QGridLayout *m_grid;
|
2013-10-02 13:53:47 +02:00
|
|
|
QLabel *m_summaryLabelIcon;
|
2011-05-18 16:48:36 +02:00
|
|
|
QLabel *m_summaryLabel;
|
|
|
|
|
QCheckBox *m_summaryCheckBox;
|
|
|
|
|
QLabel *m_additionalSummaryLabel;
|
2014-07-15 23:33:17 +03:00
|
|
|
FadingPanel *m_toolWidget;
|
2011-05-18 16:48:36 +02:00
|
|
|
QWidget *m_widget;
|
|
|
|
|
|
|
|
|
|
QPixmap m_collapsedPixmap;
|
|
|
|
|
QPixmap m_expandedPixmap;
|
|
|
|
|
|
|
|
|
|
DetailsWidget::State m_state;
|
|
|
|
|
bool m_hovered;
|
|
|
|
|
bool m_useCheckBox;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DetailsWidgetPrivate::DetailsWidgetPrivate(QWidget *parent) :
|
|
|
|
|
q(parent),
|
|
|
|
|
m_detailsButton(new DetailsButton),
|
|
|
|
|
m_grid(new QGridLayout),
|
2013-10-02 13:53:47 +02:00
|
|
|
m_summaryLabelIcon(new QLabel(parent)),
|
2011-05-18 16:48:36 +02:00
|
|
|
m_summaryLabel(new QLabel(parent)),
|
|
|
|
|
m_summaryCheckBox(new QCheckBox(parent)),
|
|
|
|
|
m_additionalSummaryLabel(new QLabel(parent)),
|
|
|
|
|
m_toolWidget(0),
|
|
|
|
|
m_widget(0),
|
|
|
|
|
m_state(DetailsWidget::Collapsed),
|
|
|
|
|
m_hovered(false),
|
|
|
|
|
m_useCheckBox(false)
|
|
|
|
|
{
|
2011-07-25 15:59:53 +00:00
|
|
|
QHBoxLayout *summaryLayout = new QHBoxLayout;
|
|
|
|
|
summaryLayout->setContentsMargins(MARGIN, MARGIN, MARGIN, MARGIN);
|
|
|
|
|
summaryLayout->setSpacing(0);
|
|
|
|
|
|
2013-10-02 13:53:47 +02:00
|
|
|
m_summaryLabelIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
|
m_summaryLabelIcon->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_summaryLabelIcon->setFixedWidth(0);
|
|
|
|
|
summaryLayout->addWidget(m_summaryLabelIcon);
|
|
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
m_summaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
|
2011-08-24 11:04:19 +02:00
|
|
|
m_summaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
2011-07-25 15:59:53 +00:00
|
|
|
m_summaryLabel->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
summaryLayout->addWidget(m_summaryLabel);
|
2011-05-18 16:48:36 +02:00
|
|
|
|
2011-08-24 11:04:19 +02:00
|
|
|
m_summaryCheckBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
2011-05-18 16:48:36 +02:00
|
|
|
m_summaryCheckBox->setAttribute(Qt::WA_LayoutUsesWidgetRect); /* broken layout on mac otherwise */
|
|
|
|
|
m_summaryCheckBox->setVisible(false);
|
2011-07-25 15:59:53 +00:00
|
|
|
m_summaryCheckBox->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
summaryLayout->addWidget(m_summaryCheckBox);
|
2011-05-18 16:48:36 +02:00
|
|
|
|
|
|
|
|
m_additionalSummaryLabel->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
2011-08-24 11:04:19 +02:00
|
|
|
m_additionalSummaryLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
2011-05-18 16:48:36 +02:00
|
|
|
m_additionalSummaryLabel->setContentsMargins(MARGIN, MARGIN, MARGIN, MARGIN);
|
|
|
|
|
m_additionalSummaryLabel->setWordWrap(true);
|
|
|
|
|
m_additionalSummaryLabel->setVisible(false);
|
|
|
|
|
|
|
|
|
|
m_grid->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
m_grid->setSpacing(0);
|
2011-07-25 15:59:53 +00:00
|
|
|
m_grid->addLayout(summaryLayout, 0, 0);
|
2011-05-18 16:48:36 +02:00
|
|
|
m_grid->addWidget(m_detailsButton, 0, 2);
|
|
|
|
|
m_grid->addWidget(m_additionalSummaryLabel, 1, 0, 1, 3);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-15 17:14:40 +01:00
|
|
|
QPixmap DetailsWidget::createBackground(const QSize &size, int topHeight, QWidget *widget)
|
2011-05-18 16:48:36 +02:00
|
|
|
{
|
|
|
|
|
QPixmap pixmap(size);
|
|
|
|
|
pixmap.fill(Qt::transparent);
|
|
|
|
|
QPainter p(&pixmap);
|
|
|
|
|
|
|
|
|
|
QRect topRect(0, 0, size.width(), topHeight);
|
|
|
|
|
QRect fullRect(0, 0, size.width(), size.height());
|
2012-08-23 15:53:58 +02:00
|
|
|
if (HostOsInfo::isMacHost())
|
|
|
|
|
p.fillRect(fullRect, qApp->palette().window().color());
|
|
|
|
|
else
|
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
|
|
|
p.fillRect(fullRect, creatorTheme()->color(Theme::DetailsWidgetBackgroundColor));
|
|
|
|
|
|
2016-03-04 17:55:20 +01:00
|
|
|
if (!creatorTheme()->flag(Theme::FlatProjectsMode)) {
|
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
|
|
|
QLinearGradient lg(topRect.topLeft(), topRect.bottomLeft());
|
|
|
|
|
lg.setStops(creatorTheme()->gradient(Theme::DetailsWidgetHeaderGradient));
|
|
|
|
|
p.fillRect(topRect, lg);
|
|
|
|
|
p.setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
|
p.translate(0.5, 0.5);
|
|
|
|
|
p.setPen(QColor(0, 0, 0, 40));
|
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
|
p.drawRoundedRect(fullRect.adjusted(0, 0, -1, -1), 2, 2);
|
|
|
|
|
p.setBrush(Qt::NoBrush);
|
|
|
|
|
p.setPen(QColor(255,255,255,140));
|
|
|
|
|
p.drawRoundedRect(fullRect.adjusted(1, 1, -2, -2), 2, 2);
|
|
|
|
|
p.setPen(QPen(widget->palette().color(QPalette::Mid)));
|
|
|
|
|
}
|
2011-05-18 16:48:36 +02:00
|
|
|
|
|
|
|
|
return pixmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidgetPrivate::updateControls()
|
|
|
|
|
{
|
|
|
|
|
if (m_widget)
|
|
|
|
|
m_widget->setVisible(m_state == DetailsWidget::Expanded || m_state == DetailsWidget::NoSummary);
|
|
|
|
|
m_detailsButton->setChecked(m_state == DetailsWidget::Expanded && m_widget);
|
2011-12-08 14:29:24 +01:00
|
|
|
m_detailsButton->setVisible(m_state == DetailsWidget::Expanded || m_state == DetailsWidget::Collapsed);
|
2013-10-02 13:53:47 +02:00
|
|
|
m_summaryLabelIcon->setVisible(m_state != DetailsWidget::NoSummary && !m_useCheckBox);
|
2011-05-18 16:48:36 +02:00
|
|
|
m_summaryLabel->setVisible(m_state != DetailsWidget::NoSummary && !m_useCheckBox);
|
|
|
|
|
m_summaryCheckBox->setVisible(m_state != DetailsWidget::NoSummary && m_useCheckBox);
|
|
|
|
|
|
|
|
|
|
for (QWidget *w = q; w; w = w->parentWidget()) {
|
|
|
|
|
if (w->layout())
|
|
|
|
|
w->layout()->activate();
|
|
|
|
|
if (QScrollArea *area = qobject_cast<QScrollArea*>(w)) {
|
|
|
|
|
QEvent e(QEvent::LayoutRequest);
|
|
|
|
|
QCoreApplication::sendEvent(area, &e);
|
2010-02-23 15:29:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-05-18 16:48:36 +02:00
|
|
|
}
|
2009-10-02 10:12:32 +02:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
void DetailsWidgetPrivate::changeHoverState(bool hovered)
|
|
|
|
|
{
|
|
|
|
|
if (!m_toolWidget)
|
|
|
|
|
return;
|
2012-08-23 15:53:58 +02:00
|
|
|
if (HostOsInfo::isMacHost())
|
|
|
|
|
m_toolWidget->setOpacity(hovered ? 1.0 : 0);
|
|
|
|
|
else
|
|
|
|
|
m_toolWidget->fadeTo(hovered ? 1.0 : 0);
|
2011-05-18 16:48:36 +02:00
|
|
|
m_hovered = hovered;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DetailsWidget::DetailsWidget(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
d(new DetailsWidgetPrivate(this))
|
|
|
|
|
{
|
|
|
|
|
setLayout(d->m_grid);
|
|
|
|
|
|
2011-07-25 15:59:53 +00:00
|
|
|
setUseCheckBox(false);
|
|
|
|
|
|
2015-03-05 22:00:05 +02:00
|
|
|
connect(d->m_detailsButton, &QAbstractButton::toggled,
|
|
|
|
|
this, &DetailsWidget::setExpanded);
|
|
|
|
|
connect(d->m_summaryCheckBox, &QAbstractButton::toggled,
|
|
|
|
|
this, &DetailsWidget::checked);
|
|
|
|
|
connect(d->m_summaryLabel, &QLabel::linkActivated,
|
|
|
|
|
this, &DetailsWidget::linkActivated);
|
2011-05-18 16:48:36 +02:00
|
|
|
d->updateControls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DetailsWidget::~DetailsWidget()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DetailsWidget::useCheckBox()
|
|
|
|
|
{
|
|
|
|
|
return d->m_useCheckBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setUseCheckBox(bool b)
|
|
|
|
|
{
|
|
|
|
|
d->m_useCheckBox = b;
|
2013-10-02 13:51:44 +02:00
|
|
|
d->updateControls();
|
2011-05-18 16:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setChecked(bool b)
|
|
|
|
|
{
|
|
|
|
|
d->m_summaryCheckBox->setChecked(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DetailsWidget::isChecked() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_useCheckBox && d->m_summaryCheckBox->isChecked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setSummaryFontBold(bool b)
|
|
|
|
|
{
|
|
|
|
|
QFont f;
|
|
|
|
|
f.setBold(b);
|
|
|
|
|
d->m_summaryCheckBox->setFont(f);
|
|
|
|
|
d->m_summaryLabel->setFont(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setIcon(const QIcon &icon)
|
|
|
|
|
{
|
2013-10-02 13:53:47 +02:00
|
|
|
int iconSize = style()->pixelMetric(QStyle::PM_ButtonIconSize, 0, this);
|
|
|
|
|
d->m_summaryLabelIcon->setFixedWidth(icon.isNull() ? 0 : iconSize);
|
|
|
|
|
d->m_summaryLabelIcon->setPixmap(icon.pixmap(iconSize, iconSize));
|
2011-05-18 16:48:36 +02:00
|
|
|
d->m_summaryCheckBox->setIcon(icon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::paintEvent(QPaintEvent *paintEvent)
|
|
|
|
|
{
|
|
|
|
|
QWidget::paintEvent(paintEvent);
|
|
|
|
|
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
|
2013-10-02 13:53:47 +02:00
|
|
|
QWidget *topLeftWidget = d->m_useCheckBox ? static_cast<QWidget *>(d->m_summaryCheckBox) : static_cast<QWidget *>(d->m_summaryLabelIcon);
|
2011-07-25 15:59:53 +00:00
|
|
|
QPoint topLeft(topLeftWidget->geometry().left() - MARGIN, contentsRect().top());
|
2011-05-18 16:48:36 +02:00
|
|
|
const QRect paintArea(topLeft, contentsRect().bottomRight());
|
|
|
|
|
|
2012-11-15 17:14:40 +01:00
|
|
|
int topHeight = d->m_useCheckBox ? d->m_summaryCheckBox->height() : d->m_summaryLabel->height();
|
|
|
|
|
if (d->m_state == DetailsWidget::Expanded || d->m_state == DetailsWidget::Collapsed) // Details Button is shown
|
|
|
|
|
topHeight = qMax(d->m_detailsButton->height(), topHeight);
|
|
|
|
|
|
2011-12-08 14:29:24 +01:00
|
|
|
if (d->m_state == Collapsed) {
|
2011-05-18 16:48:36 +02:00
|
|
|
if (d->m_collapsedPixmap.isNull() ||
|
|
|
|
|
d->m_collapsedPixmap.size() != size())
|
2012-11-15 17:14:40 +01:00
|
|
|
d->m_collapsedPixmap = createBackground(paintArea.size(), topHeight, this);
|
2011-05-18 16:48:36 +02:00
|
|
|
p.drawPixmap(paintArea, d->m_collapsedPixmap);
|
|
|
|
|
} else {
|
|
|
|
|
if (d->m_expandedPixmap.isNull() ||
|
|
|
|
|
d->m_expandedPixmap.size() != size())
|
2012-11-15 17:14:40 +01:00
|
|
|
d->m_expandedPixmap = createBackground(paintArea.size(), topHeight, this);
|
2011-05-18 16:48:36 +02:00
|
|
|
p.drawPixmap(paintArea, d->m_expandedPixmap);
|
2010-03-10 19:19:46 +01:00
|
|
|
}
|
2011-05-18 16:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::enterEvent(QEvent * event)
|
|
|
|
|
{
|
|
|
|
|
QWidget::enterEvent(event);
|
|
|
|
|
d->changeHoverState(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::leaveEvent(QEvent * event)
|
|
|
|
|
{
|
|
|
|
|
QWidget::leaveEvent(event);
|
|
|
|
|
d->changeHoverState(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setSummaryText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
if (d->m_useCheckBox)
|
|
|
|
|
d->m_summaryCheckBox->setText(text);
|
|
|
|
|
else
|
|
|
|
|
d->m_summaryLabel->setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DetailsWidget::summaryText() const
|
|
|
|
|
{
|
|
|
|
|
if (d->m_useCheckBox)
|
|
|
|
|
return d->m_summaryCheckBox->text();
|
|
|
|
|
return d->m_summaryLabel->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString DetailsWidget::additionalSummaryText() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_additionalSummaryLabel->text();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setAdditionalSummaryText(const QString &text)
|
|
|
|
|
{
|
|
|
|
|
d->m_additionalSummaryLabel->setText(text);
|
|
|
|
|
d->m_additionalSummaryLabel->setVisible(!text.isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DetailsWidget::State DetailsWidget::state() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setState(State state)
|
|
|
|
|
{
|
|
|
|
|
if (state == d->m_state)
|
|
|
|
|
return;
|
|
|
|
|
d->m_state = state;
|
|
|
|
|
d->updateControls();
|
2011-09-21 15:17:24 +02:00
|
|
|
emit expanded(d->m_state == Expanded);
|
2011-05-18 16:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DetailsWidget::setExpanded(bool expanded)
|
|
|
|
|
{
|
|
|
|
|
setState(expanded ? Expanded : Collapsed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *DetailsWidget::widget() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-16 15:59:10 +02:00
|
|
|
QWidget *DetailsWidget::takeWidget()
|
|
|
|
|
{
|
|
|
|
|
QWidget *widget = d->m_widget;
|
|
|
|
|
d->m_widget = 0;
|
|
|
|
|
d->m_grid->removeWidget(widget);
|
|
|
|
|
if (widget)
|
|
|
|
|
widget->setParent(0);
|
|
|
|
|
return widget;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
void DetailsWidget::setWidget(QWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
if (d->m_widget == widget)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (d->m_widget) {
|
|
|
|
|
d->m_grid->removeWidget(d->m_widget);
|
|
|
|
|
delete d->m_widget;
|
2010-03-10 19:19:46 +01:00
|
|
|
}
|
2009-11-30 15:16:05 +01:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
d->m_widget = widget;
|
2009-11-30 15:16:05 +01:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
if (d->m_widget) {
|
|
|
|
|
d->m_widget->setContentsMargins(MARGIN, MARGIN, MARGIN, MARGIN);
|
|
|
|
|
d->m_grid->addWidget(d->m_widget, 2, 0, 1, 3);
|
2010-03-10 19:19:46 +01:00
|
|
|
}
|
2011-05-18 16:48:36 +02:00
|
|
|
d->updateControls();
|
|
|
|
|
}
|
2010-03-10 19:19:46 +01:00
|
|
|
|
2014-07-15 23:33:17 +03:00
|
|
|
void DetailsWidget::setToolWidget(FadingPanel *widget)
|
2011-05-18 16:48:36 +02:00
|
|
|
{
|
|
|
|
|
if (d->m_toolWidget == widget)
|
|
|
|
|
return;
|
2009-11-30 15:16:05 +01:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
d->m_toolWidget = widget;
|
2009-11-30 15:16:05 +01:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
if (!d->m_toolWidget)
|
|
|
|
|
return;
|
2009-11-30 15:16:05 +01:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
d->m_toolWidget->adjustSize();
|
|
|
|
|
d->m_grid->addWidget(d->m_toolWidget, 0, 1, 1, 1, Qt::AlignRight);
|
2009-10-01 14:39:31 +02:00
|
|
|
|
2012-08-23 15:53:58 +02:00
|
|
|
if (HostOsInfo::isMacHost())
|
|
|
|
|
d->m_toolWidget->setOpacity(1.0);
|
2011-05-18 16:48:36 +02:00
|
|
|
d->changeHoverState(d->m_hovered);
|
|
|
|
|
}
|
2010-03-10 19:19:46 +01:00
|
|
|
|
2011-05-18 16:48:36 +02:00
|
|
|
QWidget *DetailsWidget::toolWidget() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_toolWidget;
|
|
|
|
|
}
|
2010-02-02 09:59:55 +01:00
|
|
|
|
|
|
|
|
} // namespace Utils
|