QtBase  v6.3.1
window.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
51 #include "window.h"
52 
53 #include <QComboBox>
54 #include <QGridLayout>
55 #include <QGroupBox>
56 #include <QLabel>
57 #include <QLineEdit>
58 
61  : QWidget(parent)
62 {
63  QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
64 
65  QLabel *echoLabel = new QLabel(tr("Mode:"));
66  QComboBox *echoComboBox = new QComboBox;
67  echoComboBox->addItem(tr("Normal"));
68  echoComboBox->addItem(tr("Password"));
69  echoComboBox->addItem(tr("PasswordEchoOnEdit"));
70  echoComboBox->addItem(tr("No Echo"));
71 
72  echoLineEdit = new QLineEdit;
73  echoLineEdit->setPlaceholderText("Placeholder Text");
74  echoLineEdit->setFocus();
76 
78  QGroupBox *validatorGroup = new QGroupBox(tr("Validator"));
79 
80  QLabel *validatorLabel = new QLabel(tr("Type:"));
81  QComboBox *validatorComboBox = new QComboBox;
82  validatorComboBox->addItem(tr("No validator"));
83  validatorComboBox->addItem(tr("Integer validator"));
84  validatorComboBox->addItem(tr("Double validator"));
85 
86  validatorLineEdit = new QLineEdit;
87  validatorLineEdit->setPlaceholderText("Placeholder Text");
89 
91  QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment"));
92 
93  QLabel *alignmentLabel = new QLabel(tr("Type:"));
94  QComboBox *alignmentComboBox = new QComboBox;
95  alignmentComboBox->addItem(tr("Left"));
96  alignmentComboBox->addItem(tr("Centered"));
97  alignmentComboBox->addItem(tr("Right"));
98 
99  alignmentLineEdit = new QLineEdit;
100  alignmentLineEdit->setPlaceholderText("Placeholder Text");
102 
104  QGroupBox *inputMaskGroup = new QGroupBox(tr("Input mask"));
105 
106  QLabel *inputMaskLabel = new QLabel(tr("Type:"));
107  QComboBox *inputMaskComboBox = new QComboBox;
108  inputMaskComboBox->addItem(tr("No mask"));
109  inputMaskComboBox->addItem(tr("Phone number"));
110  inputMaskComboBox->addItem(tr("ISO date"));
111  inputMaskComboBox->addItem(tr("License key"));
112 
113  inputMaskLineEdit = new QLineEdit;
114  inputMaskLineEdit->setPlaceholderText("Placeholder Text");
116 
118  QGroupBox *accessGroup = new QGroupBox(tr("Access"));
119 
120  QLabel *accessLabel = new QLabel(tr("Read-only:"));
121  QComboBox *accessComboBox = new QComboBox;
122  accessComboBox->addItem(tr("False"));
123  accessComboBox->addItem(tr("True"));
124 
125  accessLineEdit = new QLineEdit;
126  accessLineEdit->setPlaceholderText("Placeholder Text");
128 
130  connect(echoComboBox, &QComboBox::activated,
131  this, &Window::echoChanged);
132  connect(validatorComboBox, &QComboBox::activated,
133  this, &Window::validatorChanged);
134  connect(alignmentComboBox, &QComboBox::activated,
135  this, &Window::alignmentChanged);
136  connect(inputMaskComboBox, &QComboBox::activated,
137  this, &Window::inputMaskChanged);
138  connect(accessComboBox, &QComboBox::activated,
139  this, &Window::accessChanged);
141 
143  QGridLayout *echoLayout = new QGridLayout;
144  echoLayout->addWidget(echoLabel, 0, 0);
145  echoLayout->addWidget(echoComboBox, 0, 1);
146  echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2);
147  echoGroup->setLayout(echoLayout);
149 
151  QGridLayout *validatorLayout = new QGridLayout;
152  validatorLayout->addWidget(validatorLabel, 0, 0);
153  validatorLayout->addWidget(validatorComboBox, 0, 1);
154  validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2);
155  validatorGroup->setLayout(validatorLayout);
156 
157  QGridLayout *alignmentLayout = new QGridLayout;
158  alignmentLayout->addWidget(alignmentLabel, 0, 0);
159  alignmentLayout->addWidget(alignmentComboBox, 0, 1);
160  alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2);
161  alignmentGroup-> setLayout(alignmentLayout);
162 
163  QGridLayout *inputMaskLayout = new QGridLayout;
164  inputMaskLayout->addWidget(inputMaskLabel, 0, 0);
165  inputMaskLayout->addWidget(inputMaskComboBox, 0, 1);
166  inputMaskLayout->addWidget(inputMaskLineEdit, 1, 0, 1, 2);
167  inputMaskGroup->setLayout(inputMaskLayout);
168 
169  QGridLayout *accessLayout = new QGridLayout;
170  accessLayout->addWidget(accessLabel, 0, 0);
171  accessLayout->addWidget(accessComboBox, 0, 1);
172  accessLayout->addWidget(accessLineEdit, 1, 0, 1, 2);
173  accessGroup->setLayout(accessLayout);
175 
178  layout->addWidget(echoGroup, 0, 0);
179  layout->addWidget(validatorGroup, 1, 0);
180  layout->addWidget(alignmentGroup, 2, 0);
181  layout->addWidget(inputMaskGroup, 0, 1);
182  layout->addWidget(accessGroup, 1, 1);
183  setLayout(layout);
184 
185  setWindowTitle(tr("Line Edits"));
186 }
188 
191 {
192  switch (index) {
193  case 0:
194  echoLineEdit->setEchoMode(QLineEdit::Normal);
195  break;
196  case 1:
197  echoLineEdit->setEchoMode(QLineEdit::Password);
198  break;
199  case 2:
201  break;
202  case 3:
203  echoLineEdit->setEchoMode(QLineEdit::NoEcho);
204  break;
205  }
206 }
208 
211 {
212  switch (index) {
213  case 0:
214  validatorLineEdit->setValidator(nullptr);
215  break;
216  case 1:
217  validatorLineEdit->setValidator(new QIntValidator(
218  validatorLineEdit));
219  break;
220  case 2:
221  validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
222  999.0, 2, validatorLineEdit));
223  break;
224  }
225 
226  validatorLineEdit->clear();
227 }
229 
232 {
233  switch (index) {
234  case 0:
235  alignmentLineEdit->setAlignment(Qt::AlignLeft);
236  break;
237  case 1:
238  alignmentLineEdit->setAlignment(Qt::AlignCenter);
239  break;
240  case 2:
241  alignmentLineEdit->setAlignment(Qt::AlignRight);
242  break;
243  }
244 }
246 
249 {
250  switch (index) {
251  case 0:
252  inputMaskLineEdit->setInputMask("");
253  break;
254  case 1:
255  inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
256  break;
257  case 2:
258  inputMaskLineEdit->setInputMask("0000-00-00");
259  inputMaskLineEdit->setText("00000000");
260  inputMaskLineEdit->setCursorPosition(0);
261  break;
262  case 3:
263  inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
264  break;
265  }
266 }
268 
271 {
272  switch (index) {
273  case 0:
274  accessLineEdit->setReadOnly(false);
275  break;
276  case 1:
277  accessLineEdit->setReadOnly(true);
278  break;
279  }
280 }
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:60
void activated(int index)
void addItem(const QString &text, const QVariant &userData=QVariant())
Definition: qcombobox.h:260
The QDoubleValidator class provides range checking of floating-point numbers. \inmodule QtGui.
Definition: qvalidator.h:125
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:57
void addWidget(QWidget *w)
Definition: qgridlayout.h:100
The QGroupBox widget provides a group box frame with a title.
Definition: qgroupbox.h:53
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition: qvalidator.h:92
The QLabel widget provides a text or image display.
Definition: qlabel.h:56
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:64
void setValidator(const QValidator *)
Definition: qlineedit.cpp:622
void setAlignment(Qt::Alignment flag)
Definition: qlineedit.cpp:784
void clear()
Definition: qlineedit.cpp:1313
void setPlaceholderText(const QString &)
Definition: qlineedit.cpp:346
void setReadOnly(bool)
Definition: qlineedit.cpp:1364
void setInputMask(const QString &inputMask)
Definition: qlineedit.cpp:1260
void setCursorPosition(int)
Definition: qlineedit.cpp:748
void setText(const QString &)
Definition: qlineedit.cpp:316
void setEchoMode(EchoMode)
Definition: qlineedit.cpp:572
@ PasswordEchoOnEdit
Definition: qlineedit.h:113
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
void setLayout(QLayout *)
Definition: qwidget.cpp:10146
void echoChanged(int)
[8]
Definition: window.cpp:190
void validatorChanged(int)
[9]
Definition: window.cpp:210
void accessChanged(int)
[12]
Definition: window.cpp:270
Window()
[0]
Definition: window.cpp:60
void inputMaskChanged(int)
[11]
Definition: window.cpp:248
void alignmentChanged(int)
[10]
Definition: window.cpp:231
@ AlignRight
Definition: qnamespace.h:171
@ AlignCenter
Definition: qnamespace.h:188
@ AlignLeft
Definition: qnamespace.h:169
GLuint index
[2]
#define tr(X)
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QVBoxLayout * layout
form setLayout(layout)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent