QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCMovableItem.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7// This item can be dragged around within its parent.
8// Double click issues a signal the parent can use to
9// reset its default position.
10
11Item {
12 id: root
13 property bool allowDragging: true
14 property real minimumWidth: ScreenTools.defaultFontPixelHeight * (5)
15 property real minimumHeight: ScreenTools.defaultFontPixelHeight * (5)
16 property alias tForm: tform
17 signal resetRequested()
18 transform: Scale {
19 id: tform
20 }
21 MouseArea {
22 property double factor: 25
23 enabled: root.allowDragging
24 cursorShape: Qt.OpenHandCursor
25 anchors.fill: parent
26 drag.target: parent
27 drag.axis: Drag.XAndYAxis
28 drag.minimumX: 0
29 drag.minimumY: 0
30 drag.maximumX: root.parent.width - (root.width * tform.xScale)
31 drag.maximumY: root.parent.height - (root.height * tform.yScale)
32 drag.filterChildren: true
33 onPressed: (mouse) => {
34 root.anchors.left = undefined
35 root.anchors.right = undefined
36 }
37 onDoubleClicked: {
38 root.resetRequested();
39 }
40 onWheel: (wheel) =>
41 {
42 var zoomFactor = 1;
43 if(wheel.angleDelta.y > 0)
44 zoomFactor = 1 + (1/factor)
45 else
46 zoomFactor = 1 - (1/factor)
47 var realX = wheel.x * tform.xScale
48 var realY = wheel.y * tform.yScale
49 var tx = root.x + (1-zoomFactor)*realX
50 var ty = root.y + (1-zoomFactor)*realY
51 if(tx < 0) tx = 0
52 if(ty < 0) ty = 0
53 var ts = tform.xScale * zoomFactor
54 if(root.width * ts >= root.minimumWidth) {
55 if(root.height * ts >= root.minimumHeight) {
56 if(((root.width * ts) + tx) < root.parent.width && ((root.height * ts) + ty) < root.parent.height) {
57 root.x = tx
58 root.y = ty
59 tform.xScale = ts
60 tform.yScale = ts
61 }
62 }
63 }
64 }
65 }
66}