From a697ee84cd4c854046b5876a44d6215c468cce18 Mon Sep 17 00:00:00 2001 From: Lorn Potter Date: Fri, 18 May 2012 11:48:52 +1000 Subject: make twist dependent upon an orientation change. This fixes getting a twist gesture by just moving the device left or right. and update one test data that did not have needed orientation change when the gesture was performed. Change-Id: I4fd9148d3f9c3d093530d08c2f6834f0972c659e Reviewed-by: Lincoln Ramsay --- .../qtsensors/qtwistsensorgesturerecognizer.cpp | 29 +++++++++++++--------- .../qtsensors/qtwistsensorgesturerecognizer.h | 1 + 2 files changed, 18 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp index fbbb37d0..01e7d234 100644 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp +++ b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.cpp @@ -167,19 +167,13 @@ void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) if (detecting && qAbs(degrees) < RESTING_VARIANCE && qAbs(pitch) < RESTING_VARIANCE - && (qAbs(lastRoll + degrees) > (degrees / 2)) - ) { - if (lastRoll > 0 ) { - Q_EMIT twistLeft(); - Q_EMIT detected("twistLeft"); - } else { - Q_EMIT twistRight(); - Q_EMIT detected("twistRight"); - } + && (qAbs(lastRoll + degrees) > (degrees / 2))) { + + QTimer::singleShot(0,this,SLOT(checkTwist())); // don't give two signals for same gestures - detecting = false; - timer->stop(); - lastRoll = degrees; + detecting = false; + timer->stop(); + lastRoll = degrees; } if (orientationReading->orientation() == QOrientationReading::FaceUp @@ -207,6 +201,17 @@ void QTwistSensorGestureRecognizer::accelChanged(QAccelerometerReading *reading) lastX = x; lastY = y; } +void QTwistSensorGestureRecognizer::checkTwist() +{ + if (lastRoll > 0 && orientationReading->orientation() == QOrientationReading::RightUp) { + Q_EMIT twistLeft(); + Q_EMIT detected("twistLeft"); + } else if (orientationReading->orientation() == QOrientationReading::LeftUp){ + Q_EMIT twistRight(); + Q_EMIT detected("twistRight"); + } +} + void QTwistSensorGestureRecognizer::timeout() { detecting = false; diff --git a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h index 6beb7c82..9cd46f64 100644 --- a/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h +++ b/src/plugins/sensorgestures/qtsensors/qtwistsensorgesturerecognizer.h @@ -72,6 +72,7 @@ private slots: void accelChanged(QAccelerometerReading *reading); void orientationReadingChanged(QOrientationReading *reading); void timeout(); + void checkTwist(); private: -- cgit v1.2.3