qstmgesturelib/recognisers/qstmlongpressgesturerecogniser.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 "qstmlongpressgesturerecogniser.h"
       
    20 #include "qstmuievent_if.h"
       
    21 #include "qstmfilelogger.h"
       
    22 
       
    23 using namespace qstmGesture ;
       
    24 
       
    25 QStm_LongPressGestureRecogniser::QStm_LongPressGestureRecogniser(QStm_GestureListenerIf* listener) :
       
    26                                     QStm_GestureRecogniser(listener)
       
    27 {
       
    28 }
       
    29 
       
    30 QStm_LongPressGestureRecogniser::~QStm_LongPressGestureRecogniser()
       
    31 {
       
    32 }
       
    33 
       
    34 /*!
       
    35  * recognise the long press; basically it is just the EHold UI event
       
    36  */
       
    37 QStm_GestureRecognitionState QStm_LongPressGestureRecogniser::recognise(int numOfActiveStreams,
       
    38                                  QStm_GestureEngineIf* pge)
       
    39 {
       
    40     QStm_GestureRecognitionState state = m_state = ENotMyGesture;
       
    41     // Check if we are enabled or not
       
    42     if (!m_gestureEnabled) return state ;
       
    43 
       
    44 
       
    45     // Look at the events to see if it looks like long press with one pointer
       
    46     if (numOfActiveStreams == 1) {
       
    47         // Then look at the event stream, it has to be EHold
       
    48         const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0);
       
    49         int countOfEvents = puie->countOfEvents();
       
    50         qstmUiEventEngine::QStm_UiEventCode eventCode = puie->code();
       
    51 
       
    52         if (m_loggingenabled) {
       
    53             LOGARG("QStm_LongPressGestureRecogniser: %d num %d code %d", eventCode, countOfEvents, eventCode);
       
    54         }
       
    55         if (puie->target() == m_powner && eventCode == qstmUiEventEngine::EHold) { 
       
    56         	// The last one is EHold, look if it is near our borders
       
    57             const QPoint& p = puie->currentXY() ;
       
    58             if (m_loggingenabled) {
       
    59                 LOGARG("QStm_LongPressGestureRecogniser: (%d, %d) in (%d,%d)(%d,%d)", p.x(), p.y(),
       
    60                         m_area.x(), m_area.y(), m_area.x() + m_area.width(), m_area.y() + m_area.height());
       
    61             }
       
    62             // check where the point is inside the area defined
       
    63             if (m_area.contains(p)) {
       
    64                 state = EGestureActive ;
       
    65                 // issue the long press gesture
       
    66                 qstmGesture::QStm_GenericSimpleGesture pgest(KUid, p, 0, puie) ; // TODO: speed is 0?
       
    67                 pgest.setTarget(puie->target());
       
    68                 // Call the listener to inform that the gesture has occurred...
       
    69                 m_listener->gestureEnter(pgest) ;
       
    70             }
       
    71         }
       
    72     }
       
    73     m_state = state;
       
    74     return state;
       
    75 }
       
    76 
       
    77 void QStm_LongPressGestureRecogniser::release(QStm_GestureEngineIf* /*ge*/)
       
    78 {
       
    79     if (m_loggingenabled) {
       
    80         LOGARG("QStm_LongPressGestureRecogniser: 0x%x release", this);
       
    81     }
       
    82     m_state = ENotMyGesture;
       
    83 }
       
    84 
       
    85 void QStm_LongPressGestureRecogniser::setArea(const QRect& theArea)
       
    86 {
       
    87     m_area = theArea ;
       
    88 }