|
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 "qstmedgescrollgesturerecogniser.h" |
|
19 #include "qstmgenericsimplegesture.h" |
|
20 #include "qstmuievent_if.h" |
|
21 #include "qstmfilelogger.h" |
|
22 |
|
23 |
|
24 using namespace qstmGesture ; |
|
25 |
|
26 QStm_EdgeScrollGestureRecogniser::QStm_EdgeScrollGestureRecogniser(QStm_GestureListenerIf* listener) : |
|
27 QStm_GestureRecogniser(listener), |
|
28 m_listener(listener) , m_area() |
|
29 { |
|
30 m_powner = listener->getOwner() ; |
|
31 m_gestureEnabled = true ; |
|
32 m_rangesizeInPixels = 10 ; // by default 10 pixels from the edges is the area |
|
33 } |
|
34 |
|
35 |
|
36 QStm_EdgeScrollGestureRecogniser::~QStm_EdgeScrollGestureRecogniser() |
|
37 { |
|
38 } |
|
39 |
|
40 QStm_GestureRecognitionState QStm_EdgeScrollGestureRecogniser::recognise(int numOfActiveStreams, |
|
41 QStm_GestureEngineIf* pge) |
|
42 { |
|
43 QStm_GestureRecognitionState state = m_state = ENotMyGesture; |
|
44 // Check if we are enabled or not |
|
45 if (!m_gestureEnabled) return state ; |
|
46 |
|
47 // Look at the events to see if it looks like edge scroll with one pointer |
|
48 if (numOfActiveStreams == 1) { |
|
49 // Then look at the event stream, it has to be EHold |
|
50 const qstmUiEventEngine::QStm_UiEventIf* puie = pge->getUiEvents(0); |
|
51 int countOfEvents = puie->countOfEvents(); |
|
52 qstmUiEventEngine::QStm_UiEventCode eventCode = puie->code(); |
|
53 |
|
54 if (m_loggingenabled) { |
|
55 LOGARG("QStm_EdgeScrollGestureRecogniser: %d num %d code %d", eventCode, countOfEvents, eventCode); |
|
56 } |
|
57 |
|
58 if (eventCode == qstmUiEventEngine::EHold) { // The last one is EHold, look if it is near the area defined |
|
59 const QPoint& p = puie->currentXY(); |
|
60 if (m_loggingenabled) { |
|
61 LOGARG("QStm_EdgeScrollGestureRecogniser: 0x%x EHold: num %d code %d, %d", |
|
62 this, countOfEvents, p.x(), p.y()); |
|
63 LOGARG("QStm_EdgeScrollGestureRecogniser: area, %d,%d %d,%d, range: %d", |
|
64 m_area.x(), m_area.y(), m_area.x() + m_area.width(), m_area.y() + m_area.height(), |
|
65 m_rangesizeInPixels); |
|
66 } |
|
67 // check where the point is inside the area defined but outside of the area shrunk by m_rangesizeInPixels. |
|
68 QRect rcInner(QPoint(0,0), m_area.size() - QSize(m_rangesizeInPixels, m_rangesizeInPixels)); |
|
69 rcInner.moveCenter(m_area.center()) ; |
|
70 if (m_area.contains(p) && !rcInner.contains(p)) |
|
71 { |
|
72 if (m_loggingenabled) { |
|
73 LOGARG("QStm_EdgeScrollGestureRecogniser: HIT, (%d,%d) in %d,%d %d,%d, range: %d", |
|
74 p.x(), p.y(), m_area.x(), m_area.y(), |
|
75 m_area.x() + m_area.width(), m_area.y() + m_area.height(), |
|
76 m_rangesizeInPixels); |
|
77 } |
|
78 |
|
79 state = EGestureActive ; |
|
80 // this is edge scroll, check where it is about... |
|
81 QStm_EdgeScroll scrolltype = EEdgeScrollUnknown ; |
|
82 if (p.y() < m_area.y() + m_rangesizeInPixels) |
|
83 scrolltype = EEdgeScrollUp ; // if Y is small enough, it is always up |
|
84 else if (p.y() > m_area.y() + m_area.height() - m_rangesizeInPixels) |
|
85 scrolltype = EEdgeScrollDown ; // if Y is big enough, it is always down |
|
86 else if (p.x() < m_area.x() + m_rangesizeInPixels) |
|
87 scrolltype = EEdgeScrollLeft ; // if X is small enough, it is always left |
|
88 else if (p.x() > m_area.x() + m_area.width() - m_rangesizeInPixels) |
|
89 scrolltype = EEdgeScrollRight ; // if X is big enough, it is always right |
|
90 // issue the edge scroll gesture |
|
91 qstmGesture::QStm_GenericSimpleGesture pgest(KUid, p, scrolltype, puie) ; |
|
92 pgest.setTarget(puie->target()); |
|
93 // Call the listener to inform that a Tap has occurred... |
|
94 m_listener->gestureEnter(pgest) ; |
|
95 } |
|
96 } |
|
97 } |
|
98 m_state = state; |
|
99 return state; |
|
100 } |
|
101 |
|
102 void QStm_EdgeScrollGestureRecogniser::release(QStm_GestureEngineIf* /*ge*/) |
|
103 { |
|
104 if (m_loggingenabled) { |
|
105 LOGARG("QStm_EdgeScrollGestureRecogniser: 0x%x release", this); |
|
106 } |
|
107 m_state = m_state = ENotMyGesture; |
|
108 } |
|
109 |
|
110 |
|
111 void QStm_EdgeScrollGestureRecogniser::enableLogging(bool loggingOn) |
|
112 { |
|
113 m_loggingenabled = loggingOn; |
|
114 } |
|
115 |
|
116 void QStm_EdgeScrollGestureRecogniser::enable(bool enabled) |
|
117 { |
|
118 m_gestureEnabled = enabled ; |
|
119 } |
|
120 |
|
121 bool QStm_EdgeScrollGestureRecogniser::isEnabled() |
|
122 { |
|
123 return m_gestureEnabled ; |
|
124 } |
|
125 |
|
126 void QStm_EdgeScrollGestureRecogniser::setOwner(void* owner) |
|
127 { |
|
128 m_powner = owner; |
|
129 } |
|
130 |
|
131 void QStm_EdgeScrollGestureRecogniser::setScrollRange(int rangeInPixels) |
|
132 { |
|
133 m_rangesizeInPixels = rangeInPixels ; |
|
134 } |
|
135 |
|
136 void QStm_EdgeScrollGestureRecogniser::setArea(const QRect& theArea) |
|
137 { |
|
138 m_area = theArea ; |
|
139 if (m_loggingenabled) |
|
140 { |
|
141 LOGARG("QStm_EdgeScrollGestureRecogniser: set area, %d,%d %d,%d", |
|
142 m_area.x(), m_area.y(), m_area.x() + m_area.width(), m_area.y() + m_area.height()); |
|
143 } |
|
144 } |