author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
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 |
"toni.buddenbrook@example.de."); |
|
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 |
"thomas.gradgrind@example.co.uk."); |
|
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., john.smith@example.com).")); |
|
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., tanaka.aya@example.co.jp).")); |
|
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 |
} |