1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | #include <QtGui>
|
---|
42 |
|
---|
43 | #include "controllerwindow.h"
|
---|
44 |
|
---|
45 | //! [0]
|
---|
46 | ControllerWindow::ControllerWindow()
|
---|
47 | {
|
---|
48 | previewWindow = new PreviewWindow(this);
|
---|
49 |
|
---|
50 | createTypeGroupBox();
|
---|
51 | createHintsGroupBox();
|
---|
52 |
|
---|
53 | quitButton = new QPushButton(tr("&Quit"));
|
---|
54 | connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
|
---|
55 |
|
---|
56 | QHBoxLayout *bottomLayout = new QHBoxLayout;
|
---|
57 | bottomLayout->addStretch();
|
---|
58 | bottomLayout->addWidget(quitButton);
|
---|
59 |
|
---|
60 | QHBoxLayout *mainLayout = new QHBoxLayout;
|
---|
61 | mainLayout->addWidget(typeGroupBox);
|
---|
62 | mainLayout->addWidget(hintsGroupBox);
|
---|
63 | mainLayout->addLayout(bottomLayout);
|
---|
64 | setLayout(mainLayout);
|
---|
65 |
|
---|
66 | setWindowTitle(tr("Window Flags"));
|
---|
67 | updatePreview();
|
---|
68 | }
|
---|
69 | //! [0]
|
---|
70 |
|
---|
71 | //! [1]
|
---|
72 | void ControllerWindow::updatePreview()
|
---|
73 | {
|
---|
74 | Qt::WindowFlags flags = 0;
|
---|
75 |
|
---|
76 | if (windowRadioButton->isChecked()) {
|
---|
77 | flags = Qt::Window;
|
---|
78 | } else if (dialogRadioButton->isChecked()) {
|
---|
79 | flags = Qt::Dialog;
|
---|
80 | } else if (sheetRadioButton->isChecked()) {
|
---|
81 | flags = Qt::Sheet;
|
---|
82 | } else if (drawerRadioButton->isChecked()) {
|
---|
83 | flags = Qt::Drawer;
|
---|
84 | } else if (popupRadioButton->isChecked()) {
|
---|
85 | flags = Qt::Popup;
|
---|
86 | } else if (toolRadioButton->isChecked()) {
|
---|
87 | flags = Qt::Tool;
|
---|
88 | } else if (toolTipRadioButton->isChecked()) {
|
---|
89 | flags = Qt::ToolTip;
|
---|
90 | } else if (splashScreenRadioButton->isChecked()) {
|
---|
91 | flags = Qt::SplashScreen;
|
---|
92 | //! [1] //! [2]
|
---|
93 | }
|
---|
94 | //! [2] //! [3]
|
---|
95 |
|
---|
96 | if (msWindowsFixedSizeDialogCheckBox->isChecked())
|
---|
97 | flags |= Qt::MSWindowsFixedSizeDialogHint;
|
---|
98 | if (x11BypassWindowManagerCheckBox->isChecked())
|
---|
99 | flags |= Qt::X11BypassWindowManagerHint;
|
---|
100 | if (framelessWindowCheckBox->isChecked())
|
---|
101 | flags |= Qt::FramelessWindowHint;
|
---|
102 | if (windowTitleCheckBox->isChecked())
|
---|
103 | flags |= Qt::WindowTitleHint;
|
---|
104 | if (windowSystemMenuCheckBox->isChecked())
|
---|
105 | flags |= Qt::WindowSystemMenuHint;
|
---|
106 | if (windowMinimizeButtonCheckBox->isChecked())
|
---|
107 | flags |= Qt::WindowMinimizeButtonHint;
|
---|
108 | if (windowMaximizeButtonCheckBox->isChecked())
|
---|
109 | flags |= Qt::WindowMaximizeButtonHint;
|
---|
110 | if (windowCloseButtonCheckBox->isChecked())
|
---|
111 | flags |= Qt::WindowCloseButtonHint;
|
---|
112 | if (windowContextHelpButtonCheckBox->isChecked())
|
---|
113 | flags |= Qt::WindowContextHelpButtonHint;
|
---|
114 | if (windowShadeButtonCheckBox->isChecked())
|
---|
115 | flags |= Qt::WindowShadeButtonHint;
|
---|
116 | if (windowStaysOnTopCheckBox->isChecked())
|
---|
117 | flags |= Qt::WindowStaysOnTopHint;
|
---|
118 | if (windowStaysOnBottomCheckBox->isChecked())
|
---|
119 | flags |= Qt::WindowStaysOnBottomHint;
|
---|
120 | if (customizeWindowHintCheckBox->isChecked())
|
---|
121 | flags |= Qt::CustomizeWindowHint;
|
---|
122 |
|
---|
123 | previewWindow->setWindowFlags(flags);
|
---|
124 | //! [3] //! [4]
|
---|
125 |
|
---|
126 | QPoint pos = previewWindow->pos();
|
---|
127 | if (pos.x() < 0)
|
---|
128 | pos.setX(0);
|
---|
129 | if (pos.y() < 0)
|
---|
130 | pos.setY(0);
|
---|
131 | previewWindow->move(pos);
|
---|
132 | previewWindow->show();
|
---|
133 | }
|
---|
134 | //! [4]
|
---|
135 |
|
---|
136 | //! [5]
|
---|
137 | void ControllerWindow::createTypeGroupBox()
|
---|
138 | {
|
---|
139 | typeGroupBox = new QGroupBox(tr("Type"));
|
---|
140 |
|
---|
141 | windowRadioButton = createRadioButton(tr("Window"));
|
---|
142 | dialogRadioButton = createRadioButton(tr("Dialog"));
|
---|
143 | sheetRadioButton = createRadioButton(tr("Sheet"));
|
---|
144 | drawerRadioButton = createRadioButton(tr("Drawer"));
|
---|
145 | popupRadioButton = createRadioButton(tr("Popup"));
|
---|
146 | toolRadioButton = createRadioButton(tr("Tool"));
|
---|
147 | toolTipRadioButton = createRadioButton(tr("Tooltip"));
|
---|
148 | splashScreenRadioButton = createRadioButton(tr("Splash screen"));
|
---|
149 | windowRadioButton->setChecked(true);
|
---|
150 |
|
---|
151 | QGridLayout *layout = new QGridLayout;
|
---|
152 | layout->addWidget(windowRadioButton, 0, 0);
|
---|
153 | layout->addWidget(dialogRadioButton, 1, 0);
|
---|
154 | layout->addWidget(sheetRadioButton, 2, 0);
|
---|
155 | layout->addWidget(drawerRadioButton, 3, 0);
|
---|
156 | layout->addWidget(popupRadioButton, 0, 1);
|
---|
157 | layout->addWidget(toolRadioButton, 1, 1);
|
---|
158 | layout->addWidget(toolTipRadioButton, 2, 1);
|
---|
159 | layout->addWidget(splashScreenRadioButton, 3, 1);
|
---|
160 | typeGroupBox->setLayout(layout);
|
---|
161 | }
|
---|
162 | //! [5]
|
---|
163 |
|
---|
164 | //! [6]
|
---|
165 | void ControllerWindow::createHintsGroupBox()
|
---|
166 | {
|
---|
167 | hintsGroupBox = new QGroupBox(tr("Hints"));
|
---|
168 |
|
---|
169 | msWindowsFixedSizeDialogCheckBox =
|
---|
170 | createCheckBox(tr("MS Windows fixed size dialog"));
|
---|
171 | x11BypassWindowManagerCheckBox =
|
---|
172 | createCheckBox(tr("X11 bypass window manager"));
|
---|
173 | framelessWindowCheckBox = createCheckBox(tr("Frameless window"));
|
---|
174 | windowTitleCheckBox = createCheckBox(tr("Window title"));
|
---|
175 | windowSystemMenuCheckBox = createCheckBox(tr("Window system menu"));
|
---|
176 | windowMinimizeButtonCheckBox = createCheckBox(tr("Window minimize button"));
|
---|
177 | windowMaximizeButtonCheckBox = createCheckBox(tr("Window maximize button"));
|
---|
178 | windowCloseButtonCheckBox = createCheckBox(tr("Window close button"));
|
---|
179 | windowContextHelpButtonCheckBox =
|
---|
180 | createCheckBox(tr("Window context help button"));
|
---|
181 | windowShadeButtonCheckBox = createCheckBox(tr("Window shade button"));
|
---|
182 | windowStaysOnTopCheckBox = createCheckBox(tr("Window stays on top"));
|
---|
183 | windowStaysOnBottomCheckBox = createCheckBox(tr("Window stays on bottom"));
|
---|
184 | customizeWindowHintCheckBox= createCheckBox(tr("Customize window"));
|
---|
185 |
|
---|
186 | QGridLayout *layout = new QGridLayout;
|
---|
187 | layout->addWidget(msWindowsFixedSizeDialogCheckBox, 0, 0);
|
---|
188 | layout->addWidget(x11BypassWindowManagerCheckBox, 1, 0);
|
---|
189 | layout->addWidget(framelessWindowCheckBox, 2, 0);
|
---|
190 | layout->addWidget(windowTitleCheckBox, 3, 0);
|
---|
191 | layout->addWidget(windowSystemMenuCheckBox, 4, 0);
|
---|
192 | layout->addWidget(windowMinimizeButtonCheckBox, 0, 1);
|
---|
193 | layout->addWidget(windowMaximizeButtonCheckBox, 1, 1);
|
---|
194 | layout->addWidget(windowCloseButtonCheckBox, 2, 1);
|
---|
195 | layout->addWidget(windowContextHelpButtonCheckBox, 3, 1);
|
---|
196 | layout->addWidget(windowShadeButtonCheckBox, 4, 1);
|
---|
197 | layout->addWidget(windowStaysOnTopCheckBox, 5, 1);
|
---|
198 | layout->addWidget(windowStaysOnBottomCheckBox, 6, 1);
|
---|
199 | layout->addWidget(customizeWindowHintCheckBox, 5, 0);
|
---|
200 | hintsGroupBox->setLayout(layout);
|
---|
201 | }
|
---|
202 | //! [6]
|
---|
203 |
|
---|
204 | //! [7]
|
---|
205 | QCheckBox *ControllerWindow::createCheckBox(const QString &text)
|
---|
206 | {
|
---|
207 | QCheckBox *checkBox = new QCheckBox(text);
|
---|
208 | connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
---|
209 | return checkBox;
|
---|
210 | }
|
---|
211 | //! [7]
|
---|
212 |
|
---|
213 | //! [8]
|
---|
214 | QRadioButton *ControllerWindow::createRadioButton(const QString &text)
|
---|
215 | {
|
---|
216 | QRadioButton *button = new QRadioButton(text);
|
---|
217 | connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
---|
218 | return button;
|
---|
219 | }
|
---|
220 | //! [8]
|
---|