1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the examples of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include <QtGui>
|
---|
43 |
|
---|
44 | #include "licensewizard.h"
|
---|
45 |
|
---|
46 | //! [0] //! [1] //! [2]
|
---|
47 | LicenseWizard::LicenseWizard(QWidget *parent)
|
---|
48 | : QWizard(parent)
|
---|
49 | {
|
---|
50 | //! [0]
|
---|
51 | setPage(Page_Intro, new IntroPage);
|
---|
52 | setPage(Page_Evaluate, new EvaluatePage);
|
---|
53 | setPage(Page_Register, new RegisterPage);
|
---|
54 | setPage(Page_Details, new DetailsPage);
|
---|
55 | setPage(Page_Conclusion, new ConclusionPage);
|
---|
56 | //! [1]
|
---|
57 |
|
---|
58 | setStartId(Page_Intro);
|
---|
59 | //! [2]
|
---|
60 |
|
---|
61 | //! [3]
|
---|
62 | #ifndef Q_WS_MAC
|
---|
63 | //! [3] //! [4]
|
---|
64 | setWizardStyle(ModernStyle);
|
---|
65 | #endif
|
---|
66 | //! [4] //! [5]
|
---|
67 | setOption(HaveHelpButton, true);
|
---|
68 | //! [5] //! [6]
|
---|
69 | setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo.png"));
|
---|
70 |
|
---|
71 | //! [7]
|
---|
72 | connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
|
---|
73 | //! [7]
|
---|
74 |
|
---|
75 | setWindowTitle(tr("License Wizard"));
|
---|
76 | //! [8]
|
---|
77 | }
|
---|
78 | //! [6] //! [8]
|
---|
79 |
|
---|
80 | //! [9] //! [10]
|
---|
81 | void LicenseWizard::showHelp()
|
---|
82 | //! [9] //! [11]
|
---|
83 | {
|
---|
84 | static QString lastHelpMessage;
|
---|
85 |
|
---|
86 | QString message;
|
---|
87 |
|
---|
88 | switch (currentId()) {
|
---|
89 | case Page_Intro:
|
---|
90 | message = tr("The decision you make here will affect which page you "
|
---|
91 | "get to see next.");
|
---|
92 | break;
|
---|
93 | //! [10] //! [11]
|
---|
94 | case Page_Evaluate:
|
---|
95 | message = tr("Make sure to provide a valid email address, such as "
|
---|
96 | "[email protected].");
|
---|
97 | break;
|
---|
98 | case Page_Register:
|
---|
99 | message = tr("If you don't provide an upgrade key, you will be "
|
---|
100 | "asked to fill in your details.");
|
---|
101 | break;
|
---|
102 | case Page_Details:
|
---|
103 | message = tr("Make sure to provide a valid email address, such as "
|
---|
104 | "[email protected].");
|
---|
105 | break;
|
---|
106 | case Page_Conclusion:
|
---|
107 | message = tr("You must accept the terms and conditions of the "
|
---|
108 | "license to proceed.");
|
---|
109 | break;
|
---|
110 | //! [12] //! [13]
|
---|
111 | default:
|
---|
112 | message = tr("This help is likely not to be of any help.");
|
---|
113 | }
|
---|
114 | //! [12]
|
---|
115 |
|
---|
116 | if (lastHelpMessage == message)
|
---|
117 | message = tr("Sorry, I already gave what help I could. "
|
---|
118 | "Maybe you should try asking a human?");
|
---|
119 |
|
---|
120 | //! [14]
|
---|
121 | QMessageBox::information(this, tr("License Wizard Help"), message);
|
---|
122 | //! [14]
|
---|
123 |
|
---|
124 | lastHelpMessage = message;
|
---|
125 | //! [15]
|
---|
126 | }
|
---|
127 | //! [13] //! [15]
|
---|
128 |
|
---|
129 | //! [16]
|
---|
130 | IntroPage::IntroPage(QWidget *parent)
|
---|
131 | : QWizardPage(parent)
|
---|
132 | {
|
---|
133 | setTitle(tr("Introduction"));
|
---|
134 | setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
|
---|
135 |
|
---|
136 | topLabel = new QLabel(tr("This wizard will help you register your copy of "
|
---|
137 | "<i>Super Product One</i>™ or start "
|
---|
138 | "evaluating the product."));
|
---|
139 | topLabel->setWordWrap(true);
|
---|
140 |
|
---|
141 | registerRadioButton = new QRadioButton(tr("&Register your copy"));
|
---|
142 | evaluateRadioButton = new QRadioButton(tr("&Evaluate the product for 30 "
|
---|
143 | "days"));
|
---|
144 | registerRadioButton->setChecked(true);
|
---|
145 |
|
---|
146 | QVBoxLayout *layout = new QVBoxLayout;
|
---|
147 | layout->addWidget(topLabel);
|
---|
148 | layout->addWidget(registerRadioButton);
|
---|
149 | layout->addWidget(evaluateRadioButton);
|
---|
150 | setLayout(layout);
|
---|
151 | }
|
---|
152 | //! [16] //! [17]
|
---|
153 |
|
---|
154 | //! [18]
|
---|
155 | int IntroPage::nextId() const
|
---|
156 | //! [17] //! [19]
|
---|
157 | {
|
---|
158 | if (evaluateRadioButton->isChecked()) {
|
---|
159 | return LicenseWizard::Page_Evaluate;
|
---|
160 | } else {
|
---|
161 | return LicenseWizard::Page_Register;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | //! [18] //! [19]
|
---|
165 |
|
---|
166 | //! [20]
|
---|
167 | EvaluatePage::EvaluatePage(QWidget *parent)
|
---|
168 | : QWizardPage(parent)
|
---|
169 | {
|
---|
170 | setTitle(tr("Evaluate <i>Super Product One</i>™"));
|
---|
171 | setSubTitle(tr("Please fill both fields. Make sure to provide a valid "
|
---|
172 | "email address (e.g., [email protected])."));
|
---|
173 |
|
---|
174 | nameLabel = new QLabel(tr("N&ame:"));
|
---|
175 | nameLineEdit = new QLineEdit;
|
---|
176 | //! [20]
|
---|
177 | nameLabel->setBuddy(nameLineEdit);
|
---|
178 |
|
---|
179 | emailLabel = new QLabel(tr("&Email address:"));
|
---|
180 | emailLineEdit = new QLineEdit;
|
---|
181 | emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
|
---|
182 | emailLabel->setBuddy(emailLineEdit);
|
---|
183 |
|
---|
184 | //! [21]
|
---|
185 | registerField("evaluate.name*", nameLineEdit);
|
---|
186 | registerField("evaluate.email*", emailLineEdit);
|
---|
187 | //! [21]
|
---|
188 |
|
---|
189 | QGridLayout *layout = new QGridLayout;
|
---|
190 | layout->addWidget(nameLabel, 0, 0);
|
---|
191 | layout->addWidget(nameLineEdit, 0, 1);
|
---|
192 | layout->addWidget(emailLabel, 1, 0);
|
---|
193 | layout->addWidget(emailLineEdit, 1, 1);
|
---|
194 | setLayout(layout);
|
---|
195 | //! [22]
|
---|
196 | }
|
---|
197 | //! [22]
|
---|
198 |
|
---|
199 | //! [23]
|
---|
200 | int EvaluatePage::nextId() const
|
---|
201 | {
|
---|
202 | return LicenseWizard::Page_Conclusion;
|
---|
203 | }
|
---|
204 | //! [23]
|
---|
205 |
|
---|
206 | RegisterPage::RegisterPage(QWidget *parent)
|
---|
207 | : QWizardPage(parent)
|
---|
208 | {
|
---|
209 | setTitle(tr("Register Your Copy of <i>Super Product One</i>™"));
|
---|
210 | setSubTitle(tr("If you have an upgrade key, please fill in "
|
---|
211 | "the appropriate field."));
|
---|
212 |
|
---|
213 | nameLabel = new QLabel(tr("N&ame:"));
|
---|
214 | nameLineEdit = new QLineEdit;
|
---|
215 | nameLabel->setBuddy(nameLineEdit);
|
---|
216 |
|
---|
217 | upgradeKeyLabel = new QLabel(tr("&Upgrade key:"));
|
---|
218 | upgradeKeyLineEdit = new QLineEdit;
|
---|
219 | upgradeKeyLabel->setBuddy(upgradeKeyLineEdit);
|
---|
220 |
|
---|
221 | registerField("register.name*", nameLineEdit);
|
---|
222 | registerField("register.upgradeKey", upgradeKeyLineEdit);
|
---|
223 |
|
---|
224 | QGridLayout *layout = new QGridLayout;
|
---|
225 | layout->addWidget(nameLabel, 0, 0);
|
---|
226 | layout->addWidget(nameLineEdit, 0, 1);
|
---|
227 | layout->addWidget(upgradeKeyLabel, 1, 0);
|
---|
228 | layout->addWidget(upgradeKeyLineEdit, 1, 1);
|
---|
229 | setLayout(layout);
|
---|
230 | }
|
---|
231 |
|
---|
232 | //! [24]
|
---|
233 | int RegisterPage::nextId() const
|
---|
234 | {
|
---|
235 | if (upgradeKeyLineEdit->text().isEmpty()) {
|
---|
236 | return LicenseWizard::Page_Details;
|
---|
237 | } else {
|
---|
238 | return LicenseWizard::Page_Conclusion;
|
---|
239 | }
|
---|
240 | }
|
---|
241 | //! [24]
|
---|
242 |
|
---|
243 | DetailsPage::DetailsPage(QWidget *parent)
|
---|
244 | : QWizardPage(parent)
|
---|
245 | {
|
---|
246 | setTitle(tr("Fill In Your Details"));
|
---|
247 | setSubTitle(tr("Please fill all three fields. Make sure to provide a valid "
|
---|
248 | "email address (e.g., [email protected])."));
|
---|
249 |
|
---|
250 | companyLabel = new QLabel(tr("&Company name:"));
|
---|
251 | companyLineEdit = new QLineEdit;
|
---|
252 | companyLabel->setBuddy(companyLineEdit);
|
---|
253 |
|
---|
254 | emailLabel = new QLabel(tr("&Email address:"));
|
---|
255 | emailLineEdit = new QLineEdit;
|
---|
256 | emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
|
---|
257 | emailLabel->setBuddy(emailLineEdit);
|
---|
258 |
|
---|
259 | postalLabel = new QLabel(tr("&Postal address:"));
|
---|
260 | postalLineEdit = new QLineEdit;
|
---|
261 | postalLabel->setBuddy(postalLineEdit);
|
---|
262 |
|
---|
263 | registerField("details.company*", companyLineEdit);
|
---|
264 | registerField("details.email*", emailLineEdit);
|
---|
265 | registerField("details.postal*", postalLineEdit);
|
---|
266 |
|
---|
267 | QGridLayout *layout = new QGridLayout;
|
---|
268 | layout->addWidget(companyLabel, 0, 0);
|
---|
269 | layout->addWidget(companyLineEdit, 0, 1);
|
---|
270 | layout->addWidget(emailLabel, 1, 0);
|
---|
271 | layout->addWidget(emailLineEdit, 1, 1);
|
---|
272 | layout->addWidget(postalLabel, 2, 0);
|
---|
273 | layout->addWidget(postalLineEdit, 2, 1);
|
---|
274 | setLayout(layout);
|
---|
275 | }
|
---|
276 |
|
---|
277 | //! [25]
|
---|
278 | int DetailsPage::nextId() const
|
---|
279 | {
|
---|
280 | return LicenseWizard::Page_Conclusion;
|
---|
281 | }
|
---|
282 | //! [25]
|
---|
283 |
|
---|
284 | ConclusionPage::ConclusionPage(QWidget *parent)
|
---|
285 | : QWizardPage(parent)
|
---|
286 | {
|
---|
287 | setTitle(tr("Complete Your Registration"));
|
---|
288 | setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
|
---|
289 |
|
---|
290 | bottomLabel = new QLabel;
|
---|
291 | bottomLabel->setWordWrap(true);
|
---|
292 |
|
---|
293 | agreeCheckBox = new QCheckBox(tr("I agree to the terms of the license"));
|
---|
294 |
|
---|
295 | registerField("conclusion.agree*", agreeCheckBox);
|
---|
296 |
|
---|
297 | QVBoxLayout *layout = new QVBoxLayout;
|
---|
298 | layout->addWidget(bottomLabel);
|
---|
299 | layout->addWidget(agreeCheckBox);
|
---|
300 | setLayout(layout);
|
---|
301 | }
|
---|
302 |
|
---|
303 | //! [26]
|
---|
304 | int ConclusionPage::nextId() const
|
---|
305 | {
|
---|
306 | return -1;
|
---|
307 | }
|
---|
308 | //! [26]
|
---|
309 |
|
---|
310 | //! [27]
|
---|
311 | void ConclusionPage::initializePage()
|
---|
312 | {
|
---|
313 | QString licenseText;
|
---|
314 |
|
---|
315 | if (wizard()->hasVisitedPage(LicenseWizard::Page_Evaluate)) {
|
---|
316 | licenseText = tr("<u>Evaluation License Agreement:</u> "
|
---|
317 | "You can use this software for 30 days and make one "
|
---|
318 | "backup, but you are not allowed to distribute it.");
|
---|
319 | } else if (wizard()->hasVisitedPage(LicenseWizard::Page_Details)) {
|
---|
320 | licenseText = tr("<u>First-Time License Agreement:</u> "
|
---|
321 | "You can use this software subject to the license "
|
---|
322 | "you will receive by email.");
|
---|
323 | } else {
|
---|
324 | licenseText = tr("<u>Upgrade License Agreement:</u> "
|
---|
325 | "This software is licensed under the terms of your "
|
---|
326 | "current license.");
|
---|
327 | }
|
---|
328 | bottomLabel->setText(licenseText);
|
---|
329 | }
|
---|
330 | //! [27]
|
---|
331 |
|
---|
332 | //! [28]
|
---|
333 | void ConclusionPage::setVisible(bool visible)
|
---|
334 | {
|
---|
335 | QWizardPage::setVisible(visible);
|
---|
336 |
|
---|
337 | if (visible) {
|
---|
338 | //! [29]
|
---|
339 | wizard()->setButtonText(QWizard::CustomButton1, tr("&Print"));
|
---|
340 | wizard()->setOption(QWizard::HaveCustomButton1, true);
|
---|
341 | connect(wizard(), SIGNAL(customButtonClicked(int)),
|
---|
342 | this, SLOT(printButtonClicked()));
|
---|
343 | //! [29]
|
---|
344 | } else {
|
---|
345 | wizard()->setOption(QWizard::HaveCustomButton1, false);
|
---|
346 | disconnect(wizard(), SIGNAL(customButtonClicked(int)),
|
---|
347 | this, SLOT(printButtonClicked()));
|
---|
348 | }
|
---|
349 | }
|
---|
350 | //! [28]
|
---|
351 |
|
---|
352 | void ConclusionPage::printButtonClicked()
|
---|
353 | {
|
---|
354 | QPrinter printer;
|
---|
355 | QPrintDialog dialog(&printer, this);
|
---|
356 | if (dialog.exec())
|
---|
357 | QMessageBox::warning(this, tr("Print License"),
|
---|
358 | tr("As an environmentally friendly measure, the "
|
---|
359 | "license text will not actually be printed."));
|
---|
360 | }
|
---|