src/hbcore/gestures/hbpangesturelogic_p.cpp
changeset 30 80e4d18b72f5
parent 28 b7da29130b0e
--- a/src/hbcore/gestures/hbpangesturelogic_p.cpp	Fri Sep 17 08:32:10 2010 +0300
+++ b/src/hbcore/gestures/hbpangesturelogic_p.cpp	Mon Oct 04 00:38:12 2010 +0300
@@ -23,18 +23,19 @@
 **
 ****************************************************************************/
 
+#include "hbpangesture.h"
+#include "hbpangesturelogic_p.h"
+#include "hbgestures_p.h"
+
+#include "hbnamespace_p.h"
+#include <hbdeviceprofile.h>
+
 #include <QEvent>
 #include <QGestureRecognizer>
 #include <QGraphicsView>
 #include <QMouseEvent>
 #include <QGraphicsScene>
 
-#include <hbdeviceprofile.h>
-
-#include "hbpangesture.h"
-#include "hbpangesture_p.h"
-#include "hbpangesturelogic_p.h"
-#include "hbnamespace_p.h"
 
 #define followedTouchPoint(te, gesture) te->touchPoints().at(followedTouchPointIndex(te, gesture))
 
@@ -56,7 +57,6 @@
 */
 HbPanGestureLogic::HbPanGestureLogic()
 {
-    mCurrentTime = QTime();
 }
 
 HbPanGestureLogic::~HbPanGestureLogic() {}
@@ -102,10 +102,10 @@
     gesture->d_ptr->mSceneLastOffset              = QPointF(0,0);
     gesture->d_ptr->mSceneOffset                  = QPointF(0,0);
     gesture->d_ptr->mSceneDeltaSinceLastTimeStamp = QPointF(0,0);
-    gesture->d_ptr->mAxisX.clear();
-    gesture->d_ptr->mAxisY.clear();
-    gesture->d_ptr->mSceneAxisX.clear();
-    gesture->d_ptr->mSceneAxisY.clear();
+    gesture->d_ptr->mAxisX.resetRecorder();
+    gesture->d_ptr->mAxisY.resetRecorder();
+    gesture->d_ptr->mSceneAxisX.resetRecorder();
+    gesture->d_ptr->mSceneAxisY.resetRecorder();
 
     gesture->setLastOffset(QPointF());
     gesture->setOffset(QPointF(0,0));
@@ -126,7 +126,8 @@
         Qt::GestureState gestureState,
         HbPanGesture *gesture,
         QObject *watched,
-        QMouseEvent *me )
+        QMouseEvent *me,
+        qint64 currentTime )
 {
     // Just ignore situations that are not interesting at all.
     if ( !( gestureState == Qt::NoGesture && me->button() == Qt::LeftButton ) )
@@ -142,7 +143,7 @@
     gesture->d_ptr->mSceneStartPos       = scenePos;
     gesture->d_ptr->mSceneOffset         = HbGestureUtils::mapToScene(watched, QPointF(0,0));
     gesture->d_ptr->mSceneLastOffset     = HbGestureUtils::mapToScene(watched, QPointF(0,0));
-    gesture->d_ptr->mLastTimeStamp = mCurrentTime;
+    gesture->d_ptr->mLastTimeStamp = currentTime;
 
 
     gesture->d_ptr->mThresholdSquare = HbDefaultPanThreshold * HbDeviceProfile::current().ppmValue();
@@ -154,10 +155,10 @@
     gesture->d_ptr->mAxisY.resetRecorder(velocityThreshold);
     gesture->d_ptr->mSceneAxisX.resetRecorder(velocityThreshold);
     gesture->d_ptr->mSceneAxisY.resetRecorder(velocityThreshold);
-    gesture->d_ptr->mAxisX.record( me->globalPos().x(), mCurrentTime );
-    gesture->d_ptr->mAxisY.record( me->globalPos().y(), mCurrentTime );
-    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), mCurrentTime );
-    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), mCurrentTime );
+    gesture->d_ptr->mAxisX.record( me->globalPos().x(), currentTime );
+    gesture->d_ptr->mAxisY.record( me->globalPos().y(), currentTime );
+    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), currentTime );
+    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), currentTime );
 
     return QGestureRecognizer::MayBeGesture;
 }
