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