diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2013-01-10 13:38:43 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-23 18:33:17 +0100 |
commit | 78ad1fabee403ac910d29bb212cf0e3b9a670708 (patch) | |
tree | 9dbfdfdab19de9666eaf2923e79d2b9141cc4eaa /src/imports | |
parent | 5700ab09b06617d73b0495d2db0696512913ba51 (diff) | |
download | qtsensors-78ad1fabee403ac910d29bb212cf0e3b9a670708.tar.gz |
Add a axes remapping feature
This allows orientable sensors like accelerometer or compass
to change to adapt the reading values based on the current
screen orientation.
Add support for the BlackBerry backend.
Change-Id: If7cfde8f20da4f677fdd13c38f7e11f2ed96bedd
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/sensors/plugins.qmltypes | 15 | ||||
-rw-r--r-- | src/imports/sensors/qmlsensor.cpp | 53 | ||||
-rw-r--r-- | src/imports/sensors/qmlsensor.h | 23 |
3 files changed, 91 insertions, 0 deletions
diff --git a/src/imports/sensors/plugins.qmltypes b/src/imports/sensors/plugins.qmltypes index fe9c961..94db26d 100644 --- a/src/imports/sensors/plugins.qmltypes +++ b/src/imports/sensors/plugins.qmltypes @@ -172,10 +172,25 @@ Module { Property { name: "error"; type: "int"; isReadonly: true } Property { name: "alwaysOn"; type: "bool" } Property { name: "skipDuplicates"; revision: 1; type: "bool" } + Property { name: "axesOrientationMode"; revision: 1; type: "AxesOrientationMode" } + Property { name: "currentOrientation"; revision: 1; type: "int"; isReadonly: true } + Property { name: "userOrientation"; revision: 1; type: "int" } Signal { name: "skipDuplicatesChanged" Parameter { name: "skipDuplicates"; type: "bool" } } + Signal { + name: "axesOrientationModeChanged" + Parameter { name: "axesOrientationMode"; type: "AxesOrientationMode" } + } + Signal { + name: "currentOrientationChanged" + Parameter { name: "currentOrientation"; type: "int" } + } + Signal { + name: "userOrientationChanged" + Parameter { name: "userOrientation"; type: "int" } + } Method { name: "start"; type: "bool" } Method { name: "stop" } } diff --git a/src/imports/sensors/qmlsensor.cpp b/src/imports/sensors/qmlsensor.cpp index 40a0ebf..727526a 100644 --- a/src/imports/sensors/qmlsensor.cpp +++ b/src/imports/sensors/qmlsensor.cpp @@ -307,6 +307,55 @@ QmlSensorReading *QmlSensor::reading() const } /*! + \qmlproperty Sensor::AxesOrientationMode Sensor::axesOrientationMode + \since QtSensors 5.1 + This property holds the mode that affects how the screen orientation changes reading values. + + Please see QSensor::axesOrientationMode for information about this property. +*/ + +QmlSensor::AxesOrientationMode QmlSensor::axesOrientationMode() const +{ + return static_cast<QmlSensor::AxesOrientationMode>(sensor()->axesOrientationMode()); +} + +void QmlSensor::setAxesOrientationMode(QmlSensor::AxesOrientationMode axesOrientationMode) +{ + sensor()->setAxesOrientationMode(static_cast<QSensor::AxesOrientationMode>(axesOrientationMode)); +} + +/*! + \qmlproperty int Sensor::currentOrientation + \since QtSensors 5.1 + This property holds the current orientation that is used for rotating the reading values. + + Please see QSensor::currentOrientation for information about this property. +*/ + +int QmlSensor::currentOrientation() const +{ + return sensor()->currentOrientation(); +} + +/*! + \qmlproperty int Sensor::userOrientation + \since QtSensors 5.1 + This property holds the angle used for rotating the reading values in the UserOrientation mode. + + Please see QSensor::userOrientation for information about this property. +*/ + +int QmlSensor::userOrientation() const +{ + return sensor()->userOrientation(); +} + +void QmlSensor::setUserOrientation(int userOrientation) +{ + sensor()->setUserOrientation(userOrientation); +} + +/*! \qmlmethod bool Sensor::start() Start retrieving values from the sensor. Returns true if the sensor was started, false otherwise. @@ -343,6 +392,10 @@ void QmlSensor::componentComplete() connect(sensor(), SIGNAL(activeChanged()), this, SIGNAL(activeChanged())); connect(sensor(), SIGNAL(alwaysOnChanged()), this, SIGNAL(alwaysOnChanged())); connect(sensor(), SIGNAL(skipDuplicatesChanged(bool)), this, SIGNAL(skipDuplicatesChanged(bool))); + connect(sensor(), SIGNAL(axesOrientationModeChanged(AxesOrientationMode)), + this, SIGNAL(axesOrientationModeChanged(AxesOrientationMode))); + connect(sensor(), SIGNAL(userOrientationChanged(int)), this, SIGNAL(userOrientationChanged(int))); + connect(sensor(), SIGNAL(currentOrientationChanged(int)), this, SIGNAL(currentOrientationChanged(int))); // We need to set this on the sensor object now sensor()->setIdentifier(m_identifier.toLocal8Bit()); diff --git a/src/imports/sensors/qmlsensor.h b/src/imports/sensors/qmlsensor.h index e287f19..9b8f7b7 100644 --- a/src/imports/sensors/qmlsensor.h +++ b/src/imports/sensors/qmlsensor.h @@ -57,6 +57,7 @@ class QmlSensorReading; class QmlSensor : public QObject, public QQmlParserStatus { Q_OBJECT + Q_ENUMS(AxesOrientationMode) Q_INTERFACES(QQmlParserStatus) Q_PROPERTY(QString identifier READ identifier WRITE setIdentifier NOTIFY identifierChanged) Q_PROPERTY(QString type READ type NOTIFY typeChanged) @@ -72,7 +73,18 @@ class QmlSensor : public QObject, public QQmlParserStatus Q_PROPERTY(int error READ error NOTIFY errorChanged) Q_PROPERTY(bool alwaysOn READ isAlwaysOn WRITE setAlwaysOn NOTIFY alwaysOnChanged) Q_PROPERTY(bool skipDuplicates READ skipDuplicates WRITE setSkipDuplicates NOTIFY skipDuplicatesChanged REVISION 1) + Q_PROPERTY(AxesOrientationMode axesOrientationMode READ axesOrientationMode WRITE setAxesOrientationMode NOTIFY axesOrientationModeChanged REVISION 1) + Q_PROPERTY(int currentOrientation READ currentOrientation NOTIFY currentOrientationChanged REVISION 1) + Q_PROPERTY(int userOrientation READ userOrientation WRITE setUserOrientation NOTIFY userOrientationChanged REVISION 1) + public: + // Keep in sync with QSensor::AxesOrientationMode + enum AxesOrientationMode { + FixedOrientation, + AutomaticOrientation, + UserOrientation + }; + explicit QmlSensor(QObject *parent = 0); ~QmlSensor(); @@ -107,6 +119,14 @@ public: QmlSensorReading *reading() const; + AxesOrientationMode axesOrientationMode() const; + void setAxesOrientationMode(AxesOrientationMode axesOrientationMode); + + int currentOrientation() const; + + int userOrientation() const; + void setUserOrientation(int userOrientation); + public Q_SLOTS: bool start(); void stop(); @@ -125,6 +145,9 @@ Q_SIGNALS: void errorChanged(); void alwaysOnChanged(); void skipDuplicatesChanged(bool skipDuplicates); + void axesOrientationModeChanged(AxesOrientationMode axesOrientationMode); + void currentOrientationChanged(int currentOrientation); + void userOrientationChanged(int userOrientation); protected: virtual QSensor *sensor() const = 0; |