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 committed Oct 21, 2024
1 parent 80671b4 commit ba2dc75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 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
16 changes: 12 additions & 4 deletions libshvvisu/src/svgscene/graphicsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@

#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)
{
#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);
}
}
#else
#ifdef ANDROID
QScroller::grabGesture(viewport(), QScroller::LeftMouseButtonGesture);
grabGesture(Qt::PinchGesture);
#endif
#endif
}

void GraphicsView::zoomToFit()
Expand Down Expand Up @@ -105,7 +115,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 +133,5 @@ bool GraphicsView::event(QEvent *event)
}
return Super::event(event);
}
#endif

}

0 comments on commit ba2dc75

Please sign in to comment.