1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the examples of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:BSD$
9
** You may use this file under the terms of the BSD license as follows:
11
** "Redistribution and use in source and binary forms, with or without
12
** modification, are permitted provided that the following conditions are
14
** * Redistributions of source code must retain the above copyright
15
** notice, this list of conditions and the following disclaimer.
16
** * Redistributions in binary form must reproduce the above copyright
17
** notice, this list of conditions and the following disclaimer in
18
** the documentation and/or other materials provided with the
20
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21
** of its contributors may be used to endorse or promote products derived
22
** from this software without specific prior written permission.
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39
****************************************************************************/
43
#include <QPrintDialog>
45
#include "licensewizard.h"
47
//! [0] //! [1] //! [2]
48
LicenseWizard::LicenseWizard(QWidget *parent)
52
setPage(Page_Intro, new IntroPage);
53
setPage(Page_Evaluate, new EvaluatePage);
54
setPage(Page_Register, new RegisterPage);
55
setPage(Page_Details, new DetailsPage);
56
setPage(Page_Conclusion, new ConclusionPage);
59
setStartId(Page_Intro);
65
setWizardStyle(ModernStyle);
68
setOption(HaveHelpButton, true);
70
setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo.png"));
73
connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
76
setWindowTitle(tr("License Wizard"));
82
void LicenseWizard::showHelp()
85
static QString lastHelpMessage;
89
switch (currentId()) {
91
message = tr("The decision you make here will affect which page you "
96
message = tr("Make sure to provide a valid email address, such as "
97
"toni.buddenbrook@example.de.");
100
message = tr("If you don't provide an upgrade key, you will be "
101
"asked to fill in your details.");
104
message = tr("Make sure to provide a valid email address, such as "
105
"thomas.gradgrind@example.co.uk.");
107
case Page_Conclusion:
108
message = tr("You must accept the terms and conditions of the "
109
"license to proceed.");
113
message = tr("This help is likely not to be of any help.");
117
if (lastHelpMessage == message)
118
message = tr("Sorry, I already gave what help I could. "
119
"Maybe you should try asking a human?");
122
QMessageBox::information(this, tr("License Wizard Help"), message);
125
lastHelpMessage = message;
131
IntroPage::IntroPage(QWidget *parent)
132
: QWizardPage(parent)
134
setTitle(tr("Introduction"));
135
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
137
topLabel = new QLabel(tr("This wizard will help you register your copy of "
138
"<i>Super Product One</i>™ or start "
139
"evaluating the product."));
140
topLabel->setWordWrap(true);
142
registerRadioButton = new QRadioButton(tr("&Register your copy"));
143
evaluateRadioButton = new QRadioButton(tr("&Evaluate the product for 30 "
145
registerRadioButton->setChecked(true);
147
QVBoxLayout *layout = new QVBoxLayout;
148
layout->addWidget(topLabel);
149
layout->addWidget(registerRadioButton);
150
layout->addWidget(evaluateRadioButton);
156
int IntroPage::nextId() const
159
if (evaluateRadioButton->isChecked()) {
160
return LicenseWizard::Page_Evaluate;
162
return LicenseWizard::Page_Register;
168
EvaluatePage::EvaluatePage(QWidget *parent)
169
: QWizardPage(parent)
171
setTitle(tr("Evaluate <i>Super Product One</i>™"));
172
setSubTitle(tr("Please fill both fields. Make sure to provide a valid "
173
"email address (e.g., john.smith@example.com)."));
175
nameLabel = new QLabel(tr("N&ame:"));
176
nameLineEdit = new QLineEdit;
178
nameLabel->setBuddy(nameLineEdit);
180
emailLabel = new QLabel(tr("&Email address:"));
181
emailLineEdit = new QLineEdit;
182
emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
183
emailLabel->setBuddy(emailLineEdit);
186
registerField("evaluate.name*", nameLineEdit);
187
registerField("evaluate.email*", emailLineEdit);
190
QGridLayout *layout = new QGridLayout;
191
layout->addWidget(nameLabel, 0, 0);
192
layout->addWidget(nameLineEdit, 0, 1);
193
layout->addWidget(emailLabel, 1, 0);
194
layout->addWidget(emailLineEdit, 1, 1);
201
int EvaluatePage::nextId() const
203
return LicenseWizard::Page_Conclusion;
207
RegisterPage::RegisterPage(QWidget *parent)
208
: QWizardPage(parent)
210
setTitle(tr("Register Your Copy of <i>Super Product One</i>™"));
211
setSubTitle(tr("If you have an upgrade key, please fill in "
212
"the appropriate field."));
214
nameLabel = new QLabel(tr("N&ame:"));
215
nameLineEdit = new QLineEdit;
216
nameLabel->setBuddy(nameLineEdit);
218
upgradeKeyLabel = new QLabel(tr("&Upgrade key:"));
219
upgradeKeyLineEdit = new QLineEdit;
220
upgradeKeyLabel->setBuddy(upgradeKeyLineEdit);
222
registerField("register.name*", nameLineEdit);
223
registerField("register.upgradeKey", upgradeKeyLineEdit);
225
QGridLayout *layout = new QGridLayout;
226
layout->addWidget(nameLabel, 0, 0);
227
layout->addWidget(nameLineEdit, 0, 1);
228
layout->addWidget(upgradeKeyLabel, 1, 0);
229
layout->addWidget(upgradeKeyLineEdit, 1, 1);
234
int RegisterPage::nextId() const
236
if (upgradeKeyLineEdit->text().isEmpty()) {
237
return LicenseWizard::Page_Details;
239
return LicenseWizard::Page_Conclusion;
244
DetailsPage::DetailsPage(QWidget *parent)
245
: QWizardPage(parent)
247
setTitle(tr("Fill In Your Details"));
248
setSubTitle(tr("Please fill all three fields. Make sure to provide a valid "
249
"email address (e.g., tanaka.aya@example.co.jp)."));
251
companyLabel = new QLabel(tr("&Company name:"));
252
companyLineEdit = new QLineEdit;
253
companyLabel->setBuddy(companyLineEdit);
255
emailLabel = new QLabel(tr("&Email address:"));
256
emailLineEdit = new QLineEdit;
257
emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
258
emailLabel->setBuddy(emailLineEdit);
260
postalLabel = new QLabel(tr("&Postal address:"));
261
postalLineEdit = new QLineEdit;
262
postalLabel->setBuddy(postalLineEdit);
264
registerField("details.company*", companyLineEdit);
265
registerField("details.email*", emailLineEdit);
266
registerField("details.postal*", postalLineEdit);
268
QGridLayout *layout = new QGridLayout;
269
layout->addWidget(companyLabel, 0, 0);
270
layout->addWidget(companyLineEdit, 0, 1);
271
layout->addWidget(emailLabel, 1, 0);
272
layout->addWidget(emailLineEdit, 1, 1);
273
layout->addWidget(postalLabel, 2, 0);
274
layout->addWidget(postalLineEdit, 2, 1);
279
int DetailsPage::nextId() const
281
return LicenseWizard::Page_Conclusion;
285
ConclusionPage::ConclusionPage(QWidget *parent)
286
: QWizardPage(parent)
288
setTitle(tr("Complete Your Registration"));
289
setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
291
bottomLabel = new QLabel;
292
bottomLabel->setWordWrap(true);
294
agreeCheckBox = new QCheckBox(tr("I agree to the terms of the license"));
296
registerField("conclusion.agree*", agreeCheckBox);
298
QVBoxLayout *layout = new QVBoxLayout;
299
layout->addWidget(bottomLabel);
300
layout->addWidget(agreeCheckBox);
305
int ConclusionPage::nextId() const
312
void ConclusionPage::initializePage()
316
if (wizard()->hasVisitedPage(LicenseWizard::Page_Evaluate)) {
317
licenseText = tr("<u>Evaluation License Agreement:</u> "
318
"You can use this software for 30 days and make one "
319
"backup, but you are not allowed to distribute it.");
320
} else if (wizard()->hasVisitedPage(LicenseWizard::Page_Details)) {
321
licenseText = tr("<u>First-Time License Agreement:</u> "
322
"You can use this software subject to the license "
323
"you will receive by email.");
325
licenseText = tr("<u>Upgrade License Agreement:</u> "
326
"This software is licensed under the terms of your "
329
bottomLabel->setText(licenseText);
334
void ConclusionPage::setVisible(bool visible)
336
QWizardPage::setVisible(visible);
340
wizard()->setButtonText(QWizard::CustomButton1, tr("&Print"));
341
wizard()->setOption(QWizard::HaveCustomButton1, true);
342
connect(wizard(), SIGNAL(customButtonClicked(int)),
343
this, SLOT(printButtonClicked()));
346
wizard()->setOption(QWizard::HaveCustomButton1, false);
347
disconnect(wizard(), SIGNAL(customButtonClicked(int)),
348
this, SLOT(printButtonClicked()));
353
void ConclusionPage::printButtonClicked()
355
#ifndef QT_NO_PRINTER
357
QPrintDialog dialog(&printer, this);
359
QMessageBox::warning(this, tr("Print License"),
360
tr("As an environmentally friendly measure, the "
361
"license text will not actually be printed."));