FlightDisplayViewVideo.qml 6.49 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 28
    property var    _videoReceiver:     QGroundControl.videoManager.videoReceiver
    property var    _activeVehicle:     QGroundControl.multiVehicleManager.activeVehicle
29 30
    property var    _dynamicCameras:    _activeVehicle ? _activeVehicle.dynamicCameras : null
    property bool   _connected:         _activeVehicle ? !_activeVehicle.connectionLost : false
31 32 33 34 35 36 37
    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
    property bool   _hasCameraZoom:     _camera && _camera.hasZoom
    property bool   _hasVideoZoom:      QGroundControl.videoManager.hasZoom
    property bool   _hasZoom:           _hasCameraZoom || _hasVideoZoom
    property int    _fitMode:           QGroundControl.settingsManager.videoSettings.videoFit.rawValue
dogmaphobic's avatar
dogmaphobic committed
38 39 40
    Rectangle {
        id:             noVideo
        anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
41
        color:          Qt.rgba(0,0,0,0.75)
42
        visible:        !(_videoReceiver && _videoReceiver.videoRunning)
dogmaphobic's avatar
dogmaphobic committed
43
        QGCLabel {
44
            text:               QGroundControl.settingsManager.videoSettings.streamEnabled.rawValue ? qsTr("WAITING FOR VIDEO") : qsTr("VIDEO DISABLED")
45
            font.family:        ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
46
            color:              "white"
dogmaphobic's avatar
dogmaphobic committed
47
            font.pointSize:     _mainIsMap ? ScreenTools.smallFontPointSize : ScreenTools.largeFontPointSize
dogmaphobic's avatar
dogmaphobic committed
48 49
            anchors.centerIn:   parent
        }
50 51 52 53 54 55
        MouseArea {
            anchors.fill: parent
            onDoubleClicked: {
                QGroundControl.videoManager.fullScreen = !QGroundControl.videoManager.fullScreen
            }
        }
dogmaphobic's avatar
dogmaphobic committed
56
    }
57
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
58
        anchors.fill:   parent
59
        color:          "black"
60
        visible:        _videoReceiver && _videoReceiver.videoRunning
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        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
        }
77
        QGCVideoBackground {
78
            id:             videoContent
79 80
            height:         parent.getHeight()
            width:          parent.getWidth()
81
            anchors.centerIn: parent
82 83 84
            receiver:       _videoReceiver
            display:        _videoReceiver && _videoReceiver.videoSurface
            visible:        _videoReceiver && _videoReceiver.videoRunning
85
            Connections {
86
                target:         _videoReceiver
87 88
                onImageFileChanged: {
                    videoContent.grabToImage(function(result) {
89
                        if (!result.saveToFile(_videoReceiver.imageFile)) {
90 91 92 93 94
                            console.error('Error capturing video frame');
                        }
                    });
                }
            }
95 96 97 98 99
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                height: parent.height
                width:  1
                x:      parent.width * 0.33
100
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
101 102 103 104 105 106
            }
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                height: parent.height
                width:  1
                x:      parent.width * 0.66
107
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
108 109 110 111 112 113
            }
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                width:  parent.width
                height: 1
                y:      parent.height * 0.33
114
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
115 116 117 118 119 120
            }
            Rectangle {
                color:  Qt.rgba(1,1,1,0.5)
                width:  parent.width
                height: 1
                y:      parent.height * 0.66
121
                visible: _showGrid && !QGroundControl.videoManager.fullScreen
122
            }
dogmaphobic's avatar
dogmaphobic committed
123
        }
124 125 126 127
        MouseArea {
            anchors.fill: parent
            onDoubleClicked: {
                QGroundControl.videoManager.fullScreen = !QGroundControl.videoManager.fullScreen
128
            }
dogmaphobic's avatar
dogmaphobic committed
129
        }
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
        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) {
                        //-- Camera zoom takes predence
                        if(_hasCameraZoom) {
                            _camera.stepZoom(z)
                        } else if (_hasVideoZoom) {
                            //-- Video zoom is for dumb cameras that only stream (do not present a camera interface)
                            QGroundControl.videoManager.stepZoom(z)
                        }
                    }
                }
            }
            property int zoom: 0
        }
156 157
    }
}