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 rotation: _lockNoseUpCompass ? -_heading : 0
62
63 CompassDial {
64 anchors.fill: parent
65 visible: !usedByMultipleVehicleList
66 }
67
68 CompassHeadingIndicator {
69 compassSize: size
70 heading: _heading
71 simplified: usedByMultipleVehicleList
72 }
73
74 Image {
75 id: cogPointer
76 source: "/qmlimages/cOGPointer.svg"
77 mipmap: true
78 fillMode: Image.PreserveAspectFit
79 anchors.fill: parent
80 sourceSize.height: parent.height
81 visible: showCOG()
82 rotation: _courseOverGround
83 }
84
85 Image {
86 id: nextWPPointer
87 source: "/qmlimages/compassDottedLine.svg"
88 mipmap: true
89 fillMode: Image.PreserveAspectFit
90 anchors.fill: parent
91 sourceSize.height: parent.height
92 visible: showHeadingToNextWP()
93 rotation: _headingToNextWP
94 }
95
96 // Launch location indicator
97 Rectangle {
98 width: Math.max(label.contentWidth, label.contentHeight)
99 height: width
100 color: qgcPal.mapIndicator
101 radius: width / 2
102 anchors.centerIn: parent
103 visible: showHeadingHome()
104
105 QGCLabel {
106 id: label
107 text: qsTr("L")
108 font.bold: true
109 color: qgcPal.text
110 anchors.centerIn: parent
111 rotation: _lockNoseUpCompass ? _heading : 0
112 }
113
114 transform: Translate {
115 property double _angle: _headingToHome
116 property real _labelOffset: root.width / 2 + ScreenTools.defaultFontPixelHeight / 2
117
118 x: translateCenterToAngleX(_labelOffset, _angle)
119 y: translateCenterToAngleY(_labelOffset, _angle)
120 }
121 }
122 }
123
124 QGCLabel {
125 anchors.horizontalCenter: parent.horizontalCenter
126 y: size * 0.74
127 text: vehicle && !usedByMultipleVehicleList ? _heading.toFixed(0) + "°" : ""
128 horizontalAlignment: Text.AlignHCenter
129 }
130}