qt 6.5.1 original

This commit is contained in:
kleuter
2023-10-29 23:33:08 +01:00
parent 71d22ab6b0
commit 85d238dfda
21202 changed files with 5499099 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_manual_windowflags Binary:
#####################################################################
qt_internal_add_manual_test(tst_manual_windowflags
GUI
SOURCES
controllerwindow.cpp controllerwindow.h
controls.cpp controls.h
main.cpp
previewwindow.cpp previewwindow.h
LIBRARIES
Qt::Gui
Qt::Widgets
)

View File

@ -0,0 +1,330 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "controllerwindow.h"
#include "controls.h"
#include <QAction>
#include <QApplication>
#include <QCheckBox>
#include <QDebug>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLabel>
#include <QLibraryInfo>
#include <qlogging.h>
#include <QMainWindow>
#include <QMenu>
#include <QMoveEvent>
#include <QPushButton>
#include <QRadioButton>
#include <QTabWidget>
#include <QWindow>
ControllerWidget::ControllerWidget(QWidget *parent)
: QWidget(parent)
, previewWidget(0)
{
parentWindow = new QMainWindow;
parentWindow->setWindowTitle(tr("Preview parent window"));
QLabel *label = new QLabel(tr("Parent window"));
parentWindow->setCentralWidget(label);
previewWindow = new PreviewWindow;
previewWindow->installEventFilter(this);
previewWidget = new PreviewWidget;
previewWidget->installEventFilter(this);
previewDialog = new PreviewDialog;
previewDialog->installEventFilter(this);
createTypeGroupBox();
hintsControl = new HintControl;
hintsControl->setHints(previewWidget->windowFlags());
connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
statesControl = new WindowStatesControl;
statesControl->setStates(previewWidget->windowState());
statesControl->setVisibleValue(true);
connect(statesControl, SIGNAL(changed()), this, SLOT(updatePreview()));
typeControl = new TypeControl;
typeControl->setType(previewWidget->windowFlags());
connect(typeControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview()));
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(widgetTypeGroupBox);
mainLayout->addWidget(additionalOptionsGroupBox);
mainLayout->addWidget(typeControl);
mainLayout->addWidget(hintsControl);
mainLayout->addWidget(statesControl);
updatePreview();
}
bool ControllerWidget::eventFilter(QObject *, QEvent *e)
{
if (e->type() == QEvent::WindowStateChange)
updateStateControl();
return false;
}
void ControllerWidget::updateStateControl()
{
if (activePreview)
statesControl->setStates(activePreview->windowStates());
}
void ControllerWidget::updatePreview(QWindow *preview)
{
activePreview = preview;
const Qt::WindowFlags flags = typeControl->type() | hintsControl->hints();
if (modalWindowCheckBox->isChecked()) {
parentWindow->show();
preview->setModality(Qt::WindowModal);
preview->setParent(parentWindow->windowHandle());
} else {
preview->setModality(Qt::NonModal);
preview->setParent(0);
parentWindow->hide();
}
preview->setFlags(flags);
if (fixedSizeWindowCheckBox->isChecked()) {
preview->setMinimumSize(preview->size());
preview->setMaximumSize(preview->size());
} else {
preview->setMinimumSize(QSize(0, 0));
preview->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
}
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() ?
preview->size() : QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
preview->setFixedSize(fixedSize);
QPoint pos = preview->pos();
if (pos.x() < 0)
pos.setX(0);
if (pos.y() < 0)
pos.setY(0);
preview->move(pos);
preview->setWindowState(statesControl->states());
preview->setVisible(statesControl->visibleValue());
}
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);
}
}
void ControllerWidget::createTypeGroupBox()
{
widgetTypeGroupBox = new QGroupBox(tr("Window Type"));
previewWindowButton = createRadioButton(tr("QWindow"));
previewWidgetButton = createRadioButton(tr("QWidget"));
previewDialogButton = createRadioButton(tr("QDialog"));
previewWindowButton->setChecked(true);
QHBoxLayout *l = new QHBoxLayout;
l->addWidget(previewWindowButton);
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);
}
QCheckBox *ControllerWidget::createCheckBox(const QString &text)
{
QCheckBox *checkBox = new QCheckBox(text);
connect(checkBox, SIGNAL(clicked()), this, SLOT(updatePreview()));
return checkBox;
}
QRadioButton *ControllerWidget::createRadioButton(const QString &text)
{
QRadioButton *button = new QRadioButton(text);
connect(button, SIGNAL(clicked()), this, SLOT(updatePreview()));
return button;
}
static bool isTopLevel(const QObject *o)
{
if (o->isWidgetType())
return static_cast<const QWidget *>(o)->isWindow();
if (o->isWindowType())
return static_cast<const QWindow *>(o)->isTopLevel();
return false;
}
static Qt::WindowStates windowState(const QObject *o)
{
if (o->isWidgetType()) {
Qt::WindowStates states = static_cast<const QWidget *>(o)->windowState();
states &= ~Qt::WindowActive;
return states;
}
if (o->isWindowType())
return static_cast<const QWindow *>(o)->windowStates();
return Qt::WindowNoState;
}
class EventFilter : public QObject {
public:
explicit EventFilter(QObject *parent = nullptr) : 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:
case QEvent::ApplicationStateChange:
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();
debug.noquote();
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;
static QtMessageHandler originalMessageHandler = nullptr;
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &text)
{
if (LogWidget *lw = LogWidget::instance())
lw->appendText(text);
originalMessageHandler(type, context, text);
}
LogWidget::LogWidget(QWidget *parent)
: QPlainTextEdit(parent)
{
LogWidget::m_instance = this;
setReadOnly(true);
appendText(startupMessage());
}
LogWidget::~LogWidget()
{
LogWidget::m_instance = 0;
}
void LogWidget::install()
{
originalMessageHandler = qInstallMessageHandler(messageHandler);
}
QString LogWidget::startupMessage()
{
QString result;
result += QLatin1String(QLibraryInfo::build());
result += QLatin1Char(' ');
result += QGuiApplication::platformName();
return result;
}
void LogWidget::appendText(const QString &message)
{
appendPlainText(message);
ensureCursorVisible();
}
ControllerWindow::ControllerWindow()
{
setWindowTitle(tr("Window Flags (Qt version %1, %2)")
.arg(QLatin1String(qVersion()),
qApp->platformName()));
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));
}

