diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2022-03-02 15:22:16 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-03-22 14:39:25 +0000 |
commit | 8a40756f4e18830086e4b5cd3f0cc6dab081efdb (patch) | |
tree | b175d11e228cd0f2259a73e2577517ce94f22912 /tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | |
parent | 27daadc21492bf69029f31a51cfef6183d648ca0 (diff) |
QQuickFlickable: use custom content item that takes extents into account
The flickable area inside the viewport can be bigger than
the bounds of the content item itself, if the flickable is
using non-zero extents (as returned by e.g minXExtent()).
Since the default implementation in QQuickItem::contains()
only checks if the point is inside the bounds of the item, we
need to override it to check the extents as well.
This patch will implement a new QQuickItem that overrides
contains(). It will simply check if the point is inside the
bounds of the flickable rather than the content item itself.
Fixes: QTBUG-101386
Change-Id: Ifb27e899e40fde80a75e8bbbf88dd858053898af
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 768716c3f4aa4d6be953092ee737f93477164479)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests/auto/quick/qquickflickable/tst_qquickflickable.cpp')
-rw-r--r-- | tests/auto/quick/qquickflickable/tst_qquickflickable.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 315b6d4fca..f76d9a4446 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -36,6 +36,7 @@ #include <private/qquickmousearea_p.h> #include <private/qquicktransition_p.h> #include <private/qqmlvaluetype_p.h> +#include <private/qquicktaphandler_p.h> #include <math.h> #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtQuickTestUtils/private/geometrytestutils_p.h> @@ -142,6 +143,32 @@ private: bool m_active; }; +class FlickableWithExtents : public QQuickFlickable +{ +public: + qreal extent = 10; + + qreal minXExtent() const override + { + return QQuickFlickable::minXExtent() + extent; + } + + qreal maxXExtent() const override + { + return QQuickFlickable::maxXExtent() + extent; + } + + qreal minYExtent() const override + { + return QQuickFlickable::minYExtent() + extent; + } + + qreal maxYExtent() const override + { + return QQuickFlickable::maxYExtent() + extent; + } +}; + class tst_qquickflickable : public QQmlDataTest { Q_OBJECT @@ -208,6 +235,7 @@ private slots: void parallelTouch(); void ignoreNonLeftMouseButtons(); void ignoreNonLeftMouseButtons_data(); + void receiveTapOutsideContentItem(); private: void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to); @@ -2716,6 +2744,36 @@ void tst_qquickflickable::ignoreNonLeftMouseButtons_data() QTest::newRow("middle") << Qt::MiddleButton; } +void tst_qquickflickable::receiveTapOutsideContentItem() +{ + // Check that if we add a TapHandler handler to a flickable, we + // can tap on the whole flickable area inside it, which includes + // the extents in addition to the content item. + QQuickView window; + window.resize(200, 200); + FlickableWithExtents flickable; + flickable.setParentItem(window.contentItem()); + flickable.setWidth(200); + flickable.setHeight(200); + flickable.setContentWidth(100); + flickable.setContentHeight(100); + + window.show(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + QQuickTapHandler tapHandler(&flickable); + QSignalSpy clickedSpy(&tapHandler, SIGNAL(tapped(QEventPoint, Qt::MouseButton))); + + // Tap outside the content item in the top-left corner + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(5, 5)); + QCOMPARE(clickedSpy.count(), 1); + + // Tap outside the content item in the bottom-right corner + const QPoint bottomRight(flickable.contentItem()->width() + 5, flickable.contentItem()->height() + 5); + QTest::mouseClick(&window, Qt::LeftButton, {}, bottomRight); + QCOMPARE(clickedSpy.count(), 2); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" |