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

« back to all changes in this revision

Viewing changes to doc/html/widgets-spinboxes-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/spinboxes/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/spinboxes/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
        createSpinBoxes();
 
55
        createDateTimeEdits();
 
56
        createDoubleSpinBoxes();
 
57
 
 
58
        QHBoxLayout *layout = new QHBoxLayout;
 
59
        layout-&gt;addWidget(spinBoxesGroup);
 
60
        layout-&gt;addWidget(editsGroup);
 
61
        layout-&gt;addWidget(doubleSpinBoxesGroup);
 
62
        setLayout(layout);
 
63
 
 
64
        setWindowTitle(tr(&quot;Spin Boxes&quot;));
 
65
    }
 
66
 
 
67
    void Window::createSpinBoxes()
 
68
    {
 
69
        spinBoxesGroup = new QGroupBox(tr(&quot;Spinboxes&quot;));
 
70
 
 
71
        QLabel *integerLabel = new QLabel(tr(&quot;Enter a value between &quot;
 
72
            &quot;%1 and %2:&quot;).arg(-20).arg(20));
 
73
        QSpinBox *integerSpinBox = new QSpinBox;
 
74
        integerSpinBox-&gt;setRange(-20, 20);
 
75
        integerSpinBox-&gt;setSingleStep(1);
 
76
        integerSpinBox-&gt;setValue(0);
 
77
 
 
78
        QLabel *zoomLabel = new QLabel(tr(&quot;Enter a zoom value between &quot;
 
79
            &quot;%1 and %2:&quot;).arg(0).arg(1000));
 
80
        QSpinBox *zoomSpinBox = new QSpinBox;
 
81
        zoomSpinBox-&gt;setRange(0, 1000);
 
82
        zoomSpinBox-&gt;setSingleStep(10);
 
83
        zoomSpinBox-&gt;setSuffix(&quot;%&quot;);
 
84
        zoomSpinBox-&gt;setSpecialValueText(tr(&quot;Automatic&quot;));
 
85
        zoomSpinBox-&gt;setValue(100);
 
86
 
 
87
        QLabel *priceLabel = new QLabel(tr(&quot;Enter a price between &quot;
 
88
            &quot;%1 and %2:&quot;).arg(0).arg(999));
 
89
        QSpinBox *priceSpinBox = new QSpinBox;
 
90
        priceSpinBox-&gt;setRange(0, 999);
 
91
        priceSpinBox-&gt;setSingleStep(1);
 
92
        priceSpinBox-&gt;setPrefix(&quot;$&quot;);
 
93
        priceSpinBox-&gt;setValue(99);
 
94
 
 
95
        QVBoxLayout *spinBoxLayout = new QVBoxLayout;
 
96
        spinBoxLayout-&gt;addWidget(integerLabel);
 
97
        spinBoxLayout-&gt;addWidget(integerSpinBox);
 
98
        spinBoxLayout-&gt;addWidget(zoomLabel);
 
99
        spinBoxLayout-&gt;addWidget(zoomSpinBox);
 
100
        spinBoxLayout-&gt;addWidget(priceLabel);
 
101
        spinBoxLayout-&gt;addWidget(priceSpinBox);
 
102
        spinBoxesGroup-&gt;setLayout(spinBoxLayout);
 
103
    }
 
104
 
 
105
    void Window::createDateTimeEdits()
 
