QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
PhotoVideoControl.qml
Go to the documentation of this file.
1import QtQuick
2import QtPositioning
3import QtQuick.Layouts
4import QtQuick.Controls
5import QtQuick.Dialogs
6
7import QGroundControl
8import QGroundControl.Controls
9import QGroundControl.FactControls
10import QGroundControl.VideoManager
11
12Rectangle {
13 id: photoVideoControl
14 width: mainLayout.width + (_smallMargins * 2)
15 height: mainLayout.height + (_smallMargins * 2)
16 color: Qt.rgba(qgcPal.window.r, qgcPal.window.g, qgcPal.window.b, 0.5)
17 radius: _margins
18 visible: _camera.capturesVideo || _camera.capturesPhotos || _camera.hasTracking || _camera.hasVideoStream
19
20 property real _margins: ScreenTools.defaultFontPixelHeight / 2
21 property real _smallMargins: ScreenTools.defaultFontPixelWidth / 2
22 property var _activeVehicle: globals.activeVehicle
23 property var _cameraManager: _activeVehicle.cameraManager
24 property var _camera: _cameraManager.currentCameraInstance
25 property bool _cameraInPhotoMode: _camera.cameraMode === MavlinkCameraControlInterface.CAM_MODE_PHOTO || _camera.cameraMode === MavlinkCameraControlInterface.CAM_MODE_SURVEY
26 property bool _cameraInVideoMode: !_cameraInPhotoMode
27 property bool _videoCaptureIdle: _camera.captureVideoState === MavlinkCameraControlInterface.CaptureVideoStateIdle
28 property bool _photoCaptureIdle: _camera.capturePhotosState === MavlinkCameraControlInterface.CapturePhotosStateIdle
29
30 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
31
32 DeadMouseArea { anchors.fill: parent }
33
34 RowLayout {
35 id: mainLayout
36 anchors.margins: _smallMargins
37 anchors.top: parent.top
38 anchors.left: parent.left
39 spacing: _margins
40
41 ColumnLayout {
42 Layout.fillHeight: true
43 spacing: 0
44 visible: _camera.hasZoom
45
46 QGCLabel {
47 Layout.alignment: Qt.AlignHCenter
48 text: qsTr("Zoom")
49 font.pointSize: ScreenTools.smallFontPointSize
50 }
51
52 QGCSlider {
53 objectName: "photoVideoControl_zoomSlider"
54 Layout.alignment: Qt.AlignHCenter
55 Layout.fillHeight: true
56 orientation: Qt.Vertical
57 to: 100
58 from: 0
59 value: _camera.zoomLevel
60 live: true
61 onMoved: _camera.zoomLevel = value
62 }
63 }
64
65 ColumnLayout {
66 spacing: _margins
67
68 // Camera name
69 QGCLabel {
70 Layout.alignment: Qt.AlignHCenter
71 text: _camera.modelName
72 visible: _cameraManager.cameras.length > 1
73 }
74
75 // Photo/Video Mode Selector
76 Rectangle {
77 Layout.alignment: Qt.AlignHCenter
78 width: ScreenTools.defaultFontPixelWidth * 10
79 height: width / 2
80 color: qgcPal.windowCard
81 border.color: qgcPal.borderSubtle
82 radius: height * 0.5
83 visible: _camera.hasModes
84
85 //-- Video Mode
86 Rectangle {
87 anchors.verticalCenter: parent.verticalCenter
88 width: parent.height
89 height: parent.height
90 color: _cameraInVideoMode ? qgcPal.window : qgcPal.windowCard
91 radius: height * 0.5
92 anchors.left: parent.left
93 border.color: qgcPal.textPrimary
94 border.width: _cameraInPhotoMode ? 0 : 1
95
96 QGCColoredImage {
97 height: parent.height * 0.5
98 width: height
99 anchors.centerIn: parent
100 source: "/qmlimages/camera_video.svg"
101 fillMode: Image.PreserveAspectFit
102 sourceSize.height: height
103 color: _cameraInVideoMode ? qgcPal.colorGreen : qgcPal.textPrimary
104
105 MouseArea {
106 anchors.fill: parent
107 enabled: _cameraInPhotoMode ? _photoCaptureIdle : true
108 onClicked: _camera.setCameraModeVideo()
109 }
110 }
111 }
112
113 //-- Photo Mode
114 Rectangle {
115 anchors.verticalCenter: parent.verticalCenter
116 width: parent.height
117 height: parent.height
118 color: _cameraInPhotoMode ? qgcPal.window : qgcPal.windowCard
119 radius: height * 0.5
120 anchors.right: parent.right
121 border.color: qgcPal.textPrimary
122 border.width: _cameraInPhotoMode ? 1 : 0
123
124 QGCColoredImage {
125 height: parent.height * 0.5
126 width: height
127 anchors.centerIn: parent
128 source: "/qmlimages/camera_photo.svg"
129 fillMode: Image.PreserveAspectFit
130 sourceSize.height: height
131 color: _cameraInPhotoMode ? qgcPal.colorGreen : qgcPal.textPrimary
132
133 MouseArea {
134 anchors.fill: parent
135 enabled: _cameraInVideoMode ? _videoCaptureIdle : true
136 onClicked: _camera.setCameraModePhoto()
137 }
138 }
139 }
140 }
141
142 ColumnLayout {
143 Layout.alignment: Qt.AlignHCenter
144 spacing: _smallMargins
145
146 // Start/Stop Video button
147 Rectangle {
148 id: videoCaptureButton
149 Layout.alignment: Qt.AlignHCenter
150 color: videoCaptureButtonPalette.windowCard
151 width: ScreenTools.defaultFontPixelWidth * 6
152 height: width
153 radius: width * 0.5
154 border.width: 1
155 border.color: videoCaptureButtonPalette.textSecondary
156 visible: (_camera.hasModes && _cameraInVideoMode) || (!_camera.hasModes && _camera.capturesVideo)
157 enabled: _camera.captureVideoState !== MavlinkCameraControlInterface.CaptureVideoStateDisabled
158
159 QGCPalette { id: videoCaptureButtonPalette; colorGroupEnabled: videoCaptureButton.enabled }
160
161 Rectangle {
162 anchors.centerIn: parent
163 anchors.alignWhenCentered: false // Prevents anchors.centerIn from snapping to integer coordinates, which can throw off centering.
164 color: videoCaptureButtonPalette.textSecondary
165 width: parent.width * 0.75
166 height: width
167 radius: width * 0.5
168 }
169
170 Rectangle {
171 anchors.centerIn: parent
172 anchors.alignWhenCentered: false // Prevents anchors.centerIn from snapping to integer coordinates, which can throw off centering.
173 width: parent.width * (_isCapturing ? 0.5 : 0.75)
174 height: width
175 radius: _isCapturing ? ScreenTools.defaultFontPixelWidth * 0.5 : width * 0.5
176 color: videoCaptureButtonPalette.videoCaptureButtonColor
177 border.width: 1
178 border.color: videoCaptureButtonPalette.textSecondary
179
180 property bool _isCapturing: _camera.captureVideoState === MavlinkCameraControlInterface.CaptureVideoStateCapturing
181 }
182
183 MouseArea {
184 anchors.fill: parent
185 onClicked: _camera.toggleVideoRecording()
186 }
187 }
188
189 QGCLabel {
190 Layout.alignment: Qt.AlignHCenter
191 text: qsTr("Video")
192 font.pointSize: ScreenTools.smallFontPointSize
193 visible: videoCaptureButton.visible && photoCaptureButton.visible
194 }
195
196 // Record time
197 Rectangle {
198 Layout.alignment: Qt.AlignHCenter
199 color: _videoCaptureIdle ? "transparent" : videoCaptureButtonPalette.videoCaptureButtonColor
200 Layout.preferredWidth: videoRecordTime.width + (_smallMargins * 2)
201 Layout.preferredHeight: videoRecordTime.height
202 radius: _smallMargins
203 visible: videoCaptureButton.visible
204
205 // Video record time
206 QGCLabel {
207 id: videoRecordTime
208 anchors.leftMargin: _smallMargins
209 anchors.left: parent.left
210 anchors.top: parent.top
211 text: _videoCaptureIdle ? "00:00:00" : _camera.recordTimeStr
212 }
213 }
214
215 Item {
216 Layout.alignment: Qt.AlignHCenter
217 width: 1
218 height: 1
219 visible: videoCaptureButton.visible && photoCaptureButton.visible
220 }
221
222 // Take Photo button
223 Rectangle {
224 id: photoCaptureButton
225 objectName: "photoVideoControl_photoCaptureButton"
226 Layout.alignment: Qt.AlignHCenter
227 color: photoCaptureButtonPalette.windowCard
228 width: ScreenTools.defaultFontPixelWidth * 6
229 height: width
230 radius: width * 0.5
231 border.width: 1
232 border.color: photoCaptureButtonPalette.textSecondary
233 visible: (_camera.hasModes && _cameraInPhotoMode) || (!_camera.hasModes && (_camera.hasVideoStream || _camera.capturesPhotos))
234 enabled: _camera.capturePhotosState !== MavlinkCameraControlInterface.CapturePhotosStateDisabled
235
236 QGCPalette { id: photoCaptureButtonPalette; colorGroupEnabled: photoCaptureButton.enabled }
237
238 Rectangle {
239 anchors.centerIn: parent
240 anchors.alignWhenCentered: false // Prevents anchors.centerIn from snapping to integer coordinates, which can throw off centering.
241 color: photoCaptureButtonPalette.textSecondary
242 width: parent.width * 0.75
243 height: width
244 radius: width * 0.5
245 }
246
247 Rectangle {
248 anchors.centerIn: parent
249 anchors.alignWhenCentered: false // Prevents anchors.centerIn from snapping to integer coordinates, which can throw off centering.
250 width: parent.width * (_isCapturing ? 0.5 : 0.75)
251 height: width
252 radius: _isCapturing ? ScreenTools.defaultFontPixelWidth * 0.5 : width * 0.5
253 color: photoCaptureButtonPalette.photoCaptureButtonColor
254 border.width: 1
255 border.color: photoCaptureButtonPalette.textSecondary
256
257 property bool _isCapturing: _camera.capturePhotosState === MavlinkCameraControlInterface.CapturePhotosStateCapturingSinglePhoto ||
258 _camera.capturePhotosState === MavlinkCameraControlInterface.CapturePhotosStateCapturingMultiplePhotos
259 }
260
261 MouseArea {
262 anchors.fill: parent
263 onClicked: {
264 if (_camera.capturePhotosState === MavlinkCameraControlInterface.CapturePhotosStateCapturingMultiplePhotos) {
265 _camera.stopTakePhoto()
266 } else if (_camera.capturePhotosState === MavlinkCameraControlInterface.CapturePhotosStateIdle) {
267 _camera.takePhoto()
268 }
269 }
270 }
271 }
272
273 QGCLabel {
274 Layout.alignment: Qt.AlignHCenter
275 text: qsTr("Photo")
276 font.pointSize: ScreenTools.smallFontPointSize
277 visible: videoCaptureButton.visible && photoCaptureButton.visible
278 }
279
280 // Capture count
281 Rectangle {
282 Layout.alignment: Qt.AlignHCenter
283 color: _photoCaptureIdle ? "transparent" : photoCaptureButtonPalette.photoCaptureButtonColor
284 Layout.preferredWidth: photoCaptureCount.width + (_smallMargins * 2)
285 Layout.preferredHeight: photoCaptureCount.height
286 radius: _smallMargins
287 visible: photoCaptureButton.visible
288
289 // Photo capture count
290 QGCLabel {
291 id: photoCaptureCount
292 anchors.leftMargin: _smallMargins
293 anchors.left: parent.left
294 anchors.top: parent.top
295 text: _activeVehicle ? ('00000' + _activeVehicle.cameraTriggerPoints.count).slice(-5) : "00000"
296 }
297 }
298 }
299
300 //-- Status Information
301 ColumnLayout {
302 Layout.alignment: Qt.AlignHCenter
303 spacing: 0
304 visible: storageStatus.visible || batteryStatus.visible
305
306 QGCLabel {
307 id: storageStatus
308 Layout.alignment: Qt.AlignHCenter
309 text: qsTr("Free: ") + _camera.storageFreeStr
310 font.pointSize: ScreenTools.defaultFontPointSize
311 visible: _camera.storageStatus === MavlinkCameraControlInterface.STORAGE_READY
312 }
313
314 QGCLabel {
315 id: batteryStatus
316 Layout.alignment: Qt.AlignHCenter
317 text: qsTr("Battery: ") + _camera.batteryRemainingStr
318 font.pointSize: ScreenTools.defaultFontPointSize
319 visible: _camera.batteryRemaining >= 0
320 }
321 }
322
323 ColumnLayout {
324 id: trackingControls
325 Layout.alignment: Qt.AlignHCenter
326 spacing: 0
327 visible: _camera.hasTracking
328
329 Rectangle {
330 Layout.alignment: Qt.AlignHCenter
331 color: _camera.trackingEnabled ? qgcPal.colorRed : qgcPal.windowCard
332 Layout.preferredWidth: ScreenTools.defaultFontPixelWidth * 6
333 Layout.preferredHeight: Layout.preferredWidth
334 border.color: qgcPal.textPrimary
335 border.width: 3
336
337 QGCColoredImage {
338 height: parent.height * 0.5
339 width: height
340 anchors.centerIn: parent
341 source: "/qmlimages/TrackingIcon.svg"
342 fillMode: Image.PreserveAspectFit
343 sourceSize.height: height
344 color: qgcPal.textPrimary
345
346 MouseArea {
347 anchors.fill: parent
348 onClicked: {
349 _camera.trackingEnabled = !_camera.trackingEnabled;
350 if (!_camera.trackingEnabled) {
351 _camera.stopTracking()
352 }
353 }
354 }
355 }
356 }
357
358 QGCLabel {
359 Layout.alignment: Qt.AlignHCenter
360 text: qsTr("Camera Tracking")
361 font.pointSize: ScreenTools.smallFontPointSize
362 }
363 }
364
365 QGCColoredImage {
366 Layout.alignment: Qt.AlignHCenter
367 source: "/res/gear-black.svg"
368 mipmap: true
369 Layout.preferredHeight: ScreenTools.defaultFontPixelHeight * 1.5
370 Layout.preferredWidth: Layout.preferredHeight
371 sourceSize.height: Layout.preferredHeight
372 color: qgcPal.textPrimary
373 fillMode: Image.PreserveAspectFit
374
375 QGCMouseArea {
376 fillItem: parent
377 onClicked: settingsDialogFactory.open()
378 }
379 }
380 }
381
382 QGCPopupDialogFactory {
383 id: settingsDialogFactory
384
385 dialogComponent: settingsDialogComponent
386 }
387
388 Component {
389 id: settingsDialogComponent
390
391 QGCPopupDialog {
392 title: qsTr("Settings")
393 buttons: Dialog.Close
394
395 property bool _multipleMavlinkCameras: _cameraManager.cameras.count > 1
396 property bool _multipleMavlinkCameraStreams: _camera.streamLabels.length > 1
397 property bool _cameraStorageSupported: _camera.storageStatus !== MavlinkCameraControlInterface.STORAGE_NOT_SUPPORTED
398
399 ColumnLayout {
400 spacing: _margins
401
402 GridLayout {
403 id: gridLayout
404 flow: GridLayout.TopToBottom
405 rows: dynamicRows + _camera.activeSettings.length
406
407 property int dynamicRows: 8
408
409 // First column
410 QGCLabel {
411 text: qsTr("Camera")
412 visible: _multipleMavlinkCameras
413 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
414 }
415
416 QGCLabel {
417 text: qsTr("Video Stream")
418 visible: _multipleMavlinkCameraStreams
419 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
420 }
421
422 QGCLabel {
423 text: qsTr("Thermal View Mode")
424 visible: _camera.thermalStreamInstance
425 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
426 }
427
428 QGCLabel {
429 text: qsTr("Blend Opacity")
430 visible: _camera.thermalStreamInstance && _camera.thermalMode === MavlinkCameraControlInterface.THERMAL_BLEND
431 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
432 }
433
434 // Mavlink Camera Protocol active settings
435 Repeater {
436 model: _camera.activeSettings
437
438 QGCLabel {
439 text: _camera.getFact(modelData).shortDescription
440 }
441 }
442
443 QGCLabel {
444 text: qsTr("Photo Mode")
445 visible: _camera.capturesPhotos
446 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
447 }
448
449 QGCLabel {
450 text: qsTr("Photo Interval (seconds)")
451 visible: _camera.capturesPhotos && _camera.photoCaptureMode === MavlinkCameraControlInterface.PHOTO_CAPTURE_TIMELAPSE
452 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
453 }
454
455 QGCLabel {
456 text: qsTr("Reset Camera Defaults")
457 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
458 }
459
460 QGCLabel {
461 text: qsTr("Storage")
462 visible: _cameraStorageSupported
463 onVisibleChanged: gridLayout.dynamicRows += visible ? 1 : -1
464 }
465
466 // Second column
467 QGCComboBox {
468 Layout.fillWidth: true
469 sizeToContents: true
470 model: _cameraManager.cameraLabels
471 currentIndex: _cameraManager.currentCamera
472 visible: _multipleMavlinkCameras
473 onActivated: (index) => { _cameraManager.currentCamera = index }
474 }
475
476 QGCComboBox {
477 Layout.fillWidth: true
478 sizeToContents: true
479 model: _camera.streamLabels
480 currentIndex: _camera.currentStream
481 visible: _multipleMavlinkCameraStreams
482 onActivated: (index) => { _camera.currentStream = index }
483 }
484
485 QGCComboBox {
486 Layout.fillWidth: true
487 sizeToContents: true
488 model: [ qsTr("Off"), qsTr("Blend"), qsTr("Full"), qsTr("Picture In Picture") ]
489 currentIndex: _camera.thermalMode
490 visible: _camera.thermalStreamInstance
491 onActivated: (index) => { _camera.thermalMode = index }
492 }
493
494 QGCSlider {
495 Layout.fillWidth: true
496 to: 100
497 from: 0
498 value: _camera.thermalOpacity
499 live: true
500 visible: _camera.thermalStreamInstance && _camera.thermalMode === MavlinkCameraControlInterface.THERMAL_BLEND
501 onValueChanged: _camera.thermalOpacity = value
502 }
503
504 // Mavlink Camera Protocol active settings
505 Repeater {
506 model: _camera.activeSettings
507
508 RowLayout {
509 Layout.fillWidth: true
510 spacing: ScreenTools.defaultFontPixelWidth
511
512 property var _fact: _camera.getFact(modelData)
513 property bool _isBool: _fact.typeIsBool
514 property bool _isCombo: !_isBool && _fact.enumStrings.length > 0
515 property bool _isSlider: _fact && !isNaN(_fact.increment)
516 property bool _isEdit: !_isBool && !_isSlider && _fact.enumStrings.length < 1
517 property bool _isReadOnly: _fact && _fact.readOnly
518
519 FactComboBox {
520 Layout.fillWidth: true
521 sizeToContents: true
522 fact: parent._fact
523 indexModel: false
524 visible: parent._isCombo
525 enabled: !parent._isReadOnly
526 }
527 FactTextField {
528 Layout.fillWidth: true
529 fact: parent._fact
530 visible: parent._isEdit
531 enabled: !parent._isReadOnly
532 }
533 QGCSlider {
534 Layout.fillWidth: true
535 to: parent._fact.max
536 from: parent._fact.min
537 stepSize: parent._fact.increment
538 visible: parent._isSlider
539 enabled: !parent._isReadOnly
540 live: false
541 property bool initialized: false
542
543 onValueChanged: {
544 if (!initialized) {
545 return
546 }
547 parent._fact.value = value
548 }
549
550 Component.onCompleted: {
551 value = parent._fact.value
552 initialized = true
553 }
554 }
555 QGCCheckBoxSlider {
556 checked: parent._fact ? parent._fact.value : false
557 visible: parent._isBool
558 enabled: !parent._isReadOnly
559 onClicked: parent._fact.value = checked ? 1 : 0
560 }
561 }
562 }
563
564 QGCComboBox {
565 Layout.fillWidth: true
566 sizeToContents: true
567 model: [ qsTr("Single"), qsTr("Time Lapse") ]
568 currentIndex: _camera.photoCaptureMode
569 visible: _camera.capturesPhotos
570 onActivated: (index) => { _camera.photoCaptureMode = index }
571 }
572
573 QGCSlider {
574 Layout.fillWidth: true
575 to: 60
576 from: 1
577 stepSize: 1
578 value: _camera.photoLapse
579 displayValue: true
580 live: true
581 visible: _camera.capturesPhotos && _camera.photoCaptureMode === MavlinkCameraControlInterface.PHOTO_CAPTURE_TIMELAPSE
582 onValueChanged: _camera.photoLapse = value
583 }
584
585 QGCButton {
586 Layout.fillWidth: true
587 text: qsTr("Reset")
588 onClicked: resetPrompt.open()
589 MessageDialog {
590 id: resetPrompt
591 title: qsTr("Reset Camera to Factory Settings")
592 text: qsTr("Confirm resetting all settings?")
593 buttons: MessageDialog.Yes | MessageDialog.No
594
595 onButtonClicked: function (button, role) {
596 switch (button) {
597 case MessageDialog.Yes:
598 _camera.resetSettings()
599 resetPrompt.close()
600 break;
601 case MessageDialog.No:
602 resetPrompt.close()
603 break;
604 }
605 }
606 }
607 }
608
609 QGCButton {
610 Layout.fillWidth: true
611 text: qsTr("Format")
612 visible: _cameraStorageSupported
613 onClicked: formatPrompt.open()
614 MessageDialog {
615 id: formatPrompt
616 title: qsTr("Format Camera Storage")
617 text: qsTr("Confirm erasing all files?")
618 buttons: MessageDialog.Yes | MessageDialog.No
619
620 onButtonClicked: function (button, role) {
621 switch (button) {
622 case MessageDialog.Yes:
623 _camera.formatCard()
624 formatPrompt.close()
625 break;
626 case MessageDialog.No:
627 formatPrompt.close()
628 break;
629 }
630 }
631 }
632 }
633 }
634
635 VideoDisplaySettingsGroup {
636 visible: _camera.hasVideoStream
637 }
638 }
639 }
640 }
641 }
642}