1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2020 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QtCore/qvector.h> |
30 | #include <QtGui/qevent.h> |
31 | #include <QtWidgets/qgridlayout.h> |
32 | #include <QtWidgets/qlabel.h> |
33 | #include <QtWidgets/qpushbutton.h> |
34 | #include <QtWidgets/qdialogbuttonbox.h> |
35 | #include <QtGui/qpainter.h> |
36 | #include <QtGui/qpainterpath.h> |
37 | #include <QtWidgets/qstyleoption.h> |
38 | #include "versiondialog.h" |
39 | |
40 | QT_BEGIN_NAMESPACE |
41 | |
42 | class VersionLabel : public QLabel |
43 | { |
44 | Q_OBJECT |
45 | public: |
46 | VersionLabel(QWidget *parent = nullptr); |
47 | |
48 | signals: |
49 | void triggered(); |
50 | |
51 | protected: |
52 | void mousePressEvent(QMouseEvent *me) override; |
53 | void mouseMoveEvent(QMouseEvent *me) override; |
54 | void mouseReleaseEvent(QMouseEvent *me) override; |
55 | void paintEvent(QPaintEvent *pe) override; |
56 | private: |
57 | QVector<QPoint> hitPoints; |
58 | QVector<QPoint> missPoints; |
59 | QPainterPath m_path; |
60 | bool secondStage = false; |
61 | bool m_pushed = false; |
62 | }; |
63 | |
64 | VersionLabel::VersionLabel(QWidget *parent) |
65 | : QLabel(parent) |
66 | { |
67 | setPixmap(QPixmap(QStringLiteral(":/qt-project.org/designer/images/designer.png" ))); |
68 | hitPoints.append(t: QPoint(56, 25)); |
69 | hitPoints.append(t: QPoint(29, 55)); |
70 | hitPoints.append(t: QPoint(56, 87)); |
71 | hitPoints.append(t: QPoint(82, 55)); |
72 | hitPoints.append(t: QPoint(58, 56)); |
73 | |
74 | secondStage = false; |
75 | m_pushed = false; |
76 | } |
77 | |
78 | void VersionLabel::mousePressEvent(QMouseEvent *me) |
79 | { |
80 | if (me->button() == Qt::LeftButton) { |
81 | if (!secondStage) { |
82 | m_path = QPainterPath(me->pos()); |
83 | } else { |
84 | m_pushed = true; |
85 | update(); |
86 | } |
87 | } |
88 | } |
89 | |
90 | void VersionLabel::mouseMoveEvent(QMouseEvent *me) |
91 | { |
92 | if (me->buttons() & Qt::LeftButton) |
93 | if (!secondStage) |
94 | m_path.lineTo(p: me->pos()); |
95 | } |
96 | |
97 | void VersionLabel::mouseReleaseEvent(QMouseEvent *me) |
98 | { |
99 | if (me->button() == Qt::LeftButton) { |
100 | if (!secondStage) { |
101 | m_path.lineTo(p: me->pos()); |
102 | bool gotIt = true; |
103 | for (const QPoint &pt : qAsConst(t&: hitPoints)) { |
104 | if (!m_path.contains(pt)) { |
105 | gotIt = false; |
106 | break; |
107 | } |
108 | } |
109 | if (gotIt) { |
110 | for (const QPoint &pt : qAsConst(t&: missPoints)) { |
111 | if (m_path.contains(pt)) { |
112 | gotIt = false; |
113 | break; |
114 | } |
115 | } |
116 | } |
117 | if (gotIt && !secondStage) { |
118 | secondStage = true; |
119 | m_path = QPainterPath(); |
120 | update(); |
121 | } |
122 | } else { |
123 | m_pushed = false; |
124 | update(); |
125 | emit triggered(); |
126 | } |
127 | } |
128 | } |
129 | |
130 | void VersionLabel::paintEvent(QPaintEvent *pe) |
131 | { |
132 | if (secondStage) { |
133 | QPainter p(this); |
134 | QStyleOptionButton opt; |
135 | opt.init(w: this); |
136 | if (!m_pushed) |
137 | opt.state |= QStyle::State_Raised; |
138 | else |
139 | opt.state |= QStyle::State_Sunken; |
140 | opt.state &= ~QStyle::State_HasFocus; |
141 | style()->drawControl(element: QStyle::CE_PushButtonBevel, opt: &opt, p: &p, w: this); |
142 | } |
143 | QLabel::paintEvent(pe); |
144 | } |
145 | |
146 | VersionDialog::VersionDialog(QWidget *parent) |
147 | : QDialog(parent |
148 | #ifdef Q_OS_MACOS |
149 | , Qt::Tool |
150 | #endif |
151 | ) |
152 | { |
153 | setWindowFlags((windowFlags() & ~Qt::WindowContextHelpButtonHint) | Qt::MSWindowsFixedSizeDialogHint); |
154 | QGridLayout *layout = new QGridLayout(this); |
155 | VersionLabel *label = new VersionLabel; |
156 | QLabel *lbl = new QLabel; |
157 | QString version = tr(s: "<h3>%1</h3><br/><br/>Version %2" ); |
158 | version = version.arg(a: tr(s: "Qt Designer" )).arg(a: QLatin1String(QT_VERSION_STR)); |
159 | version.append(s: tr(s: "<br/>Qt Designer is a graphical user interface designer for Qt applications.<br/>" )); |
160 | |
161 | lbl->setText(tr(s: "%1" |
162 | "<br/>Copyright (C) %2 The Qt Company Ltd." |
163 | ).arg(args&: version, QStringLiteral("2022" ))); |
164 | |
165 | lbl->setWordWrap(true); |
166 | lbl->setOpenExternalLinks(true); |
167 | |
168 | QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); |
169 | connect(sender: buttonBox , signal: &QDialogButtonBox::rejected, receiver: this, slot: &QDialog::reject); |
170 | connect(sender: label, signal: &VersionLabel::triggered, receiver: this, slot: &QDialog::accept); |
171 | layout->addWidget(label, row: 0, column: 0, rowSpan: 1, columnSpan: 1); |
172 | layout->addWidget(lbl, row: 0, column: 1, rowSpan: 4, columnSpan: 4); |
173 | layout->addWidget(buttonBox, row: 4, column: 2, rowSpan: 1, columnSpan: 1); |
174 | } |
175 | |
176 | QT_END_NAMESPACE |
177 | |
178 | #include "versiondialog.moc" |
179 | |