summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-03-02 09:04:38 +0100
committerLiang Qi <liang.qi@qt.io>2017-03-02 09:04:38 +0100
commit71264bae08d81bdeceb96133fdb01c370504dfcc (patch)
treed5dadaac8209d5ef1857a4d65197b9ee12b39848 /tests/auto/widgets
parent5e785c0b83c9908c665f253c131629ac325a21f5 (diff)
parent6d10f739cd750968d0dd0e9d8fa4b64353a86c6c (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Diffstat (limited to 'tests/auto/widgets')
-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
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm34
4 files changed, 167 insertions, 15 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"
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
index 4645de4d7a..af93c18712 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm
@@ -1,31 +1,37 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**