Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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
20
21using namespace Qt::StringLiterals;
22
23class VersionLabel : public QLabel
24{
26public:
28
30 void triggered();
31
32protected:
33 void mousePressEvent(QMouseEvent *me) override;
34 void mouseMoveEvent(QMouseEvent *me) override;
35 void mouseReleaseEvent(QMouseEvent *me) override;
36 void paintEvent(QPaintEvent *pe) override;
37private:
38 QList<QPoint> hitPoints;
39 QList<QPoint> missPoints;
40 QPainterPath m_path;
41 bool secondStage = false;
42 bool m_pushed = false;
43};
44
45VersionLabel::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
58void 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
70void VersionLabel::mouseMoveEvent(QMouseEvent *me)
71{
72 if (me->buttons() & Qt::LeftButton)
73 if (!secondStage)
74 m_path.lineTo(me->pos());
75}
76
77void 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
110void 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
126VersionDialog::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
155QT_END_NAMESPACE
156
157#include "versiondialog.moc"
void mouseMoveEvent(QMouseEvent *me) override
\reimp
void paintEvent(QPaintEvent *pe) override
\reimp
void mousePressEvent(QMouseEvent *me) override
\reimp
void mouseReleaseEvent(QMouseEvent *me) override
\reimp
Combined button and popup list for selecting options.