author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the examples of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <QtGui> |
|
43 |
||
44 |
#include "norwegianwoodstyle.h" |
|
45 |
#include "widgetgallery.h" |
|
46 |
||
47 |
//! [0] |
|
48 |
WidgetGallery::WidgetGallery(QWidget *parent) |
|
49 |
: QDialog(parent) |
|
50 |
{ |
|
51 |
originalPalette = QApplication::palette(); |
|
52 |
||
53 |
styleComboBox = new QComboBox; |
|
54 |
styleComboBox->addItem("NorwegianWood"); |
|
55 |
styleComboBox->addItems(QStyleFactory::keys()); |
|
56 |
||
57 |
styleLabel = new QLabel(tr("&Style:")); |
|
58 |
styleLabel->setBuddy(styleComboBox); |
|
59 |
||
60 |
useStylePaletteCheckBox = new QCheckBox(tr("&Use style's standard palette")); |
|
61 |
useStylePaletteCheckBox->setChecked(true); |
|
62 |
||
63 |
disableWidgetsCheckBox = new QCheckBox(tr("&Disable widgets")); |
|
64 |
||
65 |
createTopLeftGroupBox(); |
|
66 |
createTopRightGroupBox(); |
|
67 |
createBottomLeftTabWidget(); |
|
68 |
createBottomRightGroupBox(); |
|
69 |
createProgressBar(); |
|
70 |
//! [0] |
|
71 |
||
72 |
//! [1] |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
connect(styleComboBox, SIGNAL(activated(QString)), |
0 | 74 |
//! [1] //! [2] |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
this, SLOT(changeStyle(QString))); |
0 | 76 |
connect(useStylePaletteCheckBox, SIGNAL(toggled(bool)), |
77 |
this, SLOT(changePalette())); |
|
78 |
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), |
|
79 |
topLeftGroupBox, SLOT(setDisabled(bool))); |
|
80 |
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), |
|
81 |
topRightGroupBox, SLOT(setDisabled(bool))); |
|
82 |
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), |
|
83 |
bottomLeftTabWidget, SLOT(setDisabled(bool))); |
|
84 |
connect(disableWidgetsCheckBox, SIGNAL(toggled(bool)), |
|
85 |
bottomRightGroupBox, SLOT(setDisabled(bool))); |
|
86 |
//! [2] |
|
87 |
||
88 |
//! [3] |
|
89 |
QHBoxLayout *topLayout = new QHBoxLayout; |
|
90 |
//! [3] //! [4] |
|
91 |
topLayout->addWidget(styleLabel); |
|
92 |
topLayout->addWidget(styleComboBox); |
|
93 |
topLayout->addStretch(1); |
|
94 |
topLayout->addWidget(useStylePaletteCheckBox); |
|
95 |
topLayout->addWidget(disableWidgetsCheckBox); |
|
96 |
||
97 |
QGridLayout *mainLayout = new QGridLayout; |
|
98 |
mainLayout->addLayout(topLayout, 0, 0, 1, 2); |
|
99 |
mainLayout->addWidget(topLeftGroupBox, 1, 0); |
|
100 |
mainLayout->addWidget(topRightGroupBox, 1, 1); |
|
101 |
mainLayout->addWidget(bottomLeftTabWidget, 2, 0); |
|
102 |
mainLayout->addWidget(bottomRightGroupBox, 2, 1); |
|
103 |
mainLayout->addWidget(progressBar, 3, 0, 1, 2); |
|
104 |
mainLayout->setRowStretch(1, 1); |
|
105 |
mainLayout->setRowStretch(2, 1); |
|
106 |
mainLayout->setColumnStretch(0, 1); |
|
107 |
mainLayout->setColumnStretch(1, 1); |
|
108 |
setLayout(mainLayout); |
|
109 |
||
110 |
setWindowTitle(tr("Styles")); |
|
111 |
changeStyle("NorwegianWood"); |
|
112 |
} |
|
113 |
//! [4] |
|
114 |
||
115 |
//! [5] |
|
116 |
void WidgetGallery::changeStyle(const QString &styleName) |
|
117 |
//! [5] //! [6] |
|
118 |
{ |
|
119 |
if (styleName == "NorwegianWood") { |
|
120 |
QApplication::setStyle(new NorwegianWoodStyle); |
|
121 |
} else { |
|
122 |
QApplication::setStyle(QStyleFactory::create(styleName)); |
|
123 |
} |
|
124 |
changePalette(); |
|
125 |
} |
|
126 |
//! [6] |
|
127 |
||
128 |
//! [7] |
|
129 |
void WidgetGallery::changePalette() |
|
130 |
//! [7] //! [8] |
|
131 |
{ |
|
132 |
if (useStylePaletteCheckBox->isChecked()) |
|
133 |
QApplication::setPalette(QApplication::style()->standardPalette()); |
|
134 |
else |
|
135 |
QApplication::setPalette(originalPalette); |
|
136 |
} |
|
137 |
//! [8] |
|
138 |
||
139 |
//! [9] |
|
140 |
void WidgetGallery::advanceProgressBar() |
|
141 |
//! [9] //! [10] |
|
142 |
{ |
|
143 |
int curVal = progressBar->value(); |
|
144 |
int maxVal = progressBar->maximum(); |
|
145 |
progressBar->setValue(curVal + (maxVal - curVal) / 100); |
|
146 |
} |
|
147 |
//! [10] |
|
148 |
||
149 |
//! [11] |
|
150 |
void WidgetGallery::createTopLeftGroupBox() |
|
151 |
//! [11] //! [12] |
|
152 |
{ |
|
153 |
topLeftGroupBox = new QGroupBox(tr("Group 1")); |
|
154 |
||
155 |
radioButton1 = new QRadioButton(tr("Radio button 1")); |
|
156 |
radioButton2 = new QRadioButton(tr("Radio button 2")); |
|
157 |
radioButton3 = new QRadioButton(tr("Radio button 3")); |
|
158 |
radioButton1->setChecked(true); |
|
159 |
||
160 |
checkBox = new QCheckBox(tr("Tri-state check box")); |
|
161 |
checkBox->setTristate(true); |
|
162 |
checkBox->setCheckState(Qt::PartiallyChecked); |
|
163 |
||
164 |
QVBoxLayout *layout = new QVBoxLayout; |
|
165 |
layout->addWidget(radioButton1); |
|
166 |
layout->addWidget(radioButton2); |
|
167 |
layout->addWidget(radioButton3); |
|
168 |
layout->addWidget(checkBox); |
|
169 |
layout->addStretch(1); |
|
170 |
topLeftGroupBox->setLayout(layout); |
|
171 |
} |
|
172 |
//! [12] |
|
173 |
||
174 |
void WidgetGallery::createTopRightGroupBox() |
|
175 |
{ |
|
176 |
topRightGroupBox = new QGroupBox(tr("Group 2")); |
|
177 |
||
178 |
defaultPushButton = new QPushButton(tr("Default Push Button")); |
|
179 |
defaultPushButton->setDefault(true); |
|
180 |
||
181 |
togglePushButton = new QPushButton(tr("Toggle Push Button")); |
|
182 |
togglePushButton->setCheckable(true); |
|
183 |
togglePushButton->setChecked(true); |
|
184 |
||
185 |
flatPushButton = new QPushButton(tr("Flat Push Button")); |
|
186 |
flatPushButton->setFlat(true); |
|
187 |
||
188 |
QVBoxLayout *layout = new QVBoxLayout; |
|
189 |
layout->addWidget(defaultPushButton); |
|
190 |
layout->addWidget(togglePushButton); |
|
191 |
layout->addWidget(flatPushButton); |
|
192 |
layout->addStretch(1); |
|
193 |
topRightGroupBox->setLayout(layout); |
|
194 |
} |
|
195 |
||
196 |
void WidgetGallery::createBottomLeftTabWidget() |
|
197 |
{ |
|
198 |
bottomLeftTabWidget = new QTabWidget; |
|
199 |
bottomLeftTabWidget->setSizePolicy(QSizePolicy::Preferred, |
|
200 |
QSizePolicy::Ignored); |
|
201 |
||
202 |
QWidget *tab1 = new QWidget; |
|
203 |
tableWidget = new QTableWidget(10, 10); |
|
204 |
||
205 |
QHBoxLayout *tab1hbox = new QHBoxLayout; |
|
206 |
tab1hbox->setMargin(5); |
|
207 |
tab1hbox->addWidget(tableWidget); |
|
208 |
tab1->setLayout(tab1hbox); |
|
209 |
||
210 |
QWidget *tab2 = new QWidget; |
|
211 |
textEdit = new QTextEdit; |
|
212 |
||
213 |
textEdit->setPlainText(tr("Twinkle, twinkle, little star,\n" |
|
214 |
"How I wonder what you are.\n" |
|
215 |
"Up above the world so high,\n" |
|
216 |
"Like a diamond in the sky.\n" |
|
217 |
"Twinkle, twinkle, little star,\n" |
|
218 |
"How I wonder what you are!\n")); |
|
219 |
||
220 |
QHBoxLayout *tab2hbox = new QHBoxLayout; |
|
221 |
tab2hbox->setMargin(5); |
|
222 |
tab2hbox->addWidget(textEdit); |
|
223 |
tab2->setLayout(tab2hbox); |
|
224 |
||
225 |
bottomLeftTabWidget->addTab(tab1, tr("&Table")); |
|
226 |
bottomLeftTabWidget->addTab(tab2, tr("Text &Edit")); |
|
227 |
} |
|
228 |
||
229 |
void WidgetGallery::createBottomRightGroupBox() |
|
230 |
{ |
|
231 |
bottomRightGroupBox = new QGroupBox(tr("Group 3")); |
|
232 |
bottomRightGroupBox->setCheckable(true); |
|
233 |
bottomRightGroupBox->setChecked(true); |
|
234 |
||
235 |
lineEdit = new QLineEdit("s3cRe7"); |
|
236 |
lineEdit->setEchoMode(QLineEdit::Password); |
|
237 |
||
238 |
spinBox = new QSpinBox(bottomRightGroupBox); |
|
239 |
spinBox->setValue(50); |
|
240 |
||
241 |
dateTimeEdit = new QDateTimeEdit(bottomRightGroupBox); |
|
242 |
dateTimeEdit->setDateTime(QDateTime::currentDateTime()); |
|
243 |
||
244 |
slider = new QSlider(Qt::Horizontal, bottomRightGroupBox); |
|
245 |
slider->setValue(40); |
|
246 |
||
247 |
scrollBar = new QScrollBar(Qt::Horizontal, bottomRightGroupBox); |
|
248 |
scrollBar->setValue(60); |
|
249 |
||
250 |
dial = new QDial(bottomRightGroupBox); |
|
251 |
dial->setValue(30); |
|
252 |
dial->setNotchesVisible(true); |
|
253 |
||
254 |
QGridLayout *layout = new QGridLayout; |
|
255 |
layout->addWidget(lineEdit, 0, 0, 1, 2); |
|
256 |
layout->addWidget(spinBox, 1, 0, 1, 2); |
|
257 |
layout->addWidget(dateTimeEdit, 2, 0, 1, 2); |
|
258 |
layout->addWidget(slider, 3, 0); |
|
259 |
layout->addWidget(scrollBar, 4, 0); |
|
260 |
layout->addWidget(dial, 3, 1, 2, 1); |
|
261 |
layout->setRowStretch(5, 1); |
|
262 |
bottomRightGroupBox->setLayout(layout); |
|
263 |
} |
|
264 |
||
265 |
//! [13] |
|
266 |
void WidgetGallery::createProgressBar() |
|
267 |
{ |
|
268 |
progressBar = new QProgressBar; |
|
269 |
progressBar->setRange(0, 10000); |
|
270 |
progressBar->setValue(0); |
|
271 |
||
272 |
QTimer *timer = new QTimer(this); |
|
273 |
connect(timer, SIGNAL(timeout()), this, SLOT(advanceProgressBar())); |
|
274 |
timer->start(1000); |
|
275 |
} |
|
276 |
//! [13] |