~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/widgets-lineedits-window-cpp.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<head>
 
6
    <title>Qt 4.0: window.cpp Example File (widgets/lineedits/window.cpp)</title>
 
7
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
8
a:link { color: #004faf; text-decoration: none }
 
9
a:visited { color: #672967; text-decoration: none }
 
10
td.postheader { font-family: sans-serif }
 
11
tr.address { font-family: sans-serif }
 
12
body { background: #ffffff; color: black; }</style>
 
13
</head>
 
14
<body>
 
15
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
16
<tr>
 
17
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
18
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
19
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">window.cpp Example File<br /><small><small>widgets/lineedits/window.cpp</small></small></h1>
 
20
<pre>&nbsp;   /****************************************************************************
 
21
    **
 
22
    ** Copyright (C) 2004-2005 Trolltech AS. All rights reserved.
 
23
    **
 
24
    ** This file is part of the documentation of the Qt Toolkit.
 
25
    **
 
26
    ** This file may be distributed under the terms of the Q Public License
 
27
** as defined by Trolltech AS of Norway and appearing in the file
 
28
** LICENSE.QPL included in the packaging of this file.
 
29
**
 
30
** This file may be distributed and/or modified under the terms of the
 
31
** GNU General Public License version 2 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.
 
34
**
 
35
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
36
**   information about Qt Commercial License Agreements.
 
37
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
38
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
39
**
 
40
** Contact info@trolltech.com if any conditions of this licensing are
 
41
** not clear to you.
 
42
    **
 
43
    ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
44
    ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
45
    **
 
46
    ****************************************************************************/
 
47
 
 
48
    #include &lt;QtGui&gt;
 
49
 
 
50
    #include &quot;window.h&quot;
 
51
 
 
52
    Window::Window()
 
53
    {
 
54
        QGroupBox *echoGroup = new QGroupBox(tr(&quot;Echo&quot;));
 
55
 
 
56
        QLabel *echoLabel = new QLabel(tr(&quot;Mode:&quot;));
 
57
        QComboBox *echoComboBox = new QComboBox;
 
58
        echoComboBox-&gt;addItem(tr(&quot;Normal&quot;));
 
59
        echoComboBox-&gt;addItem(tr(&quot;Password&quot;));
 
60
        echoComboBox-&gt;addItem(tr(&quot;No Echo&quot;));
 
61
 
 
62
        echoLineEdit = new QLineEdit;
 
63
        echoLineEdit-&gt;setFocus();
 
64
 
 
65
        QGroupBox *validatorGroup = new QGroupBox(tr(&quot;Validator&quot;));
 
66
 
 
67
        QLabel *validatorLabel = new QLabel(tr(&quot;Type:&quot;));
 
68
        QComboBox *validatorComboBox = new QComboBox;
 
69
        validatorComboBox-&gt;addItem(tr(&quot;No validator&quot;));
 
70
        validatorComboBox-&gt;addItem(tr(&quot;Integer validator&quot;));
 
71
        validatorComboBox-&gt;addItem(tr(&quot;Double validator&quot;));
 
72
 
 
73
        validatorLineEdit = new QLineEdit;
 
74
 
 
75
        QGroupBox *alignmentGroup = new QGroupBox(tr(&quot;Alignment&quot;));
 
76
 
 
77
        QLabel *alignmentLabel = new QLabel(tr(&quot;Type:&quot;));
 
78
        QComboBox *alignmentComboBox = new QComboBox;
 
79
        alignmentComboBox-&gt;addItem(tr(&quot;Left&quot;));
 
80
        alignmentComboBox-&gt;addItem(tr(&quot;Centered&quot;));
 
81
        alignmentComboBox-&gt;addItem(tr(&quot;Right&quot;));
 
82
 
 
83
        alignmentLineEdit = new QLineEdit;
 
84
 
 
85
        QGroupBox *inputMaskGroup = new QGroupBox(tr(&quot;Input mask&quot;));
 
86
 
 
87
        QLabel *inputMaskLabel = new QLabel(tr(&quot;Type:&quot;));
 
88
        QComboBox *inputMaskComboBox = new QComboBox;
 
89
        inputMaskComboBox-&gt;addItem(tr(&quot;No mask&quot;));
 
90
        inputMaskComboBox-&gt;addItem(tr(&quot;Phone number&quot;));
 
91
        inputMaskComboBox-&gt;addItem(tr(&quot;ISO date&quot;));
 
92
        inputMaskComboBox-&gt;addItem(tr(&quot;License key&quot;));
 
93
 
 
94
        inputMaskLineEdit = new QLineEdit;
 
95
 
 
96
        QGroupBox *accessGroup = new QGroupBox(tr(&quot;Access&quot;));
 
97
 
 
98
        QLabel *accessLabel = new QLabel(tr(&quot;Read-only:&quot;));
 
99
        QComboBox *accessComboBox = new QComboBox;
 
100
        accessComboBox-&gt;addItem(tr(&quot;False&quot;));
 
101
        accessComboBox-&gt;addItem(tr(&quot;True&quot;));
 
102
 
 
103
        accessLineEdit = new QLineEdit;
 
104
 
 
105
        connect(echoComboBox, SIGNAL(activated(int)),
 
106
                this, SLOT(slotEchoChanged(int)));
 
107
        connect(validatorComboBox, SIGNAL(activated(int)),
 
108
                this, SLOT(slotValidatorChanged(int)));
 
109
        connect(alignmentComboBox, SIGNAL(activated(int)),
 
110
                this, SLOT(slotAlignmentChanged(int)));
 
111
        connect(inputMaskComboBox, SIGNAL(activated(int)),
 
112
                this, SLOT(slotInputMaskChanged(int)));
 
113
        connect(accessComboBox, SIGNAL(activated(int)),
 
114
                this, SLOT(slotAccessChanged(int)));
 
115
 
 
116
        QGridLayout *echoLayout = new QGridLayout;
 
117
        echoLayout-&gt;addWidget(echoLabel, 0, 0);
 
118
        echoLayout-&gt;addWidget(echoComboBox, 0, 1);
 
119
        echoLayout-&gt;addWidget(echoLineEdit, 1, 0, 1, 2);
 
120
        echoGroup-&gt;setLayout(echoLayout);
 
121
 
 
122
        QGridLayout *validatorLayout = new QGridLayout;
 
123
        validatorLayout-&gt;addWidget(validatorLabel, 0, 0);
 
124
        validatorLayout-&gt;addWidget(validatorComboBox, 0, 1);
 
125
        validatorLayout-&gt;addWidget(validatorLineEdit, 1, 0, 1, 2);
 
126
        validatorGroup-&gt;setLayout(validatorLayout);
 
127
 
 
128
        QGridLayout *alignmentLayout = new QGridLayout;
 
129
        alignmentLayout-&gt;addWidget(alignmentLabel, 0, 0);
 
130
        alignmentLayout-&gt;addWidget(alignmentComboBox, 0, 1);
 
131
        alignmentLayout-&gt;addWidget(alignmentLineEdit, 1, 0, 1, 2);
 
132
        alignmentGroup-&gt; setLayout(alignmentLayout);
 
133
 
 
134
        QGridLayout *inputMaskLayout = new QGridLayout;
 
135
        inputMaskLayout-&gt;addWidget(inputMaskLabel, 0, 0);
 
136
        inputMaskLayout-&gt;addWidget(inputMaskComboBox, 0, 1);
 
137
        inputMaskLayout-&gt;addWidget(inputMaskLineEdit, 1, 0, 1, 2);
 
138
        inputMaskGroup-&gt;setLayout(inputMaskLayout);
 
139
 
 
140
        QGridLayout *accessLayout = new QGridLayout;
 
141
        accessLayout-&gt;addWidget(accessLabel, 0, 0);
 
142
        accessLayout-&gt;addWidget(accessComboBox, 0, 1);
 
143
        accessLayout-&gt;addWidget(accessLineEdit, 1, 0, 1, 2);
 
144
        accessGroup-&gt;setLayout(accessLayout);
 
145
 
 
146
        QVBoxLayout *layout = new QVBoxLayout;
 
147
        layout-&gt;addWidget(echoGroup);
 
148
        layout-&gt;addWidget(validatorGroup);
 
149
        layout-&gt;addWidget(alignmentGroup);
 
150
        layout-&gt;addWidget(inputMaskGroup);
 
151
        layout-&gt;addWidget(accessGroup);
 
152
        setLayout(layout);
 
153
 
 
154
        setWindowTitle(tr(&quot;Line Edits&quot;));
 
155
    }
 
156
 
 
157
    void Window::slotEchoChanged(int index)
 
158
    {
 
159
        switch (index) {
 
160
            case 0:
 
161
                echoLineEdit-&gt;setEchoMode(QLineEdit::Normal);
 
162
                break;
 
163
            case 1:
 
164
                echoLineEdit-&gt;setEchoMode(QLineEdit::Password);
 
165
                break;
 
166
            case 2:
 
167
                echoLineEdit-&gt;setEchoMode(QLineEdit::NoEcho);
 
168
                break;
 
169
            }
 
170
    }
 
171
 
 
172
    void Window::slotValidatorChanged(int index)
 
173
    {
 
174
        switch (index) {
 
175
            case 0:
 
176
                validatorLineEdit-&gt;setValidator(0);
 
177
                break;
 
178
            case 1:
 
179
                validatorLineEdit-&gt;setValidator(new QIntValidator(
 
180
                    validatorLineEdit));
 
181
                break;
 
182
            case 2:
 
183
                validatorLineEdit-&gt;setValidator(new QDoubleValidator(-999.0,
 
184
                    999.0, 2, validatorLineEdit));
 
185
                break;
 
186
        }
 
187
 
 
188
        validatorLineEdit-&gt;setText(&quot;&quot;);
 
189
    }
 
190
 
 
191
    void Window::slotAlignmentChanged(int index)
 
192
    {
 
193
        switch (index) {
 
194
            case 0:
 
195
                alignmentLineEdit-&gt;setAlignment(Qt::AlignLeft);
 
196
                break;
 
197
            case 1:
 
198
                alignmentLineEdit-&gt;setAlignment(Qt::AlignCenter);
 
199
                break;
 
200
            case 2:
 
201
                alignmentLineEdit-&gt;setAlignment(Qt::AlignRight);
 
202
                break;
 
203
            }
 
204
    }
 
205
 
 
206
    void Window::slotInputMaskChanged(int index)
 
207
    {
 
208
        switch (index) {
 
209
            case 0:
 
210
                inputMaskLineEdit-&gt;setInputMask(QString());
 
211
                break;
 
212
            case 1:
 
213
                inputMaskLineEdit-&gt;setInputMask(&quot;+99 99 99 99 99;_&quot;);
 
214
                break;
 
215
            case 2:
 
216
                inputMaskLineEdit-&gt;setInputMask(&quot;0000-00-00&quot;);
 
217
                inputMaskLineEdit-&gt;setText(&quot;00000000&quot;);
 
218
                inputMaskLineEdit-&gt;setCursorPosition(0);
 
219
                break;
 
220
            case 3:
 
221
                inputMaskLineEdit-&gt;setInputMask(&quot;&gt;AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#&quot;);
 
222
                break;
 
223
        }
 
224
    }
 
225
 
 
226
    void Window::slotAccessChanged(int index)
 
227
    {
 
228
        switch (index) {
 
229
        case 0:
 
230
            accessLineEdit-&gt;setReadOnly(false);
 
231
            break;
 
232
        case 1:
 
233
            accessLineEdit-&gt;setReadOnly(true);
 
234
            break;
 
235
        }
 
236
    }</pre>
 
237
<p /><address><hr /><div align="center">
 
238
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
239
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
240
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
241
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
242
</tr></table></div></address></body>
 
243
</html>