From bb0794e2ad195d7c458a06537baf7d57ba7446be Mon Sep 17 00:00:00 2001 From: janbar Date: Tue, 17 Sep 2024 11:03:16 +0200 Subject: [PATCH] final fix for screen touch/pointer event with qt6 On platform without mouse pointer, touch events should be accepted and processed without translations. --- .../src/osmscoutclientqt/MapWidget.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp b/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp index 965942e1a..58e1b29ff 100644 --- a/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp +++ b/libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp @@ -41,6 +41,9 @@ MapWidget::MapWidget(QQuickItem* parent) setOpaquePainting(true); setAcceptedMouseButtons(Qt::LeftButton); setAcceptHoverEvents(true); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + setAcceptTouchEvents(true); +#endif renderer = OSMScoutQt::GetInstance().MakeMapRenderer(renderingType); auto settings=OSMScoutQt::GetInstance().GetSettings(); @@ -101,24 +104,21 @@ void MapWidget::translateToTouch(QMouseEvent* event, Qt::TouchPointStates states { assert(event); -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + // translate the mouse event for desktop device without touch pointer + QTouchEvent touchEvnt(QEvent::TouchBegin, event->pointingDevice(), Qt::NoModifier, event->points()); +#else QTouchEvent::TouchPoint touchPoint; touchPoint.setPressure(1); touchPoint.setPos(event->pos()); touchPoint.setState(states); QList points; points << touchPoint; -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - QTouchEvent touchEvnt(QEvent::TouchBegin, 0, Qt::NoModifier, 0, points); -#else +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) QTouchEvent touchEvnt(QEvent::TouchBegin, 0, Qt::NoModifier, Qt::TouchPointStates(), points); -#endif #else - // TODO: rework - // 6.7.2: CTOR QEventPoint fails to initialize the position, so pass directly event points - // 6.7.2: Without passing a valid pointer to device, it will crash later on released event by - // calling QQuickWindowPrivate::clearGrabbers >> QPointerEvent::setExclusiveGrabber - QTouchEvent touchEvnt(QEvent::TouchBegin, event->pointingDevice(), Qt::NoModifier, event->points()); + QTouchEvent touchEvnt(QEvent::TouchBegin, 0, Qt::NoModifier, 0, points); +#endif #endif //qDebug() << "translate mouse event to touch event: "<< touchEvnt;