1 /****************************************************************************
3 ** Copyright (C) 2008 Trolltech ASA. All rights reserved.
5 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 ****************************************************************************/
24 function tr(s) { return s; }
26 function Window(parent) {
27 QWidget.call(this, parent);
29 var echoGroup = new QGroupBox(tr("Echo"));
31 var echoLabel = new QLabel(tr("Mode:"));
32 var echoComboBox = new QComboBox();
33 echoComboBox.addItem(tr("Normal"));
34 echoComboBox.addItem(tr("Password"));
35 echoComboBox.addItem(tr("PasswordEchoOnEdit"));
36 echoComboBox.addItem(tr("No Echo"));
38 this.echoLineEdit = new QLineEdit();
39 this.echoLineEdit.setFocus();
41 var validatorGroup = new QGroupBox(tr("Validator"));
43 var validatorLabel = new QLabel(tr("Type:"));
44 var validatorComboBox = new QComboBox();
45 validatorComboBox.addItem(tr("No validator"));
46 validatorComboBox.addItem(tr("Integer validator"));
47 validatorComboBox.addItem(tr("Double validator"));
49 this.validatorLineEdit = new QLineEdit();
51 var alignmentGroup = new QGroupBox(tr("Alignment"));
53 var alignmentLabel = new QLabel(tr("Type:"));
54 var alignmentComboBox = new QComboBox();
55 alignmentComboBox.addItem(tr("Left"));
56 alignmentComboBox.addItem(tr("Centered"));
57 alignmentComboBox.addItem(tr("Right"));
59 this.alignmentLineEdit = new QLineEdit();
61 var inputMaskGroup = new QGroupBox(tr("Input mask"));
63 var inputMaskLabel = new QLabel(tr("Type:"));
64 var inputMaskComboBox = new QComboBox;
65 inputMaskComboBox.addItem(tr("No mask"));
66 inputMaskComboBox.addItem(tr("Phone number"));
67 inputMaskComboBox.addItem(tr("ISO date"));
68 inputMaskComboBox.addItem(tr("License key"));
70 this.inputMaskLineEdit = new QLineEdit();
72 var accessGroup = new QGroupBox(tr("Access"));
74 var accessLabel = new QLabel(tr("Read-only:"));
75 var accessComboBox = new QComboBox;
76 accessComboBox.addItem(tr("False"));
77 accessComboBox.addItem(tr("True"));
79 this.accessLineEdit = new QLineEdit();
81 echoComboBox["activated(int)"].connect(
83 validatorComboBox["activated(int)"].connect(
84 this, "validatorChanged");
85 alignmentComboBox["activated(int)"].connect(
86 this, "alignmentChanged");
87 inputMaskComboBox["activated(int)"].connect(
88 this, "inputMaskChanged");
89 accessComboBox["activated(int)"].connect(
90 this, "accessChanged");
92 var echoLayout = new QGridLayout;
93 echoLayout.addWidget(echoLabel, 0, 0);
94 echoLayout.addWidget(echoComboBox, 0, 1);
95 echoLayout.addWidget(this.echoLineEdit, 1, 0, 1, 2);
96 echoGroup.setLayout(echoLayout);
98 var validatorLayout = new QGridLayout;
99 validatorLayout.addWidget(validatorLabel, 0, 0);
100 validatorLayout.addWidget(validatorComboBox, 0, 1);
101 validatorLayout.addWidget(this.validatorLineEdit, 1, 0, 1, 2);
102 validatorGroup.setLayout(validatorLayout);
104 var alignmentLayout = new QGridLayout;
105 alignmentLayout.addWidget(alignmentLabel, 0, 0);
106 alignmentLayout.addWidget(alignmentComboBox, 0, 1);
107 alignmentLayout.addWidget(this.alignmentLineEdit, 1, 0, 1, 2);
108 alignmentGroup.setLayout(alignmentLayout);
110 var inputMaskLayout = new QGridLayout;
111 inputMaskLayout.addWidget(inputMaskLabel, 0, 0);
112 inputMaskLayout.addWidget(inputMaskComboBox, 0, 1);
113 inputMaskLayout.addWidget(this.inputMaskLineEdit, 1, 0, 1, 2);
114 inputMaskGroup.setLayout(inputMaskLayout);
116 var accessLayout = new QGridLayout;
117 accessLayout.addWidget(accessLabel, 0, 0);
118 accessLayout.addWidget(accessComboBox, 0, 1);
119 accessLayout.addWidget(this.accessLineEdit, 1, 0, 1, 2);
120 accessGroup.setLayout(accessLayout);
122 var layout = new QGridLayout;
123 layout.addWidget(echoGroup, 0, 0);
124 layout.addWidget(validatorGroup, 1, 0);
125 layout.addWidget(alignmentGroup, 2, 0);
126 layout.addWidget(inputMaskGroup, 0, 1);
127 layout.addWidget(accessGroup, 1, 1);
128 this.setLayout(layout);
130 this.setWindowTitle(tr("Line Edits"));
133 Window.prototype = new QWidget();
135 Window.prototype.echoChanged = function(index) {
138 this.echoLineEdit.echoMode = QLineEdit.Normal;
141 this.echoLineEdit.echoMode = QLineEdit.Password;
144 this.echoLineEdit.echoMode = QLineEdit.PasswordEchoOnEdit;
147 this.echoLineEdit.echoMode = QLineEdit.NoEcho;
152 Window.prototype.validatorChanged = function(index) {
155 this.validatorLineEdit.setValidator(null);
158 this.validatorLineEdit.setValidator(
159 new QIntValidator(this.validatorLineEdit));
162 this.validatorLineEdit.setValidator(
163 new QDoubleValidator(-999.0, 999.0, 2, this.validatorLineEdit));
166 this.validatorLineEdit.clear();
169 Window.prototype.alignmentChanged = function(index) {
172 this.alignmentLineEdit.alignment = Qt.Alignment(Qt.AlignLeft);
175 this.alignmentLineEdit.alignment = Qt.Alignment(Qt.AlignCenter);
178 this.alignmentLineEdit.alignment = Qt.Alignment(Qt.AlignRight);
182 Window.prototype.inputMaskChanged = function(index)
186 this.inputMaskLineEdit.inputMask = "";
189 this.inputMaskLineEdit.inputMask = "+99 99 99 99 99;_";
192 this.inputMaskLineEdit.inputMask = "0000-00-00";
193 this.inputMaskLineEdit.text = "00000000";
194 this.inputMaskLineEdit.cursorPosition = 0;
197 this.inputMaskLineEdit.inputMask = ">AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#";
201 Window.prototype.accessChanged = function(index) {
204 this.accessLineEdit.readOnly = false;
207 this.accessLineEdit.readOnly = true;
211 var win = new Window(null);
214 QCoreApplication.exec();