summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel/qwidget
diff options
context:
space:
mode:
authorAlexander Volkov <a.volkov@rusbitech.ru>2014-09-18 13:13:21 +0400
committerShawn Rutledge <shawn.rutledge@theqtcompany.com>2016-03-05 21:49:59 +0000
commit559152d911ceff8af5020355b35d7a1da100398c (patch)
treeb522f0c3403dd961ffdf711675ad8335ffc12456 /tests/auto/widgets/kernel/qwidget
parent00f1c4ac3a0bbaac6996a0192abc3240972a34b5 (diff)
Make an implicit grab on TouchBegin for a widget subscribed to a gesture
A receiver of TouchUpdate and TouchEnd events is determined either as a widget which has an implicit grab for the touch point or as a visible widget if there are no implicit grabs. The events are sent if the receiver has accepted TouchBegin event or if it is subscribed to a gesture. Before sending the events to the widget they are delivered to the gesture manager. Thus, in order to detect gestures for the widget, it must own an implicit grab or be a visible widget. It can happen that the parent widget is subscribed to a gesture, but doesn't accept TouchBegin event, as in the case of QScrollArea. Then it will not get an implicit grab and gesture detection will be impossible. Activate an implicit grab for such widgets. Also don't send TouchUpdate and TouchEnd to them, because it's against the documentation. Task-number: QTBUG-43277 Change-Id: Id767583991def6d76c48ad15eb39af822cad115d Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets/kernel/qwidget')
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 293689bff3..fb3e644a5c 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -447,6 +447,7 @@ private slots:
void touchEventSynthesizedMouseEvent();
void touchUpdateOnNewTouch();
+ void touchEventsForGesturePendingWidgets();
void styleSheetPropagation();
@@ -9788,6 +9789,7 @@ public:
m_touchUpdateCount(0),
m_touchEndCount(0),
m_touchEventCount(0),
+ m_gestureEventCount(0),
m_acceptTouch(false),
m_mouseEventCount(0),
m_acceptMouse(true)
@@ -9825,6 +9827,9 @@ protected:
else
e->ignore();
return true;
+ case QEvent::Gesture:
+ ++m_gestureEventCount;
+ return true;
case QEvent::MouseButtonPress:
case QEvent::MouseMove:
@@ -9847,6 +9852,7 @@ public:
int m_touchUpdateCount;
int m_touchEndCount;
int m_touchEventCount;
+ int m_gestureEventCount;
bool m_acceptTouch;
int m_mouseEventCount;
bool m_acceptMouse;
@@ -10002,6 +10008,48 @@ void tst_QWidget::touchUpdateOnNewTouch()
QCOMPARE(widget.m_touchEndCount, 1);
}
+void tst_QWidget::touchEventsForGesturePendingWidgets()
+{
+ QTouchDevice *device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+
+ TouchMouseWidget parent;
+ TouchMouseWidget child(&parent);
+ parent.grabGesture(Qt::TapAndHoldGesture);
+ parent.show();
+
+ QWindow* window = parent.windowHandle();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+ QTest::qWait(500); // needed for QApplication::topLevelAt(), which is used by QGestureManager
+ QCOMPARE(child.m_touchEventCount, 0);
+ QCOMPARE(child.m_gestureEventCount, 0);
+ QCOMPARE(parent.m_touchEventCount, 0);
+ QCOMPARE(parent.m_gestureEventCount, 0);
+ QTest::touchEvent(window, device).press(0, QPoint(20, 20), window);
+ QCOMPARE(child.m_touchEventCount, 0);
+ QCOMPARE(child.m_gestureEventCount, 0);
+ QCOMPARE(parent.m_touchBeginCount, 1); // QTapAndHoldGestureRecognizer::create() sets Qt::WA_AcceptTouchEvents
+ QCOMPARE(parent.m_touchUpdateCount, 0);
+ QCOMPARE(parent.m_touchEndCount, 0);
+ QCOMPARE(parent.m_gestureEventCount, 0);
+ QTest::touchEvent(window, device).move(0, QPoint(25, 25), window);
+ QCOMPARE(child.m_touchEventCount, 0);
+ QCOMPARE(child.m_gestureEventCount, 0);
+ QCOMPARE(parent.m_touchBeginCount, 1);
+ QCOMPARE(parent.m_touchUpdateCount, 0);
+ QCOMPARE(parent.m_touchEndCount, 0);
+ QCOMPARE(parent.m_gestureEventCount, 0);
+ QTest::qWait(1000);
+ QTest::touchEvent(window, device).release(0, QPoint(25, 25), window);
+ QCOMPARE(child.m_touchEventCount, 0);
+ QCOMPARE(child.m_gestureEventCount, 0);
+ QCOMPARE(parent.m_touchBeginCount, 1);
+ QCOMPARE(parent.m_touchUpdateCount, 0);
+ QCOMPARE(parent.m_touchEndCount, 0);
+ QVERIFY(parent.m_gestureEventCount > 0);
+}
+
void tst_QWidget::styleSheetPropagation()
{
QTableView tw;