Skip to content

Commit

Permalink
support touchscreen even on non android device
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Špirk authored and fvacek committed Oct 21, 2024
1 parent a2811c6 commit 5d49c61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 0 additions & 2 deletions libshvvisu/include/shv/visu/svgscene/graphicsview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 11 additions & 7 deletions libshvvisu/src/svgscene/graphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

#include <shv/visu/svgscene/graphicsview.h>

#if QT_VERSION_MAJOR >= 6
#include <QInputDevice>
#endif
#include <QMouseEvent>

#ifdef ANDROID
#include <QGestureEvent>
#include <QScroller>
#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
}

Expand Down Expand Up @@ -105,7 +111,6 @@ void GraphicsView::mouseMoveEvent(QMouseEvent* ev)
Super::mouseMoveEvent(ev);
}

#ifdef ANDROID
bool GraphicsView::event(QEvent *event)
{
if (event->type() == QEvent::Gesture) {
Expand All @@ -124,6 +129,5 @@ bool GraphicsView::event(QEvent *event)
}
return Super::event(event);
}
#endif

}

0 comments on commit 5d49c61

Please sign in to comment.