21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
|
26 #include "hbtapandholdgesture.h" |
26 #include "hbgestures_p.h" |
27 #include "hbgestures_p.h" |
27 #include "hbtapandholdgesture_p.h" |
|
28 #include "hbtapandholdgesture.h" |
|
29 |
28 |
30 #include <QObject> |
29 #include <QObject> |
31 |
30 |
32 /*! |
31 /*! |
33 @hbcore |
32 @hbcore |
45 |
44 |
46 Use HbTapAndHoldGesture for a custom widget that is only interested in |
45 Use HbTapAndHoldGesture for a custom widget that is only interested in |
47 the tap-and-hold (long tap) gesture. If you want your custom widget to |
46 the tap-and-hold (long tap) gesture. If you want your custom widget to |
48 receive both short and long taps, use HbTapGesture instead, since it |
47 receive both short and long taps, use HbTapGesture instead, since it |
49 supports both. |
48 supports both. |
|
49 |
|
50 For the tap-and-hold gesture, start and finish events are both sent after |
|
51 a time threshold, first Qt::GestureStarted and then Qt::GestureFinished |
|
52 immediately after that. |
50 |
53 |
51 \section _usecases_hbtapandholdgesture Using the HbTapAndHoldGesture class |
54 \section _usecases_hbtapandholdgesture Using the HbTapAndHoldGesture class |
52 |
55 |
53 This example shows how to make a custom widget recognize the tap-and-hold |
56 This example shows how to make a custom widget recognize the tap-and-hold |
54 gesture. The custom widget in the example derives from HbWidget. |
57 gesture. The custom widget in the example derives from HbWidget. |
71 Reimplement HbWidgetBase::gestureEvent() to handle gestures that are |
74 Reimplement HbWidgetBase::gestureEvent() to handle gestures that are |
72 meaningful for your custom widget. |
75 meaningful for your custom widget. |
73 |
76 |
74 \code |
77 \code |
75 void MyWidget::gestureEvent(QGestureEvent *event) |
78 void MyWidget::gestureEvent(QGestureEvent *event) |
76 { |
79 { |
77 if (HbTapAndHoldGesture *tapAndHold = |
80 if (HbTapAndHoldGesture *tapAndHold = |
78 qobject_cast<HbTapAndHoldGesture *> |
81 qobject_cast<HbTapAndHoldGesture *> |
79 (event->gesture(Qt::TapAndHoldGesture))) { |
82 (event->gesture(Qt::TapAndHoldGesture))) { |
80 |
83 |
81 switch (tapAndHold->state()) { |
84 switch (tapAndHold->state()) { |
82 |
85 |
83 case Qt::GestureStarted: |
86 // The only interesting event for the tap-and-hold gesture |
84 // Visualize the active state of the widget. |
87 // is GestureFinished, so all handling related to |
85 break; |
88 // the gesture is best done here. |
86 |
89 |
87 // No GestureUpdated events are sent for this gesture type, |
90 case Qt::GestureFinished: |
88 // so no handling is needed for those |
91 // Tap-and-hold gesture is recognized. |
89 |
92 // Emit a long tap signal. |
90 case Qt::GestureCanceled: |
|
91 // Visualize the non-active state of the widget. |
|
92 break; |
|
93 case Qt::GestureFinished: |
|
94 // Visualize the non-active state of the widget. |
|
95 // Emit a long tap signal. |
|
96 break; |
93 break; |
97 default: |
94 default: |
98 break; |
95 break; |
99 } |
96 } |
100 } |
97 } |
101 |
|
102 // Handle other gesture types that have been grabbed. There may be |
98 // Handle other gesture types that have been grabbed. There may be |
103 // several, since all gestures that are active at the same moment |
99 // several, since all gestures that are active at the same moment |
104 // are sent within the same gesture event. |
100 // are sent within the same gesture event. |
105 if (HbPanGesture *pan = qobject_cast<HbPanGesture *> |
101 if (HbPanGesture *pan = qobject_cast<HbPanGesture *> |
106 (event->gesture(Qt::PanGesture))) { |
102 (event->gesture(Qt::PanGesture))) { |
119 Constructor. |
115 Constructor. |
120 \param parent Parent for the gesture |
116 \param parent Parent for the gesture |
121 */ |
117 */ |
122 HbTapAndHoldGesture::HbTapAndHoldGesture(QObject* parent) |
118 HbTapAndHoldGesture::HbTapAndHoldGesture(QObject* parent) |
123 : |
119 : |
124 QTapAndHoldGesture(parent) |
120 QTapAndHoldGesture(parent), |
|
121 priv(new HbTapAndHoldGesturePrivate) |
125 { |
122 { |
126 priv = new HbTapAndHoldGesturePrivate(this); |
|
127 } |
123 } |
128 |
124 |
129 /*! |
125 /*! |
130 Constructor required by the shared d-pointer paradigm. |
126 Constructor required by the shared d-pointer paradigm. |
131 \param dd Custom private data |
127 \param dd Custom private data |