examples/widgets/windowflags/controllerwindow.cpp
changeset 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
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 "controllerwindow.h"
       
    45 
       
    46 //! [0]
       
    47 ControllerWindow::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]
       
    73 void 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]
       
   138 void 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]
       
   166 void 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]
       
   206 QCheckBox *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]
       
   215 QRadioButton *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]