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 "detailsdialog.h" |
|
45 |
||
46 |
//! [0] |
|
47 |
DetailsDialog::DetailsDialog(const QString &title, QWidget *parent) |
|
48 |
: QDialog(parent) |
|
49 |
{ |
|
50 |
nameLabel = new QLabel(tr("Name:")); |
|
51 |
addressLabel = new QLabel(tr("Address:")); |
|
52 |
addressLabel->setAlignment(Qt::AlignLeft | Qt::AlignTop); |
|
53 |
||
54 |
nameEdit = new QLineEdit; |
|
55 |
addressEdit = new QTextEdit; |
|
56 |
||
57 |
offersCheckBox = new QCheckBox(tr("Send information about products and " |
|
58 |
"special offers")); |
|
59 |
||
60 |
setupItemsTable(); |
|
61 |
||
62 |
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok |
|
63 |
| QDialogButtonBox::Cancel); |
|
64 |
||
65 |
connect(buttonBox, SIGNAL(accepted()), this, SLOT(verify())); |
|
66 |
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); |
|
67 |
//! [0] |
|
68 |
||
69 |
//! [1] |
|
70 |
QGridLayout *mainLayout = new QGridLayout; |
|
71 |
mainLayout->addWidget(nameLabel, 0, 0); |
|
72 |
mainLayout->addWidget(nameEdit, 0, 1); |
|
73 |
mainLayout->addWidget(addressLabel, 1, 0); |
|
74 |
mainLayout->addWidget(addressEdit, 1, 1); |
|
75 |
mainLayout->addWidget(itemsTable, 0, 2, 2, 1); |
|
76 |
mainLayout->addWidget(offersCheckBox, 2, 1, 1, 2); |
|
77 |
mainLayout->addWidget(buttonBox, 3, 0, 1, 3); |
|
78 |
setLayout(mainLayout); |
|
79 |
||
80 |
setWindowTitle(title); |
|
81 |
} |
|
82 |
//! [1] |
|
83 |
||
84 |
//! [2] |
|
85 |
void DetailsDialog::setupItemsTable() |
|
86 |
{ |
|
87 |
items << tr("T-shirt") << tr("Badge") << tr("Reference book") |
|
88 |
<< tr("Coffee cup"); |
|
89 |
||
90 |
itemsTable = new QTableWidget(items.count(), 2); |
|
91 |
||
92 |
for (int row = 0; row < items.count(); ++row) { |
|
93 |
QTableWidgetItem *name = new QTableWidgetItem(items[row]); |
|
94 |
name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable); |
|
95 |
itemsTable->setItem(row, 0, name); |
|
96 |
QTableWidgetItem *quantity = new QTableWidgetItem("1"); |
|
97 |
itemsTable->setItem(row, 1, quantity); |
|
98 |
} |
|
99 |
} |
|
100 |
//! [2] |
|
101 |
||
102 |
//! [3] |
|
103 |
QList<QPair<QString, int> > DetailsDialog::orderItems() |
|
104 |
{ |
|
105 |
QList<QPair<QString, int> > orderList; |
|
106 |
||
107 |
for (int row = 0; row < items.count(); ++row) { |
|
108 |
QPair<QString, int> item; |
|
109 |
item.first = itemsTable->item(row, 0)->text(); |
|
110 |
int quantity = itemsTable->item(row, 1)->data(Qt::DisplayRole).toInt(); |
|
111 |
item.second = qMax(0, quantity); |
|
112 |
orderList.append(item); |
|
113 |
} |
|
114 |
||
115 |
return orderList; |
|
116 |
} |
|
117 |
//! [3] |
|
118 |
||
119 |
//! [4] |
|
120 |
QString DetailsDialog::senderName() const |
|
121 |
{ |
|
122 |
return nameEdit->text(); |
|
123 |
} |
|
124 |
//! [4] |
|
125 |
||
126 |
//! [5] |
|
127 |
QString DetailsDialog::senderAddress() const |
|
128 |
{ |
|
129 |
return addressEdit->toPlainText(); |
|
130 |
} |
|
131 |
//! [5] |
|
132 |
||
133 |
//! [6] |
|
134 |
bool DetailsDialog::sendOffers() |
|
135 |
{ |
|
136 |
return offersCheckBox->isChecked(); |
|
137 |
} |
|
138 |
//! [6] |
|
139 |
||
140 |
//! [7] |
|
141 |
void DetailsDialog::verify() |
|
142 |
{ |
|
143 |
if (!nameEdit->text().isEmpty() && !addressEdit->toPlainText().isEmpty()) { |
|
144 |
accept(); |
|
145 |
return; |
|
146 |
} |
|
147 |
||
148 |
QMessageBox::StandardButton answer; |
|
149 |
answer = QMessageBox::warning(this, tr("Incomplete Form"), |
|
150 |
tr("The form does not contain all the necessary information.\n" |
|
151 |
"Do you want to discard it?"), |
|
152 |
QMessageBox::Yes | QMessageBox::No); |
|
153 |
||
154 |
if (answer == QMessageBox::Yes) |
|
155 |
reject(); |
|
156 |
} |
|
157 |
//! [7] |