|
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 "qstmhoveringgesturerecogniser.h" |
|
20 #include "qstmgenericsimplegesture.h" |
|
21 #include "qstmuievent_if.h" |
|
22 #include "qstmfilelogger.h" |
|
23 |
|
24 using namespace qstmGesture ; |
|
25 |
|
26 QStm_HoveringGestureRecogniser::QStm_HoveringGestureRecogniser(QStm_GestureListenerIf* listener) : |
|
27 QStm_GestureRecogniser(listener) |
|
28 { |
|
29 m_hovering = false ; |
|
30 m_hoveringspeed = 0.9f ; |
|
31 } |
|
32 |
|
33 QStm_HoveringGestureRecogniser::~QStm_HoveringGestureRecogniser() |
|
34 { |
|
35 } |
|
36 |
|
37 QStm_GestureRecognitionState QStm_HoveringGestureRecogniser::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 // Look at the events to see if it looks like hovering |
|
45 if (numOfActiveStreams == 1) { |
|
46 // Then look at the event stream, it has to be tap and release |
|
47 const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0); |
|
48 int countOfEvents = puie->countOfEvents() ; |
|
49 qstmUiEventEngine::QStm_UiEventCode eventCode = puie->code() ; |
|
50 if (countOfEvents > 1) {// do we have more than one event in the stream? |
|
51 // Then look at the events to see if they are suitable for us |
|
52 // should we check that all of the events are targeted to our window? |
|
53 // currently we only check if the last one is for us and is EMove, then we pan... |
|
54 if (puie->target() == m_powner && |
|
55 eventCode == qstmUiEventEngine::EMove) {// The last one is move in our window |
|
56 float speed = puie->speed() ; |
|
57 if (m_loggingenabled) { |
|
58 LOGARG("QStm_HoveringGestureRecogniser: %d: num %d code %d, speed %f, limit %f", |
|
59 m_hovering, countOfEvents, eventCode, double(speed), double(m_hoveringspeed)); |
|
60 } |
|
61 // It might be hovering gesture in our window, handle it |
|
62 if (!m_hovering) { |
|
63 // we are not yet hovering, so lets see if it is slow movement |
|
64 // but it must be movement; if it is 0.0 do not hover |
|
65 if (speed > 0.01f && speed < m_hoveringspeed) { |
|
66 state = EGestureActive; |
|
67 m_hovering = true; |
|
68 } |
|
69 } |
|
70 if (m_hovering) { |
|
71 // after we've started hovering, the speed could be increased a little before we loose hovering |
|
72 // but this adjustment is not implemented now... |
|
73 if (speed < m_hoveringspeed) { |
|
74 using qstmUiEventEngine::QStm_UiEventSpeed; |
|
75 |
|
76 state = EGestureActive; |
|
77 QStm_UiEventSpeed speedIf(speed); |
|
78 qstmGesture::QStm_DirectionalGesture pgest( |
|
79 KUid, |
|
80 puie->currentXY(), |
|
81 puie->previousXY(), |
|
82 &speedIf, |
|
83 m_loggingenabled); |
|
84 |
|
85 pgest.setTarget(puie->target()); // Call the listener to inform that a Hover has occurred... |
|
86 m_listener->gestureEnter(pgest); |
|
87 } |
|
88 } |
|
89 } |
|
90 else if (m_hovering) { |
|
91 if (eventCode == qstmUiEventEngine::ERelease) { // The last one is release in any window |
|
92 m_hovering = false ; |
|
93 // release will handle informing of the listener |
|
94 } |
|
95 } |
|
96 } |
|
97 else { |
|
98 // count of events == 1, lets see if it is EMove, then we take it and start hovering |
|
99 if (puie->target() == m_powner && |
|
100 eventCode == qstmUiEventEngine::EMove) {// The only one is move in our window |
|
101 if (m_loggingenabled) { |
|
102 LOGARG("QStm_HoveringGestureRecogniser: move: num %d code %d", countOfEvents, eventCode); |
|
103 } |
|
104 state = EGestureActive; |
|
105 qstmGesture::QStm_DirectionalGesture pgest( |
|
106 KUid, |
|
107 puie->currentXY(), |
|
108 puie->previousXY(), |
|
109 puie, |
|
110 m_loggingenabled); |
|
111 pgest.setTarget(puie->target()); |
|
112 |
|
113 // Call the listener to inform that a Hover has occurred... |
|
114 m_listener->gestureEnter(pgest); |
|
115 } |
|
116 } |
|
117 } |
|
118 if (state == ENotMyGesture) { |
|
119 // if it was not our gesture, then the state can not be hovering... |
|
120 m_hovering = false ; |
|
121 } |
|
122 m_state = state; |
|
123 return state; |
|
124 } |
|
125 |
|
126 void QStm_HoveringGestureRecogniser::release(QStm_GestureEngineIf* pge) |
|
127 { |
|
128 m_hovering = false ; |
|
129 const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0); |
|
130 using qstmUiEventEngine::QStm_UiEventSpeed; |
|
131 qstmGesture::QStm_DirectionalGesture pgest( |
|
132 KUid, |
|
133 puie->currentXY(), |
|
134 puie->previousXY(), |
|
135 puie, |
|
136 m_loggingenabled); |
|
137 pgest.setTarget(puie->target()); |
|
138 |
|
139 m_listener->gestureExit(pgest) ; |
|
140 m_state = ENotMyGesture; |
|
141 } |
|
142 |
|
143 void QStm_HoveringGestureRecogniser::setHoveringSpeed(float aSpeed) /*__SOFTFP */ |
|
144 { |
|
145 m_hoveringspeed = aSpeed ; |
|
146 } |
|
147 |