1pragma ComponentBehavior: Bound
9import QGroundControl.AnalyzeView
10import QGroundControl.Controls
12// Plays the videos QGroundControl recorded, newest first, with the telemetry of their subtitle files drawn over them.
16 pageComponent: recordingsComponent
17 pageDescription: qsTr("Play the videos QGroundControl recorded, with the telemetry recorded alongside them.")
19 readonly property real _margin: ScreenTools.defaultFontPixelWidth
21 QGCPalette { id: qgcPal; colorGroupEnabled: true }
23 VideoRecordingList { id: recordingList }
25 function _formatTime(ms) {
26 const totalSeconds = Math.floor(ms / 1000)
27 const seconds = totalSeconds % 60
28 return Math.floor(totalSeconds / 60) + ":" + (seconds < 10 ? "0" : "") + seconds
31 function _formatSize(bytes) {
32 return bytes >= 1024 * 1024 * 1024
33 ? qsTr("%1 GB").arg((bytes / (1024 * 1024 * 1024)).toFixed(1))
34 : qsTr("%1 MB").arg((bytes / (1024 * 1024)).toFixed(1))
38 id: recordingsComponent
43 /// The path of the recording playing, empty for none.
44 property string selectedPath: ""
45 readonly property var _selected: {
46 const recordings = recordingList.recordings
47 for (let i = 0; i < recordings.length; i++) {
48 if (recordings[i].path === page.selectedPath) {
54 readonly property bool _hasSubtitles: page._selected !== null && page._selected.subtitles.toString() !== ""
55 readonly property int _seekStepMs: 5000
57 width: root.availableWidth
58 height: root.availableHeight
62 Keys.onSpacePressed: page._togglePlayback()
63 Keys.onLeftPressed: page._seekBy(-page._seekStepMs)
64 Keys.onRightPressed: page._seekBy(page._seekStepMs)
66 function _togglePlayback() {
67 if (page.selectedPath === "") {
70 if (player.playbackState === MediaPlayer.PlayingState) {
77 function _seekBy(ms) {
78 if (player.seekable) {
79 player.position = Math.max(0, Math.min(player.duration, player.position + ms))
83 function _deleteSelected() {
84 const path = page.selectedPath
85 // Releases the file, which some platforms won't delete while it is open.
86 page.selectedPath = ""
87 if (!recordingList.remove(path)) {
88 QGroundControl.showMessageDialog(root, qsTr("Delete Recording"),
89 qsTr("The recording could not be deleted."))
96 source: page._selected ? page._selected.url : ""
97 videoOutput: playerOutput
98 audioOutput: AudioOutput { }
99 playbackRate: speedComboBox.currentValue ?? 1
102 if (player.source.toString() !== "") {
111 source: page._hasSubtitles ? page._selected.subtitles : ""
112 position: player.position
116 id: recordingListView
118 model: recordingList.recordings
119 spacing: root._margin / 2
120 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 32
121 Layout.fillHeight: true
123 delegate: Rectangle {
124 id: recordingDelegate
126 required property var modelData
128 width: recordingListView.width
129 height: recordingColumn.height + root._margin
130 color: page.selectedPath === recordingDelegate.modelData.path ? qgcPal.accent : qgcPal.windowCard
131 radius: root._margin / 2
139 verticalCenter: parent.verticalCenter
142 margins: root._margin / 2
146 text: recordingDelegate.modelData.name
147 elide: Text.ElideMiddle
148 color: page.selectedPath === recordingDelegate.modelData.path ? qgcPal.accentText : qgcPal.textPrimary
149 Layout.fillWidth: true
153 text: root._formatSize(recordingDelegate.modelData.size) + " "
154 + recordingDelegate.modelData.modified.toLocaleString(Qt.locale(), Locale.ShortFormat)
155 font.pointSize: ScreenTools.smallFontPointSize
156 color: page.selectedPath === recordingDelegate.modelData.path ? qgcPal.accentText : qgcPal.textPrimary
157 Layout.fillWidth: true
164 page.selectedPath = recordingDelegate.modelData.path
165 page.forceActiveFocus()
172 anchors.margins: root._margin
173 visible: recordingListView.count === 0
174 text: qsTr("No recordings in %1").arg(recordingList.directory)
175 wrapMode: Text.WrapAnywhere
176 horizontalAlignment: Text.AlignHCenter
181 spacing: root._margin
182 Layout.fillWidth: true
183 Layout.fillHeight: true
187 Layout.fillWidth: true
188 Layout.fillHeight: true
194 endOfStreamPolicy: VideoOutput.KeepLastFrame
200 page.forceActiveFocus()
201 page._togglePlayback()
205 // The subtitle file's coordinates span the video's frame, as shown.
209 readonly property real _scaleX: subtitleArea.width / subtitles.playResX
210 readonly property real _scaleY: subtitleArea.height / subtitles.playResY
211 // ASS font sizes are line heights, as players (libass) draw them, not em sizes.
212 readonly property real _fontPixelSize: Math.max(1, subtitles.fontSize * subtitleArea._scaleY
213 * subtitleMetrics.font.pixelSize / subtitleMetrics.height)
215 x: playerOutput.contentRect.x
216 y: playerOutput.contentRect.y
217 width: playerOutput.contentRect.width
218 height: playerOutput.contentRect.height
219 visible: page._hasSubtitles && telemetryCheckBox.checked
224 font.family: ScreenTools.fixedFontFamily
229 model: subtitles.events
234 required property var modelData
236 // Alignment as a numeric keypad: the column and row of the text the anchor point is on.
237 readonly property int _column: (subtitleText.modelData.alignment - 1) % 3
238 readonly property int _row: Math.floor((subtitleText.modelData.alignment - 1) / 3)
240 x: subtitleText.modelData.x * subtitleArea._scaleX - subtitleText._column * subtitleText.width / 2
241 y: subtitleText.modelData.y * subtitleArea._scaleY - (2 - subtitleText._row) * subtitleText.height / 2
242 text: subtitleText.modelData.text
243 horizontalAlignment: subtitleText._column === 0 ? Text.AlignLeft
244 : (subtitleText._column === 1 ? Text.AlignHCenter : Text.AlignRight)
248 font.family: ScreenTools.fixedFontFamily
249 font.pixelSize: subtitleArea._fontPixelSize
255 anchors.centerIn: parent
256 visible: page.selectedPath === ""
257 text: qsTr("Select a recording to play it")
262 visible: player.error !== MediaPlayer.NoError
263 text: player.errorString
265 wrapMode: Text.WordWrap
270 bottom: parent.bottom
271 margins: root._margin
277 spacing: root._margin
278 enabled: page.selectedPath !== ""
279 Layout.fillWidth: true
282 text: player.playbackState === MediaPlayer.PlayingState ? qsTr("Pause") : qsTr("Play")
283 onClicked: page._togglePlayback()
290 to: Math.max(1, player.duration)
291 stepSize: page._seekStepMs
292 enabled: player.seekable
293 Layout.fillWidth: true
294 onMoved: player.position = seekSlider.value
296 // Playback must not pull the handle back from under a drag.
298 value: player.position
299 when: !seekSlider.pressed
300 restoreMode: Binding.RestoreNone
305 text: root._formatTime(player.position) + " / " + root._formatTime(player.duration)
316 { text: "0.5x", value: 0.5 },
317 { text: "1x", value: 1.0 },
318 { text: "2x", value: 2.0 }
323 id: telemetryCheckBox
325 text: qsTr("Telemetry")
327 visible: page._hasSubtitles
332 onClicked: QGroundControl.showMessageDialog(
334 qsTr("Delete Recording"),
335 qsTr("%1 and its telemetry will be deleted permanently. Is this really what you want?")
336 .arg(page._selected ? page._selected.name : ""),
337 Dialog.Yes | Dialog.No,
338 function() { page._deleteSelected() })