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 <QPlainTextEdit>
|
2012-07-11 13:12:26 +00:00
|
|
|
#include <QPushButton>
|
2016-11-16 11:34:00 +00:00
|
|
|
#include <QGridLayout>
|
2012-07-11 13:12:26 +00:00
|
|
|
#include <QVBoxLayout>
|
2016-11-16 11:34:00 +00:00
|
|
|
#include <QTextStream>
|
|
|
|
#include <QTimer>
|
2018-02-16 17:02:45 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QLinearGradient>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#include "previewwindow.h"
|
|
|
|
|
2018-02-16 17:02:45 +00:00
|
|
|
void PreviewWindow::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
QPainter painter(this);
|
|
|
|
QLinearGradient gradient(0, 0, width(), height());
|
|
|
|
gradient.setColorAt(0, QColor("#64b3f4"));
|
|
|
|
gradient.setColorAt(1, QColor("#c2e59c"));
|
|
|
|
painter.fillRect(QRect(0, 0, width(), height()), gradient);
|
|
|
|
}
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
static void formatWindowFlags(QTextStream &str, Qt::WindowFlags flags)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "Window flags: " << hex << showbase << unsigned(flags) << noshowbase << dec << ' ';
|
|
|
|
switch (flags & Qt::WindowType_Mask) {
|
|
|
|
case Qt::Window:
|
|
|
|
str << "Qt::Window";
|
|
|
|
break;
|
|
|
|
case Qt::Dialog:
|
|
|
|
str << "Qt::Dialog";
|
|
|
|
break;
|
|
|
|
case Qt::Sheet:
|
|
|
|
str << "Qt::Sheet";
|
|
|
|
break;
|
|
|
|
case Qt::Drawer:
|
|
|
|
str << "Qt::Drawer";
|
|
|
|
break;
|
|
|
|
case Qt::Popup:
|
|
|
|
str << "Qt::Popup";
|
|
|
|
break;
|
|
|
|
case Qt::Tool:
|
|
|
|
str << "Qt::Tool";
|
|
|
|
break;
|
|
|
|
case Qt::ToolTip:
|
|
|
|
str << "Qt::ToolTip";
|
|
|
|
break;
|
|
|
|
case Qt::SplashScreen:
|
|
|
|
str << "Qt::SplashScreen";
|
|
|
|
break;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & Qt::MSWindowsFixedSizeDialogHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::MSWindowsFixedSizeDialogHint";
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
if (flags & Qt::BypassWindowManagerHint)
|
|
|
|
str << "\n| Qt::BypassWindowManagerHint";
|
|
|
|
#else
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::X11BypassWindowManagerHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::X11BypassWindowManagerHint";
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::FramelessWindowHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::FramelessWindowHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowTitleHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowTitleHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowSystemMenuHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowSystemMenuHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowMinimizeButtonHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowMinimizeButtonHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowMaximizeButtonHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowMaximizeButtonHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowCloseButtonHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowCloseButtonHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowContextHelpButtonHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowContextHelpButtonHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowShadeButtonHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowShadeButtonHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::WindowStaysOnTopHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::WindowStaysOnTopHint";
|
2011-04-27 10:05:43 +00:00
|
|
|
if (flags & Qt::CustomizeWindowHint)
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "\n| Qt::CustomizeWindowHint";
|
|
|
|
if (flags & Qt::WindowStaysOnBottomHint)
|
|
|
|
str << "\n| Qt::WindowStaysOnBottomHint";
|
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
if (flags & Qt::WindowFullscreenButtonHint)
|
|
|
|
str << "\n| Qt::WindowFullscreenButtonHint";
|
|
|
|
if (flags & Qt::WindowTransparentForInput)
|
|
|
|
str << "\n| Qt::WindowTransparentForInput";
|
|
|
|
if (flags & Qt::WindowOverridesSystemGestures)
|
|
|
|
str << "\n| Qt::WindowOverridesSystemGestures";
|
|
|
|
if (flags & Qt::WindowDoesNotAcceptFocus)
|
|
|
|
str << "\n| Qt::WindowDoesNotAcceptFocus";
|
|
|
|
if (flags & Qt::MaximizeUsingFullscreenGeometryHint)
|
|
|
|
str << "\n| Qt::MaximizeUsingFullscreenGeometryHint";
|
|
|
|
if (flags & Qt::NoDropShadowWindowHint)
|
|
|
|
str << "\n| Qt::NoDropShadowWindowHint";
|
|
|
|
#endif // Qt 5
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
static void formatWindowStates(QTextStream &str, Qt::WindowStates states)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2016-11-16 11:34:00 +00:00
|
|
|
str << "Window states: " << hex << showbase << unsigned(states) << noshowbase << dec << ' ';
|
|
|
|
if (states & Qt::WindowActive) {
|
|
|
|
str << "Qt::WindowActive ";
|
|
|
|
states &= ~Qt::WindowActive;
|
|
|
|
}
|
|
|
|
switch (states) {
|
|
|
|
case Qt::WindowNoState:
|
|
|
|
str << "Qt::WindowNoState";
|
|
|
|
break;
|
|
|
|
case Qt::WindowMinimized:
|
|
|
|
str << "Qt::WindowMinimized";
|
|
|
|
break;
|
|
|
|
case Qt::WindowMaximized:
|
|
|
|
str << "Qt::WindowMaximized";
|
|
|
|
break;
|
|
|
|
case Qt::WindowFullScreen:
|
|
|
|
str << "Qt::WindowFullScreen";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
QTextStream &operator<<(QTextStream &str, const QRect &r)
|
|
|
|
{
|
|
|
|
str << r.width() << 'x' << r.height() << forcesign << r.x() << r.y() << noforcesign;
|
|
|
|
return str;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
static QString formatWidgetInfo(const QWidget *w)
|
|
|
|
{
|
|
|
|
QString result;
|
|
|
|
QTextStream str(&result);
|
|
|
|
formatWindowFlags(str, w->windowFlags());
|
|
|
|
str << '\n';
|
|
|
|
formatWindowStates(str, w->windowState());
|
|
|
|
const QRect frame = w->frameGeometry();
|
|
|
|
const QRect geometry = w->geometry();
|
|
|
|
str << "\n\nFrame: " << frame << "\nGeometry: " << geometry << "\nMargins: "
|
|
|
|
<< (geometry.x() - frame.x()) << ", " << (geometry.top() - frame.top())
|
|
|
|
<< ", " << (frame.right() - geometry.right()) << ", "
|
|
|
|
<< (frame.bottom() - geometry.bottom());
|
|
|
|
return result;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
static QPlainTextEdit *createControlPanel(QWidget *widget)
|
|
|
|
{
|
|
|
|
QVBoxLayout *layout = new QVBoxLayout(widget);
|
|
|
|
QPlainTextEdit *textEdit = new QPlainTextEdit;
|
|
|
|
textEdit->setReadOnly(true);
|
|
|
|
textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
|
2011-04-27 10:05:43 +00:00
|
|
|
layout->addWidget(textEdit);
|
2016-11-16 11:34:00 +00:00
|
|
|
|
|
|
|
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
|
|
|
layout ->addLayout(bottomLayout);
|
|
|
|
QGridLayout *buttonLayout = new QGridLayout;
|
|
|
|
bottomLayout->addStretch();
|
|
|
|
bottomLayout->addLayout(buttonLayout);
|
2017-06-22 13:43:31 +00:00
|
|
|
QPushButton *showNormalButton = new QPushButton(PreviewWidget::tr("Show normal"));
|
2016-11-16 11:34:00 +00:00
|
|
|
QObject::connect(showNormalButton, SIGNAL(clicked()), widget, SLOT(showNormal()));
|
|
|
|
buttonLayout->addWidget(showNormalButton, 0, 0);
|
2017-06-22 13:43:31 +00:00
|
|
|
QPushButton *showMinimizedButton = new QPushButton(PreviewWidget::tr("Show minimized"));
|
2016-11-16 11:34:00 +00:00
|
|
|
QObject::connect(showMinimizedButton, SIGNAL(clicked()), widget, SLOT(showMinimized()));
|
|
|
|
buttonLayout->addWidget(showMinimizedButton, 0, 1);
|
2017-06-22 13:43:31 +00:00
|
|
|
QPushButton *showMaximizedButton = new QPushButton(PreviewWidget::tr("Show maximized"));
|
2016-11-16 11:34:00 +00:00
|
|
|
QObject::connect(showMaximizedButton, SIGNAL(clicked()), widget, SLOT(showMaximized()));
|
|
|
|
buttonLayout->addWidget(showMaximizedButton, 0, 2);
|
2017-06-22 13:43:31 +00:00
|
|
|
QPushButton *showFullScreenButton = new QPushButton(PreviewWidget::tr("Show fullscreen"));
|
2016-11-16 11:34:00 +00:00
|
|
|
QObject::connect(showFullScreenButton, SIGNAL(clicked()), widget, SLOT(showFullScreen()));
|
|
|
|
buttonLayout->addWidget(showFullScreenButton, 0, 3);
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
QPushButton *updateInfoButton = new QPushButton(PreviewWidget::tr("&Update Info"));
|
2016-11-16 11:34:00 +00:00
|
|
|
QObject::connect(updateInfoButton, SIGNAL(clicked()), widget, SLOT(updateInfo()));
|
|
|
|
buttonLayout->addWidget(updateInfoButton, 1, 0);
|
2017-06-22 13:43:31 +00:00
|
|
|
QPushButton *closeButton = new QPushButton(PreviewWidget::tr("&Close"));
|
2016-11-16 11:34:00 +00:00
|
|
|
QObject::connect(closeButton, SIGNAL(clicked()), widget, SLOT(close()));
|
|
|
|
buttonLayout->addWidget(closeButton, 1, 3);
|
|
|
|
|
|
|
|
return textEdit;
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
PreviewWidget::PreviewWidget(QWidget *parent)
|
2016-11-16 11:34:00 +00:00
|
|
|
: QWidget(parent)
|
|
|
|
{
|
|
|
|
textEdit = createControlPanel(this);
|
|
|
|
setWindowTitle(tr("Preview <QWidget> Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
|
|
|
}
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
bool PreviewWidget::event(QEvent *event)
|
2016-11-16 11:34:00 +00:00
|
|
|
{
|
2017-02-17 14:33:46 +00:00
|
|
|
const bool ret = QWidget::event(event);
|
2016-11-16 11:34:00 +00:00
|
|
|
|
2017-02-17 14:33:46 +00:00
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::Resize:
|
|
|
|
case QEvent::WindowStateChange:
|
|
|
|
updateInfo();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
void PreviewWidget::setWindowFlags(Qt::WindowFlags flags)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2016-11-16 11:34:00 +00:00
|
|
|
if (flags == windowFlags())
|
|
|
|
return;
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget::setWindowFlags(flags);
|
2016-11-16 11:34:00 +00:00
|
|
|
QTimer::singleShot(0, this, SLOT(updateInfo()));
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-06-22 13:43:31 +00:00
|
|
|
void PreviewWidget::updateInfo()
|
2016-11-16 11:34:00 +00:00
|
|
|
{
|
|
|
|
textEdit->setPlainText(formatWidgetInfo(this));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PreviewDialog::PreviewDialog(QWidget *parent)
|
|
|
|
: QDialog(parent)
|
|
|
|
{
|
2016-11-16 11:34:00 +00:00
|
|
|
textEdit = createControlPanel(this);
|
|
|
|
setWindowTitle(tr("Preview <QDialog> Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-02-17 14:33:46 +00:00
|
|
|
bool PreviewDialog::event(QEvent *event)
|
2016-11-16 11:34:00 +00:00
|
|
|
{
|
2017-02-17 14:33:46 +00:00
|
|
|
const bool ret = QDialog::event(event);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2017-02-17 14:33:46 +00:00
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::Move:
|
|
|
|
case QEvent::Resize:
|
|
|
|
case QEvent::WindowStateChange:
|
|
|
|
updateInfo();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PreviewDialog::setWindowFlags(Qt::WindowFlags flags)
|
|
|
|
{
|
2016-11-16 11:34:00 +00:00
|
|
|
if (flags == windowFlags())
|
|
|
|
return;
|
2011-04-27 10:05:43 +00:00
|
|
|
QWidget::setWindowFlags(flags);
|
2016-11-16 11:34:00 +00:00
|
|
|
QTimer::singleShot(0, this, SLOT(updateInfo()));
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-11-16 11:34:00 +00:00
|
|
|
void PreviewDialog::updateInfo()
|
|
|
|
{
|
|
|
|
textEdit->setPlainText(formatWidgetInfo(this));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|