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

source code of qtbase/examples/widgets/widgets/windowflags/controllerwindow.cpp