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

« back to all changes in this revision

Viewing changes to tests/manual/windowflags/previewwindow.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:LGPL$
 
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 Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <QTextEdit>
 
43
#include <QPushButton>
 
44
#include <QVBoxLayout>
 
45
 
 
46
#include "previewwindow.h"
 
47
 
 
48
static QString windowFlagsToString(Qt::WindowFlags flags)
 
49
{
 
50
    QString text;
 
51
 
 
52
    Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
 
53
    if (type == Qt::Window) {
 
54
        text = "Qt::Window";
 
55
    } else if (type == Qt::Dialog) {
 
56
        text = "Qt::Dialog";
 
57
    } else if (type == Qt::Sheet) {
 
58
        text = "Qt::Sheet";
 
59
    } else if (type == Qt::Drawer) {
 
60
        text = "Qt::Drawer";
 
61
    } else if (type == Qt::Popup) {
 
62
        text = "Qt::Popup";
 
63
    } else if (type == Qt::Tool) {
 
64
        text = "Qt::Tool";
 
65
    } else if (type == Qt::ToolTip) {
 
66
        text = "Qt::ToolTip";
 
67
    } else if (type == Qt::SplashScreen) {
 
68
        text = "Qt::SplashScreen";
 
69
    }
 
70
 
 
71
    if (flags & Qt::MSWindowsFixedSizeDialogHint)
 
72
        text += "\n| Qt::MSWindowsFixedSizeDialogHint";
 
73
    if (flags & Qt::X11BypassWindowManagerHint)
 
74
        text += "\n| Qt::X11BypassWindowManagerHint";
 
75
    if (flags & Qt::FramelessWindowHint)
 
76
        text += "\n| Qt::FramelessWindowHint";
 
77
    if (flags & Qt::WindowTitleHint)
 
78
        text += "\n| Qt::WindowTitleHint";
 
79
    if (flags & Qt::WindowSystemMenuHint)
 
80
        text += "\n| Qt::WindowSystemMenuHint";
 
81
    if (flags & Qt::WindowMinimizeButtonHint)
 
82
        text += "\n| Qt::WindowMinimizeButtonHint";
 
83
    if (flags & Qt::WindowMaximizeButtonHint)
 
84
        text += "\n| Qt::WindowMaximizeButtonHint";
 
85
    if (flags & Qt::WindowCloseButtonHint)
 
86
        text += "\n| Qt::WindowCloseButtonHint";
 
87
    if (flags & Qt::WindowContextHelpButtonHint)
 
88
        text += "\n| Qt::WindowContextHelpButtonHint";
 
89
    if (flags & Qt::WindowShadeButtonHint)
 
90
        text += "\n| Qt::WindowShadeButtonHint";
 
91
    if (flags & Qt::WindowStaysOnTopHint)
 
92
        text += "\n| Qt::WindowStaysOnTopHint";
 
93
    if (flags & Qt::CustomizeWindowHint)
 
94
        text += "\n| Qt::CustomizeWindowHint";
 
95
    return text;
 
96
}
 
97
 
 
98
PreviewWindow::PreviewWindow(QWidget *parent)
 
99
    : QWidget(parent)
 
100
{
 
101
    textEdit = new QTextEdit;
 
102
    textEdit->setReadOnly(true);
 
103
    textEdit->setLineWrapMode(QTextEdit::NoWrap);
 
104
 
 
105
    closeButton = new QPushButton(tr("&Close"));
 
106
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
 
107
 
 
108
    showNormalButton = new QPushButton(tr("Show normal"));
 
109
    connect(showNormalButton, SIGNAL(clicked()), this, SLOT(showNormal()));
 
110
    showMinimizedButton = new QPushButton(tr("Show minimized"));
 
111
    connect(showMinimizedButton, SIGNAL(clicked()), this, SLOT(showMinimized()));
 
112
    showMaximizedButton = new QPushButton(tr("Show maximized"));
 
113
    connect(showMaximizedButton, SIGNAL(clicked()), this, SLOT(showMaximized()));
 
114
    showFullScreenButton = new QPushButton(tr("Show fullscreen"));
 
115
    connect(showFullScreenButton, SIGNAL(clicked()), this, SLOT(showFullScreen()));
 
116
 
 
117
    QVBoxLayout *layout = new QVBoxLayout;
 
118
    layout->addWidget(textEdit);
 
119
    layout->addWidget(showNormalButton);
 
120
    layout->addWidget(showMinimizedButton);
 
121
    layout->addWidget(showMaximizedButton);
 
122
    layout->addWidget(showFullScreenButton);
 
123
    layout->addWidget(closeButton);
 
124
    setLayout(layout);
 
125
 
 
126
    setWindowTitle(tr("Preview <QWidget>"));
 
127
}
 
128
 
 
129
void PreviewWindow::setWindowFlags(Qt::WindowFlags flags)
 
130
{
 
131
    QWidget::setWindowFlags(flags);
 
132
 
 
133
    QString text = windowFlagsToString(flags);
 
134
    textEdit->setPlainText(text);
 
135
}
 
136
 
 
137
PreviewDialog::PreviewDialog(QWidget *parent)
 
138
    : QDialog(parent)
 
139
{
 
140
    textEdit = new QTextEdit;
 
141
    textEdit->setReadOnly(true);
 
142
    textEdit->setLineWrapMode(QTextEdit::NoWrap);
 
143
 
 
144
    closeButton = new QPushButton(tr("&Close"));
 
145
    connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
 
146
 
 
147
    showNormalButton = new QPushButton(tr("Show normal"));
 
148
    connect(showNormalButton, SIGNAL(clicked()), this, SLOT(showNormal()));
 
149
    showMinimizedButton = new QPushButton(tr("Show minimized"));
 
150
    connect(showMinimizedButton, SIGNAL(clicked()), this, SLOT(showMinimized()));
 
151
    showMaximizedButton = new QPushButton(tr("Show maximized"));
 
152
    connect(showMaximizedButton, SIGNAL(clicked()), this, SLOT(showMaximized()));
 
153
    showFullScreenButton = new QPushButton(tr("Show fullscreen"));
 
154
    connect(showFullScreenButton, SIGNAL(clicked()), this, SLOT(showFullScreen()));
 
155
 
 
156
    QVBoxLayout *layout = new QVBoxLayout;
 
157
    layout->addWidget(textEdit);
 
158
    layout->addWidget(showNormalButton);
 
159
    layout->addWidget(showMinimizedButton);
 
160
    layout->addWidget(showMaximizedButton);
 
161
    layout->addWidget(showFullScreenButton);
 
162
    layout->addWidget(closeButton);
 
163
    setLayout(layout);
 
164
 
 
165
    setWindowTitle(tr("Preview <QDialog>"));
 
166
}
 
167
 
 
168
void PreviewDialog::setWindowFlags(Qt::WindowFlags flags)
 
169
{
 
170
    QWidget::setWindowFlags(flags);
 
171
 
 
172
    QString text = windowFlagsToString(flags);
 
173
    textEdit->setPlainText(text);
 
174
}