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