From af74ca8e0ccf0fc59d6e918c679fcc5139aab59d Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 4 Jul 2017 15:08:51 +0200 Subject: PageIndicator: don't block touch when non-interactive Unlike with mouse events there's setAcceptedMouseButtons(), currently there's no way to control whether a control receives touch events or not. As a temporary workaround until QQuickItem::setAcceptTouchEvents() has been added, we'll have to ignore touch events by hand. Task-number: QTBUG-61785 Change-Id: I8e3bdc3df1c3b28afaf8f80965569135e6a53120 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickpageindicator.cpp | 11 ++++++++ src/quicktemplates2/qquickpageindicator_p.h | 4 +++ tests/auto/controls/data/tst_pageindicator.qml | 36 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/quicktemplates2/qquickpageindicator.cpp b/src/quicktemplates2/qquickpageindicator.cpp index 7387b019..8f9c8525 100644 --- a/src/quicktemplates2/qquickpageindicator.cpp +++ b/src/quicktemplates2/qquickpageindicator.cpp @@ -335,6 +335,17 @@ void QQuickPageIndicator::contentItemChange(QQuickItem *newItem, QQuickItem *old QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children); } +#if QT_CONFIG(quicktemplates2_multitouch) +void QQuickPageIndicator::touchEvent(QTouchEvent *event) +{ + Q_D(QQuickPageIndicator); + if (d->interactive) + QQuickControl::touchEvent(event); + else + event->ignore(); // QTBUG-61785 +} +#endif + #if QT_CONFIG(accessibility) QAccessible::Role QQuickPageIndicator::accessibleRole() const { diff --git a/src/quicktemplates2/qquickpageindicator_p.h b/src/quicktemplates2/qquickpageindicator_p.h index ea20a37a..01352016 100644 --- a/src/quicktemplates2/qquickpageindicator_p.h +++ b/src/quicktemplates2/qquickpageindicator_p.h @@ -87,6 +87,10 @@ Q_SIGNALS: protected: void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override; +#if QT_CONFIG(quicktemplates2_multitouch) + void touchEvent(QTouchEvent *event) override; +#endif + #if QT_CONFIG(accessibility) QAccessible::Role accessibleRole() const override; #endif diff --git a/tests/auto/controls/data/tst_pageindicator.qml b/tests/auto/controls/data/tst_pageindicator.qml index 0ceefa35..70813cb8 100644 --- a/tests/auto/controls/data/tst_pageindicator.qml +++ b/tests/auto/controls/data/tst_pageindicator.qml @@ -65,6 +65,11 @@ TestCase { PageIndicator { } } + Component { + id: mouseArea + MouseArea { } + } + function test_count() { var control = createTemporaryObject(pageIndicator, testCase) verify(control) @@ -132,4 +137,35 @@ TestCase { } } } + + function test_mouseArea_data() { + return [ + { tag: "interactive", interactive: true }, + { tag: "non-interactive", interactive: false } + ] + } + + // QTBUG-61785 + function test_mouseArea(data) { + var ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) + verify(ma) + + var control = pageIndicator.createObject(ma, {count: 5, interactive: data.interactive, width: testCase.width, height: testCase.height}) + verify(control) + + compare(control.interactive, data.interactive) + + mousePress(control) + compare(ma.pressed, !data.interactive) + + mouseRelease(control) + verify(!ma.pressed) + + var touch = touchEvent(control) + touch.press(0, control).commit() + compare(ma.pressed, !data.interactive) + + touch.release(0, control).commit() + verify(!ma.pressed) + } } -- cgit v1.2.3