QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCCompassWidget.qml
Go to the documentation of this file.
1import QtQuick
2
3import QGroundControl
4import QGroundControl.Controls
5
6Rectangle {
7 id: root
8 width: size
9 height: size
10 radius: width / 2
11 color: qgcPal.window
12 border.color: qgcPal.text
13 border.width: usedByMultipleVehicleList ? 1 : 0
14 opacity: vehicle && usedByMultipleVehicleList && !vehicle.armed ? 0.5 : 1
15
16 property real size: _defaultSize
17 property var vehicle: null
18 property bool usedByMultipleVehicleList: false
19
20 property real _defaultSize: usedByMultipleVehicleList ? ScreenTools.defaultFontPixelHeight * 3 : ScreenTools.defaultFontPixelHeight * 10
21 property real _sizeRatio: (usedByMultipleVehicleList || ScreenTools.isTinyScreen) ? (size / _defaultSize) * 0.5 : size / _defaultSize
22 property int _fontSize: ScreenTools.defaultFontPointSize * _sizeRatio < 8 ? 8 : ScreenTools.defaultFontPointSize * _sizeRatio
23 property real _heading: vehicle ? vehicle.heading.rawValue : 0
24 property real _headingToHome: vehicle ? vehicle.headingToHome.rawValue : 0
25 property real _groundSpeed: vehicle ? vehicle.groundSpeed.rawValue : 0
26 property real _headingToNextWP: vehicle ? vehicle.headingToNextWP.rawValue : 0
27 property real _courseOverGround: vehicle ? vehicle.gps.courseOverGround.rawValue : 0
28 property var _flyViewSettings: QGroundControl.settingsManager.flyViewSettings
29 property bool _showAdditionalIndicators: _flyViewSettings.showAdditionalIndicatorsCompass.value && !usedByMultipleVehicleList
30 property bool _lockNoseUpCompass: _flyViewSettings.lockNoseUpCompass.value && !usedByMultipleVehicleList
31
32 function showCOG(){
33 if (_groundSpeed < 0.5) {
34 return false
35 } else{
36 return vehicle && _showAdditionalIndicators
37 }
38 }
39
40 function showHeadingHome() {
41 return vehicle && _showAdditionalIndicators && !isNaN(_headingToHome)
42 }
43
44 function showHeadingToNextWP() {
45 return vehicle && _showAdditionalIndicators && !isNaN(_headingToNextWP)
46 }
47
48 function translateCenterToAngleX(radius, angle) {
49 return radius * Math.sin(angle * (Math.PI / 180))
50 }
51
52 function translateCenterToAngleY(radius, angle) {
53 return -radius * Math.cos(angle * (Math.PI / 180))
54 }
55
56 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
57
58 Item {
59 id: rotationParent
60 anchors.fill: parent
61
62 transform: Rotation {
63 origin.x: rotationParent.width / 2
64 origin.y: rotationParent.height / 2
65 angle: _lockNoseUpCompass ? -_heading : 0
66 }
67
68 CompassDial {
69 anchors.fill: parent
70 visible: !usedByMultipleVehicleList
71 }
72
73 CompassHeadingIndicator {
74 compassSize: size
75 heading: _heading
76 simplified: usedByMultipleVehicleList
77 }
78
79 Image {
80 id: cogPointer
81 source: "/qmlimages/cOGPointer.svg"
82 mipmap: true
83 fillMode: Image.PreserveAspectFit
84 anchors.fill: parent
85 sourceSize.height: parent.height
86 visible: showCOG()
87
88 transform: Rotation {
89 origin.x: cogPointer.width / 2
90 origin.y: cogPointer.height / 2
91 angle: _courseOverGround
92 }
93 }
94
95 Image {
96 id: nextWPPointer
97 source: "/qmlimages/compassDottedLine.svg"
98 mipmap: true
99 fillMode: Image.PreserveAspectFit
100 anchors.fill: parent
101 sourceSize.height: parent.height
102 visible: showHeadingToNextWP()
103
104 transform: Rotation {
105 origin.x: nextWPPointer.width / 2
106 origin.y: nextWPPointer.height / 2
107 angle: _headingToNextWP
108 }
109 }
110
111 // Launch location indicator
112 Rectangle {
113 width: Math.max(label.contentWidth, label.contentHeight)
114 height: width
115 color: qgcPal.mapIndicator
116 radius: width / 2
117 anchors.centerIn: parent
118 visible: showHeadingHome()
119
120 QGCLabel {
121 id: label
122 text: qsTr("L")
123 font.bold: true
124 color: qgcPal.text
125 anchors.centerIn: parent
126 }
127
128 transform: Translate {
129 property double _angle: _headingToHome
130
131 x: translateCenterToAngleX(parent.width / 2, _angle)
132 y: translateCenterToAngleY(parent.height / 2, _angle)
133 }
134 }
135 }
136
137 QGCLabel {
138 anchors.horizontalCenter: parent.horizontalCenter
139 y: size * 0.74
140 text: vehicle && !usedByMultipleVehicleList ? _heading.toFixed(0) + "°" : ""
141 horizontalAlignment: Text.AlignHCenter
142 }
143}