Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support touchscreen even on non android device #503

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

}