106
    {
 
107
        editsGroup = new QGroupBox(tr(&quot;Date and time spin boxes&quot;));
 
108
 
 
109
        QLabel *dateLabel = new QLabel;
 
110
        QDateTimeEdit *dateEdit = new QDateTimeEdit(QDate::currentDate());
 
111
        dateEdit-&gt;setDateRange(QDate(2005, 1, 1), QDate(2010, 12, 31));
 
112
        dateLabel-&gt;setText(tr(&quot;Appointment date (between %0 and %1):&quot;)
 
113
                           .arg(dateEdit-&gt;minimumDate().toString(Qt::ISODate))
 
114
                           .arg(dateEdit-&gt;maximumDate().toString(Qt::ISODate)));
 
115
 
 
116
        QLabel *timeLabel = new QLabel;
 
117
        QDateTimeEdit *timeEdit = new QDateTimeEdit(QTime::currentTime());
 
118
        timeEdit-&gt;setTimeRange(QTime(9, 0, 0, 0), QTime(16, 30, 0, 0));
 
119
        timeLabel-&gt;setText(tr(&quot;Appointment time (between %0 and %1):&quot;)
 
120
                           .arg(timeEdit-&gt;minimumTime().toString(Qt::ISODate))
 
121
                           .arg(timeEdit-&gt;maximumTime().toString(Qt::ISODate)));
 
122
 
 
123
        meetingLabel = new QLabel;
 
124
        meetingEdit = new QDateTimeEdit(QDateTime::currentDateTime());
 
125
 
 
126
        QLabel *formatLabel = new QLabel(tr(&quot;Format string for the meeting date &quot;
 
127
                                            &quot;and time:&quot;));
 
128
        QComboBox *formatComboBox = new QComboBox;
 
129
        formatComboBox-&gt;addItem(&quot;yyyy-MM-dd hh:mm:ss (zzz ms)&quot;);
 
130
        formatComboBox-&gt;addItem(&quot;hh:mm:ss MM/dd/yyyy&quot;);
 
131
        formatComboBox-&gt;addItem(&quot;hh:mm:ss dd/MM/yyyy&quot;);
 
132
        formatComboBox-&gt;addItem(&quot;hh:mm:ss&quot;);
 
133
        formatComboBox-&gt;addItem(&quot;hh:mm ap&quot;);
 
134
 
 
135
        connect(formatComboBox, SIGNAL(activated(const QString &amp;)),
 
136
                this, SLOT(setFormatString(const QString &amp;)));
 
137
 
 
138
        setFormatString(formatComboBox-&gt;currentText());
 
139
 
 
140
        QVBoxLayout *editsLayout = new QVBoxLayout;
 
141
        editsLayout-&gt;addWidget(dateLabel);
 
142
        editsLayout-&gt;addWidget(dateEdit);
 
143
        editsLayout-&gt;addWidget(timeLabel);
 
144
        editsLayout-&gt;addWidget(timeEdit);
 
145
        editsLayout-&gt;addWidget(meetingLabel);
 
146
        editsLayout-&gt;addWidget(meetingEdit);
 
147
        editsLayout-&gt;addWidget(formatLabel);
 
148
        editsLayout-&gt;addWidget(formatComboBox);
 
149
        editsGroup-&gt;setLayout(editsLayout);
 
150
    }
 
151
 
 
152
    void Window::setFormatString(const QString &amp;formatString)
 
153
    {
 
154
        meetingEdit-&gt;setDisplayFormat(formatString);
 
155
        if (meetingEdit-&gt;displayedSections() &amp; QDateTimeEdit::DateSections_Mask) {
 
156
            meetingEdit-&gt;setDateRange(QDate(2004, 11, 1), QDate(2005, 11, 30));
 
157
            meetingLabel-&gt;setText(tr(&quot;Meeting date (between %0 and %1):&quot;)
 
158
                .arg(meetingEdit-&gt;minimumDate().toString(Qt::ISODate))
 
159
                .arg(meetingEdit-&gt;maximumDate().toString(Qt::ISODate)));
 
160
        } else {
 
161
            meetingEdit-&gt;setTimeRange(QTime(0, 7, 20, 0), QTime(21, 0, 0, 0));
 
162
            meetingLabel-&gt;setText(tr(&quot;Meeting time (between %0 and %1):&quot;)
 
163
                .arg(meetingEdit-&gt;minimumTime().toString(Qt::ISODate))
 
164
                .arg(meetingEdit-&gt;maximumTime().toString(Qt::ISODate)));
 
165
        }
 
166
    }
 
