QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
IntegratedAttitudeIndicator.qml
Go to the documentation of this file.
1import QtQuick
2
3import QGroundControl
4import QGroundControl.Controls
5import QGroundControl.FlyView
6import QGroundControl.FlightMap
7
8Item {
9 implicitWidth: _totalRadius * 2
10 implicitHeight: implicitWidth
11
12 property real compassRadius: ScreenTools.defaultFontPixelHeight * 6 / 2
13 property real attitudeAngleDegrees: 0
14
15 property real attitudeSize: ScreenTools.defaultFontPixelHeight * 0.75
16 property real attitudeSpacing: ScreenTools.defaultFontPixelHeight / 4
17
18 property real _totalRadius: compassRadius + attitudeSpacing + attitudeSize
19 property real _attitudeRadius: (width / 2) - (attitudeSize / 2)
20 property real _maxAngleDegrees: 30
21 property real _maxRadians: _maxAngleDegrees * Math.PI / 180
22 property real _zeroAttitudeRadians: Math.PI * 1.5
23 property real _clampedAngleDegrees: Math.min(Math.max(attitudeAngleDegrees, -_maxAngleDegrees), _maxAngleDegrees)
24 property real _attitudeAnglePercent: _clampedAngleDegrees / _maxAngleDegrees
25
26 property var qgcPal: QGroundControl.globalPalette
27
28 on_AttitudeAnglePercentChanged: angleIndicator.requestPaint()
29
30 // Roll background
31 Canvas {
32 anchors.fill: parent
33
34 onPaint: {
35 var centerX = width / 2
36 var centerY = height / 2
37 var ctx = getContext("2d")
38 ctx.reset()
39 ctx.strokeStyle = qgcPal.window
40 ctx.lineWidth = attitudeSize
41 ctx.beginPath()
42 ctx.arc(centerX, centerY, _attitudeRadius, _zeroAttitudeRadians - _maxRadians, _zeroAttitudeRadians + _maxRadians)
43 ctx.stroke()
44 }
45 }
46
47 // Roll value indicator
48 Canvas {
49 id: angleIndicator
50 anchors.fill: parent
51 visible: Math.abs(attitudeAngleDegrees) > 1
52
53 property real startRollRadiansRaw: _zeroAttitudeRadians
54 property real endRollRadiansRaw: _zeroAttitudeRadians + (_attitudeAnglePercent * _maxRadians)
55 property real startRollRadiansOrdered: Math.min(startRollRadiansRaw, endRollRadiansRaw)
56 property real endRollRadiansOrdered: Math.max(startRollRadiansRaw, endRollRadiansRaw)
57
58 onPaint: {
59 var centerX = width / 2
60 var centerY = height / 2
61 var ctx = getContext("2d")
62 ctx.reset()
63 ctx.strokeStyle = qgcPal.primaryButton
64 ctx.lineWidth = attitudeSize
65 ctx.beginPath()
66 ctx.arc(centerX, centerY, _attitudeRadius, startRollRadiansOrdered, endRollRadiansOrdered)
67 ctx.stroke()
68 }
69 }
70
71 // Roll 0 value tick mark
72 Canvas {
73 anchors.fill: parent
74
75 onPaint: {
76 var centerX = width / 2
77 var centerY = height / 2
78 var ctx = getContext("2d")
79 ctx.reset()
80 ctx.strokeStyle = qgcPal.text
81 ctx.lineWidth = 2
82 ctx.beginPath()
83 ctx.moveTo(centerX, 0)
84 ctx.lineTo(centerX, attitudeSize)
85 ctx.stroke()
86 }
87 }
88}