View File

@ -0,0 +1,92 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef CONTROLLERWINDOW_H
#define CONTROLLERWINDOW_H
#include <QPlainTextEdit>
#include "previewwindow.h"
QT_BEGIN_NAMESPACE
class QCheckBox;
class QGroupBox;
class QLabel;
class QPushButton;
class QRadioButton;
class QMainWindow;
QT_END_NAMESPACE
class HintControl;
class WindowStatesControl;
class TypeControl;
class ControllerWidget : public QWidget
{
Q_OBJECT
public:
explicit ControllerWidget(QWidget *parent = nullptr);
virtual bool eventFilter(QObject *o, QEvent *e);
private slots:
void updatePreview();
void updateStateControl();
private:
void updatePreview(QWindow *);
void updatePreview(QWidget *);
void createTypeGroupBox();
QCheckBox *createCheckBox(const QString &text);
QRadioButton *createRadioButton(const QString &text);
QMainWindow *parentWindow;
QWindow *previewWindow;
PreviewWidget *previewWidget;
PreviewDialog *previewDialog;
QWindow *activePreview;
QGroupBox *widgetTypeGroupBox;
QGroupBox *additionalOptionsGroupBox;
TypeControl *typeControl;
HintControl *hintsControl;
WindowStatesControl *statesControl;
QRadioButton *previewWindowButton;
QRadioButton *previewWidgetButton;
QRadioButton *previewDialogButton;
QCheckBox *modalWindowCheckBox;
QCheckBox *fixedSizeWindowCheckBox;
};
class LogWidget : public QPlainTextEdit
{
Q_OBJECT
public:
explicit LogWidget(QWidget *parent = nullptr);
~LogWidget();
static LogWidget *instance() { return m_instance; }
static void install();
public slots:
void appendText(const QString &);
private:
static QString startupMessage();
static LogWidget *m_instance;
};
class ControllerWindow : public QWidget {
Q_OBJECT
public:
ControllerWindow();
void registerEventFilter();
};
#endif // CONTROLLERWINDOW_H

