2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-01-02 11:13:29 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the examples of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 09:34:08 +00:00
|
|
|
** GNU General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2012-01-24 06:17:24 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-07-11 13:12:26 +00:00
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QHBoxLayout>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "controllerwindow.h"
|
2012-04-20 11:54:52 +00:00
|
|
|
#include "controls.h"
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
//! [0]
|
2012-07-18 08:10:01 +00:00
|
|
|
ControllerWindow::ControllerWindow() : previewWidget(0)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
parentWindow = new QMainWindow;
|
|
|
|
parentWindow->setWindowTitle(tr("Preview parent window"));
|
|
|
|
QLabel *label = new QLabel(tr("Parent window"));
|
|
|
|
parentWindow->setCentralWidget(label);
|
|
|
|
|
|
|
|
previewWindow = new PreviewWindow;
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWindow->installEventFilter(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
previewDialog = new PreviewDialog;
|
2012-07-18 08:10:01 +00:00
|
|
|
previewDialog->installEventFilter(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
createTypeGroupBox();
|
|
|
|
|
|
|
|
quitButton = new QPushButton(tr("&Quit"));
|
|
|
|
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
|
|
|
|
|
|
|
|
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
|
|
|
bottomLayout->addStretch();
|
2012-07-18 08:10:01 +00:00
|
|
|
|
|
|
|
QPushButton *updateControlsButton = new QPushButton(tr("&Update"));
|
|
|
|
connect(updateControlsButton, SIGNAL(clicked()), this, SLOT(updateStateControl()));
|
|
|
|
|
|
|
|
bottomLayout->addWidget(updateControlsButton);
|
2011-04-27 10:05:43 +00:00
|
|
|
bottomLayout->addWidget(quitButton);
|
|
|
|
|
2012-04-20 11:54:52 +00:00
|
|
|
hintsControl = new HintControl;
|
|
|
|
hintsControl->setHints(previewWindow->windowFlags());
|
|
|
|
connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
|
|
|
|
2012-07-11 13:12:26 +00:00
|
|
|
statesControl = new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox|WindowStatesControl::WantActiveCheckBox);
|
2012-04-20 11:54:52 +00:00
|
|
|
statesControl->setStates(previewWindow->windowState());
|
|
|
|
statesControl->setVisibleValue(true);
|
|
|
|
connect(statesControl, SIGNAL(changed()), this, SLOT(updatePreview()));
|
|
|
|
|
|
|
|
typeControl = new TypeControl;
|
|
|
|
typeControl->setType(previewWindow->windowFlags());
|
|
|
|
connect(typeControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout;
|
|
|
|
mainLayout->addWidget(widgetTypeGroupBox);
|
|
|
|
mainLayout->addWidget(additionalOptionsGroupBox);
|
2012-04-20 11:54:52 +00:00
|
|
|
mainLayout->addWidget(typeControl);
|
|
|
|
mainLayout->addWidget(hintsControl);
|
|
|
|
mainLayout->addWidget(statesControl);
|
2011-04-27 10:05:43 +00:00
|
|
|
mainLayout->addLayout(bottomLayout);
|
|
|
|
setLayout(mainLayout);
|
|
|
|
|
2012-04-12 10:56:20 +00:00
|
|
|
setWindowTitle(tr("Window Flags (Qt version %1, %2)")
|
2012-07-11 13:12:26 +00:00
|
|
|
.arg(QLatin1String(qVersion()),
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
qApp->platformName()));
|
|
|
|
#else
|
|
|
|
QLatin1String("<unknown>")));
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
updatePreview();
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:10:01 +00:00
|
|
|
bool ControllerWindow::eventFilter(QObject *o, QEvent *e)
|
|
|
|
{
|
|
|
|
if (e->type() == QEvent::WindowStateChange)
|
|
|
|
updateStateControl();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerWindow::updateStateControl()
|
|
|
|
{
|
|
|
|
if (previewWidget)
|
|
|
|
statesControl->setStates(previewWidget->windowState());
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void ControllerWindow::updatePreview()
|
|
|
|
{
|
2012-04-20 11:54:52 +00:00
|
|
|
const Qt::WindowFlags flags = typeControl->type() | hintsControl->hints();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
previewWindow->hide();
|
|
|
|
previewDialog->hide();
|
2012-07-18 08:10:01 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
if (previewWidgetButton->isChecked())
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget = previewWindow;
|
2011-04-27 10:05:43 +00:00
|
|
|
else
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget = previewDialog;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (modalWindowCheckBox->isChecked()) {
|
|
|
|
parentWindow->show();
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget->setWindowModality(Qt::WindowModal);
|
|
|
|
previewWidget->setParent(parentWindow);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget->setWindowModality(Qt::NonModal);
|
|
|
|
previewWidget->setParent(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
parentWindow->hide();
|
|
|
|
}
|
|
|
|
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget->setWindowFlags(flags);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (fixedSizeWindowCheckBox->isChecked()) {
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget->setFixedSize(300, 300);
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget->setFixedSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-07-18 08:10:01 +00:00
|
|
|
QPoint pos = previewWidget->pos();
|
2011-04-27 10:05:43 +00:00
|
|
|
if (pos.x() < 0)
|
|
|
|
pos.setX(0);
|
|
|
|
if (pos.y() < 0)
|
|
|
|
pos.setY(0);
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget->move(pos);
|
2012-03-21 10:07:35 +00:00
|
|
|
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWidget->setWindowState(statesControl->states());
|
|
|
|
previewWidget->setVisible(statesControl->visibleValue());
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerWindow::createTypeGroupBox()
|
|
|
|
{
|
|
|
|
widgetTypeGroupBox = new QGroupBox(tr("Widget Type"));
|
|
|
|
previewWidgetButton = createRadioButton(tr("QWidget"));
|
|
|
|
previewWidgetButton->setChecked(true);
|
|
|
|
previewDialogButton = createRadioButton(tr("QDialog"));
|
|
|
|
QHBoxLayout *l = new QHBoxLayout;
|
|
|
|
l->addWidget(previewWidgetButton);
|
|
|
|
l->addWidget(previewDialogButton);
|
|
|
|
widgetTypeGroupBox->setLayout(l);
|
|
|
|
|
|
|
|
additionalOptionsGroupBox = new QGroupBox(tr("Additional options"));
|
|
|
|
l = new QHBoxLayout;
|
|
|
|
modalWindowCheckBox = createCheckBox(tr("Modal window"));
|
|
|
|
fixedSizeWindowCheckBox = createCheckBox(tr("Fixed size window"));
|
|
|
|
l->addWidget(modalWindowCheckBox);
|
|
|
|
l->addWidget(fixedSizeWindowCheckBox);
|
|
|
|
additionalOptionsGroupBox->setLayout(l);
|
|
|
|
}
|
|
|
|
//! [5]
|
|
|
|
|
|
|
|
//! [6]
|
|
|
|
|
|
|
|
//! [7]
|
|
|
|
QCheckBox *ControllerWindow::createCheckBox(const QString &text)
|
|
|
|
{
|
|
|
|
QCheckBox *checkBox = new QCheckBox(text);
|
|
|
|
connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
|
|
|
return checkBox;
|
|
|
|
}
|
|
|
|
//! [7]
|
|
|
|
|
|
|
|
//! [8]
|
|
|
|
QRadioButton *ControllerWindow::createRadioButton(const QString &text)
|
|
|
|
{
|
|
|
|
QRadioButton *button = new QRadioButton(text);
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
//! [8]
|