~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to examples/widgets/dialogs/licensewizard/licensewizard.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the examples of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
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
 
19
**     distribution.
 
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.
 
23
**
 
24
**
 
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."
 
36
**
 
37
** $QT_END_LICENSE$
 
38
**
 
39
****************************************************************************/
 
40
 
 
41
#include <QtWidgets>
 
42
#include <QPrinter>
 
43
#include <QPrintDialog>
 
44
 
 
45
#include "licensewizard.h"
 
46
 
 
47
//! [0] //! [1] //! [2]
 
48
LicenseWizard::LicenseWizard(QWidget *parent)
 
49
    : QWizard(parent)
 
50
{
 
51
//! [0]
 
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);
 
57
//! [1]
 
58
 
 
59
    setStartId(Page_Intro);
 
60
//! [2]
 
61
 
 
62
//! [3]
 
63
#ifndef Q_OS_MAC
 
64
//! [3] //! [4]
 
65
    setWizardStyle(ModernStyle);
 
66
#endif
 
67
//! [4] //! [5]
 
68
    setOption(HaveHelpButton, true);
 
69
//! [5] //! [6]
 
70
    setPixmap(QWizard::LogoPixmap, QPixmap(":/images/logo.png"));
 
71
 
 
72
//! [7]
 
73
    connect(this, SIGNAL(helpRequested()), this, SLOT(showHelp()));
 
74
//! [7]
 
75
 
 
76
    setWindowTitle(tr("License Wizard"));
 
77
//! [8]
 
78
}
 
79
//! [6] //! [8]
 
80
 
 
81
//! [9] //! [10]
 
82
void LicenseWizard::showHelp()
 
83
//! [9] //! [11]
 
84
{
 
85
    static QString lastHelpMessage;
 
86
 
 
87
    QString message;
 
88
 
 
89
    switch (currentId()) {
 
90
    case Page_Intro:
 
91
        message = tr("The decision you make here will affect which page you "
 
92
                     "get to see next.");
 
93
        break;
 
94
//! [10] //! [11]
 
95
    case Page_Evaluate:
 
96
        message = tr("Make sure to provide a valid email address, such as "
 
97
                     "toni.buddenbrook@example.de.");
 
98
        break;
 
99
    case Page_Register:
 
100
        message = tr("If you don't provide an upgrade key, you will be "
 
101
                     "asked to fill in your details.");
 
102
        break;
 
103
    case Page_Details:
 
104
        message = tr("Make sure to provide a valid email address, such as "
 
105
                     "thomas.gradgrind@example.co.uk.");
 
106
        break;
 
107
    case Page_Conclusion:
 
108
        message = tr("You must accept the terms and conditions of the "
 
109
                     "license to proceed.");
 
110
        break;
 
111
//! [12] //! [13]
 
112
    default:
 
113
        message = tr("This help is likely not to be of any help.");
 
114
    }
 
115
//! [12]
 
116
 
 
117
    if (lastHelpMessage == message)
 
118
        message = tr("Sorry, I already gave what help I could. "
 
119
                     "Maybe you should try asking a human?");
 
120
 
 
121
//! [14]
 
122
    QMessageBox::information(this, tr("License Wizard Help"), message);
 
123
//! [14]
 
124
 
 
125
    lastHelpMessage = message;
 
126
//! [15]
 
127
}
 
128
//! [13] //! [15]
 
129
 
 
130
//! [16]
 
131
IntroPage::IntroPage(QWidget *parent)
 
132
    : QWizardPage(parent)
 
133
{
 
134
    setTitle(tr("Introduction"));
 
135
    setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
 
136
 
 
137
    topLabel = new QLabel(tr("This wizard will help you register your copy of "
 
138
                             "<i>Super Product One</i>&trade; or start "
 
139
                             "evaluating the product."));
 
140
    topLabel->setWordWrap(true);
 
141
 
 
142
    registerRadioButton = new QRadioButton(tr("&Register your copy"));
 
143
    evaluateRadioButton = new QRadioButton(tr("&Evaluate the product for 30 "
 
144
                                              "days"));
 
145
    registerRadioButton->setChecked(true);
 
146
 
 
147
    QVBoxLayout *layout = new QVBoxLayout;
 
148
    layout->addWidget(topLabel);
 
149
    layout->addWidget(registerRadioButton);
 
150
    layout->addWidget(evaluateRadioButton);
 
151
    setLayout(layout);
 
152
}
 
