Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
versiondialog.cpp
Go to the documentation of this file.
1
// Copyright (C) 2020 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant reason:default
4
5
#
include
<
QtCore
/
qlist
.
h
>
6
7
#
include
<
QtGui
/
qevent
.
h
>
8
#
include
<
QtGui
/
qpainter
.
h
>
9
#
include
<
QtGui
/
qpainterpath
.
h
>
10
11
#
include
<
QtWidgets
/
qdialogbuttonbox
.
h
>
12
#
include
<
QtWidgets
/
qgridlayout
.
h
>
13
#
include
<
QtWidgets
/
qlabel
.
h
>
14
#
include
<
QtWidgets
/
qpushbutton
.
h
>
15
#
include
<
QtWidgets
/
qstyleoption
.
h
>
16
17
#
include
"versiondialog.h"
18
19
QT_BEGIN_NAMESPACE
20
21
using
namespace
Qt::StringLiterals;
22
23
class
VersionLabel
:
public
QLabel
24
{
25
Q_OBJECT
26
public
:
27
VersionLabel
(
QWidget
*
parent
=
nullptr
);
28
29
signals
:
30
void
triggered
();
31
32
protected
:
33
void
mousePressEvent
(QMouseEvent *me)
override
;
34
void
mouseMoveEvent
(QMouseEvent *me)
override
;
35
void
mouseReleaseEvent
(QMouseEvent *me)
override
;
36
void
paintEvent
(QPaintEvent *pe)
override
;
37
private
:
38
QList<QPoint> hitPoints;
39
QList<QPoint> missPoints;
40
QPainterPath m_path;
41
bool
secondStage =
false
;
42
bool
m_pushed =
false
;
43
};
44
45
VersionLabel
::VersionLabel(QWidget *parent)
46
: QLabel(parent)
47
{
48
QPixmap pixmap(u":/qt-project.org/designer/images/designer.png"_s);
49
pixmap.setDevicePixelRatio(devicePixelRatioF());
50
setPixmap(pixmap);
51
hitPoints.append(QPoint(56, 25));
52
hitPoints.append(QPoint(29, 55));
53
hitPoints.append(QPoint(56, 87));
54
hitPoints.append(QPoint(82, 55));
55
hitPoints.append(QPoint(58, 56));
56
}
57
58
void
VersionLabel
::
mousePressEvent
(QMouseEvent *me)
59
{
60
if
(me->button() == Qt::LeftButton) {
61
if
(!secondStage) {
62
m_path = QPainterPath(me->pos());
63
}
else
{
64
m_pushed =
true
;
65
update();
66
}
67
}
68
}
69
70
void
VersionLabel
::
mouseMoveEvent
(QMouseEvent *me)
71
{
72
if
(me->buttons() & Qt::LeftButton)
73
if
(!secondStage)
74
m_path.lineTo(me->pos());
75
}
76
77
void
VersionLabel
::
mouseReleaseEvent
(QMouseEvent *me)
78
{
79
if
(me->button() == Qt::LeftButton) {
80
if
(!secondStage) {
81
m_path.lineTo(me->pos());
82
bool
gotIt =
true
;
83
for
(
const
QPoint &pt : std::as_const(hitPoints)) {
84
if
(!m_path.contains(pt)) {
85
gotIt =
false
;
86
break
;
87
}
88
}
89
if
(gotIt) {
90
for
(
const
QPoint &pt : std::as_const(missPoints)) {
91
if
(m_path.contains(pt)) {
92
gotIt =
false
;
93
break
;
94
}
95
}
96
}
97
if
(gotIt && !secondStage) {
98
secondStage =
true
;
99
m_path = QPainterPath();
100
update();
101
}
102
}
else
{
103
m_pushed =
false
;
104
update();
105
emit triggered();
106
}
107
}
108
}
109
110
void
VersionLabel
::
paintEvent
(QPaintEvent *pe)
111
{
112
if
(secondStage) {
113
QPainter p(
this
);
114
QStyleOptionButton opt;
115
opt.initFrom(
this
);
116
if
(!m_pushed)
117
opt.state |= QStyle::State_Raised;
118
else
119
opt.state |= QStyle::State_Sunken;
120
opt.state &= ~QStyle::State_HasFocus;
121
style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &p,
this
);
122
}
123
QLabel::paintEvent(pe);
124
}
125
126
VersionDialog::VersionDialog(QWidget *parent)
127
: QDialog(parent
128
#
ifdef
Q_OS_MACOS
129
, Qt::Tool
130
#
endif
131
)
132
{
133
setWindowFlag(Qt::MSWindowsFixedSizeDialogHint,
true
);
134
auto
*layout =
new
QGridLayout(
this
);
135
auto
*label =
new
VersionLabel(
this
);
136
auto
*lbl =
new
QLabel(
this
);
137
QString version = tr(
"<h3>%1</h3><br/><br/>Version %2"
);
138
version = version.arg(tr(
"Qt Widgets Designer"
)).arg(QLatin1StringView(QT_VERSION_STR));
139
version.append(tr(
"<br/>Qt Widgets Designer is a graphical user interface designer for Qt applications.<br/>"
));
140
141
lbl->setText(
142
tr(
"%1<br/>Copyright (C) The Qt Company Ltd. and other contributors."
).arg(version));
143
144
lbl->setWordWrap(
true
);
145
lbl->setOpenExternalLinks(
true
);
146
147
auto
*buttonBox =
new
QDialogButtonBox(QDialogButtonBox::Close,
this
);
148
connect(buttonBox , &QDialogButtonBox::rejected,
this
, &QDialog::reject);
149
connect(label, &VersionLabel::triggered,
this
, &QDialog::accept);
150
layout->addWidget(label, 0, 0, 1, 1);
151
layout->addWidget(lbl, 0, 1, 4, 4);
152
layout->addWidget(buttonBox, 4, 2, 1, 1);
153
}
154
155
QT_END_NAMESPACE
156
157
#
include
"versiondialog.moc"
VersionLabel
Definition
versiondialog.cpp:24
VersionLabel::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *me) override
\reimp
Definition
versiondialog.cpp:70
VersionLabel::paintEvent
void paintEvent(QPaintEvent *pe) override
\reimp
Definition
versiondialog.cpp:110
VersionLabel::mousePressEvent
void mousePressEvent(QMouseEvent *me) override
\reimp
Definition
versiondialog.cpp:58
VersionLabel::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *me) override
\reimp
Definition
versiondialog.cpp:77
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qttools
src
designer
src
designer
versiondialog.cpp
Generated on
for Qt by
1.18.0