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