153
//! [16] //! [17]
 
154
 
 
155
//! [18]
 
156
int IntroPage::nextId() const
 
157
//! [17] //! [19]
 
158
{
 
159
    if (evaluateRadioButton->isChecked()) {
 
160
        return LicenseWizard::Page_Evaluate;
 
161
    } else {
 
162
        return LicenseWizard::Page_Register;
 
163
    }
 
164
}
 
165
//! [18] //! [19]
 
166
 
 
167
//! [20]
 
168
EvaluatePage::EvaluatePage(QWidget *parent)
 
169
    : QWizardPage(parent)
 
170
{
 
171
    setTitle(tr("Evaluate <i>Super Product One</i>&trade;"));
 
172
    setSubTitle(tr("Please fill both fields. Make sure to provide a valid "
 
173
                   "email address (e.g., john.smith@example.com)."));
 
174
 
 
175
    nameLabel = new QLabel(tr("N&ame:"));
 
176
    nameLineEdit = new QLineEdit;
 
177
//! [20]
 
178
    nameLabel->setBuddy(nameLineEdit);
 
179
 
 
180
    emailLabel = new QLabel(tr("&Email address:"));
 
181
    emailLineEdit = new QLineEdit;
 
182
    emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
 
183
    emailLabel->setBuddy(emailLineEdit);
 
184
 
 
185
//! [21]
 
186
    registerField("evaluate.name*", nameLineEdit);
 
187
    registerField("evaluate.email*", emailLineEdit);
 
188
//! [21]
 
189
 
 
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);
 
195
    setLayout(layout);
 
196
//! [22]
 
197
}
 
198
//! [22]
 
199
 
 
200
//! [23]
 
201
int EvaluatePage::nextId() const
 
202
{
 
203
    return LicenseWizard::Page_Conclusion;
 
204
}
 
205
//! [23]
 
206
 
 
207
RegisterPage::RegisterPage(QWidget *parent)
 
208
    : QWizardPage(parent)
 
209
{
 
210
    setTitle(tr("Register Your Copy of <i>Super Product One</i>&trade;"));
 
211
    setSubTitle(tr("If you have an upgrade key, please fill in "
 
212
                   "the appropriate field."));
 
213
 
 
214
    nameLabel = new QLabel(tr("N&ame:"));
 
215
    nameLineEdit = new QLineEdit;
 
216
    nameLabel->setBuddy(nameLineEdit);
 
217
 
 
218
    upgradeKeyLabel = new QLabel(tr("&Upgrade key:"));
 
219
    upgradeKeyLineEdit = new QLineEdit;
 
220
    upgradeKeyLabel->setBuddy(upgradeKeyLineEdit);
 
221
 
 
222
    registerField("register.name*", nameLineEdit);
 
223
    registerField("register.upgradeKey", upgradeKeyLineEdit);
 
224
 
 
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);
 
230
    setLayout(layout);
 
231
}
 
232
 
 
233
//! [24]
 
234
int RegisterPage::nextId() const
 
235
{
 
236
    if (upgradeKeyLineEdit->text().isEmpty()) {
 
237
        return LicenseWizard::Page_Details;
 
238
    } else {
 
239
        return LicenseWizard::Page_Conclusion;
 
240
    }
 
241
}
 
242
//! [24]
 
243
 
 
244
DetailsPage::DetailsPage(QWidget *parent)
 
245
    : QWizardPage(parent)
 
246
{
 
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)."));
 
250
 
 
251
    companyLabel = new QLabel(tr("&Company name:"));
 
