QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ThermalVideoOverlay.qml
Go to the documentation of this file.
1pragma ComponentBehavior: Bound
2
3import QtQuick
4
5import QGroundControl
6import QGroundControl.Controls
7
8// The thermal stream over the main video, placed as the camera's thermal mode asks: fitting the view, blended over the
9// video, or as a picture-in-picture in the top left corner.
10Item {
11 id: root
12
13 /// The camera whose thermal mode and opacity the overlay follows; any object with those properties will do.
14 property var camera: null
15 /// Height covered at the top of the view, which the picture-in-picture stays below.
16 property real pipTopInset: 0
17 /// The manager whose thermal stream is shown.
18 property VideoManager videoManager: QGroundControl.videoManager
19
20 // Whether the thermal mode shows the overlay. Not the item's visibility, which also goes with the view it is in:
21 // behind another view the stream keeps decoding, so that coming back doesn't wait for a keyframe.
22 readonly property bool _shown: root.videoManager.hasThermal && !!root.camera
23 && root.camera.thermalMode !== MavlinkCameraControlInterface.THERMAL_OFF
24 readonly property real _aspectRatio: root.videoManager.thermalAspectRatio
25 // Size of the thermal video blended over the main one, relative to the view.
26 readonly property real _blendSizeFactor: 0.85
27 // The view the overlay is placed in: none while it is created, and again while it is destroyed.
28 readonly property real _viewWidth: root.parent ? root.parent.width : 0
29 readonly property real _viewHeight: root.parent ? root.parent.height : 0
30 // The box the thermal video fits in, as the thermal mode asks.
31 readonly property size _box: {
32 if (!root.camera) {
33 return Qt.size(0, 0)
34 }
35 switch (root.camera.thermalMode) {
36 case MavlinkCameraControlInterface.THERMAL_FULL:
37 return Qt.size(root._viewWidth, root._viewHeight)
38 case MavlinkCameraControlInterface.THERMAL_PIP:
39 return Qt.size(Math.max(0, root._viewWidth - root.anchors.leftMargin),
40 ScreenTools.defaultFontPixelHeight * 12)
41 default:
42 return Qt.size(root._viewWidth * root._blendSizeFactor, root._viewHeight * root._blendSizeFactor)
43 }
44 }
45
46 width: Math.min(root._box.width, root._box.height * root._aspectRatio)
47 height: root.width / root._aspectRatio
48 visible: root._shown
49
50 anchors {
51 horizontalCenter: root.parent ? root.parent.horizontalCenter : undefined
52 verticalCenter: root.parent ? root.parent.verticalCenter : undefined
53 // Apply only in the pip state, which anchors the top left corner instead.
54 topMargin: root.pipTopInset + (ScreenTools.defaultFontPixelHeight * 0.5)
55 leftMargin: ScreenTools.defaultFontPixelWidth * 12
56 }
57
58 // The stream decodes while it has an output: none while the overlay isn't shown.
59 Loader {
60 anchors.fill: parent
61 active: root._shown
62 opacity: !root.camera ? 0
63 : (root.camera.thermalMode === MavlinkCameraControlInterface.THERMAL_BLEND
64 ? root.camera.thermalOpacity / 100 : 1.0)
65 sourceComponent: thermalOutputComponent
66
67 Component {
68 id: thermalOutputComponent
69
70 VideoStreamOutput {
71 stream: root.videoManager.thermalStream
72 }
73 }
74 }
75
76 // In a group of its own: an item's states are a list, which a user of this type would add to, not replace.
77 StateGroup {
78 states: [
79 State {
80 name: "pip"
81 when: !!root.parent && !!root.camera
82 && root.camera.thermalMode === MavlinkCameraControlInterface.THERMAL_PIP
83
84 AnchorChanges {
85 target: root
86 anchors {
87 horizontalCenter: undefined
88 verticalCenter: undefined
89 top: root.parent.top
90 left: root.parent.left
91 }
92 }
93 }
94 ]
95 }
96}