1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the examples of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:BSD$ |
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 | ** BSD License Usage |
18 | ** Alternatively, you may use this file under the terms of the BSD license |
19 | ** as follows: |
20 | ** |
21 | ** "Redistribution and use in source and binary forms, with or without |
22 | ** modification, are permitted provided that the following conditions are |
23 | ** met: |
24 | ** * Redistributions of source code must retain the above copyright |
25 | ** notice, this list of conditions and the following disclaimer. |
26 | ** * Redistributions in binary form must reproduce the above copyright |
27 | ** notice, this list of conditions and the following disclaimer in |
28 | ** the documentation and/or other materials provided with the |
29 | ** distribution. |
30 | ** * Neither the name of The Qt Company Ltd nor the names of its |
31 | ** contributors may be used to endorse or promote products derived |
32 | ** from this software without specific prior written permission. |
33 | ** |
34 | ** |
35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
46 | ** |
47 | ** $QT_END_LICENSE$ |
48 | ** |
49 | ****************************************************************************/ |
50 | |
51 | #include <QtWidgets> |
52 | #if defined(QT_PRINTSUPPORT_LIB) |
53 | #include <QtPrintSupport/qtprintsupportglobal.h> |
54 | #if QT_CONFIG(printdialog) |
55 | #include <QPrinter> |
56 | #include <QPrintDialog> |
57 | #endif |
58 | #endif |
59 | |
60 | #include "licensewizard.h" |
61 | |
62 | QString emailRegExp = QStringLiteral(".+@.+" ); |
63 | |
64 | //! [0] //! [1] //! [2] |
65 | LicenseWizard::LicenseWizard(QWidget *parent) |
66 | : QWizard(parent) |
67 | { |
68 | //! [0] |
69 | setPage(id: Page_Intro, page: new IntroPage); |
70 | setPage(id: Page_Evaluate, page: new EvaluatePage); |
71 | setPage(id: Page_Register, page: new RegisterPage); |
72 | setPage(id: Page_Details, page: new DetailsPage); |
73 | setPage(id: Page_Conclusion, page: new ConclusionPage); |
74 | //! [1] |
75 | |
76 | setStartId(Page_Intro); |
77 | //! [2] |
78 | |
79 | //! [3] |
80 | #ifndef Q_OS_MAC |
81 | //! [3] //! [4] |
82 | setWizardStyle(ModernStyle); |
83 | #endif |
84 | //! [4] //! [5] |
85 | setOption(option: HaveHelpButton, on: true); |
86 | //! [5] //! [6] |
87 | setPixmap(which: QWizard::LogoPixmap, pixmap: QPixmap(":/images/logo.png" )); |
88 | |
89 | //! [7] |
90 | connect(sender: this, signal: &QWizard::helpRequested, receiver: this, slot: &LicenseWizard::showHelp); |
91 | //! [7] |
92 | |
93 | setWindowTitle(tr(s: "License Wizard" )); |
94 | //! [8] |
95 | } |
96 | //! [6] //! [8] |
97 | |
98 | //! [9] //! [10] |
99 | void LicenseWizard::showHelp() |
100 | //! [9] //! [11] |
101 | { |
102 | static QString lastHelpMessage; |
103 | |
104 | QString message; |
105 | |
106 | switch (currentId()) { |
107 | case Page_Intro: |
108 | message = tr(s: "The decision you make here will affect which page you " |
109 | "get to see next." ); |
110 | break; |
111 | //! [10] //! [11] |
112 | case Page_Evaluate: |
113 | message = tr(s: "Make sure to provide a valid email address, such as " |
114 | "toni.buddenbrook@example.de." ); |
115 | break; |
116 | case Page_Register: |
117 | message = tr(s: "If you don't provide an upgrade key, you will be " |
118 | "asked to fill in your details." ); |
119 | break; |
120 | case Page_Details: |
121 | message = tr(s: "Make sure to provide a valid email address, such as " |
122 | "thomas.gradgrind@example.co.uk." ); |
123 | break; |
124 | case Page_Conclusion: |
125 | message = tr(s: "You must accept the terms and conditions of the " |
126 | "license to proceed." ); |
127 | break; |
128 | //! [12] //! [13] |
129 | default: |
130 | message = tr(s: "This help is likely not to be of any help." ); |
131 | } |
132 | //! [12] |
133 | |
134 | if (lastHelpMessage == message) |
135 | message = tr(s: "Sorry, I already gave what help I could. " |
136 | "Maybe you should try asking a human?" ); |
137 | |
138 | //! [14] |
139 | QMessageBox::information(parent: this, title: tr(s: "License Wizard Help" ), text: message); |
140 | //! [14] |
141 | |
142 | lastHelpMessage = message; |
143 | //! [15] |
144 | } |
145 | //! [13] //! [15] |
146 | |
147 | //! [16] |
148 | IntroPage::IntroPage(QWidget *parent) |
149 | : QWizardPage(parent) |
150 | { |
151 | setTitle(tr(s: "Introduction" )); |
152 | setPixmap(which: QWizard::WatermarkPixmap, pixmap: QPixmap(":/images/watermark.png" )); |
153 | |
154 | topLabel = new QLabel(tr(s: "This wizard will help you register your copy of " |
155 | "<i>Super Product One</i>™ or start " |
156 | "evaluating the product." )); |
157 | topLabel->setWordWrap(true); |
158 | |
159 | registerRadioButton = new QRadioButton(tr(s: "&Register your copy" )); |
160 | evaluateRadioButton = new QRadioButton(tr(s: "&Evaluate the product for 30 " |
161 | "days" )); |
162 | registerRadioButton->setChecked(true); |
163 | |
164 | QVBoxLayout *layout = new QVBoxLayout; |
165 | layout->addWidget(topLabel); |
166 | layout->addWidget(registerRadioButton); |
167 | layout->addWidget(evaluateRadioButton); |
168 | setLayout(layout); |
169 | } |
170 | //! [16] //! [17] |
171 | |
172 | //! [18] |
173 | int IntroPage::nextId() const |
174 | //! [17] //! [19] |
175 | { |
176 | if (evaluateRadioButton->isChecked()) { |
177 | return LicenseWizard::Page_Evaluate; |
178 | } else { |
179 | return LicenseWizard::Page_Register; |
180 | } |
181 | } |
182 | //! [18] //! [19] |
183 | |
184 | //! [20] |
185 | EvaluatePage::EvaluatePage(QWidget *parent) |
186 | : QWizardPage(parent) |
187 | { |
188 | setTitle(tr(s: "Evaluate <i>Super Product One</i>™" )); |
189 | setSubTitle(tr(s: "Please fill both fields. Make sure to provide a valid " |
190 | "email address (e.g., john.smith@example.com)." )); |
191 | |
192 | nameLabel = new QLabel(tr(s: "N&ame:" )); |
193 | nameLineEdit = new QLineEdit; |
194 | //! [20] |
195 | nameLabel->setBuddy(nameLineEdit); |
196 | |
197 | emailLabel = new QLabel(tr(s: "&Email address:" )); |
198 | emailLineEdit = new QLineEdit; |
199 | emailLineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression(emailRegExp), this)); |
200 | emailLabel->setBuddy(emailLineEdit); |
201 | |
202 | //! [21] |
203 | registerField(name: "evaluate.name*" , widget: nameLineEdit); |
204 | registerField(name: "evaluate.email*" , widget: emailLineEdit); |
205 | //! [21] |
206 | |
207 | QGridLayout *layout = new QGridLayout; |
208 | layout->addWidget(nameLabel, row: 0, column: 0); |
209 | layout->addWidget(nameLineEdit, row: 0, column: 1); |
210 | layout->addWidget(emailLabel, row: 1, column: 0); |
211 | layout->addWidget(emailLineEdit, row: 1, column: 1); |
212 | setLayout(layout); |
213 | //! [22] |
214 | } |
215 | //! [22] |
216 | |
217 | //! [23] |
218 | int EvaluatePage::nextId() const |
219 | { |
220 | return LicenseWizard::Page_Conclusion; |
221 | } |
222 | //! [23] |
223 | |
224 | RegisterPage::RegisterPage(QWidget *parent) |
225 | : QWizardPage(parent) |
226 | { |
227 | setTitle(tr(s: "Register Your Copy of <i>Super Product One</i>™" )); |
228 | setSubTitle(tr(s: "If you have an upgrade key, please fill in " |
229 | "the appropriate field." )); |
230 | |
231 | nameLabel = new QLabel(tr(s: "N&ame:" )); |
232 | nameLineEdit = new QLineEdit; |
233 | nameLabel->setBuddy(nameLineEdit); |
234 | |
235 | upgradeKeyLabel = new QLabel(tr(s: "&Upgrade key:" )); |
236 | upgradeKeyLineEdit = new QLineEdit; |
237 | upgradeKeyLabel->setBuddy(upgradeKeyLineEdit); |
238 | |
239 | registerField(name: "register.name*" , widget: nameLineEdit); |
240 | registerField(name: "register.upgradeKey" , widget: upgradeKeyLineEdit); |
241 | |
242 | QGridLayout *layout = new QGridLayout; |
243 | layout->addWidget(nameLabel, row: 0, column: 0); |
244 | layout->addWidget(nameLineEdit, row: 0, column: 1); |
245 | layout->addWidget(upgradeKeyLabel, row: 1, column: 0); |
246 | layout->addWidget(upgradeKeyLineEdit, row: 1, column: 1); |
247 | setLayout(layout); |
248 | } |
249 | |
250 | //! [24] |
251 | int RegisterPage::nextId() const |
252 | { |
253 | if (upgradeKeyLineEdit->text().isEmpty()) { |
254 | return LicenseWizard::Page_Details; |
255 | } else { |
256 | return LicenseWizard::Page_Conclusion; |
257 | } |
258 | } |
259 | //! [24] |
260 | |
261 | DetailsPage::DetailsPage(QWidget *parent) |
262 | : QWizardPage(parent) |
263 | { |
264 | setTitle(tr(s: "Fill In Your Details" )); |
265 | setSubTitle(tr(s: "Please fill all three fields. Make sure to provide a valid " |
266 | "email address (e.g., tanaka.aya@example.co.jp)." )); |
267 | |
268 | companyLabel = new QLabel(tr(s: "&Company name:" )); |
269 | companyLineEdit = new QLineEdit; |
270 | companyLabel->setBuddy(companyLineEdit); |
271 | |
272 | emailLabel = new QLabel(tr(s: "&Email address:" )); |
273 | emailLineEdit = new QLineEdit; |
274 | emailLineEdit->setValidator(new QRegularExpressionValidator(QRegularExpression(emailRegExp), this)); |
275 | emailLabel->setBuddy(emailLineEdit); |
276 | |
277 | postalLabel = new QLabel(tr(s: "&Postal address:" )); |
278 | postalLineEdit = new QLineEdit; |
279 | postalLabel->setBuddy(postalLineEdit); |
280 | |
281 | registerField(name: "details.company*" , widget: companyLineEdit); |
282 | registerField(name: "details.email*" , widget: emailLineEdit); |
283 | registerField(name: "details.postal*" , widget: postalLineEdit); |
284 | |
285 | QGridLayout *layout = new QGridLayout; |
286 | layout->addWidget(companyLabel, row: 0, column: 0); |
287 | layout->addWidget(companyLineEdit, row: 0, column: 1); |
288 | layout->addWidget(emailLabel, row: 1, column: 0); |
289 | layout->addWidget(emailLineEdit, row: 1, column: 1); |
290 | layout->addWidget(postalLabel, row: 2, column: 0); |
291 | layout->addWidget(postalLineEdit, row: 2, column: 1); |
292 | setLayout(layout); |
293 | } |
294 | |
295 | //! [25] |
296 | int DetailsPage::nextId() const |
297 | { |
298 | return LicenseWizard::Page_Conclusion; |
299 | } |
300 | //! [25] |
301 | |
302 | ConclusionPage::ConclusionPage(QWidget *parent) |
303 | : QWizardPage(parent) |
304 | { |
305 | setTitle(tr(s: "Complete Your Registration" )); |
306 | setPixmap(which: QWizard::WatermarkPixmap, pixmap: QPixmap(":/images/watermark.png" )); |
307 | |
308 | bottomLabel = new QLabel; |
309 | bottomLabel->setWordWrap(true); |
310 | |
311 | agreeCheckBox = new QCheckBox(tr(s: "I agree to the terms of the license" )); |
312 | |
313 | registerField(name: "conclusion.agree*" , widget: agreeCheckBox); |
314 | |
315 | QVBoxLayout *layout = new QVBoxLayout; |
316 | layout->addWidget(bottomLabel); |
317 | layout->addWidget(agreeCheckBox); |
318 | setLayout(layout); |
319 | } |
320 | |
321 | //! [26] |
322 | int ConclusionPage::nextId() const |
323 | { |
324 | return -1; |
325 | } |
326 | //! [26] |
327 | |
328 | //! [27] |
329 | void ConclusionPage::initializePage() |
330 | { |
331 | QString licenseText; |
332 | |
333 | if (wizard()->hasVisitedPage(id: LicenseWizard::Page_Evaluate)) { |
334 | licenseText = tr(s: "<u>Evaluation License Agreement:</u> " |
335 | "You can use this software for 30 days and make one " |
336 | "backup, but you are not allowed to distribute it." ); |
337 | } else if (wizard()->hasVisitedPage(id: LicenseWizard::Page_Details)) { |
338 | licenseText = tr(s: "<u>First-Time License Agreement:</u> " |
339 | "You can use this software subject to the license " |
340 | "you will receive by email." ); |
341 | } else { |
342 | licenseText = tr(s: "<u>Upgrade License Agreement:</u> " |
343 | "This software is licensed under the terms of your " |
344 | "current license." ); |
345 | } |
346 | bottomLabel->setText(licenseText); |
347 | } |
348 | //! [27] |
349 | |
350 | //! [28] |
351 | void ConclusionPage::setVisible(bool visible) |
352 | { |
353 | QWizardPage::setVisible(visible); |
354 | |
355 | if (visible) { |
356 | //! [29] |
357 | wizard()->setButtonText(which: QWizard::CustomButton1, text: tr(s: "&Print" )); |
358 | wizard()->setOption(option: QWizard::HaveCustomButton1, on: true); |
359 | connect(sender: wizard(), signal: &QWizard::customButtonClicked, |
360 | receiver: this, slot: &ConclusionPage::printButtonClicked); |
361 | //! [29] |
362 | } else { |
363 | wizard()->setOption(option: QWizard::HaveCustomButton1, on: false); |
364 | disconnect(sender: wizard(), signal: &QWizard::customButtonClicked, |
365 | receiver: this, slot: &ConclusionPage::printButtonClicked); |
366 | } |
367 | } |
368 | //! [28] |
369 | |
370 | void ConclusionPage::printButtonClicked() |
371 | { |
372 | #if defined(QT_PRINTSUPPORT_LIB) && QT_CONFIG(printdialog) |
373 | QPrinter printer; |
374 | QPrintDialog dialog(&printer, this); |
375 | if (dialog.exec()) |
376 | QMessageBox::warning(parent: this, title: tr(s: "Print License" ), |
377 | text: tr(s: "As an environmentally friendly measure, the " |
378 | "license text will not actually be printed." )); |
379 | #endif |
380 | } |
381 | |