16
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU Lesser General Public License as published by
|
|
7 |
* the Free Software Foundation, version 2.1 of the License.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU Lesser General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Lesser General Public License
|
|
15 |
* along with this program. If not,
|
|
16 |
* see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
|
|
17 |
*
|
|
18 |
* Description:
|
|
19 |
*
|
|
20 |
*/
|
|
21 |
#include "qstmgenericsimplegesture.h"
|
|
22 |
#include "qstmmaybetapgesturerecogniser.h"
|
|
23 |
#include "qstmuievent_if.h"
|
|
24 |
#include "qstmutils.h"
|
|
25 |
#include "qstmfilelogger.h"
|
|
26 |
|
|
27 |
using namespace qstmGesture ;
|
|
28 |
using namespace qstmUiEventEngine;
|
|
29 |
|
|
30 |
QStm_MaybeTapGestureRecogniser::QStm_MaybeTapGestureRecogniser(QStm_GestureListenerIf* listener) :
|
|
31 |
QStm_GestureRecogniser(listener)
|
|
32 |
{
|
|
33 |
m_powner = listener->getOwner() ;
|
|
34 |
if (listener) {
|
|
35 |
addTapListener(listener, m_powner) ;
|
|
36 |
}
|
|
37 |
m_gestureEnabled = true;
|
|
38 |
m_numOfActiveStreams = 0;
|
|
39 |
|
|
40 |
}
|
|
41 |
|
|
42 |
QStm_MaybeTapGestureRecogniser::~QStm_MaybeTapGestureRecogniser()
|
|
43 |
{
|
|
44 |
m_tapListeners.clear() ;
|
|
45 |
m_tapListenerWindows.clear() ;
|
|
46 |
}
|
|
47 |
|
|
48 |
QStm_GestureRecognitionState QStm_MaybeTapGestureRecogniser::recognise(int numOfActiveStreams,
|
|
49 |
QStm_GestureEngineIf* pge)
|
|
50 |
{
|
|
51 |
QStm_GestureRecognitionState state = m_state = ENotMyGesture;
|
|
52 |
// Check if we are enabled or not
|
|
53 |
if (!m_gestureEnabled) return state ;
|
|
54 |
|
|
55 |
// Look at the events to see if it looks like a tap or double tap
|
|
56 |
if (numOfActiveStreams == 1) {
|
|
57 |
m_numOfActiveStreams = numOfActiveStreams;
|
|
58 |
// Then look at the event stream, it has to be tap and release
|
|
59 |
const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0);
|
|
60 |
int countOfEvents = puie->countOfEvents() ;
|
|
61 |
qstmUiEventEngine::QStm_UiEventCode eventCode = puie->code() ;
|
|
62 |
|
|
63 |
if (m_loggingenabled) {
|
|
64 |
LOGARG("QStm_MaybeTapGestureRecogniser: event: %s, countOfEvents: %d, code: %d",
|
|
65 |
event_name(eventCode), countOfEvents, eventCode);
|
|
66 |
}
|
|
67 |
void* target = puie->target();
|
|
68 |
|
|
69 |
if (countOfEvents == 2) { // Do we have touch and release in the stream, check if there are two events
|
|
70 |
|
|
71 |
// Then look at the events to see if they are suitable for us
|
|
72 |
if (target && eventCode == qstmUiEventEngine::ERelease) {// The last one is release
|
|
73 |
|
|
74 |
qstmUiEventEngine::QStm_UiEventIf* puieFirst = puie->previousEvent();
|
|
75 |
|
|
76 |
if (puieFirst != NULL &&
|
|
77 |
(eventCode = puieFirst->code()) == qstmUiEventEngine::ETouch && // is the first one ETouch
|
|
78 |
isPointClose(puie->currentXY(), puie->previousXY())) { // if system failed to deliver move event between
|
|
79 |
// down and up we can get tap with two points
|
|
80 |
// too far from each other, so check for it
|
|
81 |
|
|
82 |
if (m_loggingenabled) {
|
|
83 |
LOGARG("QStm_MaybeTapGestureRecogniser: 0x%x TAP: countOfEvents: %d, event: %s", this, countOfEvents, event_name(eventCode));
|
|
84 |
}
|
|
85 |
|
|
86 |
m_firstTapXY = puieFirst->currentXY() ;
|
|
87 |
m_firstTapTarget = target ;
|
|
88 |
m_firstTapSpeed = puie->speed() ;
|
|
89 |
int inx = m_tapListenerWindows.indexOf(m_firstTapTarget) ;
|
|
90 |
if (inx == -1) {
|
|
91 |
inx = 0;
|
|
92 |
}
|
|
93 |
qstmGesture::QStm_GenericSimpleGesture pgest(
|
|
94 |
qstmGesture::EGestureUidMaybeTap,
|
|
95 |
m_firstTapXY,
|
|
96 |
puie->timestamp(),
|
|
97 |
qstmGesture::ETapTypeSingle,
|
|
98 |
puieFirst) ; // TODO: speed is 0?
|
|
99 |
pgest.setTarget(puie->target());
|
|
100 |
QStm_GestureListenerIf* plistener = m_tapListeners[inx] ;
|
|
101 |
plistener->gestureEnter(pgest) ;
|
|
102 |
}
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
m_state = state;
|
|
107 |
return state;
|
|
108 |
}
|
|
109 |
|
|
110 |
void QStm_MaybeTapGestureRecogniser::release(QStm_GestureEngineIf* /*ge*/)
|
|
111 |
{
|
|
112 |
if (m_loggingenabled) {
|
|
113 |
LOGARG("QStm_MaybeTapGestureRecogniser: 0x%x release, %d %d", this, m_firstTapXY.x(), m_firstTapXY.y());
|
|
114 |
}
|
|
115 |
m_state = ENotMyGesture;
|
|
116 |
}
|
|
117 |
|
|
118 |
void QStm_MaybeTapGestureRecogniser::enableLogging(bool loggingOn)
|
|
119 |
{
|
|
120 |
m_loggingenabled = loggingOn;
|
|
121 |
}
|
|
122 |
|
|
123 |
void QStm_MaybeTapGestureRecogniser::setOwner(void* owner)
|
|
124 |
{
|
|
125 |
m_powner = owner;
|
|
126 |
}
|
|
127 |
|
|
128 |
|
|
129 |
void QStm_MaybeTapGestureRecogniser::enable(bool enabled)
|
|
130 |
{
|
|
131 |
m_gestureEnabled = enabled ;
|
|
132 |
}
|
|
133 |
|
|
134 |
bool QStm_MaybeTapGestureRecogniser::isEnabled()
|
|
135 |
{
|
|
136 |
return m_gestureEnabled ;
|
|
137 |
}
|
|
138 |
|
|
139 |
void QStm_MaybeTapGestureRecogniser::setTapRange(int rangeInMillimetres)
|
|
140 |
{
|
|
141 |
m_rangesizeInPixels = QStm_Utils::mm2Pixels(rangeInMillimetres) ;
|
|
142 |
}
|
|
143 |
|
|
144 |
bool QStm_MaybeTapGestureRecogniser::isPointClose(const QPoint& firstPoint, const QPoint& secondPoint)
|
|
145 |
{
|
|
146 |
QRect tolerance = QStm_Utils::toleranceRectPx(secondPoint, m_rangesizeInPixels) ;
|
|
147 |
bool aretheyclose = tolerance.contains(firstPoint);
|
|
148 |
return aretheyclose ;
|
|
149 |
}
|
|
150 |
|
|
151 |
void QStm_MaybeTapGestureRecogniser::addTapListener(QStm_GestureListenerIf* listener, void* listenerOwner)
|
|
152 |
{
|
|
153 |
m_tapListeners.append(listener) ;
|
|
154 |
m_tapListenerWindows.append(listenerOwner) ;
|
|
155 |
}
|
|
156 |
|
|
157 |
void QStm_MaybeTapGestureRecogniser::removeTapListener(QStm_GestureListenerIf* listener, void* /*listenerOwner*/)
|
|
158 |
{
|
|
159 |
int inx = m_tapListeners.indexOf(listener) ;
|
|
160 |
if(inx != -1) {
|
|
161 |
m_tapListeners.removeAt(inx) ;
|
|
162 |
m_tapListenerWindows.removeAt(inx) ;
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|