qstmgesturelib/recognisers/qstmpangesturerecogniser.cpp
changeset 0 1450b09d0cfd
child 3 0954f5dd2cd0
equal deleted inserted replaced
-1:000000000000 0:1450b09d0cfd
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "qstmpangesturerecogniser.h"
       
    19 #include "qstmgenericsimplegesture.h"
       
    20 #include "qstmuievent_if.h"
       
    21 
       
    22 #include "qstmfilelogger.h"
       
    23 
       
    24 using namespace qstmGesture ;
       
    25 
       
    26 QStm_PanGestureRecogniser::QStm_PanGestureRecogniser(QStm_GestureListenerIf* listener) : 
       
    27 		                         QStm_GestureRecogniser(listener)
       
    28 {
       
    29 }
       
    30 
       
    31 QStm_PanGestureRecogniser::~QStm_PanGestureRecogniser()
       
    32 {
       
    33 }
       
    34 
       
    35 QStm_GestureRecognitionState QStm_PanGestureRecogniser::recognise(int numOfActiveStreams,
       
    36                                     QStm_GestureEngineIf* pge)
       
    37 {
       
    38     QStm_GestureRecognitionState state = ENotMyGesture;
       
    39     // Check if we are enabled or not
       
    40     if (!m_gestureEnabled) return state ;
       
    41 
       
    42     
       
    43     if (numOfActiveStreams == 1) {   
       
    44         const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0);
       
    45         int countOfEvents = puie->countOfEvents() ;
       
    46         qstmUiEventEngine::QStm_UiEventCode eventCode = puie->code() ;
       
    47         
       
    48         if (countOfEvents > 1) { // do we have more than one event in the stream?
       
    49             // Then look at the events to see if they are suitable for us
       
    50             // should we check that all of the events are targeted to our window?
       
    51             // currently we only check if the last one is for us and is EMove, then we pan if the speed is OK
       
    52             if (m_loggingenabled) {
       
    53             	LOGARG("QStm_PanGestureRecogniser: Got: numer of events %d, event code %d", countOfEvents, eventCode);
       
    54             }
       
    55         	
       
    56             if (puie->target() == m_powner &&
       
    57                 eventCode == qstmUiEventEngine::EMove) { // The last one is move in our window
       
    58 
       
    59                 float speed = puie->speed();
       
    60                 if (m_loggingenabled) {
       
    61                     LOGARG("QStm_PanGestureRecogniser: Pan: num %d code %d, speed %f, pos(%d, %d), prev pos(%d, %d)", 
       
    62                             countOfEvents, eventCode, speed, puie->currentXY().x(), puie->currentXY().y(), 
       
    63                             puie->previousXY().x(), puie->previousXY().y());
       
    64                 }
       
    65                 
       
    66                 // It is pan gesture in our window, handle it, if the speed is inside limits
       
    67                 if (speed > m_panningspeedlow && speed < m_panningspeedhigh) {
       
    68                     using qstmUiEventEngine::QStm_UiEventSpeed;
       
    69 
       
    70                     state = EGestureActive;
       
    71                     QStm_UiEventSpeed speedIf(speed, puie->speedVec());
       
    72                     // Panning gesture
       
    73                     qstmGesture::QStm_DirectionalGesture pgest(
       
    74                                     KUid,
       
    75                                     puie->currentXY(),
       
    76                                     puie->previousXY(),
       
    77                                     &speedIf,
       
    78                                     m_loggingenabled);
       
    79                     pgest.setTarget(puie->target());
       
    80 
       
    81                     // Call the listener to inform that a Pan has occurred...
       
    82                     m_listener->gestureEnter(pgest);
       
    83                 }
       
    84             }
       
    85             else if (eventCode == qstmUiEventEngine::ERelease) {
       
    86             	LOGARG("QStm_PanGestureRecogniser::recognise: (0x%x) eventCode == ERelease", this);
       
    87             }
       
    88         }
       
    89     }
       
    90     m_state = state;
       
    91     return state;
       
    92 }
       
    93 
       
    94 void QStm_PanGestureRecogniser::release(QStm_GestureEngineIf* pge)
       
    95 {
       
    96 	if (m_loggingenabled) {
       
    97 	    LOGARG("QStm_PanGestureRecogniser: release (0x%x)", this);	
       
    98 	}
       
    99 	const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0);
       
   100     using qstmUiEventEngine::QStm_UiEventSpeed;
       
   101     QStm_UiEventSpeed speedIf(puie->speed(), puie->speedVec());
       
   102     qstmGesture::QStm_DirectionalGesture pgest(
       
   103                     KUid,
       
   104                     puie->currentXY(),
       
   105                     puie->previousXY(),
       
   106                     &speedIf,
       
   107                     m_loggingenabled);
       
   108 	pgest.setTarget(puie->target());
       
   109     m_listener->gestureExit(pgest) ;
       
   110     m_state = ENotMyGesture;
       
   111 }
       
   112 
       
   113 void QStm_PanGestureRecogniser::setPanningSpeedLow(float aSpeed)/* __SOFTFP */
       
   114 {
       
   115     m_panningspeedlow = aSpeed ;
       
   116 }
       
   117 
       
   118 void QStm_PanGestureRecogniser::setPanningSpeedHigh(float aSpeed) /*__SOFTFP */
       
   119 {
       
   120     m_panningspeedhigh = aSpeed ;
       
   121 }
       
   122