qstmgesturelib/recognisers/qstmleftrightgesturerecogniser.cpp
author William Roberts <williamr@symbian.org>
Fri, 11 Jun 2010 16:23:26 +0100
branchGCC_SURGE
changeset 2 bf4420e9fa4d
parent 0 1450b09d0cfd
child 3 0954f5dd2cd0
permissions -rw-r--r--
Branch for GCC_SURGE fixes

/*
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include "qstmleftrightgesturerecogniser.h"
#include "qstmgenericsimplegesture.h"
#include "qstmuievent_if.h"
#include "qstmutils.h"
#include "qstmfilelogger.h"

using namespace qstmGesture ;

QStm_LeftrightGestureRecogniser::QStm_LeftrightGestureRecogniser(QStm_GestureListenerIf* listener) : 
		                         QStm_GestureRecogniser(listener)
{
}

QStm_LeftrightGestureRecogniser::~QStm_LeftrightGestureRecogniser()
{
}

QStm_GestureRecognitionState QStm_LeftrightGestureRecogniser::recognise(int numOfActiveStreams,
                                  QStm_GestureEngineIf* pge)
{
    QStm_GestureRecognitionState state = m_state = ENotMyGesture;
    // Check if we are enabled or not
    if (!m_gestureEnabled) return state ;

    // Look at the events to see if it looks like a tap or double tap
    if (numOfActiveStreams == 1) {
        // Then look at the event stream, it has to be tap and release
        const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0);
        int countOfEvents = puie->countOfEvents() ;
        qstmUiEventEngine::QStm_UiEventCode eventCode = puie->code() ;
        if (countOfEvents > 1) { // do we have more than one event in the stream?
            // Then look at the events to see if they are suitable for us
            // should we check that all of the events are targeted to our window?
            // currently we only check if the last one is for us and is EMove, then check if |x| > |y|
            if (puie->target() == m_powner &&
                    eventCode == qstmUiEventEngine::EMove) {// The last one is move in our window

                if (m_loggingenabled) {
                    LOGARG("QStm_LeftrightGestureRecogniser: Leftright: num %d code %d", countOfEvents, eventCode);
                }
                // Is it leftright gesture in our window?
                const QPoint& p = puie->currentXY();
                QPoint dp = p - puie->previousXY();
                if (ABS(dp.x()) > ABS(dp.y())) {
                    state = EGestureActive;
                    qstmGesture::QStm_GenericSimpleGesture pgest(KUid, p, dp.x(), puie) ;
                    pgest.setTarget(puie->target());
                    pgest.setName(QString("Leftlight")) ;
                    // Call the listener to inform that a Leftright has occurred...
                    m_listener->gestureEnter(pgest) ;
                }
            }
        }
    }
    m_state = state;
    return state;
}

void QStm_LeftrightGestureRecogniser::release(QStm_GestureEngineIf* pge)
{
	const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0);
    using qstmUiEventEngine::QStm_UiEventSpeed;
    const QPoint& p = puie->currentXY();
    QPoint dp = p - puie->previousXY();
    qstmGesture::QStm_GenericSimpleGesture pgest(KUid, p, dp.x(), puie) ;
    pgest.setTarget(puie->target());
    m_listener->gestureExit(pgest) ;
    m_state = ENotMyGesture;
}