QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GeoMapControls.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.
19/// Used by every view that hosts a GeoMap; the host decides where it goes.
20Row {
21 id: root
22
23 required property var geoMap
24
25 spacing: ScreenTools.defaultFontPixelWidth / 2
26
27 readonly property var _camera: root.geoMap ? root.geoMap.camera : null
28 readonly property real _diameter: ScreenTools.defaultFontPixelHeight * 2.25
29
30 QGCPalette { id: qgcPal; colorGroupEnabled: true }
31
32 Rectangle {
33 objectName: "geoMapModeButton"
34
35 // Shows the mode a click switches to (UI tests read this too)
36 property string text: root._camera && root._camera.mode === GeoMapCamera.Mode2D ? qsTr("3D") : qsTr("2D")
37
38 width: root._diameter
39 height: root._diameter
40 radius: root._diameter / 2
41 color: modeMouseArea.pressed ? qgcPal.accent : qgcPal.windowCard
42
43 QGCLabel {
44 anchors.centerIn: parent
45 text: parent.text
46 font.bold: true
47 color: modeMouseArea.pressed ? qgcPal.accentText : qgcPal.textPrimary
48 }
49
50 MouseArea {
51 id: modeMouseArea
52 anchors.fill: parent
53 onClicked: {
54 if (root._camera) {
55 root._camera.mode = (root._camera.mode === GeoMapCamera.Mode2D)
56 ? GeoMapCamera.Mode3D : GeoMapCamera.Mode2D
57 }
58 }
59 }
60 }
61
62 Rectangle {
63 objectName: "geoMapCompassButton"
64 width: root._diameter
65 height: root._diameter
66 radius: root._diameter / 2
67 color: compassMouseArea.pressed ? qgcPal.accent : qgcPal.windowCard
68
69 // The face tilts with the camera like Google Earth, foreshortening
70 // the needle as the view moves off top-down
71 Item {
72 id: compassFace
73 anchors.fill: parent
74 transform: Rotation {
75 origin.x: compassFace.width / 2
76 origin.y: compassFace.height / 2
77 axis { x: 1; y: 0; z: 0 }
78 angle: root._camera ? root._camera.tilt : 0
79 }
80
81 // Nested so the in-plane heading rotation applies before the tilt
82 Item {
83 id: needle
84 anchors.fill: parent
85 rotation: root._camera ? -root._camera.heading : 0
86
87 Shape {
88 anchors.fill: parent
89 preferredRendererType: Shape.CurveRenderer
90
91 // North half: conventional red needle tip
92 ShapePath {
93 strokeWidth: 1
94 strokeColor: "#80404040"
95 fillColor: "#e8594b"
96 startX: needle.width / 2
97 startY: needle.height * 0.14
98 PathLine { x: needle.width * 0.32; y: needle.height / 2 }
99 PathLine { x: needle.width * 0.68; y: needle.height / 2 }
100 PathLine { x: needle.width / 2; y: needle.height * 0.14 }
101 }
102
103 // South half
104 ShapePath {
105 strokeWidth: 1
106 strokeColor: "#80404040"
107 fillColor: "white"
108 startX: needle.width / 2
109 startY: needle.height * 0.86
110 PathLine { x: needle.width * 0.32; y: needle.height / 2 }
111 PathLine { x: needle.width * 0.68; y: needle.height / 2 }
112 PathLine { x: needle.width / 2; y: needle.height * 0.86 }
113 }
114 }
115 }
116 }
117
118 MouseArea {
119 id: compassMouseArea
120 anchors.fill: parent
121 onClicked: {
122 if (root.geoMap) {
123 root.geoMap.animateHeadingToNorth()
124 }
125 }
126 }
127 }
128}