3/// Click and drag handling shared by the GeoMap point markers: a press that stays under the drag threshold is a click,
4/// past it a draggable marker reports where the cursor drags it to.
8 required property var marker ///< GeoMapItem this area belongs to
9 property bool draggable: false ///< The marker can be dragged; the map is not panned meanwhile
11 // Cursor-to-anchor offset at press, so the marker doesn't jump to the cursor
12 property point _grabOffset
13 property point _pressPosition
14 property bool _moved: false
16 signal markerClicked()
17 signal dragged(point target) ///< Where the marker's anchor is dragged to, in the marker's parent coordinates
20 function _parentPosition(mouse) {
21 return root.marker.mapToItem(root.marker.parent, mouse.x, mouse.y)
24 // The map pan DragHandler would otherwise take over past the drag threshold
25 preventStealing: root.draggable
27 onPressed: (mouse) => {
28 // Modified drags are the map's orbit and look gestures
29 if (mouse.modifiers !== Qt.NoModifier) {
30 mouse.accepted = false
33 const pos = _parentPosition(mouse)
35 _grabOffset = Qt.point(root.marker.x + root.marker.anchorPoint.x - pos.x,
36 root.marker.y + root.marker.anchorPoint.y - pos.y)
40 onPositionChanged: (mouse) => {
41 if (!root.draggable || !pressed) {
44 const pos = _parentPosition(mouse)
45 if (!_moved && Math.hypot(pos.x - _pressPosition.x, pos.y - _pressPosition.y) < Qt.styleHints.startDragDistance) {
49 root.dragged(Qt.point(pos.x + _grabOffset.x, pos.y + _grabOffset.y))