diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2015-12-06 13:28:24 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2015-12-07 19:07:25 +0000 |
commit | c807454297e171abc822e56dc5940d61a3d9abd3 (patch) | |
tree | 3fb36a0aadc22713352a1ea8aedbc300f71615d7 /src/input/frontend | |
parent | a48bf6131e07efc178d4175df7eee9704ca97826 (diff) |
Add sensitivity property to QMouseController
The sensitivity is defined as the recipricol of the number of pixels
the mouse is required to move to obtain the extreme axis value (-1 or
+1). That is if you set it to 0.1 you need to move the mouse 10 pixels
to get an axis value of magnitude 1. If it is 0.01, 100 pixels gives
an axis value of magnitude 1.
The user is responsible for applying any additional transformations in
a suitable handler.
Change-Id: I51cd28a17d4fc0b8461ac3e49efb26b2c66081b3
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/input/frontend')
-rw-r--r-- | src/input/frontend/qmousecontroller.cpp | 24 | ||||
-rw-r--r-- | src/input/frontend/qmousecontroller.h | 11 | ||||
-rw-r--r-- | src/input/frontend/qmousecontroller_p.h | 2 |
3 files changed, 36 insertions, 1 deletions
diff --git a/src/input/frontend/qmousecontroller.cpp b/src/input/frontend/qmousecontroller.cpp index 1ec91ec9b..a8e3cbc61 100644 --- a/src/input/frontend/qmousecontroller.cpp +++ b/src/input/frontend/qmousecontroller.cpp @@ -46,6 +46,7 @@ namespace Qt3DInput { QMouseControllerPrivate::QMouseControllerPrivate() : QAbstractPhysicalDevicePrivate() + , m_sensitivity(0.1f) { } @@ -126,6 +127,29 @@ int QMouseController::buttonIdentifier(const QString &name) return -1; } +float QMouseController::sensitivity() const +{ + Q_D(const QMouseController); + return d->m_sensitivity; +} + +void QMouseController::setSensitivity(float value) +{ + Q_D(QMouseController); + if (qFuzzyCompare(value, d->m_sensitivity)) + return; + + d->m_sensitivity = value; + emit sensitivityChanged(value); +} + +void QMouseController::copy(const Qt3DCore::QNode *ref) +{ + QNode::copy(ref); + const QMouseController *object = static_cast<const QMouseController *>(ref); + d_func()->m_sensitivity = object->d_func()->m_sensitivity; +} + void QMouseController::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) { Q_UNUSED(change); diff --git a/src/input/frontend/qmousecontroller.h b/src/input/frontend/qmousecontroller.h index ce9c2b2bc..8a03d7e14 100644 --- a/src/input/frontend/qmousecontroller.h +++ b/src/input/frontend/qmousecontroller.h @@ -50,6 +50,7 @@ class QMouseInput; class QT3DINPUTSHARED_EXPORT QMouseController : public Qt3DInput::QAbstractPhysicalDevice { Q_OBJECT + Q_PROPERTY(float sensitivity READ sensitivity WRITE setSensitivity NOTIFY sensitivityChanged) public: explicit QMouseController(Qt3DCore::QNode *parent = 0); ~QMouseController(); @@ -74,9 +75,17 @@ public: int axisIdentifier(const QString &name) Q_DECL_FINAL; int buttonIdentifier(const QString &name) Q_DECL_FINAL; + float sensitivity() const; + +public Q_SLOTS: + void setSensitivity(float value); + +Q_SIGNALS: + void sensitivityChanged(float value); + protected: QMouseController(QMouseControllerPrivate &dd, Qt3DCore::QNode *parent = 0); - + void copy(const Qt3DCore::QNode *ref) Q_DECL_OVERRIDE; void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE; private: diff --git a/src/input/frontend/qmousecontroller_p.h b/src/input/frontend/qmousecontroller_p.h index efffdf51b..4e0faa6f2 100644 --- a/src/input/frontend/qmousecontroller_p.h +++ b/src/input/frontend/qmousecontroller_p.h @@ -62,6 +62,8 @@ public: QMouseControllerPrivate(); Q_DECLARE_PUBLIC(QMouseController) + + float m_sensitivity; }; } // namespace Qt3DInput |