diff options
author | Lincoln Ramsay <lincoln.ramsay@nokia.com> | 2012-08-17 11:29:22 +1000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2012-10-08 22:59:38 +0200 |
commit | 3c599b87f33673932a55f3f5621073885dea5bc1 (patch) | |
tree | 5d675221908f7b7bc9ef31dd611dc562e69f8717 /src/imports/sensors2 | |
parent | 0156de8c1aab48e43a762fb034c3f885ff2b6efe (diff) |
Add SensorGesture QtMobility.sensors 1.3
This has been imported from QtSensors 5.0 without changes.
Change-Id: Ie6a919f9b806bf19287a693fb7cdb563f8697e13
Reviewed-by: Lorn Potter <lorn.potter@gmail.com>
Diffstat (limited to 'src/imports/sensors2')
-rw-r--r-- | src/imports/sensors2/qsensor2gesture.cpp | 103 | ||||
-rw-r--r-- | src/imports/sensors2/qsensor2gesture.h | 21 |
2 files changed, 54 insertions, 70 deletions
diff --git a/src/imports/sensors2/qsensor2gesture.cpp b/src/imports/sensors2/qsensor2gesture.cpp index d68966cd..8341c521 100644 --- a/src/imports/sensors2/qsensor2gesture.cpp +++ b/src/imports/sensors2/qsensor2gesture.cpp @@ -45,8 +45,6 @@ QT_BEGIN_NAMESPACE -//#define LOGGESTURQMLAPI - /*! \qmltype SensorGesture \instantiates QSensor2Gesture @@ -58,7 +56,7 @@ QT_BEGIN_NAMESPACE This type is part of the \b{QtSensors 5} module. - The following QML code creates a "shake" and "template" SensorGesture QML type, and + The following QML code creates a "shake" and "SecondCounter" SensorGesture QML type, and displays the detected gesture in a text type. QtSensors.shake gesture is available with the Qt Sensors API, but the QtSensors.SecondCounter @@ -90,14 +88,12 @@ QT_BEGIN_NAMESPACE */ QSensor2Gesture::QSensor2Gesture(QObject* parent) : QObject(parent) - , _enabled(false) - , _oldEnabled(false) - , _init(true) - , _sensorGesture(0) - , _sensorGestureManager(0) + , isEnabled(false) + , initDone(false) + , sensorGesture(0) + , sensorGestureManager(new QSensorGestureManager(this)) { - _sensorGestureManager = new QSensorGestureManager(this); - connect(_sensorGestureManager, SIGNAL(newSensorGestureAvailable()), SIGNAL(availableGesturesChanged())); + connect(sensorGestureManager, SIGNAL(newSensorGestureAvailable()), SIGNAL(availableGesturesChanged())); } QSensor2Gesture::~QSensor2Gesture() @@ -116,8 +112,8 @@ void QSensor2Gesture::componentComplete() /* this is needed in the case the customer defines the type(s) and set it enabled = true */ - _init = false; - setEnabled(_enabled); + initDone = true; + setEnabled(isEnabled); } /* End of QQmlParserStatus interface implementation @@ -129,7 +125,7 @@ void QSensor2Gesture::componentComplete() */ QStringList QSensor2Gesture::availableGestures() { - return _sensorGestureManager->gestureIds(); + return sensorGestureManager->gestureIds(); } /*! @@ -145,20 +141,20 @@ QStringList QSensor2Gesture::availableGestures() */ QStringList QSensor2Gesture::gestures() const { - return _gestures; + return gestureList; } void QSensor2Gesture::setGestures(const QStringList& value) { - if (_gestures == value) + if (gestureList == value) return; - if (!_init && enabled()){ + if (initDone && enabled()) { qWarning() << "Cannot change gestures while running."; return; } - _gestures.clear(); - _gestures = value; + gestureList.clear(); + gestureList = value; createGesture(); Q_EMIT gesturesChanged(); } @@ -170,8 +166,8 @@ void QSensor2Gesture::setGestures(const QStringList& value) */ QStringList QSensor2Gesture::validGestures() const { - if (_sensorGesture) - return _sensorGesture->validIds(); + if (sensorGesture) + return sensorGesture->validIds(); return QStringList(); } @@ -181,8 +177,8 @@ QStringList QSensor2Gesture::validGestures() const */ QStringList QSensor2Gesture::invalidGestures() const { - if (_sensorGesture) - return _sensorGesture->invalidIds(); + if (sensorGesture) + return sensorGesture->invalidIds(); return QStringList(); } @@ -194,33 +190,28 @@ QStringList QSensor2Gesture::invalidGestures() const */ bool QSensor2Gesture::enabled() const { - return _enabled; + return isEnabled; } void QSensor2Gesture::setEnabled(bool value) { - _enabled = value; - if (_init) + bool hasChanged = false; + if (isEnabled != value) { + isEnabled = value; + hasChanged = true; + } + if (!initDone) return; - if (_enabled != _oldEnabled){ - _oldEnabled = _enabled; - if (_sensorGesture){ - if (_enabled){ -#ifdef LOGGESTUREQMLAPI - qDebug() << "start detection" << _gestureIds; -#endif - _sensorGesture->startDetection(); - } - else { -#ifdef LOGGESTUREQMLAPI - qDebug() << "stop detection" << _gestureIds; -#endif - _sensorGesture->stopDetection(); - } + if (sensorGesture) { + if (value) { + sensorGesture->startDetection(); + } else { + sensorGesture->stopDetection(); } - Q_EMIT enabledChanged(); } + if (hasChanged) + Q_EMIT enabledChanged(); } /*! @@ -234,20 +225,20 @@ void QSensor2Gesture::setEnabled(bool value) */ void QSensor2Gesture::deleteGesture() { - if (_sensorGesture){ - bool emitinvalidchange = !invalidGestures().isEmpty(); - bool emitvalidchange = !validGestures().isEmpty(); + if (sensorGesture) { + bool emitInvalidChange = !invalidGestures().isEmpty(); + bool emitValidChange = !validGestures().isEmpty(); - if (_sensorGesture->isActive()) { - _sensorGesture->stopDetection(); + if (sensorGesture->isActive()) { + sensorGesture->stopDetection(); } - delete _sensorGesture; - _sensorGesture = 0; + delete sensorGesture; + sensorGesture = 0; - if (emitinvalidchange){ + if (emitInvalidChange) { Q_EMIT invalidGesturesChanged(); } - if (emitvalidchange){ + if (emitValidChange) { Q_EMIT validGesturesChanged(); } } @@ -256,15 +247,9 @@ void QSensor2Gesture::deleteGesture() void QSensor2Gesture::createGesture() { deleteGesture(); -#ifdef LOGGESTURQMLAPI - qDebug() << "Create Gestrues:"; - for (int i = 0; i < _gestures.count(); i++){ - qDebug() << " -" << _gestures[i]; - } -#endif - _sensorGesture = new QSensorGesture(_gestures, this); - if (!validGestures().isEmpty()){ - QObject::connect(_sensorGesture + sensorGesture = new QSensorGesture(gestureList, this); + if (!validGestures().isEmpty()) { + QObject::connect(sensorGesture , SIGNAL(detected(QString)) , this , SIGNAL(detected(QString))); diff --git a/src/imports/sensors2/qsensor2gesture.h b/src/imports/sensors2/qsensor2gesture.h index 0c9b6fb0..2a27b055 100644 --- a/src/imports/sensors2/qsensor2gesture.h +++ b/src/imports/sensors2/qsensor2gesture.h @@ -62,10 +62,10 @@ class QSensor2Gesture : public QObject, public QQmlParserStatus Q_INTERFACES(QQmlParserStatus) public: - QSensor2Gesture(QObject* parent = 0); - virtual ~QSensor2Gesture(); - void classBegin(); - void componentComplete(); + explicit QSensor2Gesture(QObject* parent = 0); + ~QSensor2Gesture(); + void classBegin() Q_DECL_OVERRIDE; + void componentComplete() Q_DECL_OVERRIDE; Q_SIGNALS: void detected(const QString &gesture); @@ -89,14 +89,13 @@ private: void createGesture(); private: - QStringList _gestureIds; - bool _enabled; - bool _oldEnabled; - bool _init; - QStringList _gestures; + QStringList gestureIds; + bool isEnabled; + bool initDone; + QStringList gestureList; - QSensorGesture* _sensorGesture; - QSensorGestureManager* _sensorGestureManager; + QSensorGesture* sensorGesture; + QSensorGestureManager* sensorGestureManager; }; QT_END_NAMESPACE |