| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the examples of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <QtGui>
|
|---|
| 43 |
|
|---|
| 44 | #include "window.h"
|
|---|
| 45 |
|
|---|
| 46 | //! [0]
|
|---|
| 47 | Window::Window()
|
|---|
| 48 | {
|
|---|
| 49 | QGroupBox *echoGroup = new QGroupBox(tr("Echo"));
|
|---|
| 50 |
|
|---|
| 51 | QLabel *echoLabel = new QLabel(tr("Mode:"));
|
|---|
| 52 | QComboBox *echoComboBox = new QComboBox;
|
|---|
| 53 | echoComboBox->addItem(tr("Normal"));
|
|---|
| 54 | echoComboBox->addItem(tr("Password"));
|
|---|
| 55 | echoComboBox->addItem(tr("PasswordEchoOnEdit"));
|
|---|
| 56 | echoComboBox->addItem(tr("No Echo"));
|
|---|
| 57 |
|
|---|
| 58 | echoLineEdit = new QLineEdit;
|
|---|
| 59 | echoLineEdit->setFocus();
|
|---|
| 60 | //! [0]
|
|---|
| 61 |
|
|---|
| 62 | //! [1]
|
|---|
| 63 | QGroupBox *validatorGroup = new QGroupBox(tr("Validator"));
|
|---|
| 64 |
|
|---|
| 65 | QLabel *validatorLabel = new QLabel(tr("Type:"));
|
|---|
| 66 | QComboBox *validatorComboBox = new QComboBox;
|
|---|
| 67 | validatorComboBox->addItem(tr("No validator"));
|
|---|
| 68 | validatorComboBox->addItem(tr("Integer validator"));
|
|---|
| 69 | validatorComboBox->addItem(tr("Double validator"));
|
|---|
| 70 |
|
|---|
| 71 | validatorLineEdit = new QLineEdit;
|
|---|
| 72 | //! [1]
|
|---|
| 73 |
|
|---|
| 74 | //! [2]
|
|---|
| 75 | QGroupBox *alignmentGroup = new QGroupBox(tr("Alignment"));
|
|---|
| 76 |
|
|---|
| 77 | QLabel *alignmentLabel = new QLabel(tr("Type:"));
|
|---|
| 78 | QComboBox *alignmentComboBox = new QComboBox;
|
|---|
| 79 | alignmentComboBox->addItem(tr("Left"));
|
|---|
| 80 | alignmentComboBox->addItem(tr("Centered"));
|
|---|
| 81 | alignmentComboBox->addItem(tr("Right"));
|
|---|
| 82 |
|
|---|
| 83 | alignmentLineEdit = new QLineEdit;
|
|---|
| 84 | //! [2]
|
|---|
| 85 |
|
|---|
| 86 | //! [3]
|
|---|
| 87 | QGroupBox *inputMaskGroup = new QGroupBox(tr("Input mask"));
|
|---|
| 88 |
|
|---|
| 89 | QLabel *inputMaskLabel = new QLabel(tr("Type:"));
|
|---|
| 90 | QComboBox *inputMaskComboBox = new QComboBox;
|
|---|
| 91 | inputMaskComboBox->addItem(tr("No mask"));
|
|---|
| 92 | inputMaskComboBox->addItem(tr("Phone number"));
|
|---|
| 93 | inputMaskComboBox->addItem(tr("ISO date"));
|
|---|
| 94 | inputMaskComboBox->addItem(tr("License key"));
|
|---|
| 95 |
|
|---|
| 96 | inputMaskLineEdit = new QLineEdit;
|
|---|
| 97 | //! [3]
|
|---|
| 98 |
|
|---|
| 99 | //! [4]
|
|---|
| 100 | QGroupBox *accessGroup = new QGroupBox(tr("Access"));
|
|---|
| 101 |
|
|---|
| 102 | QLabel *accessLabel = new QLabel(tr("Read-only:"));
|
|---|
| 103 | QComboBox *accessComboBox = new QComboBox;
|
|---|
| 104 | accessComboBox->addItem(tr("False"));
|
|---|
| 105 | accessComboBox->addItem(tr("True"));
|
|---|
| 106 |
|
|---|
| 107 | accessLineEdit = new QLineEdit;
|
|---|
| 108 | //! [4]
|
|---|
| 109 |
|
|---|
| 110 | //! [5]
|
|---|
| 111 | connect(echoComboBox, SIGNAL(activated(int)),
|
|---|
| 112 | this, SLOT(echoChanged(int)));
|
|---|
| 113 | connect(validatorComboBox, SIGNAL(activated(int)),
|
|---|
| 114 | this, SLOT(validatorChanged(int)));
|
|---|
| 115 | connect(alignmentComboBox, SIGNAL(activated(int)),
|
|---|
| 116 | this, SLOT(alignmentChanged(int)));
|
|---|
| 117 | connect(inputMaskComboBox, SIGNAL(activated(int)),
|
|---|
| 118 | this, SLOT(inputMaskChanged(int)));
|
|---|
| 119 | connect(accessComboBox, SIGNAL(activated(int)),
|
|---|
| 120 | this, SLOT(accessChanged(int)));
|
|---|
| 121 | //! [5]
|
|---|
| 122 |
|
|---|
| 123 | //! [6]
|
|---|
| 124 | QGridLayout *echoLayout = new QGridLayout;
|
|---|
| 125 | echoLayout->addWidget(echoLabel, 0, 0);
|
|---|
| 126 | echoLayout->addWidget(echoComboBox, 0, 1);
|
|---|
| 127 | echoLayout->addWidget(echoLineEdit, 1, 0, 1, 2);
|
|---|
| 128 | echoGroup->setLayout(echoLayout);
|
|---|
| 129 | //! [6]
|
|---|
| 130 |
|
|---|
| 131 | //! [7]
|
|---|
| 132 | QGridLayout *validatorLayout = new QGridLayout;
|
|---|
| 133 | validatorLayout->addWidget(validatorLabel, 0, 0);
|
|---|
| 134 | validatorLayout->addWidget(validatorComboBox, 0, 1);
|
|---|
| 135 | validatorLayout->addWidget(validatorLineEdit, 1, 0, 1, 2);
|
|---|
| 136 | validatorGroup->setLayout(validatorLayout);
|
|---|
| 137 |
|
|---|
| 138 | QGridLayout *alignmentLayout = new QGridLayout;
|
|---|
| 139 | alignmentLayout->addWidget(alignmentLabel, 0, 0);
|
|---|
| 140 | alignmentLayout->addWidget(alignmentComboBox, 0, 1);
|
|---|
| 141 | alignmentLayout->addWidget(alignmentLineEdit, 1, 0, 1, 2);
|
|---|
| 142 | alignmentGroup-> setLayout(alignmentLayout);
|
|---|
| 143 |
|
|---|
| 144 | QGridLayout *inputMaskLayout = new QGridLayout;
|
|---|
| 145 | inputMaskLayout->addWidget(inputMaskLabel, 0, 0);
|
|---|
| 146 | inputMaskLayout->addWidget(inputMaskComboBox, 0, 1);
|
|---|
| 147 | inputMaskLayout->addWidget(inputMaskLineEdit, 1, 0, 1, 2);
|
|---|
| 148 | inputMaskGroup->setLayout(inputMaskLayout);
|
|---|
| 149 |
|
|---|
| 150 | QGridLayout *accessLayout = new QGridLayout;
|
|---|
| 151 | accessLayout->addWidget(accessLabel, 0, 0);
|
|---|
| 152 | accessLayout->addWidget(accessComboBox, 0, 1);
|
|---|
| 153 | accessLayout->addWidget(accessLineEdit, 1, 0, 1, 2);
|
|---|
| 154 | accessGroup->setLayout(accessLayout);
|
|---|
| 155 | //! [7]
|
|---|
| 156 |
|
|---|
| 157 | //! [8]
|
|---|
| 158 | QGridLayout *layout = new QGridLayout;
|
|---|
| 159 | layout->addWidget(echoGroup, 0, 0);
|
|---|
| 160 | layout->addWidget(validatorGroup, 1, 0);
|
|---|
| 161 | layout->addWidget(alignmentGroup, 2, 0);
|
|---|
| 162 | layout->addWidget(inputMaskGroup, 0, 1);
|
|---|
| 163 | layout->addWidget(accessGroup, 1, 1);
|
|---|
| 164 | setLayout(layout);
|
|---|
| 165 |
|
|---|
| 166 | setWindowTitle(tr("Line Edits"));
|
|---|
| 167 | }
|
|---|
| 168 | //! [8]
|
|---|
| 169 |
|
|---|
| 170 | //! [9]
|
|---|
| 171 | void Window::echoChanged(int index)
|
|---|
| 172 | {
|
|---|
| 173 | switch (index) {
|
|---|
| 174 | case 0:
|
|---|
| 175 | echoLineEdit->setEchoMode(QLineEdit::Normal);
|
|---|
| 176 | break;
|
|---|
| 177 | case 1:
|
|---|
| 178 | echoLineEdit->setEchoMode(QLineEdit::Password);
|
|---|
| 179 | break;
|
|---|
| 180 | case 2:
|
|---|
| 181 | echoLineEdit->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
|---|
| 182 | break;
|
|---|
| 183 | case 3:
|
|---|
| 184 | echoLineEdit->setEchoMode(QLineEdit::NoEcho);
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 | //! [9]
|
|---|
| 188 |
|
|---|
| 189 | //! [10]
|
|---|
| 190 | void Window::validatorChanged(int index)
|
|---|
| 191 | {
|
|---|
| 192 | switch (index) {
|
|---|
| 193 | case 0:
|
|---|
| 194 | validatorLineEdit->setValidator(0);
|
|---|
| 195 | break;
|
|---|
| 196 | case 1:
|
|---|
| 197 | validatorLineEdit->setValidator(new QIntValidator(
|
|---|
| 198 | validatorLineEdit));
|
|---|
| 199 | break;
|
|---|
| 200 | case 2:
|
|---|
| 201 | validatorLineEdit->setValidator(new QDoubleValidator(-999.0,
|
|---|
| 202 | 999.0, 2, validatorLineEdit));
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | validatorLineEdit->clear();
|
|---|
| 206 | }
|
|---|
| 207 | //! [10]
|
|---|
| 208 |
|
|---|
| 209 | //! [11]
|
|---|
| 210 | void Window::alignmentChanged(int index)
|
|---|
| 211 | {
|
|---|
| 212 | switch (index) {
|
|---|
| 213 | case 0:
|
|---|
| 214 | alignmentLineEdit->setAlignment(Qt::AlignLeft);
|
|---|
| 215 | break;
|
|---|
| 216 | case 1:
|
|---|
| 217 | alignmentLineEdit->setAlignment(Qt::AlignCenter);
|
|---|
| 218 | break;
|
|---|
| 219 | case 2:
|
|---|
| 220 | alignmentLineEdit->setAlignment(Qt::AlignRight);
|
|---|
| 221 | }
|
|---|
| 222 | }
|
|---|
| 223 | //! [11]
|
|---|
| 224 |
|
|---|
| 225 | //! [12]
|
|---|
| 226 | void Window::inputMaskChanged(int index)
|
|---|
| 227 | {
|
|---|
| 228 | switch (index) {
|
|---|
| 229 | case 0:
|
|---|
| 230 | inputMaskLineEdit->setInputMask("");
|
|---|
| 231 | break;
|
|---|
| 232 | case 1:
|
|---|
| 233 | inputMaskLineEdit->setInputMask("+99 99 99 99 99;_");
|
|---|
| 234 | break;
|
|---|
| 235 | case 2:
|
|---|
| 236 | inputMaskLineEdit->setInputMask("0000-00-00");
|
|---|
| 237 | inputMaskLineEdit->setText("00000000");
|
|---|
| 238 | inputMaskLineEdit->setCursorPosition(0);
|
|---|
| 239 | break;
|
|---|
| 240 | case 3:
|
|---|
| 241 | inputMaskLineEdit->setInputMask(">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#");
|
|---|
| 242 | }
|
|---|
| 243 | }
|
|---|
| 244 | //! [12]
|
|---|
| 245 |
|
|---|
| 246 | //! [13]
|
|---|
| 247 | void Window::accessChanged(int index)
|
|---|
| 248 | {
|
|---|
| 249 | switch (index) {
|
|---|
| 250 | case 0:
|
|---|
| 251 | accessLineEdit->setReadOnly(false);
|
|---|
| 252 | break;
|
|---|
| 253 | case 1:
|
|---|
| 254 | accessLineEdit->setReadOnly(true);
|
|---|
| 255 | }
|
|---|
| 256 | }
|
|---|
| 257 | //! [13]
|
|---|