summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/kernel')
-rw-r--r--tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp5
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp106
-rw-r--r--tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp37
3 files changed, 147 insertions, 1 deletions
diff --git a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
index 4ae1f02ce2..d50f46cc16 100644
--- a/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
+++ b/tests/auto/widgets/kernel/qsizepolicy/tst_qsizepolicy.cpp
@@ -114,7 +114,10 @@ void tst_QSizePolicy::constExpr()
{ Q_CONSTEXPR QSizePolicy sp; Q_UNUSED(sp); }
{ Q_CONSTEXPR QSizePolicy sp = QSizePolicy(); Q_UNUSED(sp); }
{ Q_CONSTEXPR QSizePolicy sp = QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); Q_UNUSED(sp); }
- { Q_CONSTEXPR QSizePolicy sp = QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding, QSizePolicy::DefaultType); Q_UNUSED(sp); }
+ { Q_CONSTEXPR QSizePolicy sp = QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding, QSizePolicy::DefaultType);
+ Q_CONSTEXPR QSizePolicy tp = sp.transposed(); Q_UNUSED(tp); }
+ { Q_RELAXED_CONSTEXPR auto sp = QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::CheckBox);
+ Q_RELAXED_CONSTEXPR auto tp = sp.transposed(); Q_UNUSED(tp); }
#else
QSKIP("QSizePolicy cannot be constexpr with this version of the compiler.");
#endif
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 2657b28d30..7afa7ca42b 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -407,6 +407,8 @@ private slots:
void testForOutsideWSRangeFlag();
+ void tabletTracking();
+
private:
bool ensureScreenSize(int width, int height);
@@ -10529,5 +10531,109 @@ void tst_QWidget::testForOutsideWSRangeFlag()
}
}
+class TabletWidget : public QWidget
+{
+public:
+ TabletWidget(QWidget *parent) : QWidget(parent) { }
+
+ int tabletEventCount = 0;
+ int pressEventCount = 0;
+ int moveEventCount = 0;
+ int releaseEventCount = 0;
+ int trackingChangeEventCount = 0;
+ qint64 uid = -1;
+
+protected:
+ void tabletEvent(QTabletEvent *event) override {
+ ++tabletEventCount;
+ uid = event->uniqueId();
+ switch (event->type()) {
+ case QEvent::TabletMove:
+ ++moveEventCount;
+ break;
+ case QEvent::TabletPress:
+ ++pressEventCount;
+ break;
+ case QEvent::TabletRelease:
+ ++releaseEventCount;
+ break;
+ default:
+ break;
+ }
+ }
+
+ bool event(QEvent *ev) override {
+ if (ev->type() == QEvent::TabletTrackingChange)
+ ++trackingChangeEventCount;
+ return QWidget::event(ev);
+ }
+};
+
+void tst_QWidget::tabletTracking()
+{
+ QWidget parent;
+ parent.resize(200,200);
+ // QWidgetWindow::handleTabletEvent doesn't deliver tablet events to the window's widget, only to a child.
+ // So it doesn't do any good to show a TabletWidget directly: it needs a parent.
+ TabletWidget widget(&parent);
+ widget.resize(200,200);
+ parent.showNormal();
+ QVERIFY(QTest::qWaitForWindowExposed(&parent));
+ widget.setAttribute(Qt::WA_TabletTracking);
+ QTRY_COMPARE(widget.trackingChangeEventCount, 1);
+ QVERIFY(widget.hasTabletTracking());
+
+ QWindow *window = parent.windowHandle();
+ QPointF local(10, 10);
+ QPointF global = window->mapToGlobal(local.toPoint());
+ QPointF deviceLocal = QHighDpi::toNativeLocalPosition(local, window);
+ QPointF deviceGlobal = QHighDpi::toNativePixels(global, window->screen());
+ qint64 uid = 1234UL;
+
+ QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal,
+ QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier);
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(widget.moveEventCount, 1);
+ QCOMPARE(widget.uid, uid);
+
+ local += QPoint(10, 10);
+ deviceLocal += QPoint(10, 10);
+ deviceGlobal += QPoint(10, 10);
+ QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal,
+ QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier);
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(widget.moveEventCount, 2);
+
+ widget.setTabletTracking(false);
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(widget.trackingChangeEventCount, 2);
+
+ QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal,
+ QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier);
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(widget.pressEventCount, 1);
+
+ local += QPoint(10, 10);
+ deviceLocal += QPoint(10, 10);
+ deviceGlobal += QPoint(10, 10);
+ QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal,
+ QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier);
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(widget.moveEventCount, 3);
+
+ QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal,
+ QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier);
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(widget.releaseEventCount, 1);
+
+ local += QPoint(10, 10);
+ deviceLocal += QPoint(10, 10);
+ deviceGlobal += QPoint(10, 10);
+ QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal,
+ QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier);
+ QCoreApplication::processEvents();
+ QTRY_COMPARE(widget.moveEventCount, 3);
+}
+
QTEST_MAIN(tst_QWidget)
#include "tst_qwidget.moc"
diff --git a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
index 5e3868ea8f..6ec1b754d0 100644
--- a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
+++ b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
@@ -37,6 +37,7 @@
#include <qmainwindow.h>
#include <qscreen.h>
#include <qscopedpointer.h>
+#include <qevent.h>
class Window : public QWindow
@@ -77,6 +78,7 @@ private slots:
void testAncestorChange();
void testDockWidget();
void testNativeContainerParent();
+ void testPlatformSurfaceEvent();
void cleanup();
private:
@@ -343,6 +345,41 @@ void tst_QWindowContainer::testNativeContainerParent()
QTRY_COMPARE(window->parent(), container->windowHandle());
}
+class EventWindow : public QWindow
+{
+public:
+ EventWindow(bool *surfaceDestroyFlag) : m_surfaceDestroyFlag(surfaceDestroyFlag) { }
+ bool event(QEvent *e) override;
+
+private:
+ bool *m_surfaceDestroyFlag;
+};
+
+bool EventWindow::event(QEvent *e)
+{
+ if (e->type() == QEvent::PlatformSurface) {
+ if (static_cast<QPlatformSurfaceEvent *>(e)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed)
+ *m_surfaceDestroyFlag = true;
+ }
+ return QWindow::event(e);
+}
+
+void tst_QWindowContainer::testPlatformSurfaceEvent()
+{
+ // Verify that SurfaceAboutToBeDestroyed is delivered and the
+ // window subclass still gets a chance to process it.
+
+ bool ok = false;
+ QPointer<EventWindow> window(new EventWindow(&ok));
+ window->create();
+ QWidget *container = QWidget::createWindowContainer(window);
+
+ delete container;
+
+ QCOMPARE(window.data(), nullptr);
+ QVERIFY(ok);
+}
+
QTEST_MAIN(tst_QWindowContainer)
#include "tst_qwindowcontainer.moc"