From 64f983af68440ff73b985b133a73bd66178557da Mon Sep 17 00:00:00 2001 From: Paul Lemire Date: Mon, 13 Jan 2020 07:53:41 +0100 Subject: QMouseDevice: add updateAxesContinuously property The default behavior is to only update axes when one of the mouse buttons is pressed. This property, when enabled, allows to record X/Y axes value changes regardless of the state of the mouse buttons. [ChangeLog] QMouseDevice add updateAxesContinuously property Change-Id: Ib54a1e54c6c278ea08722760c2d317ec46437b2f Reviewed-by: Mike Krus --- src/input/backend/mousedevice.cpp | 11 +++++++++-- src/input/backend/mousedevice_p.h | 2 ++ src/input/frontend/qmousedevice.cpp | 38 +++++++++++++++++++++++++++++++++++++ src/input/frontend/qmousedevice.h | 4 ++++ src/input/frontend/qmousedevice_p.h | 1 + 5 files changed, 54 insertions(+), 2 deletions(-) (limited to 'src/input') diff --git a/src/input/backend/mousedevice.cpp b/src/input/backend/mousedevice.cpp index 47045a1a1..c5b2a22ce 100644 --- a/src/input/backend/mousedevice.cpp +++ b/src/input/backend/mousedevice.cpp @@ -57,6 +57,7 @@ MouseDevice::MouseDevice() , m_inputHandler(nullptr) , m_wasPressed(false) , m_sensitivity(0.1f) + , m_updateAxesContinuously(false) { } @@ -126,6 +127,11 @@ float MouseDevice::sensitivity() const return m_sensitivity; } +bool MouseDevice::updateAxesContinuously() const +{ + return m_updateAxesContinuously; +} + #if QT_CONFIG(wheelevent) void MouseDevice::updateWheelEvents(const QList &events) { @@ -153,8 +159,8 @@ void MouseDevice::updateMouseEvents(const QListsensitivity(); + m_updateAxesContinuously = node->updateAxesContinuously(); } MouseDeviceFunctor::MouseDeviceFunctor(QInputAspect *inputAspect, InputHandler *handler) diff --git a/src/input/backend/mousedevice_p.h b/src/input/backend/mousedevice_p.h index 283eeaeaf..d41bb527b 100644 --- a/src/input/backend/mousedevice_p.h +++ b/src/input/backend/mousedevice_p.h @@ -107,6 +107,7 @@ public: QPointF previousPos() const; bool wasPressed() const; float sensitivity() const; + bool updateAxesContinuously() const; void syncFromFrontEnd(const Qt3DCore::QNode *frontEnd, bool firstTime) override; @@ -117,6 +118,7 @@ private: QPointF m_previousPos; bool m_wasPressed; float m_sensitivity; + bool m_updateAxesContinuously; }; class MouseDeviceFunctor : public Qt3DCore::QBackendNodeMapper diff --git a/src/input/frontend/qmousedevice.cpp b/src/input/frontend/qmousedevice.cpp index 4a78b3b21..5872fbcd2 100644 --- a/src/input/frontend/qmousedevice.cpp +++ b/src/input/frontend/qmousedevice.cpp @@ -52,6 +52,7 @@ namespace Qt3DInput { QMouseDevicePrivate::QMouseDevicePrivate() : QAbstractPhysicalDevicePrivate() , m_sensitivity(0.1f) + , m_updateContinuously(false) { } @@ -106,6 +107,27 @@ QMouseDevicePrivate::QMouseDevicePrivate() Default is 0.1. */ +/*! + \property Qt3DInput::QMouseDevice::updateAxesContinously + + If true, axes will be updated anytime they change regardless of whether + any mouse button is being pressed. Otherwise, axes are updated only when + one of the mouse buttons is being pressed. + + \since 5.15 + \default false +*/ + +/*! + \qmlproperty bool MouseDevice::updateAxesContinously + + If true, axes will be updated anytime they change regardless of whether + any mouse button is being pressed. Otherwise, axes are updated only when + one of the mouse buttons is being pressed. + + \since 5.15 + \default false +*/ /*! Constructs a new QMouseDevice instance with parent \a parent. @@ -211,6 +233,12 @@ float QMouseDevice::sensitivity() const return d->m_sensitivity; } +bool QMouseDevice::updateAxesContinuously() const +{ + Q_D(const QMouseDevice); + return d->m_updateContinuously; +} + void QMouseDevice::setSensitivity(float value) { Q_D(QMouseDevice); @@ -221,6 +249,16 @@ void QMouseDevice::setSensitivity(float value) emit sensitivityChanged(value); } +void QMouseDevice::setUpdateAxesContinuously(bool updateAxesContinuously) +{ + Q_D(QMouseDevice); + if (d->m_updateContinuously == updateAxesContinuously) + return; + + d->m_updateContinuously = updateAxesContinuously; + emit updateAxesContinuouslyChanged(updateAxesContinuously); +} + /*! \internal */ void QMouseDevice::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) { diff --git a/src/input/frontend/qmousedevice.h b/src/input/frontend/qmousedevice.h index 01e243790..7754c2e29 100644 --- a/src/input/frontend/qmousedevice.h +++ b/src/input/frontend/qmousedevice.h @@ -57,6 +57,7 @@ class Q_3DINPUTSHARED_EXPORT QMouseDevice : public Qt3DInput::QAbstractPhysicalD { Q_OBJECT Q_PROPERTY(float sensitivity READ sensitivity WRITE setSensitivity NOTIFY sensitivityChanged) + Q_PROPERTY(bool updateAxesContinuously READ updateAxesContinuously WRITE setUpdateAxesContinuously NOTIFY updateAxesContinuouslyChanged REVISION 15) public: explicit QMouseDevice(Qt3DCore::QNode *parent = nullptr); ~QMouseDevice(); @@ -77,12 +78,15 @@ public: int buttonIdentifier(const QString &name) const final; float sensitivity() const; + bool updateAxesContinuously() const; public Q_SLOTS: void setSensitivity(float value); + void setUpdateAxesContinuously(bool updateAxesContinuously); Q_SIGNALS: void sensitivityChanged(float value); + void updateAxesContinuouslyChanged(bool updateAxesContinuously); protected: void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override; diff --git a/src/input/frontend/qmousedevice_p.h b/src/input/frontend/qmousedevice_p.h index 49c1c6191..91daccb6f 100644 --- a/src/input/frontend/qmousedevice_p.h +++ b/src/input/frontend/qmousedevice_p.h @@ -67,6 +67,7 @@ public: Q_DECLARE_PUBLIC(QMouseDevice) float m_sensitivity; + bool m_updateContinuously; }; struct QMouseDeviceData -- cgit v1.2.3