~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to examples/widgets/widgets/windowflags/controllerwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the examples of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:BSD$
 
9
** You may use this file under the terms of the BSD license as follows:
 
10
**
 
11
** "Redistribution and use in source and binary forms, with or without
 
12
** modification, are permitted provided that the following conditions are
 
13
** met:
 
14
**   * Redistributions of source code must retain the above copyright
 
15
**     notice, this list of conditions and the following disclaimer.
 
16
**   * Redistributions in binary form must reproduce the above copyright
 
17
**     notice, this list of conditions and the following disclaimer in
 
18
**     the documentation and/or other materials provided with the
 
19
**     distribution.
 
20
**   * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
 
21
**     of its contributors may be used to endorse or promote products derived
 
22
**     from this software without specific prior written permission.
 
23
**
 
24
**
 
25
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
26
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
27
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
28
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
29
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
30
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
31
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
32
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
33
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
34
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
35
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
 
36
**
 
37
** $QT_END_LICENSE$
 
38
**
 
39
****************************************************************************/
 
40
 
 
41
#include <QtWidgets>
 
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 (windowNoShadowCheckBox->isChecked())
 
103
        flags |= Qt::NoDropShadowWindowHint;
 
104
    if (windowTitleCheckBox->isChecked())
 
105
        flags |= Qt::WindowTitleHint;
 
106
    if (windowSystemMenuCheckBox->isChecked())
 
107
        flags |= Qt::WindowSystemMenuHint;
 
108
    if (windowMinimizeButtonCheckBox->isChecked())
 
109
        flags |= Qt::WindowMinimizeButtonHint;
 
110
    if (windowMaximizeButtonCheckBox->isChecked())
 
111
        flags |= Qt::WindowMaximizeButtonHint;
 
112
    if (windowCloseButtonCheckBox->isChecked())
 
113
        flags |= Qt::WindowCloseButtonHint;
 
114
    if (windowContextHelpButtonCheckBox->isChecked())
 
115
        flags |= Qt::WindowContextHelpButtonHint;
 
116
    if (windowShadeButtonCheckBox->isChecked())
 
117
        flags |= Qt::WindowShadeButtonHint;
 
118
    if (windowStaysOnTopCheckBox->isChecked())
 
119
        flags |= Qt::WindowStaysOnTopHint;
 
120
    if (windowStaysOnBottomCheckBox->isChecked())
 
121
        flags |= Qt::WindowStaysOnBottomHint;
 
122
    if (customizeWindowHintCheckBox->isChecked())
 
123
        flags |= Qt::CustomizeWindowHint;
 
124
 
 
125
    previewWindow->setWindowFlags(flags);
 
126
//! [3] //! [4]
 
127
 
 
128
    QPoint pos = previewWindow->pos();
 
129
    if (pos.x() < 0)
 
130
        pos.setX(0);
 
131
    if (pos.y() < 0)
 
132
        pos.setY(0);
 
133
    previewWindow->move(pos);
 
134
    previewWindow->show();
 
135
}
 
136
//! [4]
 
137
 
 
138
//! [5]
 
139
void ControllerWindow::createTypeGroupBox()
 
140
{
 
141
    typeGroupBox = new QGroupBox(tr("Type"));
 
142
 
 
143
    windowRadioButton = createRadioButton(tr("Window"));
 
144
    dialogRadioButton = createRadioButton(tr("Dialog"));
 
145
    sheetRadioButton = createRadioButton(tr("Sheet"));
 
146
    drawerRadioButton = createRadioButton(tr("Drawer"));
 
147
    popupRadioButton = createRadioButton(tr("Popup"));
 
148
    toolRadioButton = createRadioButton(tr("Tool"));
 
149
    toolTipRadioButton = createRadioButton(tr("Tooltip"));
 
150
    splashScreenRadioButton = createRadioButton(tr("Splash screen"));
 
151
    windowRadioButton->setChecked(true);
 
152
 
 
153
    QGridLayout *layout = new QGridLayout;
 
154
    layout->addWidget(windowRadioButton, 0, 0);
 
155
    layout->addWidget(dialogRadioButton, 1, 0);
 
156
    layout->addWidget(sheetRadioButton, 2, 0);
 
157
    layout->addWidget(drawerRadioButton, 3, 0);
 
158
    layout->addWidget(popupRadioButton, 0, 1);
 
159
    layout->addWidget(toolRadioButton, 1, 1);
 
160
    layout->addWidget(toolTipRadioButton, 2, 1);
 
161
    layout->addWidget(splashScreenRadioButton, 3, 1);
 
162
    typeGroupBox->setLayout(layout);
 
163
}
 
