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