|
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 #ifndef QSTMTAPGESTURERECOGNISER_H_ |
|
20 #define QSTMTAPGESTURERECOGNISER_H_ |
|
21 |
|
22 #include <qstmgestureengine_if.h> |
|
23 #include <qstmgesture_if.h> |
|
24 #include <qstmgesturelistener_if.h> |
|
25 |
|
26 namespace qstmGesture |
|
27 { |
|
28 |
|
29 /*! |
|
30 * QStm_TapGestureRecogniser handles both tap and double tap recognition. |
|
31 * Doubletap needs to work even if it crosses window boundaries, so |
|
32 * QStm_TapGestureRecogniser is a "global" recogniser. The application |
|
33 * creates only one instance of it (TODO later: how to use Singleton |
|
34 * pattern in Symbian, seems to be tricky since we would need to have |
|
35 * writable static variable to hold the one instance, so currently |
|
36 * we need well-behaving app to handle this: the application must known |
|
37 * the nature of this gesture recogniser). |
|
38 * The different windows can add their callbacks, and when recognising tap |
|
39 * the target window is stored so that proper callback can be called. |
|
40 * Doubletap is reported either to the target of second tap, or if that windows parent |
|
41 * has a doubletap listener, to that. |
|
42 * Use separate listeners for tap and doubletap. |
|
43 */ |
|
44 class QStm_TapGestureRecogniser : public QStm_GestureRecogniser |
|
45 { |
|
46 Q_OBJECT |
|
47 public: |
|
48 static const QStm_GestureUid KUid = EGestureUidTap; |
|
49 |
|
50 virtual ~QStm_TapGestureRecogniser(); |
|
51 |
|
52 virtual QStm_GestureRecognitionState recognise(int numOfActiveStreams, QStm_GestureEngineIf* ge) ; |
|
53 virtual void release(QStm_GestureEngineIf* ge) ; |
|
54 virtual void enable(bool enabled) ; |
|
55 virtual bool isEnabled() ; |
|
56 virtual void setOwner(void* owner) ; |
|
57 |
|
58 virtual QStm_GestureUid gestureUid() const { return KUid; } |
|
59 |
|
60 /*! |
|
61 * Additional methods to set up tap gesture recogniser: |
|
62 * define the double tap timeout in microseconds. |
|
63 * \param timeoutInMicroseconds |
|
64 */ |
|
65 void setDoubleTapTimeout(int timeoutInMicroseconds) ; |
|
66 |
|
67 /*! |
|
68 * Additional methods to set up tap gesture recogniser: |
|
69 * define how close the two taps need to be to be recognised |
|
70 * as a double tap. |
|
71 * \param rangeInMillimetres |
|
72 */ |
|
73 void setDoubleTapRange(int rangeInMillimetres) ; |
|
74 /*! |
|
75 * Additional methods to set up tap gesture recogniser: |
|
76 * Produce two separate taps or just ignore the first one |
|
77 * if the second tap is outside range. |
|
78 */ |
|
79 void ignoreFirstTap(bool ignore) ; |
|
80 |
|
81 /*! |
|
82 * Method to add a listener to tap gestures |
|
83 */ |
|
84 void addTapListener(QStm_GestureListenerIf* listener, void* listenerOwner) ; |
|
85 /*! |
|
86 * Method to remove a listener from tap gestures |
|
87 */ |
|
88 void removeTapListener(QStm_GestureListenerIf* listener, void* listenerOwner) ; |
|
89 /*! |
|
90 * Method to add a listener to doubletap gestures |
|
91 */ |
|
92 void addDoubleTapListener(QStm_GestureListenerIf* listener, void* listenerOwner) ; |
|
93 /*! |
|
94 * Method to remove a listener from doubletap gestures |
|
95 */ |
|
96 void removeDoubleTapListener(QStm_GestureListenerIf* listener, void* listenerOwner) ; |
|
97 |
|
98 /*! |
|
99 * for testing purposes we need to log the stuff somewhere... |
|
100 */ |
|
101 |
|
102 virtual void enableLogging(bool loggingOn) ; |
|
103 |
|
104 /*! |
|
105 * The timer function to handle timeout for tap |
|
106 */ |
|
107 |
|
108 QStm_TapGestureRecogniser(QStm_GestureListenerIf* listener) ; |
|
109 |
|
110 public slots: |
|
111 void timeoutCallback(); |
|
112 |
|
113 private: |
|
114 bool m_loggingenabled ; |
|
115 bool isPointClose(const QPoint& firstPoint, const QPoint& secondPoint) ; |
|
116 private: |
|
117 void* m_powner ; // The owning control for this gesture |
|
118 bool m_waitingforsecondtap ; |
|
119 QPoint m_firstTapXY ; |
|
120 void* m_firstTapTarget ; |
|
121 float m_firstTapSpeed ; |
|
122 int m_doubleTapTimeout ; |
|
123 bool m_gestureEnabled ; |
|
124 bool m_ignorefirst ; |
|
125 int m_rangesizeInPixels ; |
|
126 // use simple arrays to store the listeners and corresponding windows |
|
127 QList<QStm_GestureListenerIf*> m_tapListeners ; |
|
128 QList<void*> m_tapListenerWindows ; |
|
129 QList<QStm_GestureListenerIf*> m_doubleTapListeners ; |
|
130 QList<void*> m_doubleTapListenerWindows ; |
|
131 QTimer m_timer; |
|
132 }; |
|
133 |
|
134 } // namespace |
|
135 |
|
136 #endif /* QSTMTAPGESTURERECOGNISER_H_ */ |