diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-08-18 17:33:29 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-26 14:14:32 +0000 |
commit | c50313b7126917edeb335288153dd4a7290c8c3f (patch) | |
tree | 02e398588e425f30b6565e5211bf74ce48d2b8d8 /src | |
parent | aaa79cf73512a16724f084450025d223154b9f9e (diff) |
Forward touchEvents to children inside QGraphicsProxyWidget
Just sending the event to the embedded widget is not enough, we
have to perform hit-testing for the different touch points, and
send the event to the child widget under the point. Fortunately,
QApplicationPrivate::translateRawTouchEvent provides the logic
that generates multiple events for groups of touch points.
Since that helper always sent events spontaneously, add an
optional parameter to allow sending of non-spontaneous events.
Add a test case that simulates touch events to different widget
configurations inside a QGraphicsProxyWidget.
Fixes: QTBUG-67819
Task-number: QTBUG-45737
Change-Id: Iffd5c84c64ee2ceadc7e31863675fdf227582c81
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 1ecf2212fae176b78c9951a37df9e33eb24d4f2d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsproxywidget.cpp | 17 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication.cpp | 11 | ||||
-rw-r--r-- | src/widgets/kernel/qapplication_p.h | 3 |
3 files changed, 19 insertions, 12 deletions
diff --git a/src/widgets/graphicsview/qgraphicsproxywidget.cpp b/src/widgets/graphicsview/qgraphicsproxywidget.cpp index aaddaa894f..2641e24b9a 100644 --- a/src/widgets/graphicsview/qgraphicsproxywidget.cpp +++ b/src/widgets/graphicsview/qgraphicsproxywidget.cpp @@ -916,16 +916,17 @@ bool QGraphicsProxyWidget::event(QEvent *event) case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: { - if (event->spontaneous()) - qt_sendSpontaneousEvent(d->widget, event); - else - QCoreApplication::sendEvent(d->widget, event); - - if (event->isAccepted()) + QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); + auto touchPoints = touchEvent->points(); + bool res = QApplicationPrivate::translateRawTouchEvent(d->widget, touchEvent->pointingDevice(), + touchPoints, touchEvent->timestamp(), + event->spontaneous()); + if (res) { + event->accept(); return true; - + } break; - } + } default: break; } diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 0daa0cfcb6..b73db6d583 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -3928,7 +3928,8 @@ void QApplicationPrivate::activateImplicitTouchGrab(QWidget *widget, QTouchEvent bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, const QPointingDevice *device, QList<QEventPoint> &touchPoints, - ulong timestamp) + ulong timestamp, + bool spontaneous) { QApplicationPrivate *d = self; // TODO get rid of this QPair @@ -4030,7 +4031,9 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, { // if the TouchBegin handler recurses, we assume that means the event // has been implicitly accepted and continue to send touch events - if (QApplication::sendSpontaneousEvent(widget, &touchEvent) && touchEvent.isAccepted()) { + bool res = spontaneous ? QApplication::sendSpontaneousEvent(widget, &touchEvent) + : QApplication::sendEvent(widget, &touchEvent); + if (res && touchEvent.isAccepted()) { accepted = true; if (!widget.isNull()) widget->setAttribute(Qt::WA_WState_AcceptedTouchBeginEvent); @@ -4043,7 +4046,9 @@ bool QApplicationPrivate::translateRawTouchEvent(QWidget *window, || QGestureManager::gesturePending(widget) #endif ) { - if (QApplication::sendSpontaneousEvent(widget, &touchEvent) && touchEvent.isAccepted()) + bool res = spontaneous ? QApplication::sendSpontaneousEvent(widget, &touchEvent) + : QApplication::sendEvent(widget, &touchEvent); + if (res && touchEvent.isAccepted()) accepted = true; // widget can be deleted on TouchEnd if (touchEvent.type() == QEvent::TouchEnd && !widget.isNull()) diff --git a/src/widgets/kernel/qapplication_p.h b/src/widgets/kernel/qapplication_p.h index f690b07924..31dde00dd9 100644 --- a/src/widgets/kernel/qapplication_p.h +++ b/src/widgets/kernel/qapplication_p.h @@ -253,7 +253,8 @@ public: static bool translateRawTouchEvent(QWidget *widget, const QPointingDevice *device, QList<QEventPoint> &touchPoints, - ulong timestamp); + ulong timestamp, + bool spontaneous = true); static void translateTouchCancel(const QPointingDevice *device, ulong timestamp); QPixmap applyQIconStyleHelper(QIcon::Mode mode, const QPixmap& base) const override; |