@@ -172,7 +173,8 @@
         Qt::GestureState gestureState,
         HbPanGesture *gesture,
         QObject *watched,
-        QMouseEvent *me )
+        QMouseEvent *me,
+        qint64 currentTime )
 {
     if ( !me->buttons().testFlag(Qt::LeftButton))
     {
@@ -185,13 +187,13 @@
     gesture->d_ptr->mSceneLastOffset = gesture->d_ptr->mSceneOffset;
     gesture->d_ptr->mSceneOffset =
             HbGestureUtils::mapToScene(watched, me->globalPos()) - gesture->d_ptr->mSceneStartPos;
-    gesture->d_ptr->mLastTimeStamp = mCurrentTime;
+    gesture->d_ptr->mLastTimeStamp = currentTime;
 
     QPointF scenePos = HbGestureUtils::mapToScene(watched, me->globalPos());
-    gesture->d_ptr->mAxisX.record( me->globalPos().x(), mCurrentTime );
-    gesture->d_ptr->mAxisY.record( me->globalPos().y(), mCurrentTime );
-    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), mCurrentTime );
-    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), mCurrentTime );
+    gesture->d_ptr->mAxisX.record( me->globalPos().x(), currentTime );
+    gesture->d_ptr->mAxisY.record( me->globalPos().y(), currentTime );
+    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), currentTime );
+    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), currentTime );
 
 
     QGraphicsView* view = qobject_cast<QGraphicsView*>(watched->parent());
@@ -227,13 +229,14 @@
         Qt::GestureState gestureState,
         HbPanGesture *gesture,
         QObject *watched,
