22 property bool touchAreaPressed: false
23 property real swipeDelta: units.gu(1)
26 signal mouseMoveDetected(int x, int y, int button, int buttons, int modifiers);
27 signal doubleClickDetected(
int x,
int y,
int button,
int buttons,
int modifiers);
28 signal mousePressDetected(
int x,
int y,
int button,
int buttons,
int modifiers);
29 signal mouseReleaseDetected(
int x,
int y,
int button,
int buttons,
int modifiers);
30 signal mouseWheelDetected(
int x,
int y,
int buttons,
int modifiers, point angleDelta);
33 signal touchPressAndHold(
int x,
int y);
34 signal touchClick(
int x,
int y);
35 signal touchPress(
int x,
int y);
36 signal touchRelease(
int x,
int y);
38 signal swipeYDetected(
int steps);
39 signal swipeXDetected(
int steps);
40 signal twoFingerSwipeYDetected(
int steps);
41 signal twoFingerSwipeXDetected(
int steps);
44 signal alternateAction(
int x,
int y);
46 function avg(p1, p2) {
47 return Qt.point((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5);
51 return Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
54 function absFloor(val) {
55 return val > 0 ? Math.floor(val) : Math.ceil(val);
59 property bool __moved:
false
60 property bool __multiTouch:
false
61 property point __pressPosition:
Qt.point(0, 0);
62 property real __prevDragStepsY: 0
63 property real __prevDragStepsX: 0
69 readonly
property int noDragging: 0
70 readonly
property int yDragging: 1
71 readonly
property int xDragging: 2
72 property real __dragging: noDragging
74 id: singleTouchTouchArea
85 touchPressAndHold(singleTouchTouchArea.__pressPosition.x,
86 singleTouchTouchArea.__pressPosition.y);
98 touchAreaPressed =
true;
100 __multiTouch =
false;
101 __prevDragStepsY = 0.0;
102 __prevDragStepsX = 0.0;
103 __dragging = noDragging;
104 __pressPosition =
Qt.point(touchPoints[0].x, touchPoints[0].y);
105 pressAndHoldTimer.start();
106 multiTouchTimer.start();
108 touchPress(touchPoints[0].x, touchPoints[0].y);
111 if (__multiTouch || multiTouchTimer.running)
114 var dragValueY = touchPoints[0].y - __pressPosition.y;
115 var dragValueX = touchPoints[0].x - __pressPosition.x;
116 var dragStepsY = dragValueY / swipeDelta;
117 var dragStepsX = dragValueX / swipeDelta;
119 var dragStepsFloorY = absFloor(dragStepsY);
120 var dragStepsFloorX = absFloor(dragStepsX);
122 if (!__moved &&
distance(touchPoints[0], __pressPosition) > swipeDelta) {
124 __dragging = (Math.abs(dragValueY) >= Math.abs(dragValueX)) ? yDragging : xDragging;
125 }
else if (!__moved) {
129 if (__dragging === yDragging && dragStepsFloorY !== __prevDragStepsY) {
130 swipeYDetected(dragStepsFloorY - __prevDragStepsY);
131 }
else if (__dragging === xDragging && dragStepsFloorX !== __prevDragStepsX) {
132 swipeXDetected(dragStepsFloorX - __prevDragStepsX);
135 __prevDragStepsY = dragStepsFloorY;
136 __prevDragStepsX = dragStepsFloorX;
139 var timerRunning = pressAndHoldTimer.running;
140 pressAndHoldTimer.stop();
141 touchAreaPressed =
false;
143 if (!__moved && timerRunning) {
144 touchClick(touchPoints[0].x, touchPoints[0].y);
147 touchRelease(touchPoints[0].x, touchPoints[0].y);
150 MultiPointTouchArea {
151 property point __pressPosition:
Qt.point(0, 0);
152 property real __prevDragSteps: 0
154 id: doubleTouchTouchArea
158 maximumTouchPoints: 2
159 minimumTouchPoints: 2
161 if (!multiTouchTimer.running)
164 __pressPosition = avg(touchPoints[0], touchPoints[1]);
167 singleTouchTouchArea.__moved =
true;
168 singleTouchTouchArea.__multiTouch =
true;
172 if (touchPoints.length !== 2)
175 if (!singleTouchTouchArea.__multiTouch)
178 var touchPoint = avg(touchPoints[0], touchPoints[1]);
179 var dragValue = touchPoint.y - __pressPosition.y;
180 var dragSteps = dragValue / swipeDelta;
182 var dragStepsFloorY = absFloor(dragSteps);
184 if (dragStepsFloorY !== __prevDragSteps) {
185 twoFingerSwipeYDetected(dragStepsFloorY - __prevDragSteps);
188 __prevDragSteps = dragStepsFloorY;
200 enabled: !parent.touchAreaPressed
201 acceptedButtons:
Qt.AllButtons
202 cursorShape:
Qt.IBeamCursor
206 onDoubleClicked: (mouse) => {
207 doubleClickDetected(mouse.x, mouse.y, mouse.button, mouse.buttons, mouse.modifiers);
209 onPositionChanged: (mouse) => {
210 mouseMoveDetected(mouse.x, mouse.y, mouse.button, mouse.buttons, mouse.modifiers);
212 onPressed: (mouse) => {
214 if (mouse.button ===
Qt.RightButton ) {
215 alternateAction(mouse.x, mouse.y);
217 mousePressDetected(mouse.x, mouse.y, mouse.button, mouse.buttons, mouse.modifiers);
220 onReleased: (mouse) => {
221 mouseReleaseDetected(mouse.x, mouse.y, mouse.button, mouse.buttons, mouse.modifiers);
223 onWheel: (wheel) => {
224 mouseWheelDetected(wheel.x, wheel.y, wheel.buttons, wheel.modifiers, wheel.angleDelta);
KOSM_EXPORT double distance(const std::vector< const OSM::Node * > &path, Coordinate coord)