diff options
author | Rafael Roquetto <rafael.roquetto@kdab.com> | 2015-09-03 16:53:53 +0000 |
---|---|---|
committer | Rafael Roquetto <rafael.roquetto@kdab.com> | 2015-09-22 20:54:44 +0000 |
commit | f5b682d320401dd82c37cee0b2e400966460e37c (patch) | |
tree | 4a0240315bbcc3f726a8e3baecc6a96522825bfb /tests/auto | |
parent | 24d0f9ef5aa81390fc315fccae616191a88c26d9 (diff) |
QGraphicsProxyWidget: forward touch events to QWidget
When working with QGraphicsView/QGraphicsScene, touch events are sent to
QGraphicsView's viewport() event handler, which then dispatches it to the
corresponding QGraphicsItem, if any. In the case of QGraphicsProxyWidget, we
need to forward these touch events to the encapsulated QWidget, otherwise it
will never receive them (i.e. the event chain for touch events terminates at
QGraphicsProxyWidget).
This also enables QWidgets associated with QGraphicsProxyWidget to grab
gestures.
Task-id: QTBUG-45737
Change-Id: Ia441d3576afb6c97376be6f2ff073901e6e928a5
Reviewed-by: Andreas Aardal Hanssen <andreas@hanssen.name>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 4896d52343..8760dc176c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -179,6 +179,7 @@ private slots: void mapToGlobal(); void mapToGlobalWithoutScene(); void QTBUG_43780_visibility(); + void forwardTouchEvent(); }; // Subclass that exposes the protected functions. @@ -3760,5 +3761,73 @@ void tst_QGraphicsProxyWidget::QTBUG_43780_visibility() QVERIFY(comboPopup->isVisible()); } +class TouchWidget : public QWidget +{ +public: + TouchWidget(QWidget *parent = 0) : QWidget(parent) {} + + bool event(QEvent *event) + { + switch (event->type()) { + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + event->accept(); + return true; + break; + default: + break; + } + + return QWidget::event(event); + } +}; + +// QTBUG_45737 +void tst_QGraphicsProxyWidget::forwardTouchEvent() +{ + QGraphicsScene *scene = new QGraphicsScene; + + TouchWidget *widget = new TouchWidget; + + widget->setAttribute(Qt::WA_AcceptTouchEvents); + + QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget; + + proxy->setAcceptTouchEvents(true); + proxy->setWidget(widget); + + scene->addItem(proxy); + + QGraphicsView *view = new QGraphicsView(scene); + + view->show(); + + EventSpy eventSpy(widget); + + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + + QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 0); + QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 0); + QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 0); + + QTest::touchEvent(view, device).press(0, QPoint(10, 10), view); + QTest::touchEvent(view, device).move(0, QPoint(15, 15), view); + QTest::touchEvent(view, device).move(0, QPoint(16, 16), view); + QTest::touchEvent(view, device).release(0, QPoint(15, 15), view); + + QApplication::processEvents(); + + QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 1); + QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 2); + QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 1); + + delete view; + delete proxy; + delete scene; +} + QTEST_MAIN(tst_QGraphicsProxyWidget) #include "tst_qgraphicsproxywidget.moc" |