32 |
32 |
33 /*! |
33 /*! |
34 @hbcore |
34 @hbcore |
35 \class HbSwipeGesture |
35 \class HbSwipeGesture |
36 |
36 |
37 \brief HbSwipeGesture is an extension to Qt standard HbSwipeGesture |
37 \brief The HbSwipeGesture class provides support for receiving a swipe |
|
38 (flick) gesture. |
|
39 |
|
40 HbSwipeGesture is an extension to Qt standard QSwipeGesture. It is |
|
41 optimized for mobile touch screens, and also supports recognition of |
|
42 mouse events for development purposes. Moreover, HbSwipeGesture |
|
43 has convenience functions for handling the QSwipeGesture properties |
|
44 (horizontalDirection, verticalDirection, swipeAngle) directly in scene |
|
45 coordinates. They remove the need for any manual conversions from the |
|
46 screen (global) coordinates offered by the QSwipeGesture base class |
|
47 properties. |
|
48 |
|
49 The swipe gesture is designed to be used as a single-shot gesture which |
|
50 is activated after a flick and release. No events are sent until the |
|
51 gesture is finished. Swipe should be used when feedback during the |
|
52 gesture is not possible or desired. |
|
53 |
|
54 \section _usecases_hbswipegesture Using the HbSwipeGesture class |
|
55 |
|
56 This example shows how to make a custom widget recognize the swipe |
|
57 gesture. The custom widget in the example derives from HbWidget. |
|
58 |
|
59 <ol> |
|
60 <li> |
|
61 Register for swipe gestures by using the base class function |
|
62 QGraphicsObject::grabGesture(). QGraphicsObject::grabGesture() can be |
|
63 called several times with different arguments, if the widget is |
|
64 interested in other gesture types as well. |
|
65 |
|
66 \code |
|
67 // This widget is interested in swipe and tap gestures. |
|
68 grabGesture(Qt::SwipeGesture); |
|
69 grabGesture(Qt::TapGesture); |
|
70 \endcode |
|
71 </li> |
|
72 |
|
73 <li> |
|
74 Reimplement HbWidgetBase::gestureEvent() to handle gestures that are |
|
75 meaningful for your custom widget. |
|
76 |
|
77 \code |
|
78 void MyWidget::gestureEvent(QGestureEvent *event) |
|
79 { |
|
80 if (HbSwipeGesture *swipe = qobject_cast<HbSwipeGesture *> |
|
81 (event->gesture(Qt::SwipeGesture))) { |
|
82 |
|
83 switch (swipe->state()) { |
|
84 |
|
85 case Qt::GestureStarted: // fall-through |
|
86 case Qt::GestureUpdated: // fall-through |
|
87 case Qt::GestureCanceled: |
|
88 break; |
|
89 case Qt::GestureFinished: |
|
90 // Emit a signal to show the swipe movement. |
|
91 break; |
|
92 default: |
|
93 break; |
|
94 } |
|
95 } |
|
96 |
|
97 // Handle other gesture types that have been grabbed. There may be |
|
98 // several, since all gestures that are active at the same moment |
|
99 // are sent within the same gesture event. |
|
100 if (HbTapGesture *tap = qobject_cast<HbTapGesture *> |
|
101 (event->gesture(Qt::TapGesture))) { |
|
102 // handle the tap gesture |
|
103 } |
|
104 |
|
105 } |
|
106 \endcode |
|
107 </li> |
|
108 </ol> |
|
109 |
38 \sa QSwipeGesture |
110 \sa QSwipeGesture |
39 */ |
111 */ |
40 |
112 |
41 const int KHbDirectionThreshold = 45; // degrees |
113 const int KHbDirectionThreshold = 45; // degrees |
42 |
114 |
43 /*! |
115 /*! |
44 \brief HbSwipeGesture constructor |
116 Constructor. |
45 \param parent Owner for gesture |
117 \param parent Owner for gesture |
46 */ |
118 */ |
47 HbSwipeGesture::HbSwipeGesture(QObject *parent) |
119 HbSwipeGesture::HbSwipeGesture(QObject *parent) |
48 : QSwipeGesture(parent), d_ptr(new HbSwipeGesturePrivate) |
120 : QSwipeGesture(parent), d_ptr(new HbSwipeGesturePrivate) |
49 |
121 |
50 { |
122 { |
51 d_ptr->mSceneSwipeAngle = 0; |
123 d_ptr->mSceneSwipeAngle = 0; |
52 } |
124 } |
53 |
125 |
54 /*! |
126 /*! |
55 \brief HbSwipeGesture constructor |
127 Constructor required by the shared d-pointer paradigm. |
56 \param dd Private data |
128 \param dd Private data |
57 \param parent Owner for gesture |
129 \param parent Owner for gesture |
58 */ |
130 */ |
59 HbSwipeGesture::HbSwipeGesture(HbSwipeGesturePrivate &dd, QObject *parent) |
131 HbSwipeGesture::HbSwipeGesture(HbSwipeGesturePrivate &dd, QObject *parent) |
60 : QSwipeGesture(parent), d_ptr(&dd) |
132 : QSwipeGesture(parent), d_ptr(&dd) |
61 { |
133 { |
62 |
134 |
63 } |
135 } |
64 |
136 |
65 /*! |
137 /*! |
66 \brief HbSwipeGesture destructor |
138 Destructor. |
67 */ |
139 */ |
68 HbSwipeGesture::~HbSwipeGesture() |
140 HbSwipeGesture::~HbSwipeGesture() |
69 { |
141 { |
70 delete d_ptr; |
142 delete d_ptr; |
71 } |
143 } |
72 |
144 |
73 /*! |
145 /*! |
74 \property sceneHorizontalDirection |
146 Returns the horizontal direction of the swipe gesture |
75 \brief Horizontal direction of swipe in scene coordinates. |
147 relative to scene coordinates. |
76 |
148 |
77 \sa QSwipeGesture::horizontalDirection() |
149 \sa QSwipeGesture::horizontalDirection() |
78 */ |
150 */ |
79 QSwipeGesture::SwipeDirection HbSwipeGesture::sceneHorizontalDirection() const |
151 QSwipeGesture::SwipeDirection HbSwipeGesture::sceneHorizontalDirection() const |
80 { |
152 { |
99 else |
171 else |
100 return QSwipeGesture::NoDirection; |
172 return QSwipeGesture::NoDirection; |
101 } |
173 } |
102 |
174 |
103 /*! |
175 /*! |
104 \property sceneSwipeAngle |
176 Returns the angle for the swipe gesture in degrees, |
105 \brief Angle for swipe in scene coordinates. |
177 taking into account any scene transformations. |
106 \sa QSwipeGesture::swipeAngle() |
178 \sa setSceneSwipeAngle(), QSwipeGesture::swipeAngle() |
107 */ |
179 */ |
108 qreal HbSwipeGesture::sceneSwipeAngle() const |
180 qreal HbSwipeGesture::sceneSwipeAngle() const |
109 { |
181 { |
110 return d_ptr->mSceneSwipeAngle; |
182 return d_ptr->mSceneSwipeAngle; |
111 } |
183 } |
112 |
184 |
|
185 /*! |
|
186 Sets the angle for the swipe gesture. |
|
187 This function is used by the framework gesture recognition logic, |
|
188 and it should not be used by the widget receiving the gesture. |
|
189 \sa sceneSwipeAngle(), QSwipeGesture::setSwipeAngle() |
|
190 */ |
113 void HbSwipeGesture::setSceneSwipeAngle(qreal value) |
191 void HbSwipeGesture::setSceneSwipeAngle(qreal value) |
114 { |
192 { |
115 d_ptr->mSceneSwipeAngle = value; |
193 d_ptr->mSceneSwipeAngle = value; |
116 } |
194 } |
117 |
195 |
118 |
196 |
119 /*! |
197 /*! |
120 \deprecated |
198 \deprecated |
121 \property speed |
199 Returns the speed. |
122 */ |
200 */ |
123 qreal HbSwipeGesture::speed() const |
201 qreal HbSwipeGesture::speed() const |
124 { |
202 { |
125 HB_DEPRECATED("HbSwipeGesture::speed is deprecated"); |
203 HB_DEPRECATED("HbSwipeGesture::speed is deprecated"); |
126 return 1; |
204 return 1; |
127 } |
205 } |
128 |
206 |
|
207 /*! |
|
208 \deprecated |
|
209 Sets the speed. |
|
210 */ |
129 void HbSwipeGesture::setSpeed(qreal speed) |
211 void HbSwipeGesture::setSpeed(qreal speed) |
130 { |
212 { |
131 Q_UNUSED (speed); |
213 Q_UNUSED (speed); |
132 HB_DEPRECATED("HbSwipeGesture::setSpeed is deprecated"); |
214 HB_DEPRECATED("HbSwipeGesture::setSpeed is deprecated"); |
133 } |
215 } |
134 |
216 |
135 /*! |
217 /*! |
136 \deprecated |
218 \deprecated |
137 \property touchPointCount |
219 Returns the touchPointCount. |
138 */ |
220 */ |
139 int HbSwipeGesture::touchPointCount() const |
221 int HbSwipeGesture::touchPointCount() const |
140 { |
222 { |
141 HB_DEPRECATED("HbSwipeGesture::touchPointCount is deprecated"); |
223 HB_DEPRECATED("HbSwipeGesture::touchPointCount is deprecated"); |
142 return 0; |
224 return 0; |
143 } |
225 } |
144 |
226 |
|
227 /*! |
|
228 \deprecated |
|
229 Sets the touchPointCount. |
|
230 */ |
145 void HbSwipeGesture::setTouchPointCount(int touchPointCount) |
231 void HbSwipeGesture::setTouchPointCount(int touchPointCount) |
146 { |
232 { |
147 HB_DEPRECATED("HbSwipeGesture::setTouchPointCount is deprecated"); |
233 HB_DEPRECATED("HbSwipeGesture::setTouchPointCount is deprecated"); |
148 Q_UNUSED(touchPointCount) |
234 Q_UNUSED(touchPointCount) |
149 } |
235 } |