qstmgesturelib/recognisers/qstmflickgesturerecogniser.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 "qstmgenericsimplegesture.h"
       
    19 #include "qstmflickgesturerecogniser.h"
       
    20 #include "qstmuievent_if.h"
       
    21 #include "qstmfilelogger.h"
       
    22 
       
    23 using namespace qstmGesture ;
       
    24 
       
    25 QStm_FlickGestureRecogniser::QStm_FlickGestureRecogniser(QStm_GestureListenerIf* listener) :
       
    26                               QStm_GestureRecogniser(listener)
       
    27 {
       
    28 }
       
    29 
       
    30 QStm_FlickGestureRecogniser::~QStm_FlickGestureRecogniser()
       
    31 {
       
    32 }
       
    33 
       
    34 /*!
       
    35  * Release gesture recogniser.  Note that this one never owns the gesture, it just calls
       
    36  * the callback if it detects ERelease inside the area being watched.
       
    37  * There could be also check for the target window?
       
    38  */
       
    39 QStm_GestureRecognitionState QStm_FlickGestureRecogniser::recognise(int numOfActiveStreams,
       
    40                                                                     QStm_GestureEngineIf* pge)
       
    41 {
       
    42     QStm_GestureRecognitionState state = m_state = ENotMyGesture;
       
    43     // Check if we are enabled or not
       
    44     if (!m_gestureEnabled) return state ;
       
    45 
       
    46     // Look at the events to see if it looks like flick with one pointer
       
    47     if (numOfActiveStreams == 1) {
       
    48         const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0);
       
    49         int countOfEvents = puie->countOfEvents();
       
    50         qstmUiEventEngine::QStm_UiEventCode eventCode = puie->code();
       
    51         if (m_loggingenabled) {
       
    52             LOGARG("QStm_FlickGestureRecogniser: %d num %d code %d", eventCode, countOfEvents, eventCode);
       
    53         }
       
    54         
       
    55         if (m_powner == puie->target() && eventCode == qstmUiEventEngine::ERelease)
       
    56         {
       
    57             if (m_loggingenabled) {
       
    58                 LOGARG("QStm_FlickGestureRecogniser: 0x%x ERelease: num %d code %d, %d", 
       
    59                 		this, countOfEvents, puie->currentXY().x(), puie->currentXY().y());
       
    60             }
       
    61             // Check if the speed before release was fast enough for flick
       
    62             const qstmUiEventEngine::QStm_UiEventIf* puieprev = puie->previousEvent() ;
       
    63             if (puieprev && puieprev->code() == qstmUiEventEngine::EMove) {
       
    64                 using qstmUiEventEngine::QStm_UiEventSpeed;
       
    65 
       
    66                 float thespeed = puieprev->speed() ;
       
    67                 if (m_loggingenabled) {
       
    68                     LOGARG("QStm_FlickGestureRecogniser: prev speed: %f (limit: %f)", double(thespeed), double(m_speed)) ;
       
    69                 }
       
    70                 if (thespeed > m_speed) {
       
    71                     state = EGestureActive ;
       
    72 
       
    73                     QStm_UiEventSpeed speedIf(thespeed, puieprev->speedVec());
       
    74 
       
    75                     // issue the flick gesture using the TDirectionalGesture (it has the speed and direction)
       
    76                     qstmGesture::QStm_DirectionalGesture pgest(
       
    77                             KUid,
       
    78                             puieprev->currentXY(),
       
    79                             puieprev->previousXY(),
       
    80                             &speedIf,
       
    81                             m_loggingenabled);
       
    82                     pgest.setTarget(puie->target());
       
    83 
       
    84                     // Call the listener to inform that a flick has occurred...
       
    85                     m_listener->gestureEnter(pgest);
       
    86                 }
       
    87             }
       
    88         }
       
    89     }
       
    90     m_state = state;
       
    91     return state;
       
    92 }
       
    93 void QStm_FlickGestureRecogniser::release(QStm_GestureEngineIf* /*ge*/)
       
    94 {
       
    95     if (m_loggingenabled) {
       
    96         LOGARG("QStm_FlickGestureRecogniser: 0x%x flick", this);
       
    97     }
       
    98     m_state = ENotMyGesture;
       
    99 }
       
   100 
       
   101 void QStm_FlickGestureRecogniser::setFlickingSpeed(float aSpeed) /* __SOFTFP */
       
   102 {
       
   103     m_speed = aSpeed ;
       
   104 }