tests/manual/windowflags/previewwindow.cpp
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the examples of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include <QtGui>
       
    43 
       
    44 #include "previewwindow.h"
       
    45 
       
    46 static QString windowFlagsToString(Qt::WindowFlags flags)
       
    47 {
       
    48     QString text;
       
    49 
       
    50     Qt::WindowFlags type = (flags & Qt::WindowType_Mask);
       
    51     if (type == Qt::Window) {
       
    52         text = "Qt::Window";
       
    53     } else if (type == Qt::Dialog) {
       
    54         text = "Qt::Dialog";
       
    55     } else if (type == Qt::Sheet) {
       
    56         text = "Qt::Sheet";
       
    57     } else if (type == Qt::Drawer) {
       
    58         text = "Qt::Drawer";
       
    59     } else if (type == Qt::Popup) {
       
    60         text = "Qt::Popup";
       
    61     } else if (type == Qt::Tool) {
       
    62         text = "Qt::Tool";
       
    63     } else if (type == Qt::ToolTip) {
       
    64         text = "Qt::ToolTip";
       
    65     } else if (type == Qt::SplashScreen) {
       
    66         text = "Qt::SplashScreen";
       
    67     }
       
    68 
       
    69     if (flags & Qt::MSWindowsFixedSizeDialogHint)
       
    70         text += "\n| Qt::MSWindowsFixedSizeDialogHint";
       
    71     if (flags & Qt::X11BypassWindowManagerHint)
       
    72         text += "\n| Qt::X11BypassWindowManagerHint";
       
    73     if (flags & Qt::FramelessWindowHint)
       
    74         text += "\n| Qt::FramelessWindowHint";
       
    75     if (flags & Qt::WindowTitleHint)
       
    76         text += "\n| Qt::WindowTitleHint";
       
    77     if (flags & Qt::WindowSystemMenuHint)
       
    78         text += "\n| Qt::WindowSystemMenuHint";
       
    79     if (flags & Qt::WindowMinimizeButtonHint)
       
    80         text += "\n| Qt::WindowMinimizeButtonHint";
       
    81     if (flags & Qt::WindowMaximizeButtonHint)
       
    82         text += "\n| Qt::WindowMaximizeButtonHint";
       
    83     if (flags & Qt::WindowCloseButtonHint)
       
    84         text += "\n| Qt::WindowCloseButtonHint";
       
    85     if (flags & Qt::WindowContextHelpButtonHint)
       
    86         text += "\n| Qt::WindowContextHelpButtonHint";
       
    87     if (flags & Qt::WindowShadeButtonHint)
       
    88         text += "\n| Qt::WindowShadeButtonHint";
       
    89     if (flags & Qt::WindowStaysOnTopHint)
       
    90         text += "\n| Qt::WindowStaysOnTopHint";
       
    91     if (flags & Qt::CustomizeWindowHint)
       
    92         text += "\n| Qt::CustomizeWindowHint";
       
    93     return text;
       
    94 }
       
    95 
       
    96 PreviewWindow::PreviewWindow(QWidget *parent)
       
    97     : QWidget(parent)
       
    98 {
       
    99     textEdit = new QTextEdit;
       
   100     textEdit->setReadOnly(true);
       
   101     textEdit->setLineWrapMode(QTextEdit::NoWrap);
       
   102 
       
   103     closeButton = new QPushButton(tr("&Close"));
       
   104     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
       
   105 
       
   106     QVBoxLayout *layout = new QVBoxLayout;
       
   107     layout->addWidget(textEdit);
       
   108     layout->addWidget(closeButton);
       
   109     setLayout(layout);
       
   110 
       
   111     setWindowTitle(tr("Preview <QWidget>"));
       
   112 }
       
   113 
       
   114 void PreviewWindow::setWindowFlags(Qt::WindowFlags flags)
       
   115 {
       
   116     QWidget::setWindowFlags(flags);
       
   117 
       
   118     QString text = windowFlagsToString(flags);
       
   119     textEdit->setPlainText(text);
       
   120 }
       
   121 
       
   122 PreviewDialog::PreviewDialog(QWidget *parent)
       
   123     : QDialog(parent)
       
   124 {
       
   125     textEdit = new QTextEdit;
       
   126     textEdit->setReadOnly(true);
       
   127     textEdit->setLineWrapMode(QTextEdit::NoWrap);
       
   128 
       
   129     closeButton = new QPushButton(tr("&Close"));
       
   130     connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
       
   131 
       
   132     QVBoxLayout *layout = new QVBoxLayout;
       
   133     layout->addWidget(textEdit);
       
   134     layout->addWidget(closeButton);
       
   135     setLayout(layout);
       
   136 
       
   137     setWindowTitle(tr("Preview <QDialog>"));
       
   138 }
       
   139 
       
   140 void PreviewDialog::setWindowFlags(Qt::WindowFlags flags)
       
   141 {
       
   142     QWidget::setWindowFlags(flags);
       
   143 
       
   144     QString text = windowFlagsToString(flags);
       
   145     textEdit->setPlainText(text);
       
   146 }