QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MissionItemIndicatorDrag.qml
Go to the documentation of this file.
1import QtQuick
2import QtLocation
3
4import QGroundControl
5import QGroundControl.Controls
6
7/// Use to drag a MissionItemIndicator
8Rectangle {
9 id: itemDragger
10 x: _itemIndicatorX - _touchMarginHorizontal
11 y: _itemIndicatorY - _touchMarginVertical
12 width: _itemIndicatorWidth + (_touchMarginHorizontal * 2)
13 height: _itemIndicatorHeight + (_touchMarginVertical * 2)
14 color: "transparent"
15 z: QGroundControl.zOrderMapItems + 1 // Above item icons
16
17 // Properties which must be specific by consumer
18 property var mapControl ///< Map control which contains this item
19 property var itemIndicator ///< The mission item indicator to drag around
20 property var itemCoordinate ///< Coordinate we are updating during drag
21
22 signal clicked
23 signal dragStart
24 signal dragStop
25
26 property bool _preventCoordinateBindingLoop: false
27
28 property real _itemIndicatorX: itemIndicator ? itemIndicator.x : 0
29 property real _itemIndicatorY: itemIndicator ? itemIndicator.y : 0
30 property real _itemIndicatorWidth: itemIndicator ? itemIndicator.width : 0
31 property real _itemIndicatorHeight: itemIndicator ? itemIndicator.height : 0
32 property bool _mobile: ScreenTools.isMobile
33 property real _touchWidth: Math.max(_itemIndicatorWidth, ScreenTools.minTouchPixels)
34 property real _touchHeight: Math.max(_itemIndicatorHeight, ScreenTools.minTouchPixels)
35 property real _touchMarginHorizontal: _mobile ? (_touchWidth - _itemIndicatorWidth) / 2 : 0
36 property real _touchMarginVertical: _mobile ? (_touchHeight - _itemIndicatorHeight) / 2 : 0
37 property bool _dragStartSignalled: false
38
39 onXChanged: liveDrag()
40 onYChanged: liveDrag()
41
42 function liveDrag() {
43 if (!itemDragger._preventCoordinateBindingLoop && itemDrag.drag.active) {
44 var point = Qt.point(itemDragger.x + _touchMarginHorizontal + itemIndicator.anchorPoint.x, itemDragger.y + _touchMarginVertical + itemIndicator.anchorPoint.y)
45 var coordinate = mapControl.toCoordinate(point, false /* clipToViewPort */)
46 itemDragger._preventCoordinateBindingLoop = true
47 coordinate.altitude = itemCoordinate.altitude
48 itemCoordinate = coordinate
49 itemDragger._preventCoordinateBindingLoop = false
50 }
51 }
52
53 Drag.active: itemDrag.drag.active
54
55 QGCMouseArea {
56 id: itemDrag
57 anchors.fill: parent
58 drag.target: parent
59 drag.minimumX: 0
60 drag.minimumY: 0
61 drag.maximumX: itemDragger.parent.width - parent.width
62 drag.maximumY: itemDragger.parent.height - parent.height
63 preventStealing: true
64 enabled: itemDragger.visible
65
66 onClicked: {
67 focus = true
68 itemDragger.clicked()
69 }
70
71 property bool dragActive: drag.active
72 onDragActiveChanged: {
73 if (dragActive) {
74 focus = true
75 if (!_dragStartSignalled) {
76 _dragStartSignalled = true
77 dragStart()
78 }
79 } else {
80 _dragStartSignalled = false
81 dragStop()
82 }
83 }
84 }
85}