diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-07-12 10:34:50 +0200 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2016-09-08 06:44:13 +0000 |
commit | 5658ef78130eab0d83f38e4e946febfe5bc48922 (patch) | |
tree | 393382d9a0b59fc888887f28862769c0ce851ea7 | |
parent | de16b5d1409300351f98c4aa8c7103f3c6b8eaba (diff) |
MouseDevice: add wheel axes handling
Change-Id: Ie2a7c3e6e4c5ec10358bac70055c28fa81bbc117
Task-number: QTBUG-54620
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
-rw-r--r-- | src/input/backend/inputhandler.cpp | 1 | ||||
-rw-r--r-- | src/input/backend/mousedevice.cpp | 18 | ||||
-rw-r--r-- | src/input/backend/mousedevice_p.h | 5 |
3 files changed, 23 insertions, 1 deletions
diff --git a/src/input/backend/inputhandler.cpp b/src/input/backend/inputhandler.cpp index 82b017b1c..fe2a04bd7 100644 --- a/src/input/backend/inputhandler.cpp +++ b/src/input/backend/inputhandler.cpp @@ -249,6 +249,7 @@ QVector<Qt3DCore::QAspectJobPtr> InputHandler::mouseJobs() MouseDevice *controller = m_mouseDeviceManager->data(cHandle); controller->updateMouseEvents(mouseEvents); + controller->updateWheelEvents(wheelEvents); // Event dispacthing job if (!mouseEvents.isEmpty() || !wheelEvents.empty()) { // Send the events to the mouse handlers that have for sourceDevice controller diff --git a/src/input/backend/mousedevice.cpp b/src/input/backend/mousedevice.cpp index a2f106d94..e649824a4 100644 --- a/src/input/backend/mousedevice.cpp +++ b/src/input/backend/mousedevice.cpp @@ -84,7 +84,10 @@ float MouseDevice::axisValue(int axisIdentifier) const return m_mouseState.xAxis; case QMouseDevice::Y: return m_mouseState.yAxis; - break; + case QMouseDevice::WheelX: + return m_mouseState.wXAxis; + case QMouseDevice::WheelY: + return m_mouseState.wYAxis; default: break; } @@ -106,6 +109,19 @@ bool MouseDevice::isButtonPressed(int buttonIdentifier) const return false; } +void MouseDevice::updateWheelEvents(const QList<QT_PREPEND_NAMESPACE (QWheelEvent)> &events) +{ + // Reset axis values before we accumulate new values for this frame + m_mouseState.wXAxis = 0.0f; + m_mouseState.wYAxis = 0.0f; + if (!events.isEmpty()) { + for (const QT_PREPEND_NAMESPACE(QWheelEvent) &e : events) { + m_mouseState.wXAxis += m_sensitivity * e.angleDelta().x(); + m_mouseState.wYAxis += m_sensitivity * e.angleDelta().y(); + } + } +} + void MouseDevice::updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &events) { // Reset axis values before we accumulate new values for this frame diff --git a/src/input/backend/mousedevice_p.h b/src/input/backend/mousedevice_p.h index 723945554..02a6d916e 100644 --- a/src/input/backend/mousedevice_p.h +++ b/src/input/backend/mousedevice_p.h @@ -76,6 +76,7 @@ public: bool isButtonPressed(int buttonIdentifier) const Q_DECL_OVERRIDE; void updateMouseEvents(const QList<QT_PREPEND_NAMESPACE(QMouseEvent)> &events); + void updateWheelEvents(const QList<QT_PREPEND_NAMESPACE(QWheelEvent)> &events); protected: void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; @@ -90,6 +91,8 @@ private: MouseState() : xAxis(0.0f) , yAxis(0.0f) + , wXAxis(0.0f) + , wYAxis(0.0f) , leftPressed(false) , rightPressed(false) , centerPressed(false) @@ -97,6 +100,8 @@ private: float xAxis; float yAxis; + float wXAxis; + float wYAxis; bool leftPressed; bool rightPressed; bool centerPressed; |