22 |
22 |
23 #include <HbTapGesture> |
23 #include <HbTapGesture> |
24 #include <HbPanGesture> |
24 #include <HbPanGesture> |
25 |
25 |
26 #include "hswidgettoucharea.h" |
26 #include "hswidgettoucharea.h" |
27 #include "hswidgethost.h" |
27 #include "hswidgethostvisual.h" |
28 #include "hsscene.h" |
28 #include "hsscene.h" |
29 |
29 |
30 HsWidgetTouchArea::HsWidgetTouchArea(HsWidgetHost *widgetHost) |
30 HsWidgetTouchArea::HsWidgetTouchArea(HsWidgetHostVisual *visual) |
31 : HbTouchArea(widgetHost), |
31 : HbTouchArea(visual), |
32 mWidgetHost(widgetHost) |
32 mWidgetHostVisual(visual) |
33 { |
33 { |
34 grabGesture(Qt::TapAndHoldGesture); |
34 grabGesture(Qt::TapAndHoldGesture); |
35 } |
35 } |
36 |
36 |
37 HsWidgetTouchArea::~HsWidgetTouchArea() |
37 HsWidgetTouchArea::~HsWidgetTouchArea() |
42 { |
42 { |
43 HsScene *scene = HsScene::instance(); |
43 HsScene *scene = HsScene::instance(); |
44 switch (event->type()) { |
44 switch (event->type()) { |
45 case QEvent::TouchBegin: |
45 case QEvent::TouchBegin: |
46 case QEvent::GraphicsSceneMousePress: |
46 case QEvent::GraphicsSceneMousePress: |
47 emit scene->widgetTapStarted(mWidgetHost); |
47 emit scene->widgetTapStarted(mWidgetHostVisual->visualModel()); |
48 break; |
48 break; |
49 case QEvent::TouchEnd: |
49 case QEvent::TouchEnd: |
50 { |
50 { |
51 ungrabGesture(Qt::PanGesture); |
51 ungrabGesture(Qt::PanGesture); |
52 ungrabMouse(); |
52 ungrabMouse(); |
53 QPointF scenePos = static_cast<QTouchEvent *>(event)->touchPoints().first().scenePos(); |
53 QPointF scenePos = static_cast<QTouchEvent *>(event)->touchPoints().first().scenePos(); |
54 emit scene->widgetMoveFinished(scenePos, mWidgetHost); |
54 emit scene->widgetMoveFinished(scenePos, mWidgetHostVisual->visualModel()); |
55 } |
55 } |
56 break; |
56 break; |
57 case QEvent::GraphicsSceneMouseRelease: |
57 case QEvent::GraphicsSceneMouseRelease: |
58 { |
58 { |
59 ungrabGesture(Qt::PanGesture); |
59 ungrabGesture(Qt::PanGesture); |
60 ungrabMouse(); |
60 ungrabMouse(); |
61 QPointF scenePos = static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos(); |
61 QPointF scenePos = static_cast<QGraphicsSceneMouseEvent *>(event)->scenePos(); |
62 emit scene->widgetMoveFinished(scenePos, mWidgetHost); |
62 emit scene->widgetMoveFinished(scenePos, mWidgetHostVisual->visualModel()); |
63 } |
63 } |
64 break; |
64 break; |
65 default: |
65 default: |
66 break; |
66 break; |
67 } |
67 } |
69 return HbTouchArea::sceneEvent(event); |
69 return HbTouchArea::sceneEvent(event); |
70 } |
70 } |
71 |
71 |
72 QPainterPath HsWidgetTouchArea::shape() const |
72 QPainterPath HsWidgetTouchArea::shape() const |
73 { |
73 { |
74 return mWidgetHost->shape(); |
74 return mWidgetHostVisual->shape(); |
75 } |
75 } |
76 |
76 |
77 void HsWidgetTouchArea::gestureEvent(QGestureEvent *event) |
77 void HsWidgetTouchArea::gestureEvent(QGestureEvent *event) |
78 { |
78 { |
79 HsScene *scene = HsScene::instance(); |
79 HsScene *scene = HsScene::instance(); |
82 QGesture *gesture = event->gesture(Qt::TapAndHoldGesture); |
82 QGesture *gesture = event->gesture(Qt::TapAndHoldGesture); |
83 if (gesture) { |
83 if (gesture) { |
84 if (gesture->state() == Qt::GestureFinished) { |
84 if (gesture->state() == Qt::GestureFinished) { |
85 grabGesture(Qt::PanGesture); |
85 grabGesture(Qt::PanGesture); |
86 grabMouse(); |
86 grabMouse(); |
87 emit scene->widgetTapAndHoldFinished(event, mWidgetHost); |
87 emit scene->widgetTapAndHoldFinished(event, mWidgetHostVisual->visualModel()); |
88 } |
88 } |
89 return; |
89 return; |
90 } |
90 } |
91 |
91 |
92 // Pan gesture. |
92 // Pan gesture. |
94 if (gesture) { |
94 if (gesture) { |
95 QPointF scenePos = event->mapToGraphicsScene(gesture->hotSpot()); |
95 QPointF scenePos = event->mapToGraphicsScene(gesture->hotSpot()); |
96 switch (gesture->state()) { |
96 switch (gesture->state()) { |
97 case Qt::GestureStarted: |
97 case Qt::GestureStarted: |
98 case Qt::GestureUpdated: |
98 case Qt::GestureUpdated: |
99 emit scene->widgetMoveUpdated(scenePos, mWidgetHost); |
99 emit scene->widgetMoveUpdated(scenePos, mWidgetHostVisual->visualModel()); |
100 break; |
100 break; |
101 case Qt::GestureCanceled: |
101 case Qt::GestureCanceled: |
102 case Qt::GestureFinished: |
102 case Qt::GestureFinished: |
103 ungrabGesture(Qt::PanGesture); |
103 ungrabGesture(Qt::PanGesture); |
104 emit scene->widgetMoveFinished(scenePos, mWidgetHost); |
104 emit scene->widgetMoveFinished(scenePos, mWidgetHostVisual->visualModel()); |
105 break; |
105 break; |
106 default: |
106 default: |
107 break; |
107 break; |
108 } |
108 } |
109 return; |
109 return; |