qstmgesturelib/qstmgenericsimplegesture.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 
       
    19 #include "qstmgenericsimplegesture.h"
       
    20 #include "qstmfilelogger.h"
       
    21 #include "qstmutils.h"
       
    22 
       
    23 using namespace qstmGesture ;
       
    24 using qstmUiEventEngine::QStm_UiEventSpeedIf;
       
    25 
       
    26 
       
    27 QStm_GenericSimpleGesture::QStm_GenericSimpleGesture(
       
    28     QStm_GestureUid uid, const QPoint& loc, int type, const QStm_UiEventSpeedIf* speedIf) :
       
    29     m_location(loc), m_uid(uid), m_type(type), m_details(0), m_speed(speedIf), m_target(0)
       
    30 {
       
    31 }
       
    32 
       
    33 QPoint QStm_GenericSimpleGesture::getLocation()  const
       
    34 {
       
    35     return m_location ;
       
    36 }
       
    37 
       
    38 int QStm_GenericSimpleGesture::getType()  const
       
    39 {
       
    40     return m_type ;
       
    41 }
       
    42 
       
    43 void* QStm_GenericSimpleGesture::getDetails() const
       
    44 {
       
    45     return m_details ;
       
    46 }
       
    47 
       
    48 void QStm_GenericSimpleGesture::setName(const QString& name)
       
    49 {
       
    50     m_name = name ;
       
    51 }
       
    52 
       
    53 QString QStm_GenericSimpleGesture::getGestureName()
       
    54 {
       
    55     return m_name ;
       
    56 }
       
    57 
       
    58 QStm_DirectionalGesture::QStm_DirectionalGesture(
       
    59     QStm_GestureUid uid, const QPoint& loc, const QPoint& prevLoc,
       
    60     const QStm_UiEventSpeedIf* speedIf, bool logging) :
       
    61     QStm_GenericSimpleGesture(uid, loc, 0, speedIf), m_loggingEnabled(logging)
       
    62 {
       
    63     setVector(loc, prevLoc);
       
    64 }
       
    65 
       
    66 void QStm_DirectionalGesture::setVector(const QPoint& last, const QPoint& previous)
       
    67 {
       
    68     m_vector = QPoint(last.x()-previous.x(), previous.y()-last.y()) ;  // x > 0 => east, y > 0 => north
       
    69     if (m_loggingEnabled) {
       
    70         LOGARG("CHoveringGesture: x: %d , %d prev: %d, %d", last.x(), last.y(), previous.x(), previous.y()) ;
       
    71     }
       
    72 }
       
    73 
       
    74 QStm_GestureDirection QStm_DirectionalGesture::getDirection() const
       
    75 {
       
    76     QStm_GestureDirection dir = ENorth ;
       
    77     int x = ABS(m_vector.x()) ;
       
    78     int y = ABS(m_vector.x()) ;
       
    79     
       
    80     if (y <= x/2) {
       
    81         if (m_vector.x() < 0)
       
    82             dir = EWest ;
       
    83         else
       
    84             dir = EEast ;
       
    85     }
       
    86     else if (y > x/2 && y <= (x+x/2)) {
       
    87         if (m_vector.x() < 0)  {
       
    88             if (m_vector.y() < 0 )
       
    89                 dir = ESouthWest ;
       
    90             else
       
    91                 dir = ENorthWest ;
       
    92         }
       
    93         else {
       
    94             if (m_vector.y() < 0 )
       
    95                 dir = ESouthEast ;
       
    96             else
       
    97                 dir = ENorthEast ;
       
    98         }
       
    99     }
       
   100     else if (y > x+x/2) {
       
   101         if (m_vector.y() < 0)
       
   102             dir = ESouth ;
       
   103         else
       
   104             dir = ENorth ;
       
   105     }
       
   106     
       
   107     if (m_loggingEnabled) {
       
   108         LOGARG("CHoveringGesture: x: %d y: %d direction: %d", m_vector.x(), m_vector.y(), dir) ;
       
   109     }
       
   110     
       
   111     return dir ;
       
   112 }
       
   113 
       
   114 QStm_TwoPointGesture::QStm_TwoPointGesture(QStm_GestureUid uid, const QPoint& loc, const QPoint& prevLoc) :
       
   115     QStm_DirectionalGesture(uid, loc, prevLoc, NULL),
       
   116     m_location2(prevLoc)
       
   117 {
       
   118 }
       
   119 
       
   120