QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
VideoTile.qml
Go to the documentation of this file.
1pragma ComponentBehavior: Bound
2
3import QtQuick
4import QtMultimedia
5
6import QGroundControl
7import QGroundControl.Controls
8
9// One video source in a tile: its picture over its name, or why there is no picture. A tap makes the source the main
10// picture.
11Rectangle {
12 id: root
13
14 /// The source shown: a stream or the USB camera.
15 required property VideoStreamController source
16 /// The manager the source is one of.
17 property VideoManager videoManager: QGroundControl.videoManager
18 /// Whether the tile is on display, as its row is: the source plays into it only then.
19 property bool shown: true
20
21 readonly property bool _isCamera: root.source.role === VideoSourceRole.Camera
22 // A lost stream's last frame stays up, under a notice, while it reconnects.
23 readonly property bool _streamLost: !root._isCamera && root.source.reconnecting
24 readonly property bool _hasPicture: root.source.decoding || root._streamLost
25 readonly property real _margin: ScreenTools.defaultFontPixelWidth / 2
26
27 color: qgcPal.mapWidgetBorderDark
28 border.color: qgcPal.mapWidgetBorderLight
29 border.width: 1
30 // The placeholder's picture is cropped to fill the tile, and a notice can be taller than a small one.
31 clip: true
32
33 QGCPalette { id: qgcPal }
34
35 NoVideoPlaceholder {
36 anchors.fill: parent
37 anchors.margins: root.border.width
38 videoManager: root.videoManager
39 visible: !root._hasPicture
40 }
41
42 // The source plays into its output: it has one only while the tile is on display, so the stream of a tile that
43 // isn't shown isn't decoded. Not by the tile's visibility: out of sight behind another view, as the Fly View is
44 // behind the Plan view, the stream plays on like the main picture's, or coming back would wait for a keyframe.
45 Loader {
46 anchors.fill: parent
47 anchors.margins: root.border.width
48 active: root.shown
49 visible: root._hasPicture
50 sourceComponent: root._isCamera ? cameraOutputComponent : streamOutputComponent
51
52 Component {
53 id: streamOutputComponent
54
55 VideoStreamOutput {
56 stream: root.source
57 fillMode: VideoOutput.PreserveAspectFit
58 }
59 }
60
61 Component {
62 id: cameraOutputComponent
63
64 UVCVideoOutput {
65 camera: root.videoManager.uvcCamera
66 fillMode: VideoOutput.PreserveAspectFit
67 }
68 }
69 }
70
71 // Frozen video must not pass for live.
72 VideoStatusLabel {
73 anchors.centerIn: parent
74 maximumWidth: root.width - (2 * root._margin)
75 text: qsTr("VIDEO LOST - RECONNECTING")
76 visible: root._streamLost
77 }
78
79 Rectangle {
80 height: nameLabel.height + root._margin
81 color: qgcPal.mapWidgetBorderDark
82 opacity: 0.6
83 visible: nameLabel.text !== ""
84
85 anchors {
86 left: parent.left
87 right: parent.right
88 bottom: parent.bottom
89 margins: root.border.width
90 }
91 }
92
93 QGCLabel {
94 id: nameLabel
95 text: root.source.displayName
96 color: qgcPal.mapWidgetBorderLight
97 font.pointSize: ScreenTools.smallFontPointSize
98 horizontalAlignment: Text.AlignHCenter
99 elide: Text.ElideRight
100
101 anchors {
102 left: parent.left
103 right: parent.right
104 bottom: parent.bottom
105 margins: root._margin
106 }
107 }
108
109 MouseArea {
110 anchors.fill: parent
111 onClicked: root.videoManager.selectSource(root.source)
112 }
113}