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 medium: false
20 property bool child: false
21 property bool highlightSelected: false
22 property var color: checked ? "green" : (child ? qgcPal.mapIndicatorChild : qgcPal.mapIndicator)
23 property real anchorPointX: _height / 2
24 property real anchorPointY: _height / 2
25 property bool specifiesCoordinate: true
26 property real gimbalYaw
27 property real vehicleYaw
28 property bool showGimbalYaw: false
29 property bool showSequenceNumbers: true
30 property string indicatorSubText
31 property string supplementaryLabel
32
33 property real _width: showGimbalYaw ? Math.max(_gimbalYawWidth, labelControl.visible ? labelControl.width : indicator.width) : (labelControl.visible ? labelControl.width : indicator.width)
34 property real _height: showGimbalYaw ? _gimbalYawWidth : (labelControl.visible ? labelControl.height : indicator.height)
35 property real _gimbalYawRadius: ScreenTools.defaultFontPixelHeight
36 property real _gimbalYawWidth: _gimbalYawRadius * 2
37 property real _smallRadius: _oddCeil((ScreenTools.defaultFontPixelHeight * ScreenTools.smallFontPointRatio) / 2)
38 property real _largeRadius: _oddCeil(ScreenTools.defaultFontPixelHeight * 0.66)
39 property real _mediumRadius: _oddCeil(((_smallRadius * 2) + _largeRadius) / 3)
40 property real _indicatorRadius: small ? _smallRadius : (medium ? _mediumRadius : _largeRadius)
41 property real _gimbalRadians: degreesToRadians(vehicleYaw + gimbalYaw - 90)
42 property real _labelMargin: 2
43 property real _labelRadius: _indicatorRadius + _labelMargin
44 property string _label: supplementaryLabel !== "" ? supplementaryLabel : (label.length > 1 ? label : "")
45 property string _index: index === 0 || index === -1 ? label.charAt(0) : (showSequenceNumbers ? index : "")
46
47 onColorChanged: requestPaint()
48 onShowGimbalYawChanged: requestPaint()
49 onGimbalYawChanged: requestPaint()
50 onVehicleYawChanged: requestPaint()
51
52 QGCPalette { id: qgcPal }
53
54 function _oddCeil(value) {
55 const rounded = Math.ceil(value)
56 return rounded + (rounded % 2 === 0 ? 1 : 0)
57 }
58
59 function degreesToRadians(degrees) {
60 return (Math.PI/180)*degrees
61 }
62
63 function paintGimbalYaw(context) {
64 if (showGimbalYaw) {
65 context.save()
66 context.globalAlpha = 0.75
67 context.beginPath()
68 context.moveTo(anchorPointX, anchorPointY)
69 context.arc(anchorPointX, anchorPointY, _gimbalYawRadius, _gimbalRadians + degreesToRadians(45), _gimbalRadians + degreesToRadians(-45), true /* clockwise */)
70 context.closePath()
71 context.fillStyle = "white"
72 context.fill()
73 context.restore()
74 }
75 }
76
77 onPaint: {
78 var context = getContext("2d")
79 context.clearRect(0, 0, width, height)
80 paintGimbalYaw(context)
81 }
82
83 Rectangle {
84 id: labelControl
85 anchors.leftMargin: -((_labelMargin * 2) + indicator.width)
86 anchors.rightMargin: -(_labelMargin * 2)
87 anchors.fill: labelControlLabel
88 color: "white"
89 opacity: 0.5
90 radius: _labelRadius
91 visible: _label.length !== 0 && !small
92 }
93
94 QGCLabel {
95 id: labelControlLabel
96 anchors.topMargin: -_labelMargin
97 anchors.bottomMargin: -_labelMargin
98 anchors.leftMargin: _labelMargin
99 anchors.left: indicator.right
100 anchors.top: indicator.top
101 anchors.bottom: indicator.bottom
102 color: "black"
103 text: _label
104 verticalAlignment: Text.AlignVCenter
105 visible: labelControl.visible
106 }
107
108 Rectangle {
109 id: indicator
110 anchors.horizontalCenter: parent.left
111 anchors.verticalCenter: parent.top
112 anchors.horizontalCenterOffset: anchorPointX
113 anchors.verticalCenterOffset: anchorPointY
114 width: _indicatorRadius * 2
115 height: width
116 color: root.color
117 radius: _indicatorRadius
118
119 QGCLabel {
120 id: indexLabel
121 anchors.fill: parent
122 horizontalAlignment: Text.AlignHCenter
123 verticalAlignment: Text.AlignVCenter
124 color: "white"
125 font.pointSize: ScreenTools.defaultFontPointSize
126 fontSizeMode: Text.Fit
127 text: _index
128 }
129
130 QGCLabel {
131 anchors {
132 horizontalCenter: indexLabel.horizontalCenter
133 baseline: indexLabel.baseline
134 baselineOffset: indexLabel.contentHeight / 5
135 }
136 width: indicator.width
137 height: indicator.height * 0.4
138 horizontalAlignment: Text.AlignHCenter
139 verticalAlignment: Text.AlignVCenter
140 color: "white"
141 font.pointSize: ScreenTools.smallFontPointSize
142 fontSizeMode: Text.Fit
143 text: root.indicatorSubText
144 visible: text !== ""
145 }
146 }
147
148 // Extra circle to indicate selection
149 Rectangle {
150 width: indicator.width * 2
151 height: width
152 radius: width * 0.5
153 color: Qt.rgba(0,0,0,0)
154 border.color: Qt.rgba(1,1,1,0.5)
155 border.width: 1
156 visible: checked && highlightSelected
157 anchors.centerIn: indicator
158 }
159
160 // The mouse click area is always the size of a large indicator
161 Item {
162 id: mouseAreaFill
163 anchors.margins: -(root._largeRadius - root._indicatorRadius)
164 anchors.fill: indicator
165 }
166
167 QGCMouseArea {
168 fillItem: mouseAreaFill
169 onClicked: (mouse) => {
170 focus = true
171 parent.clicked(Qt.point(mouse.x, mouse.y))
172 }
173 }
174}