1pragma ComponentBehavior: Bound
7import QGroundControl.Controls
9// The video of the primary stream or the UVC camera, fitted to the view, with grid lines, the telemetry overlay and the
10// thermal stream. Where it is asked to, it shows the other video sources in tiles along its top.
14 property bool useSmallFont: true
15 /// Height covered at the top of the view, which the thermal picture-in-picture and the tiles stay below.
16 property real thermalPipTopInset: 0
17 /// Whether the other video sources are shown in tiles: for a view with room for them, not a picture-in-picture.
18 property bool showTiles: false
19 /// Width covered at the right of the view, which the tiles stay clear of.
20 property real tilesRightInset: 0
21 /// The camera whose thermal mode and zoom the view follows: the active vehicle's current camera by default. Any
22 /// object with the camera properties the view reads will do, as the tests' stand-ins.
23 property var camera: root._activeVehicle && root._activeVehicle.cameraManager
24 ? root._activeVehicle.cameraManager.currentCameraInstance : null
25 /// The manager whose video the view shows.
26 property VideoManager videoManager: QGroundControl.videoManager
28 /// Size of the video fitted to the view: larger than the view where the fit mode crops, smaller where it doesn't.
29 readonly property real videoWidth: {
31 if (root._isModeFitHeight
32 || (root._isModeFill && (root.width / root.height < root._ar))
33 || (root._isModeNoCrop && (root.width / root.height > root._ar))) {
34 // This return value has different implications depending on the mode
35 // For FIT_HEIGHT and FILL
36 // makes so the video width will be larger than (or equal to) the screen width
38 // makes so the video width will be smaller than (or equal to) the screen width
39 return root.height * root._ar
44 readonly property real videoHeight: {
46 if (root._isModeFitWidth
47 || (root._isModeFill && (root.width / root.height > root._ar))
48 || (root._isModeNoCrop && (root.width / root.height < root._ar))) {
49 // This return value has different implications depending on the mode
50 // For FIT_WIDTH and FILL
51 // makes so the video height will be larger than (or equal to) the screen height
53 // makes so the video height will be smaller than (or equal to) the screen height
54 return root.width * (1 / root._ar)
60 readonly property VideoSettings _videoSettings: QGroundControl.settingsManager.videoSettings
61 readonly property Vehicle _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
62 readonly property VideoStreamController _primaryStream: root.videoManager.primaryStream
63 // The primary stream is in a tile while the USB camera, selected in its own, is the main picture.
64 readonly property bool _streamIsMainPicture: !root._primaryStream.tile
65 // A lost stream's last frame stays up, under a notice, while it reconnects.
66 readonly property bool _streamLost: root._streamIsMainPicture && root._primaryStream.reconnecting
67 readonly property bool _showStreamLoader: root._streamIsMainPicture
68 && (root.videoManager.decoding || root._streamLost)
69 readonly property bool _showUvcLoader: root.videoManager.isUvc
70 // A UVC camera's ratio is known once its first frame sets the output's implicit size; until then the video fills the
72 readonly property real _ar: root._showUvcLoader
73 ? ((cameraLoader.status === Loader.Ready && cameraLoader.item.implicitHeight > 0)
74 ? cameraLoader.item.implicitWidth / cameraLoader.item.implicitHeight : 0)
75 : root.videoManager.aspectRatio
76 readonly property int _fitMode: root._videoSettings.videoFit.rawValue
77 readonly property bool _isModeFitWidth: root._fitMode === VideoSettings.VideoFitWidth
78 readonly property bool _isModeFitHeight: root._fitMode === VideoSettings.VideoFitHeight
79 readonly property bool _isModeFill: root._fitMode === VideoSettings.VideoFitFill
80 readonly property bool _isModeNoCrop: root._fitMode === VideoSettings.VideoFitNoCrop
81 // The outputs fill the view, and crop the video to it where the fitted video is larger.
82 readonly property real _viewAr: root.width / root.height
83 readonly property bool _cropsVideo: root._isModeFill
85 && ((root._isModeFitWidth && (root._viewAr > root._ar))
86 || (root._isModeFitHeight && (root._viewAr < root._ar))))
87 readonly property int _outputFillMode: root._cropsVideo ? VideoOutput.PreserveAspectCrop
88 : VideoOutput.PreserveAspectFit
89 readonly property real _tilesMargin: ScreenTools.defaultFontPixelHeight * 0.5
90 readonly property bool _thermalPipShown: thermalOverlay.visible && !!root.camera
91 && root.camera.thermalMode === MavlinkCameraControlInterface.THERMAL_PIP
93 /// Whether a tile is at @p x, @p y of the view: a press there is the tile's.
94 function tileAt(x, y) {
95 return tiles.visible && !!tiles.childAt(x - tiles.x, y - tiles.y)
98 // The grid lines span the fitted video, beyond the view where it crops.
103 useSmallFont: root.useSmallFont
104 videoManager: root.videoManager
105 visible: !root._showStreamLoader && !root._showUvcLoader
111 visible: root._showStreamLoader || root._showUvcLoader
115 visible: root._showStreamLoader
116 active: root._streamIsMainPicture
117 sourceComponent: videoOutputComponent
121 id: videoOutputComponent
124 stream: root._primaryStream
125 fillMode: root._outputFillMode
129 //-- UVC Video (USB Camera or Video Device)
133 visible: root._showUvcLoader
134 active: root._showUvcLoader
135 sourceComponent: uvcVideoOutputComponent
139 id: uvcVideoOutputComponent
142 camera: root.videoManager.uvcCamera
143 fillMode: root._outputFillMode
149 width: root.videoWidth
150 height: root.videoHeight
151 anchors.centerIn: parent
155 visible: root._videoSettings.gridLines.rawValue && !root.videoManager.fullScreen
159 // The part of the fitted video that is on screen.
161 width: Math.min(root.videoWidth, root.width)
162 height: Math.min(root.videoHeight, root.height)
163 anchors.centerIn: parent
165 TelemetryOverlayText {
166 objectName: "videoTelemetryOverlay"
167 text: root.videoManager.telemetryOverlayText
168 useSmallFont: root.useSmallFont
172 // Frozen video must not pass for live.
174 anchors.centerIn: parent
175 useSmallFont: root.useSmallFont
176 text: qsTr("VIDEO LOST - RECONNECTING")
177 visible: root._streamLost
180 ThermalVideoOverlay {
182 objectName: "videoViewThermal"
184 pipTopInset: root.thermalPipTopInset
185 videoManager: root.videoManager
194 // Along the top, right of the thermal picture-in-picture, or in its place: clear of the Fly View's tool strip, as
198 objectName: "videoViewTiles"
199 x: root._thermalPipShown ? thermalOverlay.x + thermalOverlay.width + root._tilesMargin
200 : ScreenTools.defaultFontPixelWidth * 12
201 y: root.thermalPipTopInset + root._tilesMargin
202 maximumWidth: root.width - tiles.x - root.tilesRightInset - root._tilesMargin
203 videoManager: root.videoManager
204 shown: root.showTiles