252
    companyLineEdit = new QLineEdit;
 
253
    companyLabel->setBuddy(companyLineEdit);
 
254
 
 
255
    emailLabel = new QLabel(tr("&Email address:"));
 
256
    emailLineEdit = new QLineEdit;
 
257
    emailLineEdit->setValidator(new QRegExpValidator(QRegExp(".*@.*"), this));
 
258
    emailLabel->setBuddy(emailLineEdit);
 
259
 
 
260
    postalLabel = new QLabel(tr("&Postal address:"));
 
261
    postalLineEdit = new QLineEdit;
 
262
    postalLabel->setBuddy(postalLineEdit);
 
263
 
 
264
    registerField("details.company*", companyLineEdit);
 
265
    registerField("details.email*", emailLineEdit);
 
266
    registerField("details.postal*", postalLineEdit);
 
267
 
 
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);
 
275
    setLayout(layout);
 
276
}
 
277
 
 
278
//! [25]
 
279
int DetailsPage::nextId() const
 
280
{
 
281
    return LicenseWizard::Page_Conclusion;
 
282
}
 
283
//! [25]
 
284
 
 
285
ConclusionPage::ConclusionPage(QWidget *parent)
 
286
    : QWizardPage(parent)
 
287
{
 
288
    setTitle(tr("Complete Your Registration"));
 
289
    setPixmap(QWizard::WatermarkPixmap, QPixmap(":/images/watermark.png"));
 
290
 
 
291
    bottomLabel = new QLabel;
 
292
    bottomLabel->setWordWrap(true);
 
293
 
 
294
    agreeCheckBox = new QCheckBox(tr("I agree to the terms of the license"));
 
295
 
 
296
    registerField("conclusion.agree*", agreeCheckBox);
 
297
 
 
298
    QVBoxLayout *layout = new QVBoxLayout;
 
299
    layout->addWidget(bottomLabel);
 
300
    layout->addWidget(agreeCheckBox);
 
301
    setLayout(layout);
 
302
}
 
303
 
 
304
//! [26]
 
305
int ConclusionPage::nextId() const
 
306
{
 
307
    return -1;
 
308
}
 
309
//! [26]
 
310
 
 
311
//! [27]
 
312
void ConclusionPage::initializePage()
 
313
{
 
314
    QString licenseText;
 
315
 
 
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.");
 
324
    } else {
 
325
        licenseText = tr("<u>Upgrade License Agreement:</u> "
 
326
                         "This software is licensed under the terms of your "
 
327
                         "current license.");
 
328
    }
 
329
    bottomLabel->setText(licenseText);
 
330
}
 
331
//! [27]
 
332
 
 
333
//! [28]
 
334
void ConclusionPage::setVisible(bool visible)
 
335
{
 
336
    QWizardPage::setVisible(visible);
 
337
 
 
338
    if (visible) {
 
339
//! [29]
 
340
        wizard()->setButtonText(QWizard::CustomButton1, tr("&Print"));
 
341
        wizard()->setOption(QWizard::HaveCustomButton1, true);
 
342
        connect(wizard(), SIGNAL(customButtonClicked(int)),
 
343
                this, SLOT(printButtonClicked()));
 
344
//! [29]
 
345
    } else {
 
346
        wizard()->setOption(QWizard::HaveCustomButton1, false);
 
347
        disconnect(wizard(), SIGNAL(customButtonClicked(int)),
 
348
                   this, SLOT(printButtonClicked()));
 
349
    }
 
350
}
 
351
//! [28]
 
352
 
 
353
void ConclusionPage::printButtonClicked()
 
354
{
 
355
#ifndef QT_NO_PRINTER
 
356
    QPrinter printer;
 
357
    QPrintDialog dialog(&printer, this);
 
358
    if (dialog.exec())
 
359
        QMessageBox::warning(this, tr("Print License"),
 
360
                             tr("As an environmentally friendly measure, the "
 
361
                                "license text will not actually be printed."));
 
362
#endif
 
363
}