1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
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 "window.h"
|
---|
44 |
|
---|
45 | //! [0]
|
---|
46 | Window::Window()
|
---|
47 | {
|
---|
48 | QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
|
---|
49 |
|
---|
50 | QLabel *echoLabel = new QLabel(tr("Mode:"));
|
---|
51 | QComboBox *echoComboBox = new QComboBox;
|
---|
52 | echoComboBox->addItem(tr("Normal"));
|
---|
53 | echoComboBox->addItem(tr("Password"));
|
---|
54 | echoComboBox->addItem(tr("PasswordEchoOnEdit"));
|
---|
55 | echoComboBox->addItem(tr("No Echo"));
|
---|
56 |
|
---|
57 | echoLineEdit = new QLineEdit;
|
---|
58 | echoLineEdit->setFocus();
|
---|
59 | //! [0]
|
---|
60 |
|
---|
61 | //! [1]
|
---|
62 | QGroupBox *validatorGroup = new QGroupBox(tr("Validator"));
|
---|
63 |
|
---|
64 | QLabel *validatorLabel = new QLabel(tr("Type:"));
|
---|
65 | QComboBox *validatorComboBox = new QComboBox;
|
---|
66 | validatorComboBox->addItem(tr("No validator"));
|
---|
67 | validatorComboBox->addItem(tr("Integer validator"));
|
---|
68 | validatorComboBox->addItem(tr("Double validator"));
|
---|
69 |
|
---|
70 | validatorLineEdit = new QLineEdit;
|
---|
71 | //! [1]
|
---|
72 |
|
---|
73 | //! [2]
|
---|
74 | QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment"));
|
---|
75 |
|
---|
76 | QLabel *alignmentLabel = new QLabel(tr("Type:"));
|
---|
77 | QComboBox *alignmentComboBox = new QComboBox;
|
---|
78 | alignmentComboBox->addItem(tr("Left"));
|
---|
79 | alignmentComboBox->addItem(tr("Centered"));
|
---|
80 | alignmentComboBox->addItem(tr("Right"));
|
---|
81 |
|
---|
82 | alignmentLineEdit = new QLineEdit;
|
---|
83 | //! [2]
|
---|
84 |
|
---|
85 | //! [3]
|
---|
86 | QGroupBox *inputMaskGroup = new QGroupBox(tr("Input mask"));
|
---|
87 |
|
---|
88 | QLabel *inputMaskLabel = new QLabel(tr("Type:"));
|
---|
89 | QComboBox *inputMaskComboBox = new QComboBox;
|
---|
90 | inputMaskComboBox->addItem(tr("No mask"));
|
---|
91 | inputMaskComboBox->addItem(tr("Phone number"));
|
---|
92 | inputMaskComboBox->addItem(tr("ISO date"));
|
---|
93 | inputMaskComboBox->addItem(tr("License key"));
|
---|
94 |
|
---|
95 | inputMaskLineEdit = new QLineEdit;
|
---|
96 | //! [3]
|
---|
97 |
|
---|
98 | //! [4]
|
---|
99 | QGroupBox *accessGroup = new QGroupBox(tr("Access"));
|
---|
100 |
|
---|
101 | QLabel *accessLabel = new QLabel(tr("Read-only:"));
|
---|
102 | QComboBox *accessComboBox = new QComboBox;
|
---|
103 | accessComboBox->addItem(tr("False"));
|
---|
104 | accessComboBox->addItem(tr("True"));
|
---|
105 |
|
---|
106 | accessLineEdit = new QLineEdit;
|
---|
107 | //! [4]
|
---|
108 |
|
---|
109 | //! [5]
|
---|
110 | connect(echoComboBox, SIGNAL(activated(int)),
|
---|
111 | this, SLOT(echoChanged(int)));
|
---|
112 | connect(validatorComboBox, SIGNAL(activated(int)),
|
---|
113 | this, SLOT(validatorChanged(int)));
|
---|
114 | connect(alignmentComboBox, SIGNAL(activated(int)),
|
---|
115 | this, SLOT(alignmentChanged(int)));
|
---|
116 | connect(inputMaskComboBox, SIGNAL(activated(int)),
|
---|
117 | this, SLOT(inputMaskChanged(int)));
|
---|
118 | connect(accessComboBox, SIGNAL(activated(int)),
|
---|
119 | this, SLOT(accessChanged(int)));
|
---|
120 | //! [5]
|
---|
121 |
|
---|
122 | //! [6]
|
---|
123 | QGridLayout *echoLayout = new QGridLayout;
|
---|
124 | echoLayout->addWidget(echoLabel, 0, 0);
|
---|
125 | echoLayout->addWidget(echoComboBox, 0, 1);
|
---|
126 | echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2);
|
---|
127 | echoGroup->setLayout(echoLayout);
|
---|
128 | //! [6]
|
---|
129 |
|
---|
130 | //! [7]
|
---|
131 | QGridLayout *validatorLayout = new QGridLayout;
|
---|
132 | validatorLayout->addWidget(validatorLabel, 0, 0);
|
---|
133 | validatorLayout->addWidget(validatorComboBox, 0, 1);
|
---|
134 | validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2);
|
---|
135 | validatorGroup->setLayout(validatorLayout);
|
---|
136 |
|
---|
137 | QGridLayout *alignmentLayout = new QGridLayout;
|
---|
138 | alignmentLayout->addWidget(alignmentLabel, 0, 0);
|
---|
139 | alignmentLayout->addWidget(alignmentComboBox, 0, 1);
|
---|
140 | alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2);
|
---|
141 | alignmentGroup-> setLayout(alignmentLayout);
|
---|
142 |
|
---|
143 | QGridLayout *inputMaskLayout = new QGridLayout;
|
---|
144 | inputMaskLayout->addWidget(inputMaskLabel, 0, 0);
|
---|
145 | inputMaskLayout->addWidget(inputMaskComboBox, 0, 1);
|
---|
146 | inputMaskLayout->addWidget(inputMaskLineEdit, 1, 0, 1, 2);
|
---|
147 | inputMaskGroup->setLayout(inputMaskLayout);
|
---|
148 |
|
---|
149 | QGridLayout *accessLayout = new QGridLayout;
|
---|
150 | accessLayout->addWidget(accessLabel, 0, 0);
|
---|
151 | accessLayout->addWidget(accessComboBox, 0, 1);
|
---|
152 | accessLayout->addWidget(accessLineEdit, 1, 0, 1, 2);
|
---|
153 | accessGroup->setLayout(accessLayout);
|
---|
154 | //! [7]
|
---|
155 |
|
---|
156 | //! [8]
|
---|
157 | QGridLayout *layout = new QGridLayout;
|
---|
158 | layout->addWidget(echoGroup, 0, 0);
|
---|
159 | layout->addWidget(validatorGroup, 1, 0);
|
---|
160 | layout->addWidget(alignmentGroup, 2, 0);
|
---|
161 | layout->addWidget(inputMaskGroup, 0, 1);
|
---|
162 | layout->addWidget(accessGroup, 1, 1);
|
---|
163 | setLayout(layout);
|
---|
164 |
|
---|
165 | setWindowTitle(tr("Line Edits"));
|
---|
166 | }
|
---|
167 | //! [8]
|
---|
168 |
|
---|
169 | //! [9]
|
---|
170 | void Window::echoChanged(int index)
|
---|
171 | {
|
---|
172 | switch (index) {
|
---|
173 | case 0:
|
---|
174 | echoLineEdit->setEchoMode(QLineEdit::Normal);
|
---|
175 | break;
|
---|
176 | case 1:
|
---|
177 | echoLineEdit->setEchoMode(QLineEdit::Password);
|
---|
178 | break;
|
---|
179 | case 2:
|
---|
180 | echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
---|
181 | break;
|
---|
182 | case 3:
|
---|
183 | echoLineEdit->setEchoMode(QLineEdit::NoEcho);
|
---|
184 | }
|
---|
185 | }
|
---|
186 | //! [9]
|
---|
187 |
|
---|
188 | //! [10]
|
---|
189 | void Window::validatorChanged(int index)
|
---|
190 | {
|
---|
191 | switch (index) {
|
---|
192 | case 0:
|
---|
193 | validatorLineEdit->setValidator(0);
|
---|
194 | break;
|
---|
195 | case 1:
|
---|
196 | validatorLineEdit->setValidator(new QIntValidator(
|
---|
197 | validatorLineEdit));
|
---|
198 | break;
|
---|
199 | case 2:
|
---|
200 | validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
|
---|
201 | 999.0, 2, validatorLineEdit));
|
---|
202 | }
|
---|
203 |
|
---|
204 | validatorLineEdit->clear();
|
---|
205 | }
|
---|
206 | //! [10]
|
---|
207 |
|
---|
208 | //! [11]
|
---|
209 | void Window::alignmentChanged(int index)
|
---|
210 | {
|
---|
211 | switch (index) {
|
---|
212 | case 0:
|
---|
213 | alignmentLineEdit->setAlignment(Qt::AlignLeft);
|
---|
214 | break;
|
---|
215 | case 1:
|
---|
216 | alignmentLineEdit->setAlignment(Qt::AlignCenter);
|
---|
217 | break;
|
---|
218 | case 2:
|
---|
219 | alignmentLineEdit->setAlignment(Qt::AlignRight);
|
---|
220 | }
|
---|
221 | }
|
---|
222 | //! [11]
|
---|
223 |
|
---|
224 | //! [12]
|
---|
225 | void Window::inputMaskChanged(int index)
|
---|
226 | {
|
---|
227 | switch (index) {
|
---|
228 | case 0:
|
---|
229 | inputMaskLineEdit->setInputMask("");
|
---|
230 | break;
|
---|
231 | case 1:
|
---|
232 | inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
|
---|
233 | break;
|
---|
234 | case 2:
|
---|
235 | inputMaskLineEdit->setInputMask("0000-00-00");
|
---|
236 | inputMaskLineEdit->setText("00000000");
|
---|
237 | inputMaskLineEdit->setCursorPosition(0);
|
---|
238 | break;
|
---|
239 | case 3:
|
---|
240 | inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
|
---|
241 | }
|
---|
242 | }
|
---|
243 | //! [12]
|
---|
244 |
|
---|
245 | //! [13]
|
---|
246 | void Window::accessChanged(int index)
|
---|
247 | {
|
---|
248 | switch (index) {
|
---|
249 | case 0:
|
---|
250 | accessLineEdit->setReadOnly(false);
|
---|
251 | break;
|
---|
252 | case 1:
|
---|
253 | accessLineEdit->setReadOnly(true);
|
---|
254 | }
|
---|
255 | }
|
---|
256 | //! [13]
|
---|