Skip to content

Commit

Permalink
Improve windowflags manual test
Browse files Browse the repository at this point in the history
Group the Qt::CustomizeWindowHint specific flags separately, to make
it clear that they only apply if Qt::CustomizeWindowHint is set, and
give the QWindow preview window a title.

Add option to visualize the safe areas of the window.

Change-Id: I25ae7229b47ceaaa02f4be5a8210dbe44f54b6fa
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
  • Loading branch information
torarnv committed Nov 21, 2024
1 parent efa0d60 commit 6d4a717
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 30 deletions.
1 change: 1 addition & 0 deletions tests/manual/windowflags/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ qt_internal_add_manual_test(tst_manual_windowflags
controls.cpp # undef QT_NO_FOREACH
LIBRARIES
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
)
7 changes: 6 additions & 1 deletion tests/manual/windowflags/controllerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void ControllerWidget::updateStateControl()
statesControl->setStates(activePreview->windowStates());
}

void ControllerWidget::updatePreview(QWindow *preview)
void ControllerWidget::updatePreview(PreviewWindow *preview)
{
activePreview = preview;

Expand All @@ -91,7 +91,10 @@ void ControllerWidget::updatePreview(QWindow *preview)
parentWindow->hide();
}

preview->setVisualizeSafeAreas(safeAreaCheckBox->isChecked());

preview->setFlags(flags);
preview->update();

if (fixedSizeWindowCheckBox->isChecked()) {
preview->setMinimumSize(preview->size());
Expand Down Expand Up @@ -172,8 +175,10 @@ void ControllerWidget::createTypeGroupBox()
l = new QHBoxLayout;
modalWindowCheckBox = createCheckBox(tr("Modal window"));
fixedSizeWindowCheckBox = createCheckBox(tr("Fixed size window"));
safeAreaCheckBox = createCheckBox(tr("Visualize safe areas"));
l->addWidget(modalWindowCheckBox);
l->addWidget(fixedSizeWindowCheckBox);
l->addWidget(safeAreaCheckBox);
additionalOptionsGroupBox->setLayout(l);
}

Expand Down
5 changes: 3 additions & 2 deletions tests/manual/windowflags/controllerwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ private slots:
void updateStateControl();

private:
void updatePreview(QWindow *);
void updatePreview(PreviewWindow *);
void updatePreview(QWidget *);
void createTypeGroupBox();
QCheckBox *createCheckBox(const QString &text);
QRadioButton *createRadioButton(const QString &text);

QMainWindow *parentWindow;

QWindow *previewWindow;
PreviewWindow *previewWindow;
PreviewWidget *previewWidget;
PreviewDialog *previewDialog;

Expand All @@ -60,6 +60,7 @@ private slots:
QRadioButton *previewDialogButton;
QCheckBox *modalWindowCheckBox;
QCheckBox *fixedSizeWindowCheckBox;
QCheckBox *safeAreaCheckBox;
};

