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

« back to all changes in this revision

Viewing changes to doc/html/widgets-styles-widgetgallery-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: widgetgallery.cpp Example File (widgets/styles/widgetgallery.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">widgetgallery.cpp Example File<br /><small><small>widgets/styles/widgetgallery.cpp</small></small></h1>
 
20
<pre>&nbsp;   /****************************************************************************
 
21
    **
 
22
    ** Copyright (C) 2005-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;norwegianwoodstyle.h&quot;
 
51
    #include &quot;widgetgallery.h&quot;
 
52
 
 
53
    WidgetGallery::WidgetGallery(QWidget *parent)
 
54
        : QDialog(parent)
 
55
    {
 
56
        originalPalette = QApplication::palette();
 
57
 
 
58
        styleComboBox = new QComboBox;
 
59
        styleComboBox-&gt;addItem(&quot;NorwegianWood&quot;);
 
60
        styleComboBox-&gt;addItems(QStyleFactory::keys());
 
61
 
 
62
        styleLabel = new QLabel(tr(&quot;&amp;Style:&quot;));
 
63
        styleLabel-&gt;setBuddy(styleComboBox);
 
64
 
 
65
        useStylePaletteCheckBox = new QCheckBox(tr(&quot;&amp;Use style's standard palette&quot;));
 
66
        useStylePaletteCheckBox-&gt;setChecked(true);
 
67
 
 
68
        disableWidgetsCheckBox = new QCheckBox(tr(&quot;&amp;Disable widgets&quot;));
 
69
 
 
70
        createTopLeftGroupBox();
 
71
        createTopRightGroupBox();
 
72
        createBottomLeftTabWidget();
 
73
        createBottomRightGroupBox();
 
74
        createProgressBar();
 
75
 
 
76
        connect(styleComboBox, SIGNAL(activated(const QString &amp;)),
 
77
                this, SLOT(changeStyle(const QString &amp;)));
 
78
        connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)),
 
79
                this, SLOT(changePalette()));
 
80
        connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
 
81
                topLeftGroupBox, SLOT(setDisabled(bool)));
 
82
        connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
 
83
                topRightGroupBox, SLOT(setDisabled(bool)));
 
84
        connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
 
85
                bottomLeftTabWidget, SLOT(setDisabled(bool)));
 
86
        connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)),
 
87
                bottomRightGroupBox, SLOT(setDisabled(bool)));
 
88
 
 
89
        QHBoxLayout *topLayout = new QHBoxLayout;
 
90
        topLayout-&gt;addWidget(styleLabel);
 
91
        topLayout-&gt;addWidget(styleComboBox);
 
92
        topLayout-&gt;addStretch(1);
 
93
        topLayout-&gt;addWidget(useStylePaletteCheckBox);
 
94
        topLayout-&gt;addWidget(disableWidgetsCheckBox);
 
95
 
 
96
        QGridLayout *mainLayout = new QGridLayout;
 
97
        mainLayout-&gt;addLayout(topLayout, 0, 0, 1, 2);
 
98
        mainLayout-&gt;addWidget(topLeftGroupBox, 1, 0);
 
99
        mainLayout-&gt;addWidget(topRightGroupBox, 1, 1);
 
100
        mainLayout-&gt;addWidget(bottomLeftTabWidget, 2, 0);
 
101
        mainLayout-&gt;addWidget(bottomRightGroupBox, 2, 1);
 
102
        mainLayout-&gt;addWidget(progressBar, 3, 0, 1, 2);
 
103
        mainLayout-&gt;setRowStretch(1, 1);
 
104
        mainLayout-&gt;setRowStretch(2, 1);
 
105
        mainLayout-&gt;setColumnStretch(0, 1);
 
106
        mainLayout-&gt;setColumnStretch(1, 1);
 
107
        setLayout(mainLayout);
 
108
 
 
109
        setWindowTitle(tr(&quot;Styles&quot;));
 
110
        changeStyle(&quot;NorwegianWood&quot;);
 
111
    }
 
112
 
 
113
    void WidgetGallery::changeStyle(const QString &amp;styleName)
 
114
    {
 
115
        if (styleName == &quot;NorwegianWood&quot;) {
 
116
            QApplication::setStyle(new NorwegianWoodStyle);
 
117
        } else {
 
118
            QApplication::setStyle(QStyleFactory::create(styleName));
 
119
        }
 
120
        changePalette();
 
121
    }
 
122
 
 
123
    void WidgetGallery::changePalette()
 
124
    {
 
125
        if (useStylePaletteCheckBox-&gt;isChecked())
 
126
            QApplication::setPalette(QApplication::style()-&gt;standardPalette());
 
127
        else
 
128
            QApplication::setPalette(originalPalette);
 
129
    }
 
130
 
 
131
    void WidgetGallery::advanceProgressBar()
 
132
    {
 
133
        int curVal = progressBar-&gt;value();
 
134
        int maxVal = progressBar-&gt;maximum();
 
135
        progressBar-&gt;setValue(curVal + (maxVal - curVal) / 100);
 
136
    }
 
137
 
 
138
    void WidgetGallery::createTopLeftGroupBox()
 
139
    {
 
140
        topLeftGroupBox = new QGroupBox(tr(&quot;Group 1&quot;));
 
141
 
 
142
        radioButton1 = new QRadioButton(tr(&quot;Radio button 1&quot;));
 
143
        radioButton2 = new QRadioButton(tr(&quot;Radio button 2&quot;));
 
144
        radioButton3 = new QRadioButton(tr(&quot;Radio button 3&quot;));
 
145
        radioButton1-&gt;setChecked(true);
 
146
 
 
147
        checkBox = new QCheckBox(tr(&quot;Tri-state check box&quot;));
 
148
        checkBox-&gt;setTristate(true);
 
149
        checkBox-&gt;setCheckState(Qt::PartiallyChecked);
 
150
 
 
151
        QVBoxLayout *layout = new QVBoxLayout;
 
152
        layout-&gt;addWidget(radioButton1);
 
153
        layout-&gt;addWidget(radioButton2);
 
154
        layout-&gt;addWidget(radioButton3);
 
155
        layout-&gt;addWidget(checkBox);
 
156
        layout-&gt;addStretch(1);
 
157
        topLeftGroupBox-&gt;setLayout(layout);
 
158
    }
 
159
 
 
160
    void WidgetGallery::createTopRightGroupBox()
 
161
    {
 
162
        topRightGroupBox = new QGroupBox(tr(&quot;Group 2&quot;));
 
163
 
 
164
        defaultPushButton = new QPushButton(tr(&quot;Default Push Button&quot;));
 
165
        defaultPushButton-&gt;setDefault(true);
 
166
 
 
167
        togglePushButton = new QPushButton(tr(&quot;Toggle Push Button&quot;));
 
168
        togglePushButton-&gt;setCheckable(true);
 
169
        togglePushButton-&gt;setChecked(true);
 
170
 
 
171
        flatPushButton = new QPushButton(tr(&quot;Flat Push Button&quot;));
 
172
        flatPushButton-&gt;setFlat(true);
 
173
 
 
174
        QVBoxLayout *layout = new QVBoxLayout;
 
175
        layout-&gt;addWidget(defaultPushButton);
 
176
        layout-&gt;addWidget(togglePushButton);
 
177
        layout-&gt;addWidget(flatPushButton);
 
178
        layout-&gt;addStretch(1);
 
179
        topRightGroupBox-&gt;setLayout(layout);
 
180
    }
 
181
 
 
182
    void WidgetGallery::createBottomLeftTabWidget()
 
183
    {
 
184
        bottomLeftTabWidget = new QTabWidget;
 
185
        bottomLeftTabWidget-&gt;setSizePolicy(QSizePolicy::Preferred,
 
186
                                           QSizePolicy::Ignored);
 
187
 
 
188
        QWidget *tab1 = new QWidget;
 
189
        tableWidget = new QTableWidget(10, 10);
 
190
 
 
191
        QHBoxLayout *tab1hbox = new QHBoxLayout;
 
192
        tab1hbox-&gt;setMargin(5);
 
193
        tab1hbox-&gt;addWidget(tableWidget);
 
194
        tab1-&gt;setLayout(tab1hbox);
 
195
 
 
196
        QWidget *tab2 = new QWidget;
 
197
        textEdit = new QTextEdit;
 
198
 
 
199
        textEdit-&gt;setPlainText(tr(&quot;Au clair de la lune,\n&quot;
 
200
                                  &quot;Mon ami Pierrot,\n&quot;
 
201
                                  &quot;Pr�te moi ta plume\n&quot;
 
202
                                  &quot;Pour �crire un mot.\n&quot;
 
203
                                  &quot;Ma chandelle est morte,\n&quot;
 
204
                                  &quot;Je n'ai plus de feu.\n&quot;
 
205
                                  &quot;Ouvre moi ta porte,\n&quot;
 
206
                                  &quot;Pour l'amour de Dieu.\n&quot;));
 
207
 
 
208
        QHBoxLayout *tab2hbox = new QHBoxLayout;
 
209
        tab2hbox-&gt;setMargin(5);
 
210
        tab2hbox-&gt;addWidget(textEdit);
 
211
        tab2-&gt;setLayout(tab2hbox);
 
212
 
 
213
        bottomLeftTabWidget-&gt;addTab(tab1, tr(&quot;&amp;Table&quot;));
 
214
        bottomLeftTabWidget-&gt;addTab(tab2, tr(&quot;Text &amp;Edit&quot;));
 
215
    }
 
216
 
 
217
    void WidgetGallery::createBottomRightGroupBox()
 
218
    {
 
219
        bottomRightGroupBox = new QGroupBox(tr(&quot;Group 3&quot;));
 
220
        bottomRightGroupBox-&gt;setCheckable(true);
 
221
        bottomRightGroupBox-&gt;setChecked(true);
 
222
 
 
223
        lineEdit = new QLineEdit(&quot;s3cRe7&quot;);
 
224
        lineEdit-&gt;setEchoMode(QLineEdit::Password);
 
225
 
 
226
        spinBox = new QSpinBox(bottomRightGroupBox);
 
227
        spinBox-&gt;setValue(50);
 
228
 
 
229
        dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox);
 
230
        dateTimeEdit-&gt;setDateTime(QDateTime::currentDateTime());
 
231
 
 
232
        slider = new QSlider(Qt::Horizontal, bottomRightGroupBox);
 
233
        slider-&gt;setValue(40);
 
234
 
 
235
        scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox);
 
236
        scrollBar-&gt;setValue(60);
 
237
 
 
238
        dial = new QDial(bottomRightGroupBox);
 
239
        dial-&gt;setValue(30);
 
240
        dial-&gt;setNotchesVisible(true);
 
241
 
 
242
        QGridLayout *layout = new QGridLayout;
 
243
        layout-&gt;addWidget(lineEdit, 0, 0, 1, 2);
 
244
        layout-&gt;addWidget(spinBox, 1, 0, 1, 2);
 
245
        layout-&gt;addWidget(dateTimeEdit, 2, 0, 1, 2);
 
246
        layout-&gt;addWidget(slider, 3, 0);
 
247
        layout-&gt;addWidget(scrollBar, 4, 0);
 
248
        layout-&gt;addWidget(dial, 3, 1, 2, 1);
 
249
        layout-&gt;setRowStretch(5, 1);
 
250
        bottomRightGroupBox-&gt;setLayout(layout);
 
251
    }
 
252
 
 
253
    void WidgetGallery::createProgressBar()
 
254
    {
 
255
        progressBar = new QProgressBar;
 
256
        progressBar-&gt;setRange(0, 10000);
 
257
        progressBar-&gt;setValue(0);
 
258
 
 
259
        QTimer *timer = new QTimer(this);
 
260
        connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar()));
 
261
        timer-&gt;start(1000);
 
262
    }</pre>
 
263
<p /><address><hr /><div align="center">
 
264
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
265
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
266
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
267
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
268
</tr></table></div></address></body>
 
269
</html>