QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FlyViewGeoMapControls.qml
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10import QtQuick
11import QtQuick.Shapes
12
13import QGroundControl
14import QGroundControl.Controls
15import QGroundControl.GeoMap
16
17/// Google Earth-style GeoMap camera controls: round 2D/3D mode toggle plus a
18/// compass whose needle tracks the camera heading and tilts with the camera.
19Row {
20 id: root
21
22 required property var geoMap
23
24 spacing: ScreenTools.defaultFontPixelWidth / 2
25
26 readonly property var _camera: root.geoMap ? root.geoMap.camera : null
27 readonly property real _diameter: ScreenTools.defaultFontPixelHeight * 2.25
28
29 QGCPalette { id: qgcPal; colorGroupEnabled: true }
30
31 Rectangle {
32 objectName: "flyViewGeoMapModeButton"
33
34 // Shows the mode a click switches to (UI tests read this too)
35 property string text: root._camera && root._camera.mode === GeoMapCamera.Mode2D ? qsTr("3D") : qsTr("2D")
36
37 width: root._diameter
38 height: root._diameter
39 radius: root._diameter / 2
40 color: modeMouseArea.pressed ? qgcPal.buttonHighlight : qgcPal.button
41
42 QGCLabel {
43 anchors.centerIn: parent
44 text: parent.text
45 font.bold: true
46 color: modeMouseArea.pressed ? qgcPal.buttonHighlightText : qgcPal.buttonText
47 }
48
49 MouseArea {
50 id: modeMouseArea
51 anchors.fill: parent
52 onClicked: {
53 if (root._camera) {
54 root._camera.mode = (root._camera.mode === GeoMapCamera.Mode2D)
55 ? GeoMapCamera.Mode3D : GeoMapCamera.Mode2D
56 }
57 }
58 }
59 }
60
61 Rectangle {
62 objectName: "flyViewGeoMapCompassButton"
63 width: root._diameter
64 height: root._diameter
65 radius: root._diameter / 2
66 color: compassMouseArea.pressed ? qgcPal.buttonHighlight : qgcPal.button
67
68 // The face tilts with the camera like Google Earth, foreshortening
69 // the needle as the view moves off top-down
70 Item {
71 id: compassFace
72 anchors.fill: parent
73 transform: Rotation {
74 origin.x: compassFace.width / 2
75 origin.y: compassFace.height / 2
76 axis { x: 1; y: 0; z: 0 }
77 angle: root._camera ? root._camera.tilt : 0
78 }
79
80 // Nested so the in-plane heading rotation applies before the tilt
81 Item {
82 id: needle
83 anchors.fill: parent
84 rotation: root._camera ? -root._camera.heading : 0
85
86 Shape {
87 anchors.fill: parent
88 preferredRendererType: Shape.CurveRenderer
89
90 // North half: conventional red needle tip
91 ShapePath {
92 strokeWidth: 1
93 strokeColor: "#80404040"
94 fillColor: "#e8594b"
95 startX: needle.width / 2
96 startY: needle.height * 0.14
97 PathLine { x: needle.width * 0.32; y: needle.height / 2 }
98 PathLine { x: needle.width * 0.68; y: needle.height / 2 }
99 PathLine { x: needle.width / 2; y: needle.height * 0.14 }
100 }
101
102 // South half
103 ShapePath {
104 strokeWidth: 1
105 strokeColor: "#80404040"
106 fillColor: "white"
107 startX: needle.width / 2
108 startY: needle.height * 0.86
109 PathLine { x: needle.width * 0.32; y: needle.height / 2 }
110 PathLine { x: needle.width * 0.68; y: needle.height / 2 }
111 PathLine { x: needle.width / 2; y: needle.height * 0.86 }
112 }
113 }
114 }
115 }
116
117 MouseArea {
118 id: compassMouseArea
119 anchors.fill: parent
120 onClicked: {
121 if (root.geoMap) {
122 root.geoMap.animateHeadingToNorth()
123 }
124 }
125 }
126 }
127}