author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
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:
0
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 "controllerwindow.h" |
|
45 |
||
46 |
//! [0] |
|
47 |
ControllerWindow::ControllerWindow() |
|
48 |
{ |
|
49 |
parentWindow = new QMainWindow; |
|
50 |
parentWindow->setWindowTitle(tr("Preview parent window")); |
|
51 |
QLabel *label = new QLabel(tr("Parent window")); |
|
52 |
parentWindow->setCentralWidget(label); |
|
53 |
||
54 |
previewWindow = new PreviewWindow; |
|
55 |
previewDialog = new PreviewDialog; |
|
56 |
||
57 |
createTypeGroupBox(); |
|
58 |
createHintsGroupBox(); |
|
59 |
||
60 |
quitButton = new QPushButton(tr("&Quit")); |
|
61 |
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); |
|
62 |
||
63 |
QHBoxLayout *bottomLayout = new QHBoxLayout; |
|
64 |
bottomLayout->addStretch(); |
|
65 |
bottomLayout->addWidget(quitButton); |
|
66 |
||
67 |
QVBoxLayout *mainLayout = new QVBoxLayout; |
|
68 |
mainLayout->addWidget(widgetTypeGroupBox); |
|
69 |
mainLayout->addWidget(additionalOptionsGroupBox); |
|
70 |
mainLayout->addWidget(typeGroupBox); |
|
71 |
mainLayout->addWidget(hintsGroupBox); |
|
72 |
mainLayout->addLayout(bottomLayout); |
|
73 |
setLayout(mainLayout); |
|
74 |
||
75 |
setWindowTitle(tr("Window Flags")); |
|
76 |
updatePreview(); |
|
77 |
} |
|
78 |
||
79 |
void ControllerWindow::updatePreview() |
|
80 |
{ |
|
81 |
Qt::WindowFlags flags = 0; |
|
82 |
||
83 |
if (windowRadioButton->isChecked()) { |
|
84 |
flags = Qt::Window; |
|
85 |
} else if (dialogRadioButton->isChecked()) { |
|
86 |
flags = Qt::Dialog; |
|
87 |
} else if (sheetRadioButton->isChecked()) { |
|
88 |
flags = Qt::Sheet; |
|
89 |
} else if (drawerRadioButton->isChecked()) { |
|
90 |
flags = Qt::Drawer; |
|
91 |
} else if (popupRadioButton->isChecked()) { |
|
92 |
flags = Qt::Popup; |
|
93 |
} else if (toolRadioButton->isChecked()) { |
|
94 |
flags = Qt::Tool; |
|
95 |
} else if (toolTipRadioButton->isChecked()) { |
|
96 |
flags = Qt::ToolTip; |
|
97 |
} else if (splashScreenRadioButton->isChecked()) { |
|
98 |
flags = Qt::SplashScreen; |
|
99 |
} |
|
100 |
||
101 |
if (msWindowsFixedSizeDialogCheckBox->isChecked()) |
|
102 |
flags |= Qt::MSWindowsFixedSizeDialogHint; |
|
103 |
if (x11BypassWindowManagerCheckBox->isChecked()) |
|
104 |
flags |= Qt::X11BypassWindowManagerHint; |
|
105 |
if (framelessWindowCheckBox->isChecked()) |
|
106 |
flags |= Qt::FramelessWindowHint; |
|
107 |
if (windowTitleCheckBox->isChecked()) |
|
108 |
flags |= Qt::WindowTitleHint; |
|
109 |
if (windowSystemMenuCheckBox->isChecked()) |
|
110 |
flags |= Qt::WindowSystemMenuHint; |
|
111 |
if (windowMinimizeButtonCheckBox->isChecked()) |
|
112 |
flags |= Qt::WindowMinimizeButtonHint; |
|
113 |
if (windowMaximizeButtonCheckBox->isChecked()) |
|
114 |
flags |= Qt::WindowMaximizeButtonHint; |
|
115 |
if (windowCloseButtonCheckBox->isChecked()) |
|
116 |
flags |= Qt::WindowCloseButtonHint; |
|
117 |
if (windowContextHelpButtonCheckBox->isChecked()) |
|
118 |
flags |= Qt::WindowContextHelpButtonHint; |
|
119 |
if (windowShadeButtonCheckBox->isChecked()) |
|
120 |
flags |= Qt::WindowShadeButtonHint; |
|
121 |
if (windowStaysOnTopCheckBox->isChecked()) |
|
122 |
flags |= Qt::WindowStaysOnTopHint; |
|
123 |
if (windowStaysOnBottomCheckBox->isChecked()) |
|
124 |
flags |= Qt::WindowStaysOnBottomHint; |
|
125 |
if (customizeWindowHintCheckBox->isChecked()) |
|
126 |
flags |= Qt::CustomizeWindowHint; |
|
127 |
||
128 |
previewWindow->hide(); |
|
129 |
previewDialog->hide(); |
|
130 |
QWidget *widget = 0; |
|
131 |
if (previewWidgetButton->isChecked()) |
|
132 |
widget = previewWindow; |
|
133 |
else |
|
134 |
widget = previewDialog; |
|
135 |
||
136 |
if (modalWindowCheckBox->isChecked()) { |
|
137 |
parentWindow->show(); |
|
138 |
widget->setWindowModality(Qt::WindowModal); |
|
139 |
widget->setParent(parentWindow); |
|
140 |
} else { |
|
141 |
widget->setWindowModality(Qt::NonModal); |
|
142 |
widget->setParent(0); |
|
143 |
parentWindow->hide(); |
|
144 |
} |
|
145 |
||
146 |
widget->setWindowFlags(flags); |
|
147 |
||
148 |
if (fixedSizeWindowCheckBox->isChecked()) { |
|
149 |
widget->setFixedSize(300, 300); |
|
150 |
} else { |
|
151 |
widget->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX); |
|
152 |
} |
|
153 |
||
154 |
QPoint pos = widget->pos(); |
|
155 |
if (pos.x() < 0) |
|
156 |
pos.setX(0); |
|
157 |
if (pos.y() < 0) |
|
158 |
pos.setY(0); |
|
159 |
widget->move(pos); |
|
160 |
widget->show(); |
|
161 |
} |
|
162 |
||
163 |
void ControllerWindow::createTypeGroupBox() |
|
164 |
{ |
|
165 |
widgetTypeGroupBox = new QGroupBox(tr("Widget Type")); |
|
166 |
previewWidgetButton = createRadioButton(tr("QWidget")); |
|
167 |
previewWidgetButton->setChecked(true); |
|
168 |
previewDialogButton = createRadioButton(tr("QDialog")); |
|
169 |
QHBoxLayout *l = new QHBoxLayout; |
|
170 |
l->addWidget(previewWidgetButton); |
|
171 |
l->addWidget(previewDialogButton); |
|
172 |
widgetTypeGroupBox->setLayout(l); |
|
173 |
||
174 |
additionalOptionsGroupBox = new QGroupBox(tr("Additional options")); |
|
175 |
l = new QHBoxLayout; |
|
176 |
modalWindowCheckBox = createCheckBox(tr("Modal window")); |
|
177 |
fixedSizeWindowCheckBox = createCheckBox(tr("Fixed size window")); |
|
178 |
l->addWidget(modalWindowCheckBox); |
|
179 |
l->addWidget(fixedSizeWindowCheckBox); |
|
180 |
additionalOptionsGroupBox->setLayout(l); |
|
181 |
||
182 |
typeGroupBox = new QGroupBox(tr("Type")); |
|
183 |
||
184 |
windowRadioButton = createRadioButton(tr("Window")); |
|
185 |
dialogRadioButton = createRadioButton(tr("Dialog")); |
|
186 |
sheetRadioButton = createRadioButton(tr("Sheet")); |
|
187 |
drawerRadioButton = createRadioButton(tr("Drawer")); |
|
188 |
popupRadioButton = createRadioButton(tr("Popup")); |
|
189 |
toolRadioButton = createRadioButton(tr("Tool")); |
|
190 |
toolTipRadioButton = createRadioButton(tr("Tooltip")); |
|
191 |
splashScreenRadioButton = createRadioButton(tr("Splash screen")); |
|
192 |
windowRadioButton->setChecked(true); |
|
193 |
||
194 |
QGridLayout *layout = new QGridLayout; |
|
195 |
layout->addWidget(windowRadioButton, 0, 0); |
|
196 |
layout->addWidget(dialogRadioButton, 1, 0); |
|
197 |
layout->addWidget(sheetRadioButton, 2, 0); |
|
198 |
layout->addWidget(drawerRadioButton, 3, 0); |
|
199 |
layout->addWidget(popupRadioButton, 0, 1); |
|
200 |
layout->addWidget(toolRadioButton, 1, 1); |
|
201 |
layout->addWidget(toolTipRadioButton, 2, 1); |
|
202 |
layout->addWidget(splashScreenRadioButton, 3, 1); |
|
203 |
typeGroupBox->setLayout(layout); |
|
204 |
} |
|
205 |
//! [5] |
|
206 |
||
207 |
//! [6] |
|
208 |
void ControllerWindow::createHintsGroupBox() |
|
209 |
{ |
|
210 |
hintsGroupBox = new QGroupBox(tr("Hints")); |
|
211 |
||
212 |
msWindowsFixedSizeDialogCheckBox = |
|
213 |
createCheckBox(tr("MS Windows fixed size dialog")); |
|
214 |
x11BypassWindowManagerCheckBox = |
|
215 |
createCheckBox(tr("X11 bypass window manager")); |
|
216 |
framelessWindowCheckBox = createCheckBox(tr("Frameless window")); |
|
217 |
windowTitleCheckBox = createCheckBox(tr("Window title")); |
|
218 |
windowSystemMenuCheckBox = createCheckBox(tr("Window system menu")); |
|
219 |
windowMinimizeButtonCheckBox = createCheckBox(tr("Window minimize button")); |
|
220 |
windowMaximizeButtonCheckBox = createCheckBox(tr("Window maximize button")); |
|
221 |
windowCloseButtonCheckBox = createCheckBox(tr("Window close button")); |
|
222 |
windowContextHelpButtonCheckBox = |
|
223 |
createCheckBox(tr("Window context help button")); |
|
224 |
windowShadeButtonCheckBox = createCheckBox(tr("Window shade button")); |
|
225 |
windowStaysOnTopCheckBox = createCheckBox(tr("Window stays on top")); |
|
226 |
windowStaysOnBottomCheckBox = createCheckBox(tr("Window stays on bottom")); |
|
227 |
customizeWindowHintCheckBox= createCheckBox(tr("Customize window")); |
|
228 |
||
229 |
QGridLayout *layout = new QGridLayout; |
|
230 |
layout->addWidget(msWindowsFixedSizeDialogCheckBox, 0, 0); |
|
231 |
layout->addWidget(x11BypassWindowManagerCheckBox, 1, 0); |
|
232 |
layout->addWidget(framelessWindowCheckBox, 2, 0); |
|
233 |
layout->addWidget(windowTitleCheckBox, 3, 0); |
|
234 |
layout->addWidget(windowSystemMenuCheckBox, 4, 0); |
|
235 |
layout->addWidget(windowMinimizeButtonCheckBox, 0, 1); |
|
236 |
layout->addWidget(windowMaximizeButtonCheckBox, 1, 1); |
|
237 |
layout->addWidget(windowCloseButtonCheckBox, 2, 1); |
|
238 |
layout->addWidget(windowContextHelpButtonCheckBox, 3, 1); |
|
239 |
layout->addWidget(windowShadeButtonCheckBox, 4, 1); |
|
240 |
layout->addWidget(windowStaysOnTopCheckBox, 5, 1); |
|
241 |
layout->addWidget(windowStaysOnBottomCheckBox, 6, 1); |
|
242 |
layout->addWidget(customizeWindowHintCheckBox, 5, 0); |
|
243 |
hintsGroupBox->setLayout(layout); |
|
244 |
} |
|
245 |
//! [6] |
|
246 |
||
247 |
//! [7] |
|
248 |
QCheckBox *ControllerWindow::createCheckBox(const QString &text) |
|
249 |
{ |
|
250 |
QCheckBox *checkBox = new QCheckBox(text); |
|
251 |
connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview())); |
|
252 |
return checkBox; |
|
253 |
} |
|
254 |
//! [7] |
|
255 |
||
256 |
//! [8] |
|
257 |
QRadioButton *ControllerWindow::createRadioButton(const QString &text) |
|
258 |
{ |
|
259 |
QRadioButton *button = new QRadioButton(text); |
|
260 |
connect(button, SIGNAL(clicked()), this, SLOT(updatePreview())); |
|
261 |
return button; |
|
262 |
} |
|
263 |
//! [8] |