source: trunk/examples/widgets/windowflags/controllerwindow.cpp@ 440

Last change on this file since 440 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
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 [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <QtGui>
43
44#include "controllerwindow.h"
45
46//! [0]
47ControllerWindow::ControllerWindow()
48{
49 previewWindow = new PreviewWindow(this);
50
51 createTypeGroupBox();
52 createHintsGroupBox();
53
54 quitButton = new QPushButton(tr("&Quit"));
55 connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
56
57 QHBoxLayout *bottomLayout = new QHBoxLayout;
58 bottomLayout->addStretch();
59 bottomLayout->addWidget(quitButton);
60
61 QVBoxLayout *mainLayout = new QVBoxLayout;
62 mainLayout->addWidget(typeGroupBox);
63 mainLayout->addWidget(hintsGroupBox);
64 mainLayout->addLayout(bottomLayout);
65 setLayout(mainLayout);
66
67 setWindowTitle(tr("Window Flags"));
68 updatePreview();
69}
70//! [0]
71
72//! [1]
73void ControllerWindow::updatePreview()
74{
75 Qt::WindowFlags flags = 0;
76
77 if (windowRadioButton->isChecked()) {
78 flags = Qt::Window;
79 } else if (dialogRadioButton->isChecked()) {
80 flags = Qt::Dialog;
81 } else if (sheetRadioButton->isChecked()) {
82 flags = Qt::Sheet;
83 } else if (drawerRadioButton->isChecked()) {
84 flags = Qt::Drawer;
85 } else if (popupRadioButton->isChecked()) {
86 flags = Qt::Popup;
87 } else if (toolRadioButton->isChecked()) {
88 flags = Qt::Tool;
89 } else if (toolTipRadioButton->isChecked()) {
90 flags = Qt::ToolTip;
91 } else if (splashScreenRadioButton->isChecked()) {
92 flags = Qt::SplashScreen;
93//! [1] //! [2]
94 }
95//! [2] //! [3]
96
97 if (msWindowsFixedSizeDialogCheckBox->isChecked())
98 flags |= Qt::MSWindowsFixedSizeDialogHint;
99 if (x11BypassWindowManagerCheckBox->isChecked())
100 flags |= Qt::X11BypassWindowManagerHint;
101 if (framelessWindowCheckBox->isChecked())
102 flags |= Qt::FramelessWindowHint;
103 if (windowTitleCheckBox->isChecked())
104 flags |= Qt::WindowTitleHint;
105 if (windowSystemMenuCheckBox->isChecked())
106 flags |= Qt::WindowSystemMenuHint;
107 if (windowMinimizeButtonCheckBox->isChecked())
108 flags |= Qt::WindowMinimizeButtonHint;
109 if (windowMaximizeButtonCheckBox->isChecked())
110 flags |= Qt::WindowMaximizeButtonHint;
111 if (windowCloseButtonCheckBox->isChecked())
112 flags |= Qt::WindowCloseButtonHint;
113 if (windowContextHelpButtonCheckBox->isChecked())
114 flags |= Qt::WindowContextHelpButtonHint;
115 if (windowShadeButtonCheckBox->isChecked())
116 flags |= Qt::WindowShadeButtonHint;
117 if (windowStaysOnTopCheckBox->isChecked())
118 flags |= Qt::WindowStaysOnTopHint;
119 if (windowStaysOnBottomCheckBox->isChecked())
120 flags |= Qt::WindowStaysOnBottomHint;
121 if (customizeWindowHintCheckBox->isChecked())
122 flags |= Qt::CustomizeWindowHint;
123
124 previewWindow->setWindowFlags(flags);
125//! [3] //! [4]
126
127 QPoint pos = previewWindow->pos();
128 if (pos.x() < 0)
129 pos.setX(0);
130 if (pos.y() < 0)
131 pos.setY(0);
132 previewWindow->move(pos);
133 previewWindow->show();
134}
135//! [4]
136
137//! [5]
138void ControllerWindow::createTypeGroupBox()
139{
140 typeGroupBox = new QGroupBox(tr("Type"));
141
142 windowRadioButton = createRadioButton(tr("Window"));
143 dialogRadioButton = createRadioButton(tr("Dialog"));
144 sheetRadioButton = createRadioButton(tr("Sheet"));
145 drawerRadioButton = createRadioButton(tr("Drawer"));
146 popupRadioButton = createRadioButton(tr("Popup"));
147 toolRadioButton = createRadioButton(tr("Tool"));
148 toolTipRadioButton = createRadioButton(tr("Tooltip"));
149 splashScreenRadioButton = createRadioButton(tr("Splash screen"));
150 windowRadioButton->setChecked(true);
151
152 QGridLayout *layout = new QGridLayout;
153 layout->addWidget(windowRadioButton, 0, 0);
154 layout->addWidget(dialogRadioButton, 1, 0);
155 layout->addWidget(sheetRadioButton, 2, 0);
156 layout->addWidget(drawerRadioButton, 3, 0);
157 layout->addWidget(popupRadioButton, 0, 1);
158 layout->addWidget(toolRadioButton, 1, 1);
159 layout->addWidget(toolTipRadioButton, 2, 1);
160 layout->addWidget(splashScreenRadioButton, 3, 1);
161 typeGroupBox->setLayout(layout);
162}
163//! [5]
164
165//! [6]
166void ControllerWindow::createHintsGroupBox()
167{
168 hintsGroupBox = new QGroupBox(tr("Hints"));
169
170 msWindowsFixedSizeDialogCheckBox =
171 createCheckBox(tr("MS Windows fixed size dialog"));
172 x11BypassWindowManagerCheckBox =
173 createCheckBox(tr("X11 bypass window manager"));
174 framelessWindowCheckBox = createCheckBox(tr("Frameless window"));
175 windowTitleCheckBox = createCheckBox(tr("Window title"));
176 windowSystemMenuCheckBox = createCheckBox(tr("Window system menu"));
177 windowMinimizeButtonCheckBox = createCheckBox(tr("Window minimize button"));
178 windowMaximizeButtonCheckBox = createCheckBox(tr("Window maximize button"));
179 windowCloseButtonCheckBox = createCheckBox(tr("Window close button"));
180 windowContextHelpButtonCheckBox =
181 createCheckBox(tr("Window context help button"));
182 windowShadeButtonCheckBox = createCheckBox(tr("Window shade button"));
183 windowStaysOnTopCheckBox = createCheckBox(tr("Window stays on top"));
184 windowStaysOnBottomCheckBox = createCheckBox(tr("Window stays on bottom"));
185 customizeWindowHintCheckBox= createCheckBox(tr("Customize window"));
186
187 QGridLayout *layout = new QGridLayout;
188 layout->addWidget(msWindowsFixedSizeDialogCheckBox, 0, 0);
189 layout->addWidget(x11BypassWindowManagerCheckBox, 1, 0);
190 layout->addWidget(framelessWindowCheckBox, 2, 0);
191 layout->addWidget(windowTitleCheckBox, 3, 0);
192 layout->addWidget(windowSystemMenuCheckBox, 4, 0);
193 layout->addWidget(windowMinimizeButtonCheckBox, 0, 1);
194 layout->addWidget(windowMaximizeButtonCheckBox, 1, 1);
195 layout->addWidget(windowCloseButtonCheckBox, 2, 1);
196 layout->addWidget(windowContextHelpButtonCheckBox, 3, 1);
197 layout->addWidget(windowShadeButtonCheckBox, 4, 1);
198 layout->addWidget(windowStaysOnTopCheckBox, 5, 1);
199 layout->addWidget(windowStaysOnBottomCheckBox, 6, 1);
200 layout->addWidget(customizeWindowHintCheckBox, 5, 0);
201 hintsGroupBox->setLayout(layout);
202}
203//! [6]
204
205//! [7]
206QCheckBox *ControllerWindow::createCheckBox(const QString &text)
207{
208 QCheckBox *checkBox = new QCheckBox(text);
209 connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
210 return checkBox;
211}
212//! [7]
213
214//! [8]
215QRadioButton *ControllerWindow::createRadioButton(const QString &text)
216{
217 QRadioButton *button = new QRadioButton(text);
218 connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
219 return button;
220}
221//! [8]
Note: See TracBrowser for help on using the repository browser.