summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Krus <mike.krus@kdab.com>2020-11-20 17:03:16 +0000
committerMike Krus <mike.krus@kdab.com>2020-12-01 09:29:29 +0000
commitb96d3752e30d0556b812ce0f620738e18ee467ea (patch)
tree7ed464e0bdd91a46583781cb89c36bc162b69767
parent4e248d8d0229f8afa283e9e9fe57f54a92bf4477 (diff)
Handle API changes for event handling
QMouseEvent position getter is different between 5.15 and 6 Change-Id: I45fd7a1350624f725bd35c5ea33f7da75d8f31a1 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r--src/input/backend/inputhandler.cpp7
-rw-r--r--src/input/backend/mousedevice.cpp9
-rw-r--r--src/input/frontend/qmouseevent.h5
-rw-r--r--src/render/jobs/pickboundingvolumejob.cpp13
-rw-r--r--src/render/picking/pickeventfilter.cpp7
5 files changed, 35 insertions, 6 deletions
diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp
index ae29ab28b..20ad24001 100644
--- a/src/input/backend/inputhandler.cpp
+++ b/src/input/backend/inputhandler.cpp
@@ -78,7 +78,12 @@ protected:
case QEvent::HoverMove: {
const QHoverEvent *he = static_cast<QHoverEvent *>(e);
auto mouseEvent = QT_PREPEND_NAMESPACE(QMouseEvent)(QEvent::MouseMove,
- he->position(), Qt::NoButton, Qt::NoButton,
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ he->position(),
+#else
+ he->pos(),
+#endif
+ Qt::NoButton, Qt::NoButton,
he->modifiers());
return processMouseEvent(obj, static_cast<QT_PREPEND_NAMESPACE(QMouseEvent) *>(&mouseEvent));
}
diff --git a/src/input/backend/mousedevice.cpp b/src/input/backend/mousedevice.cpp
index 21a765b3f..ee4e47652 100644
--- a/src/input/backend/mousedevice.cpp
+++ b/src/input/backend/mousedevice.cpp
@@ -147,11 +147,20 @@ void MouseDevice::updateMouseEvent(QT_PREPEND_NAMESPACE(QMouseEvent) *event)
m_mouseState.rightPressed = event->buttons() & (Qt::RightButton);
const bool pressed = m_mouseState.leftPressed || m_mouseState.centerPressed || m_mouseState.rightPressed;
if (m_updateAxesContinuously || (m_wasPressed && pressed)) {
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
m_mouseState.xAxis += m_sensitivity * float(event->globalPosition().x() - m_previousPos.x());
m_mouseState.yAxis += m_sensitivity * float(m_previousPos.y() - event->globalPosition().y());
+#else
+ m_mouseState.xAxis += m_sensitivity * float(event->globalX() - m_previousPos.x());
+ m_mouseState.yAxis += m_sensitivity * float(m_previousPos.y() - event->globalY());
+#endif
}
m_wasPressed = pressed;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
m_previousPos = event->globalPosition();
+#else
+ m_previousPos = event->globalPos();
+#endif
}
void MouseDevice::resetMouseAxisState()
diff --git a/src/input/frontend/qmouseevent.h b/src/input/frontend/qmouseevent.h
index 809c71ec5..884cec1d6 100644
--- a/src/input/frontend/qmouseevent.h
+++ b/src/input/frontend/qmouseevent.h
@@ -85,8 +85,13 @@ public:
explicit QMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &e);
~QMouseEvent();
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
inline int x() const { return int(m_event->position().x()); }
inline int y() const { return int(m_event->position().y()); }
+#else
+ inline int x() const { return int(m_event->x()); }
+ inline int y() const { return int(m_event->y()); }
+#endif
inline bool wasHeld() const {
#if QT_CONFIG(gestures)
return static_cast<Qt::GestureType>(m_event->type()) == Qt::TapAndHoldGesture;
diff --git a/src/render/jobs/pickboundingvolumejob.cpp b/src/render/jobs/pickboundingvolumejob.cpp
index 2420ce439..f2ae6312e 100644
--- a/src/render/jobs/pickboundingvolumejob.cpp
+++ b/src/render/jobs/pickboundingvolumejob.cpp
@@ -417,9 +417,14 @@ void PickBoundingVolumeJob::dispatchPickEvents(const QMouseEvent *event,
localIntersection = entity->worldTransform()->inverted() * hit.m_intersection;
QPickEventPtr pickEvent;
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ const auto eventPos = event->position();
+#else
+ const auto eventPos = event->pos();
+#endif
switch (hit.m_type) {
case QCollisionQueryResult::Hit::Triangle:
- pickEvent.reset(new QPickTriangleEvent(event->position(),
+ pickEvent.reset(new QPickTriangleEvent(eventPos,
convertToQVector3D(hit.m_intersection),
convertToQVector3D(localIntersection),
hit.m_distance,
@@ -432,7 +437,7 @@ void PickBoundingVolumeJob::dispatchPickEvents(const QMouseEvent *event,
convertToQVector3D(hit.m_uvw)));
break;
case QCollisionQueryResult::Hit::Edge:
- pickEvent.reset(new QPickLineEvent(event->position(),
+ pickEvent.reset(new QPickLineEvent(eventPos,
convertToQVector3D(hit.m_intersection),
convertToQVector3D(localIntersection),
hit.m_distance,
@@ -441,7 +446,7 @@ void PickBoundingVolumeJob::dispatchPickEvents(const QMouseEvent *event,
eventButton, eventButtons, eventModifiers));
break;
case QCollisionQueryResult::Hit::Point:
- pickEvent.reset(new QPickPointEvent(event->position(),
+ pickEvent.reset(new QPickPointEvent(eventPos,
convertToQVector3D(hit.m_intersection),
convertToQVector3D(localIntersection),
hit.m_distance,
@@ -449,7 +454,7 @@ void PickBoundingVolumeJob::dispatchPickEvents(const QMouseEvent *event,
eventButton, eventButtons, eventModifiers));
break;
case QCollisionQueryResult::Hit::Entity:
- pickEvent.reset(new QPickEvent(event->position(),
+ pickEvent.reset(new QPickEvent(eventPos,
convertToQVector3D(hit.m_intersection),
convertToQVector3D(localIntersection),
hit.m_distance,
diff --git a/src/render/picking/pickeventfilter.cpp b/src/render/picking/pickeventfilter.cpp
index 998829b34..a41ed6c1e 100644
--- a/src/render/picking/pickeventfilter.cpp
+++ b/src/render/picking/pickeventfilter.cpp
@@ -72,7 +72,12 @@ bool PickEventFilter::eventFilter(QObject *obj, QEvent *e)
case QEvent::HoverMove: {
QHoverEvent *he = static_cast<QHoverEvent *>(e);
auto mouseEvent = QMouseEvent(QEvent::MouseMove,
- he->position(), Qt::NoButton, Qt::NoButton,
+#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
+ he->position(),
+#else
+ he->pos(),
+#endif
+ Qt::NoButton, Qt::NoButton,
he->modifiers());
return m_aspect->processMouseEvent(obj, &mouseEvent);
}