QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
MissionItemIndexLabel.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7Canvas {
8 id: root
9
10 width: _width
11 height: _height
12
13 signal clicked(point position)
14
15 property string label ///< Label to show to the side of the index indicator
16 property int index: 0 ///< Index to show in the indicator, 0 will show single char label instead, -1 first char of label in indicator full label to the side
17 property bool checked: false
18 property bool small: !checked
19 property bool child: false
20 property bool highlightSelected: false
21 property var color: checked ? "green" : (child ? qgcPal.mapIndicatorChild : qgcPal.mapIndicator)
22 property real anchorPointX: _height / 2
23 property real anchorPointY: _height / 2
24 property bool specifiesCoordinate: true
25 property real gimbalYaw
26 property real vehicleYaw
27 property bool showGimbalYaw: false
28 property bool showSequenceNumbers: true
29
30 property real _width: showGimbalYaw ? Math.max(_gimbalYawWidth, labelControl.visible ? labelControl.width : indicator.width) : (labelControl.visible ? labelControl.width : indicator.width)
31 property real _height: showGimbalYaw ? _gimbalYawWidth : (labelControl.visible ? labelControl.height : indicator.height)
32 property real _gimbalYawRadius: ScreenTools.defaultFontPixelHeight
33 property real _gimbalYawWidth: _gimbalYawRadius * 2
34 property real _smallRadiusRaw: Math.ceil((ScreenTools.defaultFontPixelHeight * ScreenTools.smallFontPointRatio) / 2)
35 property real _smallRadius: _smallRadiusRaw + ((_smallRadiusRaw % 2 == 0) ? 1 : 0) // odd number for better centering
36 property real _normalRadiusRaw: Math.ceil(ScreenTools.defaultFontPixelHeight * 0.66)
37 property real _normalRadius: _normalRadiusRaw + ((_normalRadiusRaw % 2 == 0) ? 1 : 0)
38 property real _indicatorRadius: small ? _smallRadius : _normalRadius
39 property real _gimbalRadians: degreesToRadians(vehicleYaw + gimbalYaw - 90)
40 property real _labelMargin: 2
41 property real _labelRadius: _indicatorRadius + _labelMargin
42 property string _label: label.length > 1 ? label : ""
43 property string _index: index === 0 || index === -1 ? label.charAt(0) : (showSequenceNumbers ? index : "")
44
45 onColorChanged: requestPaint()
46 onShowGimbalYawChanged: requestPaint()
47 onGimbalYawChanged: requestPaint()
48 onVehicleYawChanged: requestPaint()
49
50 QGCPalette { id: qgcPal }
51
52 function degreesToRadians(degrees) {
53 return (Math.PI/180)*degrees
54 }
55
56 function paintGimbalYaw(context) {
57 if (showGimbalYaw) {
58 context.save()
59 context.globalAlpha = 0.75
60 context.beginPath()
61 context.moveTo(anchorPointX, anchorPointY)
62 context.arc(anchorPointX, anchorPointY, _gimbalYawRadius, _gimbalRadians + degreesToRadians(45), _gimbalRadians + degreesToRadians(-45), true /* clockwise */)
63 context.closePath()
64 context.fillStyle = "white"
65 context.fill()
66 context.restore()
67 }
68 }
69
70 onPaint: {
71 var context = getContext("2d")
72 context.clearRect(0, 0, width, height)
73 paintGimbalYaw(context)
74 }
75
76 Rectangle {
77 id: labelControl
78 anchors.leftMargin: -((_labelMargin * 2) + indicator.width)
79 anchors.rightMargin: -(_labelMargin * 2)
80 anchors.fill: labelControlLabel
81 color: "white"
82 opacity: 0.5
83 radius: _labelRadius
84 visible: _label.length !== 0 && !small
85 }
86
87 QGCLabel {
88 id: labelControlLabel
89 anchors.topMargin: -_labelMargin
90 anchors.bottomMargin: -_labelMargin
91 anchors.leftMargin: _labelMargin
92 anchors.left: indicator.right
93 anchors.top: indicator.top
94 anchors.bottom: indicator.bottom
95 color: "black"
96 text: _label
97 verticalAlignment: Text.AlignVCenter
98 visible: labelControl.visible
99 }
100
101 Rectangle {
102 id: indicator
103 anchors.horizontalCenter: parent.left
104 anchors.verticalCenter: parent.top
105 anchors.horizontalCenterOffset: anchorPointX
106 anchors.verticalCenterOffset: anchorPointY
107 width: _indicatorRadius * 2
108 height: width
109 color: root.color
110 radius: _indicatorRadius
111
112 QGCLabel {
113 anchors.fill: parent
114 horizontalAlignment: Text.AlignHCenter
115 verticalAlignment: Text.AlignVCenter
116 color: "white"
117 font.pointSize: ScreenTools.defaultFontPointSize
118 fontSizeMode: Text.Fit
119 text: _index
120 }
121 }
122
123 // Extra circle to indicate selection
124 Rectangle {
125 width: indicator.width * 2
126 height: width
127 radius: width * 0.5
128 color: Qt.rgba(0,0,0,0)
129 border.color: Qt.rgba(1,1,1,0.5)
130 border.width: 1
131 visible: checked && highlightSelected
132 anchors.centerIn: indicator
133 }
134
135 // The mouse click area is always the size of a normal indicator
136 Item {
137 id: mouseAreaFill
138 anchors.margins: small ? -(_normalRadius - _smallRadius) : 0
139 anchors.fill: indicator
140 }
141
142 QGCMouseArea {
143 fillItem: mouseAreaFill
144 onClicked: (mouse) => {
145 focus = true
146 parent.clicked(Qt.point(mouse.x, mouse.y))
147 }
148 }
149}