2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2013-05-24 13:49:24 +00:00
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
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
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
#include "controllerwindow.h"
|
|
|
|
#include "controls.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QApplication>
|
2012-07-11 13:12:26 +00:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QHBoxLayout>
|
2016-11-16 11:34:00 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QMainWindow>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QRadioButton>
|
|
|
|
#include <QTabWidget>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
#include <QMoveEvent>
|
|
|
|
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
# include <QWindow>
|
|
|
|
# include <qlogging.h>
|
|
|
|
# include <QLibraryInfo>
|
|
|
|
#endif
|
|
|
|
#include <QDebug>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
ControllerWidget::ControllerWidget(QWidget *parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, 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);
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
previewWindow = new QWindow;
|
2012-07-18 08:10:01 +00:00
|
|
|
previewWindow->installEventFilter(this);
|
2017-06-22 13:43:31 +00:00
|
|
|
previewWidget = new PreviewWidget;
|
|
|
|
previewWidget->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();
|
|
|
|
|
2012-04-20 11:54:52 +00:00
|
|
|
hintsControl = new HintControl;
|
2017-06-22 13:43:31 +00:00
|
|
|
hintsControl->setHints(previewWidget->windowFlags());
|
2012-04-20 11:54:52 +00:00
|
|
|
connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
|
|
|
|
2017-02-03 14:55:49 +00:00
|
|
|
statesControl = new WindowStatesControl;
|
2017-06-22 13:43:31 +00:00
|
|
|
statesControl->setStates(previewWidget->windowState());
|
2012-04-20 11:54:52 +00:00
|
|
|
statesControl->setVisibleValue(true);
|
|
|
|
connect(statesControl, SIGNAL(changed()), this, SLOT(updatePreview()));
|
|
|
|
|
|
|
|
typeControl = new TypeControl;
|
2017-06-22 13:43:31 +00:00
|
|
|
typeControl->setType(previewWidget->windowFlags());
|
2012-04-20 11:54:52 +00:00
|
|
|
connect(typeControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
2011-04-27 10:05:43 +00:00
|
|
|
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
|
|
|
|
|
|
|
updatePreview();
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
bool ControllerWidget::eventFilter(QObject *, QEvent *e)
|
2012-07-18 08:10:01 +00:00
|
|
|
{
|
|
|
|
if (e->type() == QEvent::WindowStateChange)
|
|
|
|
updateStateControl();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
void ControllerWidget::updateStateControl()
|
2012-07-18 08:10:01 +00:00
|
|
|
{
|
2017-06-22 13:43:31 +00:00
|
|
|
if (activePreview)
|
|
|
|
statesControl->setStates(activePreview->windowStates());
|
2012-07-18 08:10:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
void ControllerWidget::updatePreview(QWindow *preview)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2017-06-22 13:43:31 +00:00
|
|
|
activePreview = preview;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
const Qt::WindowFlags flags = typeControl->type() | hintsControl->hints();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (modalWindowCheckBox->isChecked()) {
|
|
|
|
parentWindow->show();
|
2017-06-22 13:43:31 +00:00
|
|
|
preview->setModality(Qt::WindowModal);
|
|
|
|
preview->setParent(parentWindow->windowHandle());
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2017-06-22 13:43:31 +00:00
|
|
|
preview->setModality(Qt::NonModal);
|
|
|
|
preview->setParent(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
parentWindow->hide();
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
preview->setFlags(flags);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (fixedSizeWindowCheckBox->isChecked()) {
|
2018-02-16 17:06:06 +00:00
|
|
|
preview->setMinimumSize(preview->size());
|
|
|
|
preview->setMaximumSize(preview->size());
|
2011-04-27 10:05:43 +00:00
|
|
|
} else {
|
2017-06-22 13:43:31 +00:00
|
|
|
preview->setMinimumSize(QSize(0, 0));
|
|
|
|
preview->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
preview->setWindowStates(statesControl->states());
|
|
|
|
preview->setVisible(statesControl->visibleValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerWidget::updatePreview(QWidget *preview)
|
|
|
|
{
|
|
|
|
activePreview = preview->windowHandle();
|
|
|
|
|
|
|
|
const Qt::WindowFlags flags = typeControl->type() | hintsControl->hints();
|
|
|
|
|
|
|
|
if (modalWindowCheckBox->isChecked()) {
|
|
|
|
parentWindow->show();
|
|
|
|
preview->setWindowModality(Qt::WindowModal);
|
|
|
|
preview->setParent(parentWindow);
|
|
|
|
} else {
|
|
|
|
preview->setWindowModality(Qt::NonModal);
|
|
|
|
preview->setParent(0);
|
|
|
|
parentWindow->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
preview->setWindowFlags(flags);
|
|
|
|
|
|
|
|
QSize fixedSize = fixedSizeWindowCheckBox->isChecked() ?
|
2018-02-16 17:06:06 +00:00
|
|
|
preview->size() : QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
|
2017-06-22 13:43:31 +00:00
|
|
|
preview->setFixedSize(fixedSize);
|
|
|
|
|
|
|
|
QPoint pos = preview->pos();
|
2011-04-27 10:05:43 +00:00
|
|
|
if (pos.x() < 0)
|
|
|
|
pos.setX(0);
|
|
|
|
if (pos.y() < 0)
|
|
|
|
pos.setY(0);
|
2017-06-22 13:43:31 +00:00
|
|
|
preview->move(pos);
|
|
|
|
|
|
|
|
preview->setWindowState(statesControl->states());
|
|
|
|
preview->setVisible(statesControl->visibleValue());
|
|
|
|
}
|
2012-03-21 10:07:35 +00:00
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
void ControllerWidget::updatePreview()
|
|
|
|
{
|
|
|
|
if (previewWindowButton->isChecked()) {
|
|
|
|
previewDialog->hide();
|
|
|
|
previewWidget->close();
|
|
|
|
updatePreview(previewWindow);
|
|
|
|
} else if (previewWidgetButton->isChecked()) {
|
|
|
|
previewWindow->hide();
|
|
|
|
previewDialog->hide();
|
|
|
|
updatePreview(previewWidget);
|
|
|
|
} else {
|
|
|
|
previewWindow->hide();
|
|
|
|
previewWidget->close();
|
|
|
|
updatePreview(previewDialog);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
void ControllerWidget::createTypeGroupBox()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2017-06-22 13:43:31 +00:00
|
|
|
widgetTypeGroupBox = new QGroupBox(tr("Window Type"));
|
|
|
|
previewWindowButton = createRadioButton(tr("QWindow"));
|
2011-04-27 10:05:43 +00:00
|
|
|
previewWidgetButton = createRadioButton(tr("QWidget"));
|
|
|
|
previewDialogButton = createRadioButton(tr("QDialog"));
|
2017-06-22 13:43:31 +00:00
|
|
|
previewWindowButton->setChecked(true);
|
2011-04-27 10:05:43 +00:00
|
|
|
QHBoxLayout *l = new QHBoxLayout;
|
2017-06-22 13:43:31 +00:00
|
|
|
l->addWidget(previewWindowButton);
|
2011-04-27 10:05:43 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
QCheckBox *ControllerWidget::createCheckBox(const QString &text)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QCheckBox *checkBox = new QCheckBox(text);
|
|
|
|
connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
|
|
|
return checkBox;
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
QRadioButton *ControllerWidget::createRadioButton(const QString &text)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QRadioButton *button = new QRadioButton(text);
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
|
|
|
|
return button;
|
|
|
|
}
|
2016-11-16 11:34:00 +00:00
|
|
|
|
|
|
|
static bool isTopLevel(const QObject *o)
|
|
|
|
{
|
|
|
|
if (o->isWidgetType())
|
|
|
|
return static_cast<const QWidget *>(o)->isWindow();
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
if (o->isWindowType())
|
|
|
|
return static_cast<const QWindow *>(o)->isTopLevel();
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-17 14:22:47 +00:00
|
|
|
static Qt::WindowStates windowState(const QObject *o)
|
2016-11-16 11:34:00 +00:00
|
|
|
{
|
|
|
|
if (o->isWidgetType()) {
|
|
|
|
Qt::WindowStates states = static_cast<const QWidget *>(o)->windowState();
|
|
|
|
states &= ~Qt::WindowActive;
|
2017-02-17 14:22:47 +00:00
|
|
|
return states;
|
2016-11-16 11:34:00 +00:00
|
|
|
}
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
if (o->isWindowType())
|
|
|
|
return static_cast<const QWindow *>(o)->windowState();
|
|
|
|
#endif
|
|
|
|
return Qt::WindowNoState;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EventFilter : public QObject {
|
|
|
|
public:
|
|
|
|
explicit EventFilter(QObject *parent = 0) : QObject(parent) {}
|
|
|
|
|
|
|
|
bool eventFilter(QObject *o, QEvent *e)
|
|
|
|
{
|
|
|
|
switch (e->type()) {
|
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::Resize:
|
|
|
|
case QEvent::WindowStateChange:
|
|
|
|
case QEvent::ApplicationActivate:
|
|
|
|
case QEvent::ApplicationDeactivate:
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
case QEvent::ApplicationStateChange:
|
|
|
|
#endif
|
|
|
|
if (isTopLevel(o))
|
|
|
|
formatEvent(o, e);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QObject::eventFilter(o ,e);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void formatEvent(QObject *o, QEvent *e)
|
|
|
|
{
|
|
|
|
static int n = 0;
|
|
|
|
QDebug debug = qDebug().nospace();
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
debug.noquote();
|
|
|
|
#endif
|
|
|
|
debug << '#' << n++ << ' ' << o->metaObject()->className();
|
|
|
|
const QString name = o->objectName();
|
|
|
|
if (!name.isEmpty())
|
|
|
|
debug << "/\"" << name << '"';
|
|
|
|
debug << ' ' << e;
|
|
|
|
if (e->type() == QEvent::WindowStateChange)
|
|
|
|
debug << ' ' << windowState(o);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
LogWidget *LogWidget::m_instance = 0;
|
|
|
|
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
static void qt5MessageHandler(QtMsgType, const QMessageLogContext &, const QString &text)
|
|
|
|
{
|
|
|
|
if (LogWidget *lw = LogWidget::instance())
|
|
|
|
lw->appendText(text);
|
|
|
|
}
|
|
|
|
#else // Qt 5
|
|
|
|
static void qt4MessageHandler(QtMsgType, const char *text)
|
|
|
|
{
|
|
|
|
if (LogWidget *lw = LogWidget::instance())
|
|
|
|
lw->appendText(QString::fromLocal8Bit(text));
|
|
|
|
}
|
|
|
|
#endif // Qt 4
|
|
|
|
|
|
|
|
LogWidget::LogWidget(QWidget *parent)
|
|
|
|
: QPlainTextEdit(parent)
|
|
|
|
{
|
|
|
|
LogWidget::m_instance = this;
|
|
|
|
setReadOnly(true);
|
|
|
|
appendText(startupMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
LogWidget::~LogWidget()
|
|
|
|
{
|
|
|
|
LogWidget::m_instance = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogWidget::install()
|
|
|
|
{
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
qInstallMessageHandler(qt5MessageHandler);
|
|
|
|
#else
|
|
|
|
qInstallMsgHandler(qt4MessageHandler);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
QString LogWidget::startupMessage()
|
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
#if QT_VERSION >= 0x050300
|
|
|
|
result += QLatin1String(QLibraryInfo::build());
|
|
|
|
#else
|
|
|
|
result += QLatin1String("Qt ") + QLatin1String(QT_VERSION_STR);
|
|
|
|
#endif
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
result += QLatin1Char(' ');
|
|
|
|
result += QGuiApplication::platformName();
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogWidget::appendText(const QString &message)
|
|
|
|
{
|
|
|
|
appendPlainText(message);
|
|
|
|
ensureCursorVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
ControllerWindow::ControllerWindow()
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Window Flags (Qt version %1, %2)")
|
|
|
|
.arg(QLatin1String(qVersion()),
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
qApp->platformName()));
|
|
|
|
#else
|
|
|
|
QLatin1String("<unknown>")));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
|
|
|
QTabWidget *tabWidget = new QTabWidget(this);
|
|
|
|
ControllerWidget *controllerWidget = new ControllerWidget(tabWidget);
|
|
|
|
tabWidget->addTab(controllerWidget, tr("Control"));
|
|
|
|
LogWidget *logWidget = new LogWidget(tabWidget);
|
|
|
|
tabWidget->addTab(logWidget, tr("Event log"));
|
|
|
|
layout->addWidget(tabWidget);
|
|
|
|
|
|
|
|
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
|
|
|
layout->addLayout(bottomLayout);
|
|
|
|
bottomLayout->addStretch();
|
|
|
|
QPushButton *updateControlsButton = new QPushButton(tr("&Update"));
|
|
|
|
connect(updateControlsButton, SIGNAL(clicked()), controllerWidget, SLOT(updateStateControl()));
|
|
|
|
bottomLayout->addWidget(updateControlsButton);
|
|
|
|
QPushButton *clearLogButton = new QPushButton(tr("Clear &Log"));
|
|
|
|
connect(clearLogButton, SIGNAL(clicked()), logWidget, SLOT(clear()));
|
|
|
|
bottomLayout->addWidget(clearLogButton);
|
|
|
|
QPushButton *quitButton = new QPushButton(tr("&Quit"));
|
|
|
|
connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
|
|
|
|
quitButton->setShortcut(Qt::CTRL + Qt::Key_Q);
|
|
|
|
bottomLayout->addWidget(quitButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ControllerWindow::registerEventFilter()
|
|
|
|
{
|
|
|
|
qApp->installEventFilter(new EventFilter(qApp));
|
|
|
|
}
|