View File

@ -0,0 +1,291 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "controls.h"
#include <QGridLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QRadioButton>
#include <QCheckBox>
#include <QRadioButton>
#include <QButtonGroup>
#include <QDebug>
HintControl::HintControl(QWidget *parent)
: QGroupBox(tr("Hints"), parent)
, msWindowsFixedSizeDialogCheckBox(new QCheckBox(tr("MS Windows fixed size dialog")))
, x11BypassWindowManagerCheckBox(new QCheckBox(tr("X11 bypass window manager")))
, framelessWindowCheckBox(new QCheckBox(tr("Frameless window")))
, windowTitleCheckBox(new QCheckBox(tr("Window title")))
, windowSystemMenuCheckBox(new QCheckBox(tr("Window system menu")))
, windowMinimizeButtonCheckBox(new QCheckBox(tr("Window minimize button")))
, windowMaximizeButtonCheckBox(new QCheckBox(tr("Window maximize button")))
, windowFullscreenButtonCheckBox(new QCheckBox(tr("Window fullscreen button")))
, windowCloseButtonCheckBox(new QCheckBox(tr("Window close button")))
, windowContextHelpButtonCheckBox(new QCheckBox(tr("Window context help button")))
, windowShadeButtonCheckBox(new QCheckBox(tr("Window shade button")))
, windowStaysOnTopCheckBox(new QCheckBox(tr("Window stays on top")))
, windowStaysOnBottomCheckBox(new QCheckBox(tr("Window stays on bottom")))
, customizeWindowHintCheckBox(new QCheckBox(tr("Customize window")))
, transparentForInputCheckBox(new QCheckBox(tr("Transparent for input")))
, noDropShadowCheckBox(new QCheckBox(tr("No drop shadow")))
{
connect(msWindowsFixedSizeDialogCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(x11BypassWindowManagerCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(framelessWindowCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowTitleCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowSystemMenuCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowMinimizeButtonCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowMaximizeButtonCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowFullscreenButtonCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowCloseButtonCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowContextHelpButtonCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowShadeButtonCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowStaysOnTopCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(windowStaysOnBottomCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(customizeWindowHintCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(transparentForInputCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(noDropShadowCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
QGridLayout *layout = new QGridLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(ControlLayoutMargin, ControlLayoutMargin,
ControlLayoutMargin, ControlLayoutMargin);
layout->addWidget(msWindowsFixedSizeDialogCheckBox, 0, 0);
layout->addWidget(x11BypassWindowManagerCheckBox, 1, 0);
layout->addWidget(framelessWindowCheckBox, 2, 0);
layout->addWidget(windowTitleCheckBox, 3, 0);
layout->addWidget(windowSystemMenuCheckBox, 4, 0);
layout->addWidget(windowMinimizeButtonCheckBox, 0, 1);
layout->addWidget(windowMaximizeButtonCheckBox, 1, 1);
layout->addWidget(windowFullscreenButtonCheckBox, 2, 1);
layout->addWidget(windowCloseButtonCheckBox, 3, 1);
layout->addWidget(windowContextHelpButtonCheckBox, 4, 1);
layout->addWidget(windowShadeButtonCheckBox, 5, 1);
layout->addWidget(windowStaysOnTopCheckBox, 6, 1);
layout->addWidget(windowStaysOnBottomCheckBox, 7, 1);
layout->addWidget(customizeWindowHintCheckBox, 5, 0);
layout->addWidget(transparentForInputCheckBox, 6, 0);
layout->addWidget(noDropShadowCheckBox, 7, 0);
}
Qt::WindowFlags HintControl::hints() const
{
Qt::WindowFlags flags;
if (msWindowsFixedSizeDialogCheckBox->isChecked())
flags |= Qt::MSWindowsFixedSizeDialogHint;
if (x11BypassWindowManagerCheckBox->isChecked())
flags |= Qt::X11BypassWindowManagerHint;
if (framelessWindowCheckBox->isChecked())
flags |= Qt::FramelessWindowHint;
if (windowTitleCheckBox->isChecked())
flags |= Qt::WindowTitleHint;
if (windowSystemMenuCheckBox->isChecked())
flags |= Qt::WindowSystemMenuHint;
if (windowMinimizeButtonCheckBox->isChecked())
flags |= Qt::WindowMinimizeButtonHint;
if (windowMaximizeButtonCheckBox->isChecked())
flags |= Qt::WindowMaximizeButtonHint;
if (windowFullscreenButtonCheckBox->isChecked())
flags |= Qt::WindowFullscreenButtonHint;
if (windowCloseButtonCheckBox->isChecked())
flags |= Qt::WindowCloseButtonHint;
if (windowContextHelpButtonCheckBox->isChecked())
flags |= Qt::WindowContextHelpButtonHint;
if (windowShadeButtonCheckBox->isChecked())
flags |= Qt::WindowShadeButtonHint;
if (windowStaysOnTopCheckBox->isChecked())
flags |= Qt::WindowStaysOnTopHint;
if (windowStaysOnBottomCheckBox->isChecked())
flags |= Qt::WindowStaysOnBottomHint;
if (customizeWindowHintCheckBox->isChecked())
flags |= Qt::CustomizeWindowHint;
if (transparentForInputCheckBox->isChecked())
flags |= Qt::WindowTransparentForInput;
if (noDropShadowCheckBox->isChecked())
flags |= Qt::NoDropShadowWindowHint;
return flags;
}
void HintControl::setHints(Qt::WindowFlags flags)
{
msWindowsFixedSizeDialogCheckBox->setChecked(flags & Qt::MSWindowsFixedSizeDialogHint);
x11BypassWindowManagerCheckBox->setChecked(flags & Qt::X11BypassWindowManagerHint);
framelessWindowCheckBox->setChecked(flags & Qt::FramelessWindowHint);
windowTitleCheckBox->setChecked(flags & Qt::WindowTitleHint);
windowSystemMenuCheckBox->setChecked(flags & Qt::WindowSystemMenuHint);
windowMinimizeButtonCheckBox->setChecked(flags & Qt::WindowMinimizeButtonHint);
windowMaximizeButtonCheckBox->setChecked(flags & Qt::WindowMaximizeButtonHint);
windowFullscreenButtonCheckBox->setChecked(flags & Qt::WindowFullscreenButtonHint);
windowCloseButtonCheckBox->setChecked(flags & Qt::WindowCloseButtonHint);
windowContextHelpButtonCheckBox->setChecked(flags & Qt::WindowContextHelpButtonHint);
windowShadeButtonCheckBox->setChecked(flags & Qt::WindowShadeButtonHint);
windowStaysOnTopCheckBox->setChecked(flags & Qt::WindowStaysOnTopHint);
windowStaysOnBottomCheckBox->setChecked(flags & Qt::WindowStaysOnBottomHint);
customizeWindowHintCheckBox->setChecked(flags & Qt::CustomizeWindowHint);
transparentForInputCheckBox->setChecked(flags & Qt::WindowTransparentForInput);
noDropShadowCheckBox->setChecked(flags & Qt::NoDropShadowWindowHint);
}
void HintControl::slotCheckBoxChanged()
{
emit changed(hints());
}
WindowStateControl::WindowStateControl(QWidget *parent)
: QWidget(parent)
, group(new QButtonGroup)
, restoreButton(new QCheckBox(tr("Normal")))
, minimizeButton(new QCheckBox(tr("Minimized")))
, maximizeButton(new QCheckBox(tr("Maximized")))
, fullscreenButton(new QCheckBox(tr("Fullscreen")))
{
QHBoxLayout *layout = new QHBoxLayout(this);
group->setExclusive(false);
layout->setContentsMargins(ControlLayoutMargin, ControlLayoutMargin,
ControlLayoutMargin, ControlLayoutMargin);
group->addButton(restoreButton, Qt::WindowNoState);
restoreButton->setEnabled(false);
layout->addWidget(restoreButton);
group->addButton(minimizeButton, Qt::WindowMinimized);
layout->addWidget(minimizeButton);
group->addButton(maximizeButton, Qt::WindowMaximized);
layout->addWidget(maximizeButton);
group->addButton(fullscreenButton, Qt::WindowFullScreen);
layout->addWidget(fullscreenButton);
connect(group, &QButtonGroup::idReleased, this, &WindowStateControl::stateChanged);
}
Qt::WindowStates WindowStateControl::state() const
{
Qt::WindowStates states;
foreach (QAbstractButton *button, group->buttons()) {
if (button->isChecked())
states |= Qt::WindowState(group->id(button));
}
return states;
}
void WindowStateControl::setState(Qt::WindowStates s)
{
group->blockSignals(true);
foreach (QAbstractButton *button, group->buttons())
button->setChecked(s & Qt::WindowState(group->id(button)));
if (!(s & (Qt::WindowMaximized | Qt::WindowFullScreen)))
restoreButton->setChecked(true);
group->blockSignals(false);
}
WindowStatesControl::WindowStatesControl(QWidget *parent)
: QGroupBox(tr("States"), parent)
, visibleCheckBox(new QCheckBox(tr("Visible")))
, activeCheckBox(new QCheckBox(tr("Active")))
, stateControl(new WindowStateControl)
{
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(ControlLayoutMargin, ControlLayoutMargin,
ControlLayoutMargin, ControlLayoutMargin);
connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
layout->addWidget(visibleCheckBox);
connect(activeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
layout->addWidget(activeCheckBox);
layout->addWidget(stateControl);
connect(stateControl, SIGNAL(stateChanged(int)), this, SIGNAL(changed()));
}
Qt::WindowStates WindowStatesControl::states() const
{
Qt::WindowStates s = stateControl->state();
if (activeValue())
s |= Qt::WindowActive;
return s;
}
void WindowStatesControl::setStates(Qt::WindowStates s)
{
stateControl->setState(s);
setActiveValue(s & Qt::WindowActive);
}
bool WindowStatesControl::visibleValue() const
{
return visibleCheckBox && visibleCheckBox->isChecked();
}
void WindowStatesControl::setVisibleValue(bool v)
{
if (visibleCheckBox) {
visibleCheckBox->blockSignals(true);
visibleCheckBox->setChecked(v);
visibleCheckBox->blockSignals(false);
}
}
bool WindowStatesControl::activeValue() const
{
return activeCheckBox && activeCheckBox->isChecked();
}
void WindowStatesControl::setActiveValue(bool v)
{
if (activeCheckBox) {
activeCheckBox->blockSignals(true);
activeCheckBox->setChecked(v);
activeCheckBox->blockSignals(false);
}
}
TypeControl::TypeControl(QWidget *parent)
: QGroupBox(tr("Type"), parent)
, group(new QButtonGroup)
, windowRadioButton(new QRadioButton(tr("Window")))
, dialogRadioButton(new QRadioButton(tr("Dialog")))
, sheetRadioButton(new QRadioButton(tr("Sheet")))
, drawerRadioButton(new QRadioButton(tr("Drawer")))
, popupRadioButton(new QRadioButton(tr("Popup")))
, toolRadioButton(new QRadioButton(tr("Tool")))
, toolTipRadioButton(new QRadioButton(tr("Tooltip")))
, splashScreenRadioButton(new QRadioButton(tr("Splash screen")))
{
group->setExclusive(true);
QGridLayout *layout = new QGridLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(ControlLayoutMargin, ControlLayoutMargin,
ControlLayoutMargin, ControlLayoutMargin);
group->addButton(windowRadioButton, Qt::Window);
layout->addWidget(windowRadioButton, 0, 0);
group->addButton(dialogRadioButton, Qt::Dialog);
layout->addWidget(dialogRadioButton, 1, 0);
group->addButton(sheetRadioButton, Qt::Sheet);
layout->addWidget(sheetRadioButton, 2, 0);
group->addButton(drawerRadioButton, Qt::Drawer);
layout->addWidget(drawerRadioButton, 3, 0);
group->addButton(popupRadioButton, Qt::Popup);
layout->addWidget(popupRadioButton, 0, 1);
group->addButton(toolRadioButton, Qt::Tool);
layout->addWidget(toolRadioButton, 1, 1);
group->addButton(toolTipRadioButton, Qt::ToolTip);
layout->addWidget(toolTipRadioButton, 2, 1);
group->addButton(splashScreenRadioButton, Qt::SplashScreen);
layout->addWidget(splashScreenRadioButton, 3, 1);
connect(group, &QButtonGroup::idReleased, this, &TypeControl::slotChanged);
}
Qt::WindowFlags TypeControl::type() const
{
return Qt::WindowFlags(group->checkedId());
}
void TypeControl::setType(Qt::WindowFlags s)
{
if (QAbstractButton *b = group->button(s & Qt::WindowType_Mask))
b->setChecked(true);
}
void TypeControl::slotChanged()
{
emit changed(type());
}

View File

@ -0,0 +1,125 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef CONTROLS_H
#define CONTROLS_H
#include <QGroupBox>
QT_BEGIN_NAMESPACE
class QCheckBox;
class QRadioButton;
class QButtonGroup;
QT_END_NAMESPACE
enum { ControlLayoutMargin = 4 };
// Control for the hint part of Qt::WindowFlags
class HintControl : public QGroupBox
{
Q_OBJECT
public:
explicit HintControl(QWidget *parent= 0);
Qt::WindowFlags hints() const;
void setHints(Qt::WindowFlags hints);
signals:
void changed(Qt::WindowFlags);
private slots:
void slotCheckBoxChanged();
private:
QCheckBox *msWindowsFixedSizeDialogCheckBox;
QCheckBox *x11BypassWindowManagerCheckBox;
QCheckBox *framelessWindowCheckBox;
QCheckBox *windowTitleCheckBox;
QCheckBox *windowSystemMenuCheckBox;
QCheckBox *windowMinimizeButtonCheckBox;
QCheckBox *windowMaximizeButtonCheckBox;
QCheckBox *windowFullscreenButtonCheckBox;
QCheckBox *windowCloseButtonCheckBox;
QCheckBox *windowContextHelpButtonCheckBox;
QCheckBox *windowShadeButtonCheckBox;
QCheckBox *windowStaysOnTopCheckBox;
QCheckBox *windowStaysOnBottomCheckBox;
QCheckBox *customizeWindowHintCheckBox;
QCheckBox *transparentForInputCheckBox;
QCheckBox *noDropShadowCheckBox;
};
// Control for the Qt::WindowState enum, optional with a "visible" QCheckbox
class WindowStateControl : public QWidget {
Q_OBJECT
public:
explicit WindowStateControl(QWidget *parent= 0);
Qt::WindowStates state() const;
void setState(Qt::WindowStates s);
signals:
void stateChanged(int);
private:
QButtonGroup *group;
QCheckBox *restoreButton;
QCheckBox *minimizeButton;
QCheckBox *maximizeButton;
QCheckBox *fullscreenButton;
};
// Control for the Qt::WindowStates flags (normal, maximized, fullscreen exclusively
// combined with minimized and optionally, with a "visible" QCheckbox)
class WindowStatesControl : public QGroupBox
{
Q_OBJECT
public:
explicit WindowStatesControl(QWidget *parent= 0);
Qt::WindowStates states() const;
void setStates(Qt::WindowStates s);
bool visibleValue() const;
void setVisibleValue(bool);
bool activeValue() const;
void setActiveValue(bool v);
signals:
void changed();
private:
QCheckBox *visibleCheckBox;
QCheckBox *activeCheckBox;
WindowStateControl *stateControl;
};
// Control for the type part of Qt::WindowFlags
class TypeControl : public QGroupBox
{
Q_OBJECT
public:
explicit TypeControl(QWidget *parent= 0);
Qt::WindowFlags type() const;
void setType(Qt::WindowFlags);
signals:
void changed(Qt::WindowFlags);
private slots:
void slotChanged();
private:
QButtonGroup *group;
QRadioButton *windowRadioButton;
QRadioButton *dialogRadioButton;
QRadioButton *sheetRadioButton;
QRadioButton *drawerRadioButton;
QRadioButton *popupRadioButton;
QRadioButton *toolRadioButton;
QRadioButton *toolTipRadioButton;
QRadioButton *splashScreenRadioButton;
};
#endif // CONTROLS_H

View File

@ -0,0 +1,23 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QApplication>
#include <QStringList>
#include "controllerwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QStringList arguments = QCoreApplication::arguments();
arguments.pop_front();
ControllerWindow controller;
if (!arguments.contains(QLatin1String("-l")))
LogWidget::install();
if (!arguments.contains(QLatin1String("-e")))
controller.registerEventFilter();
controller.show();
controller.lower();
return app.exec();
}

View File

@ -0,0 +1,251 @@
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QPlainTextEdit>
#include <QPushButton>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QTextStream>
#include <QTimer>
#include <QPainter>
#include <QLinearGradient>
#include "previewwindow.h"
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);
}
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::MaximizeUsingFullscreenGeometryHint)
str << "\n| Qt::MaximizeUsingFullscreenGeometryHint";
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));
}

View File

@ -0,0 +1,57 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef PREVIEWWINDOW_H
#define PREVIEWWINDOW_H
#include <QDialog>
#include <QRasterWindow>
QT_BEGIN_NAMESPACE
class QPlainTextEdit;
QT_END_NAMESPACE
class PreviewWindow : public QRasterWindow
{
void paintEvent(QPaintEvent *event);
};
class PreviewWidget : public QWidget
{
Q_OBJECT
public:
PreviewWidget(QWidget *parent = nullptr);
void setWindowFlags(Qt::WindowFlags flags);
public slots:
void updateInfo();
protected:
bool event(QEvent *) override;
private:
QPlainTextEdit *textEdit;
};
class PreviewDialog : public QDialog
{
Q_OBJECT
public:
PreviewDialog(QWidget *parent = nullptr);
void setWindowFlags(Qt::WindowFlags flags);
public slots:
void updateInfo();
protected:
bool event(QEvent *) override;
private:
QPlainTextEdit *textEdit;
};
#endif

View File

@ -0,0 +1,12 @@
TARGET = tst_manual_windowflags
HEADERS = controllerwindow.h \
previewwindow.h \
controls.h
SOURCES = controllerwindow.cpp \
previewwindow.cpp \
main.cpp \
controls.cpp
QT += widgets