-        QMouseEvent *me )
+        QMouseEvent *me,
+        qint64 currentTime)
 {
     Q_UNUSED(me);
     Q_UNUSED(gesture);
     Q_UNUSED(watched);
 
-    gesture->d_ptr->mLastTimeStamp = mCurrentTime;
+    gesture->d_ptr->mLastTimeStamp = currentTime;
 
     if ( gestureState == Qt::GestureStarted || gestureState == Qt::GestureUpdated )
     {
@@ -269,7 +272,8 @@
         Qt::GestureState gestureState,
         HbPanGesture *gesture,
         QObject *watched,
-        QTouchEvent *te )
+        QTouchEvent *te,
+        qint64 currentTime)
 {
     gesture->d_ptr->mFollowedTouchPointId = getNextId(te);
 
@@ -288,7 +292,7 @@
     gesture->d_ptr->mSceneStartPos       = scenePos;
     gesture->d_ptr->mSceneOffset         = QPointF(0,0);
     gesture->d_ptr->mSceneLastOffset     = QPointF(0,0);
-    gesture->d_ptr->mLastTimeStamp = mCurrentTime;
+    gesture->d_ptr->mLastTimeStamp = currentTime;
 
     qreal defaultThreshold = HbDefaultPanThreshold * HbDeviceProfile::current().ppmValue();
     gesture->d_ptr->mThresholdSquare = defaultThreshold * defaultThreshold;
@@ -297,10 +301,10 @@
     gesture->d_ptr->mAxisY.resetRecorder(defaultThreshold);
     gesture->d_ptr->mSceneAxisX.resetRecorder(defaultThreshold);
     gesture->d_ptr->mSceneAxisY.resetRecorder(defaultThreshold);
-    gesture->d_ptr->mAxisY.record( tp.screenPos().y(), mCurrentTime );
-    gesture->d_ptr->mAxisX.record( tp.screenPos().x(), mCurrentTime );    
-    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), mCurrentTime );
-    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), mCurrentTime );
+    gesture->d_ptr->mAxisY.record( tp.screenPos().y(), currentTime );
+    gesture->d_ptr->mAxisX.record( tp.screenPos().x(), currentTime );
+    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), currentTime );
+    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), currentTime );
 
     if (gestureState != Qt::NoGesture) {
         return QGestureRecognizer::Ignore;
@@ -319,7 +323,8 @@
         Qt::GestureState gestureState,
         HbPanGesture *gesture,
         QObject *watched,
-        QTouchEvent *te)
+        QTouchEvent *te,
+        qint64 currentTime)
 {
     QTouchEvent::TouchPoint tp = followedTouchPoint(te, gesture);
 
@@ -345,13 +350,13 @@
     gesture->d_ptr->mSceneLastOffset = gesture->d_ptr->mSceneOffset;
     gesture->d_ptr->mSceneOffset =
             HbGestureUtils::mapToScene(watched, tp.screenPos()) - gesture->d_ptr->mSceneStartPos;
-    gesture->d_ptr->mLastTimeStamp = mCurrentTime;
+    gesture->d_ptr->mLastTimeStamp = currentTime;
 
-    gesture->d_ptr->mAxisX.record( tp.screenPos().x(), mCurrentTime );
-    gesture->d_ptr->mAxisY.record( tp.screenPos().y(), mCurrentTime );
+    gesture->d_ptr->mAxisX.record( tp.screenPos().x(), currentTime );
+    gesture->d_ptr->mAxisY.record( tp.screenPos().y(), currentTime );
     QPointF scenePos = HbGestureUtils::mapToScene(watched, tp.screenPos());
-    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), mCurrentTime );
-    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), mCurrentTime );
+    gesture->d_ptr->mSceneAxisX.record( scenePos.x(), currentTime );
+    gesture->d_ptr->mSceneAxisY.record( scenePos.y(), currentTime );
 
     QGraphicsView* view = qobject_cast<QGraphicsView*>(watched->parent());
     if (view) {
@@ -375,13 +380,14 @@
         Qt::GestureState gestureState,
         HbPanGesture *gesture,
         QObject *watched,
-        QTouchEvent *te )
+        QTouchEvent *te,
+        qint64 currentTime)
 {
     Q_UNUSED(te);
     Q_UNUSED(gesture);
     Q_UNUSED(watched);
 
-    gesture->d_ptr->mLastTimeStamp = mCurrentTime;
+    gesture->d_ptr->mLastTimeStamp = currentTime;
 
     if ( gestureState == Qt::GestureStarted || gestureState == Qt::GestureUpdated )
     {
@@ -405,11 +411,8 @@
         HbPanGesture *gesture,
         QObject *watched,
         QEvent *event,
-        QTime currentTime)
+        qint64 currentTime)
 {
-    // Record the time right away.
-    mCurrentTime = currentTime;
-
     if ( isMouseEvent(event->type()) )
     {
         if (gesture->d_ptr->mIgnoreMouseEvents) {
@@ -420,11 +423,11 @@
         {
         case QEvent::MouseButtonDblClick:
         case QEvent::MouseButtonPress:
-            return handleMousePress(gestureState, gesture, watched, me);
+            return handleMousePress(gestureState, gesture, watched, me, currentTime);
         case QEvent::MouseMove:
-            return handleMouseMove(gestureState, gesture, watched, me);
+            return handleMouseMove(gestureState, gesture, watched, me, currentTime);
         case QEvent::MouseButtonRelease:
-            return handleMouseRelease(gestureState, gesture, watched, me);
+            return handleMouseRelease(gestureState, gesture, watched, me, currentTime);
         default: break;
         }
     }
@@ -435,24 +438,23 @@
         switch(event->type())
         {
         case QEvent::TouchBegin:
-            return handleTouchBegin(gestureState, gesture, watched, te);
-            break;
+            return handleTouchBegin(gestureState, gesture, watched, te, currentTime);
         case QEvent::TouchUpdate: {
                 gesture->d_ptr->mIgnoreMouseEvents = true;
 
                 if (followedTouchPoint(te, gesture).state() == Qt::TouchPointReleased) {
                     //qDebug() << "---- Finger changed ----";
-                    return handleTouchBegin(gestureState, gesture, watched, te);
+                    return handleTouchBegin(gestureState, gesture, watched, te, currentTime);
                 }
                 if (followedTouchPoint(te, gesture).state() == Qt::TouchPointMoved) {
-                    return handleTouchMove(gestureState, gesture, watched, te);
+                    return handleTouchMove(gestureState, gesture, watched, te, currentTime);
                 }
                 break;
             }
         case QEvent::TouchEnd:
             //qDebug() << "===== TOUCHEND ======" ;
             gesture->d_ptr->mIgnoreMouseEvents = false;
-            return handleTouchEnd(gestureState, gesture, watched, te);
+            return handleTouchEnd(gestureState, gesture, watched, te, currentTime);
         default:
             break;
         }