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 "hbgestures_p.h" |
26 #include "hbtapandholdgesture_p.h" |
27 #include "hbtapandholdgesture_p.h" |
27 #include "hbtapandholdgesture.h" |
28 #include "hbtapandholdgesture.h" |
28 |
29 |
29 #include <QGraphicsSceneEvent> |
30 #include <QObject> |
30 #include <QVariant> |
|
31 #include <QDebug> |
|
32 #include <QPoint> |
|
33 #include <QLine> |
|
34 |
31 |
35 /*! |
32 /*! |
36 \internal |
33 \internal |
37 \class HbTapAndHoldGesture |
34 \class HbTapAndHoldGesture |
38 |
35 |
39 \brief HbTapAndHoldGesture implements a gesture for tap and hold. |
36 \brief HbTapAndHoldGesture implements a gesture for tap and hold. |
40 */ |
37 */ |
41 |
38 |
42 HbTapAndHoldGesture::HbTapAndHoldGesture(QObject* parent) |
39 HbTapAndHoldGesture::HbTapAndHoldGesture(QObject* parent) |
43 : |
40 : |
|
41 QTapAndHoldGesture(parent) |
|
42 { |
|
43 priv = new HbTapAndHoldGesturePrivate(this); |
|
44 } |
|
45 |
|
46 HbTapAndHoldGesture::HbTapAndHoldGesture(HbTapAndHoldGesturePrivate* data, QObject* parent) |
|
47 : |
44 QTapAndHoldGesture(parent), |
48 QTapAndHoldGesture(parent), |
45 priv(new HbTapAndHoldGesturePrivate()) |
49 priv(data) |
46 { |
50 { |
|
51 priv->q_ptr = this; |
47 } |
52 } |
48 |
53 |
49 HbTapAndHoldGesture::~HbTapAndHoldGesture() |
54 HbTapAndHoldGesture::~HbTapAndHoldGesture() |
50 { |
55 { |
51 delete priv; priv = NULL; |
56 delete priv; priv = NULL; |
52 } |
57 } |
53 |
58 |
54 /*! |
59 QPointF HbTapAndHoldGesture::scenePosition() const |
55 \internal |
|
56 \brief Stores relevant values from the event. |
|
57 \param event Event to be read. |
|
58 |
|
59 Gesture needs to know its position all the time, and that information |
|
60 is provided during the event. |
|
61 */ |
|
62 void HbTapAndHoldGesture::update(QEvent& event) |
|
63 { |
60 { |
64 if ( event.type() != QEvent::Timer ) |
61 return priv->mScenePos; |
65 { |
|
66 QGraphicsSceneMouseEvent* me = static_cast<QGraphicsSceneMouseEvent*>(&event); |
|
67 setProperty("position", me ? me->screenPos() : property("startPos")); |
|
68 } |
|
69 } |
62 } |
70 |
63 |
71 bool HbTapAndHoldGesture::outsideThreshold() |
64 void HbTapAndHoldGesture::setScenePosition(const QPointF& pos) |
72 { |
65 { |
73 QPointF startPos = property("startPos").toPoint(); |
66 priv->mScenePos = pos; |
74 QPointF lastPos = property("position").toPoint(); |
|
75 return QLineF(startPos, lastPos).length() > DELTA_TOLERANCE; |
|
76 } |
67 } |