The hint requests that the window's client area is expanded to fill parts of the window that might be (partially) covered by, or conflicting with, other (system) UI elements, such as the window's title bar, resize controls, or a status bar. The safe area margins of the window will reflect any areas that may have conflicting UI elements. If the client area is expanded into the area previously covered by the frame margins, the frame margins are reduced accordingly, as the frame margins represent the non-client-area parts of the window. This new flag replaces, and overlaps in value, with the existing Qt::MaximizeUsingFullscreenGeometryHint, as the latter was added to cover this exact use-case for mobile platforms. Now that we have the use-case on desktop platforms as well we want to use a more generic flag, so the old flag has been deprecated. Semantically, on iOS and Android, without the flags set, the window can be seen as being maximized to take up the entire screen, but with a frameMargin() that reflects the system status bar and resize controls. That's not technically how we implement things right now, but this is an implementation detail that will be changed in a follow-up. On macOS the flag maps to NSWindowStyleMaskFullSizeContentView, and on Windows we have an implementation cooking that uses the DwmExtendFrameIntoClientArea function. Task-number: QTBUG-127634 Change-Id: I9b6863b1550ccc056c16bce235d87b26a7d239b9 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
265 lines
8.3 KiB
C++
265 lines
8.3 KiB
C++
// Copyright (C) 2021 The Qt Company Ltd.
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
|
|
|
#include <QPlainTextEdit>
|
|
#include <QPushButton>
|
|
#include <QGridLayout>
|
|
#include <QVBoxLayout>
|
|
#include <QTextStream>
|
|
#include <QTimer>
|
|
#include <QPainter>
|
|
#include <QLinearGradient>
|
|
|
|
#include <QtGui/qpa/qplatformwindow.h>
|
|
|
|
#include "previewwindow.h"
|
|
|
|
PreviewWindow::PreviewWindow(QWindow *parent)
|
|
: QRasterWindow(parent)
|
|
{
|
|
setTitle(tr("Preview <QWindow> Qt %1").arg(QLatin1StringView(QT_VERSION_STR)));
|
|
resize(400, 400);
|
|
}
|
|
|
|
void PreviewWindow::paintEvent(QPaintEvent *event)
|
|
{
|
|
QPainter painter(this);
|
|
QRect rect(0, 0, width(), height());
|
|
if (m_visualizeSafeAreas) {
|
|
painter.fillRect(rect, QGradient::WarmFlame);
|
|
QMargins safeAreaMargins = handle()->safeAreaMargins();
|
|
rect.adjust(safeAreaMargins.left(), safeAreaMargins.top(),
|
|
safeAreaMargins.right(), safeAreaMargins.bottom());
|
|
}
|
|
painter.fillRect(rect, QGradient::DustyGrass);
|
|
}
|
|
|
|
static void formatWindowFlags(QTextStream &str, Qt::WindowFlags flags)
|
|
{
|
|
str << "Window flags: " << Qt::hex << Qt::showbase << unsigned(flags) << Qt::noshowbase
|
|
<< Qt::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;
|
|
}
|
|
|
|
if (flags & Qt::MSWindowsFixedSizeDialogHint)
|
|
str << "\n| Qt::MSWindowsFixedSizeDialogHint";
|
|
if (flags & Qt::BypassWindowManagerHint)
|
|
str << "\n| Qt::BypassWindowManagerHint";
|
|
if (flags & Qt::FramelessWindowHint)
|
|
str << "\n| Qt::FramelessWindowHint";
|
|
if (flags & Qt::WindowTitleHint)
|
|
str << "\n| Qt::WindowTitleHint";
|
|
if (flags & Qt::WindowSystemMenuHint)
|
|
str << "\n| Qt::WindowSystemMenuHint";
|
|
if (flags & Qt::WindowMinimizeButtonHint)
|
|
str << "\n| Qt::WindowMinimizeButtonHint";
|
|
if (flags & Qt::WindowMaximizeButtonHint)
|
|
str << "\n| Qt::WindowMaximizeButtonHint";
|
|
if (flags & Qt::WindowCloseButtonHint)
|
|
str << "\n| Qt::WindowCloseButtonHint";
|
|
if (flags & Qt::WindowContextHelpButtonHint)
|
|
str << "\n| Qt::WindowContextHelpButtonHint";
|
|
if (flags & Qt::WindowShadeButtonHint)
|
|
str << "\n| Qt::WindowShadeButtonHint";
|
|
if (flags & Qt::WindowStaysOnTopHint)
|
|
str << "\n| Qt::WindowStaysOnTopHint";
|
|
if (flags & Qt::CustomizeWindowHint)
|
|
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::ExpandedClientAreaHint)
|
|
str << "\n| Qt::ExpandedClientAreaHint";
|
|
if (flags & Qt::NoDropShadowWindowHint)
|
|
str << "\n| Qt::NoDropShadowWindowHint";
|
|
}
|
|
|
|
static void formatWindowStates(QTextStream &str, Qt::WindowStates states)
|
|
{
|
|
str << "Window states: " << Qt::hex << Qt::showbase << unsigned(states) << Qt::noshowbase
|
|
<< Qt::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;
|
|
}
|
|
}
|
|
|
|
QTextStream &operator<<(QTextStream &str, const QRect &r)
|
|
{
|
|
str << r.width() << 'x' << r.height() << Qt::forcesign << r.x() << r.y() << Qt::noforcesign;
|
|
return str;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
static QPlainTextEdit *createControlPanel(QWidget *widget)
|
|
{
|
|
QVBoxLayout *layout = new QVBoxLayout(widget);
|
|
QPlainTextEdit *textEdit = new QPlainTextEdit;
|
|
textEdit->setReadOnly(true);
|
|
textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
|
|
layout->addWidget(textEdit);
|
|
|
|
QHBoxLayout *bottomLayout = new QHBoxLayout;
|
|
layout ->addLayout(bottomLayout);
|
|
QGridLayout *buttonLayout = new QGridLayout;
|
|
bottomLayout->addStretch();
|
|
bottomLayout->addLayout(buttonLayout);
|
|
QPushButton *showNormalButton = new QPushButton(PreviewWidget::tr("Show normal"));
|
|
QObject::connect(showNormalButton, SIGNAL(clicked()), widget, SLOT(showNormal()));
|
|
buttonLayout->addWidget(showNormalButton, 0, 0);
|
|
QPushButton *showMinimizedButton = new QPushButton(PreviewWidget::tr("Show minimized"));
|
|
QObject::connect(showMinimizedButton, SIGNAL(clicked()), widget, SLOT(showMinimized()));
|
|
buttonLayout->addWidget(showMinimizedButton, 0, 1);
|
|
QPushButton *showMaximizedButton = new QPushButton(PreviewWidget::tr("Show maximized"));
|
|
QObject::connect(showMaximizedButton, SIGNAL(clicked()), widget, SLOT(showMaximized()));
|
|
buttonLayout->addWidget(showMaximizedButton, 0, 2);
|
|
QPushButton *showFullScreenButton = new QPushButton(PreviewWidget::tr("Show fullscreen"));
|
|
QObject::connect(showFullScreenButton, SIGNAL(clicked()), widget, SLOT(showFullScreen()));
|
|
buttonLayout->addWidget(showFullScreenButton, 0, 3);
|
|
|
|
QPushButton *updateInfoButton = new QPushButton(PreviewWidget::tr("&Update Info"));
|
|
QObject::connect(updateInfoButton, SIGNAL(clicked()), widget, SLOT(updateInfo()));
|
|
buttonLayout->addWidget(updateInfoButton, 1, 0);
|
|
QPushButton *closeButton = new QPushButton(PreviewWidget::tr("&Close"));
|
|
QObject::connect(closeButton, SIGNAL(clicked()), widget, SLOT(close()));
|
|
buttonLayout->addWidget(closeButton, 1, 3);
|
|
|
|
return textEdit;
|
|
}
|
|
|
|
PreviewWidget::PreviewWidget(QWidget *parent)
|
|
: QWidget(parent)
|
|
{
|
|
textEdit = createControlPanel(this);
|
|
setWindowTitle(tr("Preview <QWidget> Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
|
}
|
|
|
|
bool PreviewWidget::event(QEvent *event)
|
|
{
|
|
const bool ret = QWidget::event(event);
|
|
|
|
switch (event->type()) {
|
|
case QEvent::Move:
|
|
case QEvent::Resize:
|
|
case QEvent::WindowStateChange:
|
|
updateInfo();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
void PreviewWidget::setWindowFlags(Qt::WindowFlags flags)
|
|
{
|
|
if (flags == windowFlags())
|
|
return;
|
|
QWidget::setWindowFlags(flags);
|
|
QTimer::singleShot(0, this, SLOT(updateInfo()));
|
|
}
|
|
|
|
void PreviewWidget::updateInfo()
|
|
{
|
|
textEdit->setPlainText(formatWidgetInfo(this));
|
|
}
|
|
|
|
PreviewDialog::PreviewDialog(QWidget *parent)
|
|
: QDialog(parent)
|
|
{
|
|
textEdit = createControlPanel(this);
|
|
setWindowTitle(tr("Preview <QDialog> Qt %1").arg(QLatin1String(QT_VERSION_STR)));
|
|
}
|
|
|
|
bool PreviewDialog::event(QEvent *event)
|
|
{
|
|
const bool ret = QDialog::event(event);
|
|
|
|
switch (event->type()) {
|
|
case QEvent::Move:
|
|
case QEvent::Resize:
|
|
case QEvent::WindowStateChange:
|
|
updateInfo();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
void PreviewDialog::setWindowFlags(Qt::WindowFlags flags)
|
|
{
|
|
if (flags == windowFlags())
|
|
return;
|
|
QWidget::setWindowFlags(flags);
|
|
QTimer::singleShot(0, this, SLOT(updateInfo()));
|
|
}
|
|
|
|
void PreviewDialog::updateInfo()
|
|
{
|
|
textEdit->setPlainText(formatWidgetInfo(this));
|
|
}
|