2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-04-27 10:05:43 +00:00
|
|
|
|
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
|
|
|
{
|
2019-11-11 13:03:37 +00:00
|
|
|
str << "Window flags: " << Qt::hex << Qt::showbase << unsigned(flags) << Qt::noshowbase
|
|
|
|
<< Qt::dec << ' ';
|
2016-11-16 11:34:00 +00:00
|
|
|
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 (flags & Qt::BypassWindowManagerHint)
|
|
|
|
str << "\n| Qt::BypassWindowManagerHint";
|
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 (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";
|
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
|
|
|
{
|
2019-11-11 13:03:37 +00:00
|
|
|
str << "Window states: " << Qt::hex << Qt::showbase << unsigned(states) << Qt::noshowbase
|
|
|
|
<< Qt::dec << ' ';
|
2016-11-16 11:34:00 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-11-11 13:03:37 +00:00
|
|
|
str << r.width() << 'x' << r.height() << Qt::forcesign << r.x() << r.y() << Qt::noforcesign;
|
2016-11-16 11:34:00 +00:00
|
|
|
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
|
|
|
}
|