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 secondStage = false;
57 m_pushed = false;
58}
59
60void VersionLabel::mousePressEvent(QMouseEvent *me)
61{
62 if (me->button() == Qt::LeftButton) {
63 if (!secondStage) {
64 m_path = QPainterPath(me->pos());
65 } else {
66 m_pushed = true;
67 update();
68 }
69 }
70}
71
72void VersionLabel::mouseMoveEvent(QMouseEvent *me)
73{
74 if (me->buttons() & Qt::LeftButton)
75 if (!secondStage)
76 m_path.lineTo(me->pos());
77}
78
79void VersionLabel::mouseReleaseEvent(QMouseEvent *me)
80{
81 if (me->button() == Qt::LeftButton) {
82 if (!secondStage) {
83 m_path.lineTo(me->pos());
84 bool gotIt = true;
85 for (const QPoint &pt : std::as_const(hitPoints)) {
86 if (!m_path.contains(pt)) {
87 gotIt = false;
88 break;
89 }
90 }
91 if (gotIt) {
92 for (const QPoint &pt : std::as_const(missPoints)) {
93 if (m_path.contains(pt)) {
94 gotIt = false;
95 break;
96 }
97 }
98 }
99 if (gotIt && !secondStage) {
100 secondStage = true;
101 m_path = QPainterPath();
102 update();
103 }
104 } else {
105 m_pushed = false;
106 update();
107 emit triggered();
108 }
109 }
110}
111
112void VersionLabel::paintEvent(QPaintEvent *pe)
113{
114 if (secondStage) {
115 QPainter p(this);
116 QStyleOptionButton opt;
117 opt.initFrom(this);
118 if (!m_pushed)
119 opt.state |= QStyle::State_Raised;
120 else
121 opt.state |= QStyle::State_Sunken;
122 opt.state &= ~QStyle::State_HasFocus;
123 style()->drawControl(QStyle::CE_PushButtonBevel, &opt, &p, this);
124 }
125 QLabel::paintEvent(pe);
126}
127
128VersionDialog::VersionDialog(QWidget *parent)
129 : QDialog(parent
130#ifdef Q_OS_MACOS
131 , Qt::Tool
132#endif
133 )
134{
135 setWindowFlag(Qt::MSWindowsFixedSizeDialogHint, true);
136 QGridLayout *layout = new QGridLayout(this);
137 VersionLabel *label = new VersionLabel(this);
138 QLabel *lbl = new QLabel(this);
139 QString version = tr("<h3>%1</h3><br/><br/>Version %2");
140 version = version.arg(tr("Qt Widgets Designer")).arg(QLatin1StringView(QT_VERSION_STR));
141 version.append(tr("<br/>Qt Widgets Designer is a graphical user interface designer for Qt applications.<br/>"));
142
143 lbl->setText(
144 tr("%1<br/>Copyright (C) The Qt Company Ltd. and other contributors.").arg(version));
145
146 lbl->setWordWrap(true);
147 lbl->setOpenExternalLinks(true);
148
149 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
150 connect(buttonBox , &QDialogButtonBox::rejected, this, &QDialog::reject);
151 connect(label, &VersionLabel::triggered, this, &QDialog::accept);
152 layout->addWidget(label, 0, 0, 1, 1);
153 layout->addWidget(lbl, 0, 1, 4, 4);
154 layout->addWidget(buttonBox, 4, 2, 1, 1);
155}
156
157QT_END_NAMESPACE
158
159#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.