164
//! [5]
 
165
 
 
166
//! [6]
 
167
void ControllerWindow::createHintsGroupBox()
 
168
{
 
169
    hintsGroupBox = new QGroupBox(tr("Hints"));
 
170
 
 
171
    msWindowsFixedSizeDialogCheckBox =
 
172
            createCheckBox(tr("MS Windows fixed size dialog"));
 
173
    x11BypassWindowManagerCheckBox =
 
174
            createCheckBox(tr("X11 bypass window manager"));
 
175
    framelessWindowCheckBox = createCheckBox(tr("Frameless window"));
 
176
    windowNoShadowCheckBox = createCheckBox(tr("No drop shadow"));
 
177
    windowTitleCheckBox = createCheckBox(tr("Window title"));
 
178
    windowSystemMenuCheckBox = createCheckBox(tr("Window system menu"));
 
179
    windowMinimizeButtonCheckBox = createCheckBox(tr("Window minimize button"));
 
180
    windowMaximizeButtonCheckBox = createCheckBox(tr("Window maximize button"));
 
181
    windowCloseButtonCheckBox = createCheckBox(tr("Window close button"));
 
182
    windowContextHelpButtonCheckBox =
 
183
            createCheckBox(tr("Window context help button"));
 
184
    windowShadeButtonCheckBox = createCheckBox(tr("Window shade button"));
 
185
    windowStaysOnTopCheckBox = createCheckBox(tr("Window stays on top"));
 
186
    windowStaysOnBottomCheckBox = createCheckBox(tr("Window stays on bottom"));
 
187
    customizeWindowHintCheckBox= createCheckBox(tr("Customize window"));
 
188
 
 
189
    QGridLayout *layout = new QGridLayout;
 
190
    layout->addWidget(msWindowsFixedSizeDialogCheckBox, 0, 0);
 
191
    layout->addWidget(x11BypassWindowManagerCheckBox, 1, 0);
 
192
    layout->addWidget(framelessWindowCheckBox, 2, 0);
 
193
    layout->addWidget(windowNoShadowCheckBox, 3, 0);
 
194
    layout->addWidget(windowTitleCheckBox, 4, 0);
 
195
    layout->addWidget(windowSystemMenuCheckBox, 5, 0);
 
196
    layout->addWidget(customizeWindowHintCheckBox, 6, 0);
 
197
    layout->addWidget(windowMinimizeButtonCheckBox, 0, 1);
 
198
    layout->addWidget(windowMaximizeButtonCheckBox, 1, 1);
 
199
    layout->addWidget(windowCloseButtonCheckBox, 2, 1);
 
200
    layout->addWidget(windowContextHelpButtonCheckBox, 3, 1);
 
201
    layout->addWidget(windowShadeButtonCheckBox, 4, 1);
 
202
    layout->addWidget(windowStaysOnTopCheckBox, 5, 1);
 
203
    layout->addWidget(windowStaysOnBottomCheckBox, 6, 1);
 
204
    hintsGroupBox->setLayout(layout);
 
205
}
 
206
//! [6]
 
207
 
 
208
//! [7]
 
209
QCheckBox *ControllerWindow::createCheckBox(const QString &text)
 
210
{
 
211
    QCheckBox *checkBox = new QCheckBox(text);
 
212
    connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
 
213
    return checkBox;
 
214
}
 
215
//! [7]
 
216
 
 
217
//! [8]
 
218
QRadioButton *ControllerWindow::createRadioButton(const QString &text)
 
219
{
 
220
    QRadioButton *button = new QRadioButton(text);
 
221
    connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
 
222
    return button;
 
223
}
 
224
//! [8]