167
 
 
168
    void Window::createDoubleSpinBoxes()
 
169
    {
 
170
        doubleSpinBoxesGroup = new QGroupBox(tr(&quot;Double precision spinboxes&quot;));
 
171
 
 
172
        QLabel *precisionLabel = new QLabel(tr(&quot;Number of decimal places &quot;
 
173
                                               &quot;to show:&quot;));
 
174
        QSpinBox *precisionSpinBox = new QSpinBox;
 
175
        precisionSpinBox-&gt;setRange(0, 14);
 
176
        precisionSpinBox-&gt;setValue(2);
 
177
 
 
178
        QLabel *doubleLabel = new QLabel(tr(&quot;Enter a value between &quot;
 
179
            &quot;%1 and %2:&quot;).arg(-20).arg(20));
 
180
        doubleSpinBox = new QDoubleSpinBox;
 
181
        doubleSpinBox-&gt;setRange(-20.0, 20.0);
 
182
        doubleSpinBox-&gt;setSingleStep(1.0);
 
183
        doubleSpinBox-&gt;setValue(0.0);
 
184
 
 
185
        QLabel *scaleLabel = new QLabel(tr(&quot;Enter a scale factor between &quot;
 
186
            &quot;%1 and %2:&quot;).arg(0).arg(1000.0));
 
187
        scaleSpinBox = new QDoubleSpinBox;
 
188
        scaleSpinBox-&gt;setRange(0.0, 1000.0);
 
189
        scaleSpinBox-&gt;setSingleStep(10.0);
 
190
        scaleSpinBox-&gt;setSuffix(&quot;%&quot;);
 
191
        scaleSpinBox-&gt;setSpecialValueText(tr(&quot;No scaling&quot;));
 
192
        scaleSpinBox-&gt;setValue(100.0);
 
193
 
 
194
        QLabel *priceLabel = new QLabel(tr(&quot;Enter a price between &quot;
 
195
            &quot;%1 and %2:&quot;).arg(0).arg(1000));
 
196
        priceSpinBox = new QDoubleSpinBox;
 
197
        priceSpinBox-&gt;setRange(0.0, 1000.0);
 
198
        priceSpinBox-&gt;setSingleStep(1.0);
 
199
        priceSpinBox-&gt;setPrefix(&quot;$&quot;);
 
200
        priceSpinBox-&gt;setValue(99.99);
 
201
 
 
202
        connect(precisionSpinBox, SIGNAL(valueChanged(int)),
 
203
                this, SLOT(changePrecision(int)));
 
204
 
 
205
        QVBoxLayout *spinBoxLayout = new QVBoxLayout;
 
206
        spinBoxLayout-&gt;addWidget(precisionLabel);
 
207
        spinBoxLayout-&gt;addWidget(precisionSpinBox);
 
208
        spinBoxLayout-&gt;addWidget(doubleLabel);
 
209
        spinBoxLayout-&gt;addWidget(doubleSpinBox);
 
210
        spinBoxLayout-&gt;addWidget(scaleLabel);
 
211
        spinBoxLayout-&gt;addWidget(scaleSpinBox);
 
212
        spinBoxLayout-&gt;addWidget(priceLabel);
 
213
        spinBoxLayout-&gt;addWidget(priceSpinBox);
 
214
        doubleSpinBoxesGroup-&gt;setLayout(spinBoxLayout);
 
215
    }
 
216
 
 
217
    void Window::changePrecision(int decimals)
 
218
    {
 
219
        doubleSpinBox-&gt;setDecimals(decimals);
 
220
        scaleSpinBox-&gt;setDecimals(decimals);
 
221
        priceSpinBox-&gt;setDecimals(decimals);
 
222
    }</pre>
 
223
<p /><address><hr /><div align="center">
 
224
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
225
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
226
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
227
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
228
</tr></table></div></address></body>
 
229
</html>