class LogWidget : public QPlainTextEdit
Expand Down
58 changes: 37 additions & 21 deletions tests/manual/windowflags/controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ HintControl::HintControl(QWidget *parent)
, 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")))
, customizeWindowGroup(new QGroupBox(tr("Customize window title bar controls")))
, transparentForInputCheckBox(new QCheckBox(tr("Transparent for input")))
, noDropShadowCheckBox(new QCheckBox(tr("No drop shadow")))
{
Expand All @@ -46,29 +46,45 @@ HintControl::HintControl(QWidget *parent)
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(customizeWindowGroup, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(transparentForInputCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
connect(noDropShadowCheckBox, SIGNAL(clicked()), this, SLOT(slotCheckBoxChanged()));
QGridLayout *layout = new QGridLayout(this);
auto *layout = new QHBoxLayout(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);

auto *basicHintsLayout = new QVBoxLayout;
basicHintsLayout->setSpacing(0);
basicHintsLayout->setContentsMargins(ControlLayoutMargin, ControlLayoutMargin,
ControlLayoutMargin, ControlLayoutMargin);

basicHintsLayout->addWidget(framelessWindowCheckBox);
basicHintsLayout->addWidget(noDropShadowCheckBox);
basicHintsLayout->addWidget(windowStaysOnTopCheckBox);
basicHintsLayout->addWidget(windowStaysOnBottomCheckBox);
basicHintsLayout->addWidget(transparentForInputCheckBox);
basicHintsLayout->addWidget(msWindowsFixedSizeDialogCheckBox);
basicHintsLayout->addWidget(x11BypassWindowManagerCheckBox);
layout->addLayout(basicHintsLayout);

customizeWindowGroup->setCheckable(true);
customizeWindowGroup->setChecked(false);
auto *customizeWindowLayout = new QVBoxLayout(customizeWindowGroup);
customizeWindowLayout->setSpacing(0);
customizeWindowLayout->setContentsMargins(ControlLayoutMargin, ControlLayoutMargin,
ControlLayoutMargin, ControlLayoutMargin);

customizeWindowLayout->addWidget(windowTitleCheckBox);
customizeWindowLayout->addWidget(windowSystemMenuCheckBox);
customizeWindowLayout->addWidget(windowMinimizeButtonCheckBox);
customizeWindowLayout->addWidget(windowShadeButtonCheckBox);
customizeWindowLayout->addWidget(windowMaximizeButtonCheckBox);
customizeWindowLayout->addWidget(windowFullscreenButtonCheckBox);
customizeWindowLayout->addWidget(windowCloseButtonCheckBox);
customizeWindowLayout->addWidget(windowContextHelpButtonCheckBox);

layout->addWidget(customizeWindowGroup);
}

Qt::WindowFlags HintControl::hints() const
Expand Down Expand Up @@ -100,7 +116,7 @@ Qt::WindowFlags HintControl::hints() const
flags |= Qt::WindowStaysOnTopHint;
if (windowStaysOnBottomCheckBox->isChecked())
flags |= Qt::WindowStaysOnBottomHint;
if (customizeWindowHintCheckBox->isChecked())
if (customizeWindowGroup->isChecked())
flags |= Qt::CustomizeWindowHint;
if (transparentForInputCheckBox->isChecked())
flags |= Qt::WindowTransparentForInput;
Expand All @@ -124,7 +140,7 @@ void HintControl::setHints(Qt::WindowFlags flags)
windowShadeButtonCheckBox->setChecked(flags & Qt::WindowShadeButtonHint);
windowStaysOnTopCheckBox->setChecked(flags & Qt::WindowStaysOnTopHint);
windowStaysOnBottomCheckBox->setChecked(flags & Qt::WindowStaysOnBottomHint);
customizeWindowHintCheckBox->setChecked(flags & Qt::CustomizeWindowHint);
customizeWindowGroup->setChecked(flags & Qt::CustomizeWindowHint);
transparentForInputCheckBox->setChecked(flags & Qt::WindowTransparentForInput);
noDropShadowCheckBox->setChecked(flags & Qt::NoDropShadowWindowHint);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/windowflags/controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private slots:
QCheckBox *windowShadeButtonCheckBox;
QCheckBox *windowStaysOnTopCheckBox;
QCheckBox *windowStaysOnBottomCheckBox;
QCheckBox *customizeWindowHintCheckBox;
QGroupBox *customizeWindowGroup;
QCheckBox *transparentForInputCheckBox;
QCheckBox *noDropShadowCheckBox;
};
Expand Down
21 changes: 17 additions & 4 deletions tests/manual/windowflags/previewwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@
#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);
QLinearGradient gradient(0, 0, width(), height());
gradient.setColorAt(0, QColor("#64b3f4"));
gradient.setColorAt(1, QColor("#c2e59c"));
painter.fillRect(QRect(0, 0, width(), height()), gradient);
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)
Expand Down
9 changes: 9 additions & 0 deletions tests/manual/windowflags/previewwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ QT_END_NAMESPACE

class PreviewWindow : public QRasterWindow
{
public:
PreviewWindow(QWindow *parent = nullptr);
void setVisualizeSafeAreas(bool enable)
{
m_visualizeSafeAreas = enable;
}

protected:
void paintEvent(QPaintEvent *event);
bool m_visualizeSafeAreas = false;
};

class PreviewWidget : public QWidget
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/windowflags/windowflags.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ SOURCES = controllerwindow.cpp \
main.cpp \
controls.cpp

QT += widgets
QT += widgets gui-private

0 comments on commit 6d4a717

Please sign in to comment.