From 8ac7580ab57abb59120691669703f7119dd6ec1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0pirk?= Date: Mon, 21 Oct 2024 12:49:14 +0200 Subject: [PATCH] support touchscreen even on non android device --- .../include/shv/visu/svgscene/graphicsview.h | 2 -- libshvvisu/src/svgscene/graphicsview.cpp | 18 +++++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/libshvvisu/include/shv/visu/svgscene/graphicsview.h b/libshvvisu/include/shv/visu/svgscene/graphicsview.h index 55d1e1a29..bcc678bdb 100644 --- a/libshvvisu/include/shv/visu/svgscene/graphicsview.h +++ b/libshvvisu/include/shv/visu/svgscene/graphicsview.h @@ -25,9 +25,7 @@ class SHVVISU_DECL_EXPORT GraphicsView : public QGraphicsView void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE; -#ifdef ANDROID bool event(QEvent *event) override; -#endif private: QPoint m_dragMouseStartPos; diff --git a/libshvvisu/src/svgscene/graphicsview.cpp b/libshvvisu/src/svgscene/graphicsview.cpp index 1e46d0887..11474ab98 100644 --- a/libshvvisu/src/svgscene/graphicsview.cpp +++ b/libshvvisu/src/svgscene/graphicsview.cpp @@ -2,21 +2,27 @@ #include +#if QT_VERSION_MAJOR >= 6 +#include +#endif #include -#ifdef ANDROID #include #include -#endif namespace shv::visu::svgscene { GraphicsView::GraphicsView(QWidget *parent) : Super(parent) { -#ifdef ANDROID - QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture); - grabGesture(Qt::PinchGesture); +#if QT_VERSION_MAJOR >= 6 + for (const auto &id : QInputDevice::devices()) { + if (id->type() == QInputDevice::DeviceType::TouchScreen) { + QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture); + grabGesture(Qt::PinchGesture); + break; + } + } #endif } @@ -105,7 +111,6 @@ void GraphicsView::mouseMoveEvent(QMouseEvent* ev) Super::mouseMoveEvent(ev); } -#ifdef ANDROID bool GraphicsView::event(QEvent *event) { if (event->type() == QEvent::Gesture) { @@ -124,6 +129,5 @@ bool GraphicsView::event(QEvent *event) } return Super::event(event); } -#endif }