FlightDisplayViewVideo.qml 5.9 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10


11 12
import QtQuick                          2.11
import QtQuick.Controls                 2.4
13

14 15 16 17 18 19 20 21
import QGroundControl                   1.0
import QGroundControl.FlightDisplay     1.0
import QGroundControl.FlightMap         1.0
import QGroundControl.ScreenTools       1.0
import QGroundControl.Controls          1.0
import QGroundControl.Palette           1.0
import QGroundControl.Vehicle           1.0
import QGroundControl.Controllers       1.0
22

dogmaphobic's avatar
dogmaphobic committed
23 24
Item {
    id: root
25
    property double _ar:                QGroundControl.videoManager.aspectRatio
26
    property bool   _showGrid:          QGroundControl.settingsManager.videoSettings.gridLines.rawValue > 0
27
    property var    _videoReceiver:     QGroundControl.videoManager.videoReceiver
Gus Grubba's avatar
Gus Grubba committed
28 29
    property var    _dynamicCameras:    activeVehicle ? activeVehicle.dynamicCameras : null
    property bool   _connected:         activeVehicle ? !activeVehicle.connectionLost : false
30 31 32
    property int    _curCameraIndex:    _dynamicCameras ? _dynamicCameras.currentCamera : 0
    property bool   _isCamera:          _dynamicCameras ? _dynamicCameras.cameras.count > 0 : false
    property var    _camera:            _isCamera ? _dynamicCameras.cameras.get(_curCameraIndex) : null
33
    property bool   _hasZoom:           _camera && _camera.hasZoom
34
    property int    _fitMode:           QGroundControl.settingsManager.videoSettings.videoFit.rawValue
dogmaphobic's avatar
dogmaphobic committed
35 36 37
    Rectangle {
        id:             noVideo
        anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
38
        color:          Qt.rgba(0,0,0,0.75)
39
        visible:        !(_videoReceiver && _videoReceiver.videoRunning)
dogmaphobic's avatar
dogmaphobic committed
40
        QGCLabel {
41
            text:               QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue ? qsTr("WAITING FOR VIDEO") : qsTr("VIDEO DISABLED")
42
            font.family:        ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
43
            color:              "white"
dogmaphobic's avatar
dogmaphobic committed
44
            font.pointSize:     _mainIsMap ? ScreenTools.smallFontPointSize : ScreenTools.largeFontPointSize
dogmaphobic's avatar
dogmaphobic committed
45 46
            anchors.centerIn:   parent
        }
47 48 49 50 51 52
        MouseArea {
            anchors.fill: parent
            onDoubleClicked: {
                QGroundControl.videoManager.fullScreen = !QGroundControl.videoManager.fullScreen
            }
        }
dogmaphobic's avatar
dogmaphobic committed
53
    }
54
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
55
        anchors.fill:   parent
56
        color:          "black"
57
        visible:        _videoReceiver && _videoReceiver.videoRunning
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
        function getWidth() {
            //-- Fit Width or Stretch
            if(_fitMode === 0 || _fitMode === 2) {
                return parent.width
            }
            //-- Fit Height
            return _ar != 0.0 ? parent.height * _ar : parent.width
        }
        function getHeight() {
            //-- Fit Height or Stretch
            if(_fitMode === 1 || _fitMode === 2) {
                return parent.height
            }
            //-- Fit Width
            return _ar != 0.0 ? parent.width * (1 / _ar) : parent.height
        }
74
        QGCVideoBackground {
75
            id:             videoContent
76 77
            height:         parent.getHeight()
            width:          parent.getWidth()
78
            anchors.centerIn: parent
79 80 81
            receiver:       _videoReceiver
            display:        _videoReceiver && _videoReceiver.videoSurface
            visible:        _videoReceiver && _videoReceiver.videoRunning
82
            Connections {
83
                target:         _videoReceiver
84 85
                onImageFileChanged: {
                    videoContent.grabToImage(function(result) {
86
                        if (!result.saveToFile(_videoReceiver.imageFile)) {
87 88 89 90 91
                            console.error('Error capturing video frame');
                        }
                    });
                }
            }
92 93 94 95 96
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                height: parent.height
                width:  1
                x:      parent.width * 0.33
97
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
98 99 100 101 102 103
            }
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                height: parent.height
                width:  1
                x:      parent.width * 0.66
104
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
105 106 107 108 109 110
            }
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                width:  parent.width
                height: 1
                y:      parent.height * 0.33
111
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
112 113 114 115 116 117
            }
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                width:  parent.width
                height: 1
                y:      parent.height * 0.66
118
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
119
            }
dogmaphobic's avatar
dogmaphobic committed
120
        }
121 122 123 124
        MouseArea {
            anchors.fill: parent
            onDoubleClicked: {
                QGroundControl.videoManager.fullScreen = !QGroundControl.videoManager.fullScreen
125
            }
dogmaphobic's avatar
dogmaphobic committed
126
        }
127 128 129 130 131 132 133 134 135 136 137 138 139 140
        PinchArea {
            id:             pinchZoom
            enabled:        _hasZoom
            anchors.fill:   parent
            onPinchStarted: pinchZoom.zoom = 0
            onPinchUpdated: {
                if(_hasZoom) {
                    var z = 0
                    if(pinch.scale < 1) {
                        z = Math.round(pinch.scale * -10)
                    } else {
                        z = Math.round(pinch.scale)
                    }
                    if(pinchZoom.zoom != z) {
141
                        _camera.stepZoom(z)
142 143 144 145 146
                    }
                }
            }
            property int zoom: 0
        }
147 148
    }
}