1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
// 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
#include "detailsbutton.h"
#include <utils/hostosinfo.h>
#include <utils/icon.h>
#include <utils/stylehelper.h>
#include <QGraphicsOpacityEffect>
#include <QGuiApplication>
#include <QPaintEvent>
#include <QPainter>
#include <QPropertyAnimation>
#include <QStyleOption>
#include <qdrawutil.h>
using namespace Utils;
FadingWidget::FadingWidget(QWidget *parent) :
FadingPanel(parent),
m_opacityEffect(new QGraphicsOpacityEffect)
{
m_opacityEffect->setOpacity(0);
setGraphicsEffect(m_opacityEffect);
// Workaround for issue with QGraphicsEffect. GraphicsEffect
// currently clears with Window color. Remove if flickering
// no longer occurs on fade-in
QPalette pal;
pal.setBrush(QPalette::All, QPalette::Window, Qt::transparent);
setPalette(pal);
}
void FadingWidget::setOpacity(qreal value)
{
m_opacityEffect->setOpacity(value);
}
void FadingWidget::fadeTo(qreal value)
{
QPropertyAnimation *animation = new QPropertyAnimation(m_opacityEffect, "opacity");
animation->setDuration(200);
animation->setEndValue(value);
animation->start(QAbstractAnimation::DeleteWhenStopped);
}
qreal FadingWidget::opacity()
{
return m_opacityEffect->opacity();
}
ExpandButton::ExpandButton(QWidget *parent)
: QToolButton(parent)
{
setCheckable(true);
auto updateArrow = [this] (bool checked) {
static const QIcon expand =
Icon({{":/utils/images/arrowdown.png", Theme::PanelTextColorDark}}, Icon::Tint).icon();
static const QIcon collapse =
Icon({{":/utils/images/arrowup.png", Theme::PanelTextColorDark}}, Icon::Tint).icon();
setIcon(checked ? collapse : expand);
};
updateArrow(false);
connect(this, &QToolButton::toggled, this, updateArrow);
}
DetailsButton::DetailsButton(QWidget *parent)
: ExpandButton(parent)
{
setText(tr("Details"));
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
if (HostOsInfo::isMacHost())
setFont(QGuiApplication::font());
}
QSize DetailsButton::sizeHint() const
{
const QSize textSize = fontMetrics().size(Qt::TextSingleLine, text());
return QSize(spacing + textSize.width() + spacing + 16 + spacing,
spacing + fontMetrics().height() + spacing);
}
QColor DetailsButton::outlineColor()
{
return HostOsInfo::isMacHost()
? QGuiApplication::palette().color(QPalette::Mid)
: StyleHelper::mergedColors(creatorTheme()->color(Theme::TextColorNormal),
creatorTheme()->color(Theme::BackgroundColorNormal), 15);
}
void DetailsButton::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e)
QPainter p(this);
if (isEnabled() && (isChecked() || (!HostOsInfo::isMacHost() && underMouse()))) {
p.save();
p.setOpacity(0.125);
p.fillRect(rect(), palette().color(QPalette::Text));
p.restore();
}
if (!creatorTheme()->flag(Theme::FlatProjectsMode))
qDrawPlainRect(&p, rect(), outlineColor());
const QRect textRect(spacing + 3, 0, width(), height());
p.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text());
if (creatorTheme()->flag(Theme::FlatProjectsMode) || HostOsInfo::isMacHost()) {
const QRect iconRect(width() - spacing - 15, 0, 16, height());
icon().paint(&p, iconRect);
} else {
int arrowsize = 15;
QStyleOption arrowOpt;
arrowOpt.initFrom(this);
arrowOpt.rect = QRect(size().width() - arrowsize - spacing, height() / 2 - arrowsize / 2,
arrowsize, arrowsize);
style()->drawPrimitive(isChecked() ? QStyle::PE_IndicatorArrowUp
: QStyle::PE_IndicatorArrowDown, &arrowOpt, &p, this);
}
}
|