Add embeddedwindows manual test

For the child windows we have to use showNormal() explicitly,
as the default window state logic of platforms like iOS does
not have access to the QWindow, only to its flags, and we
can not use Qt::SubWindow as a proxy for being a child window,
as that's a window flag meant to be used for MDI sub windows.

Change-Id: I2b5e669f6180ffdcb75479dece38ae5e5430aef6
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit be03c9f1d9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2023-08-02 15:34:36 +02:00 committed by Qt Cherry-pick Bot
parent 540869f4c5
commit 13d3c7fb22
3 changed files with 122 additions and 0 deletions

View File

@ -0,0 +1,15 @@
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause
qt_internal_add_manual_test(embeddedwindows
SOURCES
main.cpp
LIBRARIES
Qt::Gui
)
if(APPLE)
enable_language(OBJCXX)
set_source_files_properties(main.cpp PROPERTIES LANGUAGE OBJCXX)
set_property(TARGET embeddedwindows PROPERTY PROPERTY MACOSX_BUNDLE TRUE)
endif()

View File

@ -0,0 +1,102 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <QtGui>
#include "../../shared/nativewindow.h"
#include <QDebug>
class TestWindow : public QRasterWindow
{
public:
using QRasterWindow::QRasterWindow;
TestWindow(const QBrush &brush) : m_brush(brush) {}
protected:
void mousePressEvent(QMouseEvent *) override
{
m_pressed = true;
update();
}
void mouseReleaseEvent(QMouseEvent *) override
{
m_pressed = false;
update();
}
void paintEvent(QPaintEvent *event) override
{
QPainter painter(this);
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(event->rect(), m_pressed ? QGradient(QGradient::JuicyPeach) : m_brush);
}
private:
QBrush m_brush = QGradient(QGradient::DustyGrass);
bool m_pressed = false;
};
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
TestWindow window{QGradient(QGradient::WinterNeva)};
window.resize(500, 500);
TestWindow *opaqueChildWindow = new TestWindow;
opaqueChildWindow->setParent(&window);
opaqueChildWindow->setGeometry(50, 50, 100, 100);
opaqueChildWindow->showNormal();
TestWindow *maskedChildWindow = new TestWindow;
maskedChildWindow->setParent(&window);
maskedChildWindow->setGeometry(200, 50, 100, 100);
maskedChildWindow->setMask(QRegion(0, 0, 100, 100, QRegion::Ellipse));
maskedChildWindow->showNormal();
static const QColor transparentGreen = QColor(0, 255, 0, 20);
TestWindow *transparentChildWindow = new TestWindow(transparentGreen);
// The default surface format of a platform may not include
// an alpha, so set it explicitly.
QSurfaceFormat format = transparentChildWindow->format();
format.setAlphaBufferSize(8);
transparentChildWindow->setFormat(format);
// FIXME: Windows requires this, even for child windows
transparentChildWindow->setFlag(Qt::FramelessWindowHint);
transparentChildWindow->setParent(&window);
transparentChildWindow->setGeometry(350, 50, 100, 100);
transparentChildWindow->showNormal();
NativeWindow nativeWindow;
if (QWindow *foreignWindow = QWindow::fromWinId(nativeWindow)) {
foreignWindow->setParent(&window);
foreignWindow->setGeometry(50, 200, 100, 100);
foreignWindow->showNormal();
}
NativeWindow maskedNativeWindow;
if (QWindow *foreignWindow = QWindow::fromWinId(maskedNativeWindow)) {
foreignWindow->setParent(&window);
foreignWindow->setGeometry(200, 200, 100, 100);
foreignWindow->setMask(QRegion(0, 0, 100, 100, QRegion::Ellipse));
foreignWindow->showNormal();
}
NativeWindow nativeParentWindow;
if (QWindow *foreignWindow = QWindow::fromWinId(nativeParentWindow)) {
foreignWindow->setParent(&window);
foreignWindow->setGeometry(50, 350, 100, 100);
foreignWindow->showNormal();
TestWindow *maskedChildWindowOfNativeWindow = new TestWindow;
maskedChildWindowOfNativeWindow->setParent(foreignWindow);
maskedChildWindowOfNativeWindow->setGeometry(25, 25, 50, 50);
maskedChildWindowOfNativeWindow->showNormal();
}
window.show();
return app.exec();
}

View File

@ -44,6 +44,10 @@ private:
- (instancetype)init
{
if ((self = [super init])) {
#if defined(Q_OS_MACOS)
self.wantsLayer = YES;
#endif
self.layer.backgroundColor = CGColorCreateGenericRGB(1.0, 0.5, 1.0, 1.0);
}
return self;
}
@ -88,6 +92,7 @@ NativeWindow::NativeWindow()
wc.lpfnWndProc = DefWindowProc;
wc.hInstance = GetModuleHandle(nullptr);
wc.lpszClassName = L"Native Window";
wc.hbrBackground = CreateSolidBrush(RGB(255, 128, 255));
RegisterClass(&wc);
return wc.lpszClassName;
}();