CameraPageWidget.qml 13.9 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

10 11 12 13 14 15
import QtQuick                  2.4
import QtPositioning            5.2
import QtQuick.Layouts          1.2
import QtQuick.Controls         1.4
import QtQuick.Dialogs          1.2
import QtGraphicalEffects       1.0
16

17 18 19 20 21 22 23 24
import QGroundControl                   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
import QGroundControl.FactSystem        1.0
import QGroundControl.FactControls      1.0
25 26 27 28 29 30

/// Camera page for Instrument Panel PageView
Column {
    width:      pageWidth
    spacing:    ScreenTools.defaultFontPixelHeight

31
    property bool   showSettingsIcon:       _camera !== null
32

33 34 35 36
    property var    _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    property var    _dynamicCameras:        _activeVehicle ? _activeVehicle.dynamicCameras : null
    property bool   _isCamera:              _dynamicCameras ? _dynamicCameras.cameras.count > 0 : false
    property bool   _cameraModeUndefined:   _isCamera ? _dynamicCameras.cameras.get(0).cameraMode === QGCCameraControl.CAMERA_MODE_UNDEFINED : true
Gus Grubba's avatar
Gus Grubba committed
37 38
    property bool   _cameraVideoMode:       _isCamera ? _dynamicCameras.cameras.get(0).cameraMode === 1 : false
    property bool   _cameraPhotoMode:       _isCamera ? _dynamicCameras.cameras.get(0).cameraMode === 0 : false
39 40 41 42 43 44
    property var    _camera:                _isCamera ? _dynamicCameras.cameras.get(0) : null // Single camera support for the time being
    property real   _spacers:               ScreenTools.defaultFontPixelHeight * 0.5
    property real   _labelFieldWidth:       ScreenTools.defaultFontPixelWidth * 30
    property real   _editFieldWidth:        ScreenTools.defaultFontPixelWidth * 30
    property bool   _communicationLost:     _activeVehicle ? _activeVehicle.connectionLost : false
    property bool   _hasModes:              _isCamera && _camera && _camera.hasModes
Gus Grubba's avatar
Gus Grubba committed
45
    property bool   _videoRecording:        _camera && _camera.videoStatus === QGCCameraControl.VIDEO_CAPTURE_STATUS_RUNNING
46

47 48 49 50 51
    function showSettings() {
        qgcView.showDialog(cameraSettings, _cameraVideoMode ? qsTr("Video Settings") : qsTr("Camera Settings"), 70, StandardButton.Ok)
    }

    //-- Dumb camera trigger if no actual camera interface exists
52 53 54
    QGCButton {
        anchors.horizontalCenter:   parent.horizontalCenter
        text:                       qsTr("Trigger Camera")
55
        visible:                    !_isCamera
56 57 58
        onClicked:                  _activeVehicle.triggerCamera()
        enabled:                    _activeVehicle
    }
59 60 61 62 63 64 65 66 67 68 69
    Item { width: 1; height: ScreenTools.defaultFontPixelHeight; visible: _isCamera; }
    //-- Actual controller
    QGCLabel {
        id:             cameraLabel
        text:           _isCamera ? _dynamicCameras.cameras.get(0).modelName : qsTr("Camera")
        visible:        _isCamera
        font.pointSize: ScreenTools.smallFontPointSize
        anchors.horizontalCenter: parent.horizontalCenter
    }
    //-- Camera Mode (visible only if camera has modes)
    Rectangle {
Gus Grubba's avatar
Gus Grubba committed
70 71 72
        width:      _hasModes ? ScreenTools.defaultFontPixelWidth * 8 : 0
        height:     _hasModes ? ScreenTools.defaultFontPixelWidth * 4 : 0
        color:      qgcPal.button
73 74 75 76 77
        radius:     height * 0.5
        visible:    _hasModes
        anchors.horizontalCenter: parent.horizontalCenter
        //-- Video Mode
        Rectangle {
Gus Grubba's avatar
Gus Grubba committed
78 79 80
            width:  parent.height
            height: parent.height
            color:  _cameraVideoMode ? qgcPal.window : qgcPal.button
81 82
            radius: height * 0.5
            anchors.left: parent.left
Gus Grubba's avatar
Gus Grubba committed
83 84
            border.color: qgcPal.text
            border.width: _cameraVideoMode ? 1 : 0
85 86
            anchors.verticalCenter: parent.verticalCenter
            QGCColoredImage {
Gus Grubba's avatar
Gus Grubba committed
87 88 89
                height:             parent.height * 0.5
                width:              height
                anchors.centerIn:   parent
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
                source:             "/qmlimages/camera_video.svg"
                fillMode:           Image.PreserveAspectFit
                sourceSize.height:  height
                color:              _cameraVideoMode ? qgcPal.colorGreen : qgcPal.text
                MouseArea {
                    anchors.fill:   parent
                    enabled:        _cameraPhotoMode
                    onClicked: {
                        _camera.setVideoMode()
                    }
                }
            }
        }
        //-- Photo Mode
        Rectangle {
Gus Grubba's avatar
Gus Grubba committed
105 106 107
            width:  parent.height
            height: parent.height
            color:  _cameraPhotoMode ? qgcPal.window : qgcPal.button
108 109
            radius: height * 0.5
            anchors.right: parent.right
Gus Grubba's avatar
Gus Grubba committed
110 111
            border.color: qgcPal.text
            border.width: _cameraPhotoMode ? 1 : 0
112 113
            anchors.verticalCenter: parent.verticalCenter
            QGCColoredImage {
Gus Grubba's avatar
Gus Grubba committed
114 115 116
                height:             parent.height * 0.5
                width:              height
                anchors.centerIn:   parent
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
                source:             "/qmlimages/camera_photo.svg"
                fillMode:           Image.PreserveAspectFit
                sourceSize.height:  height
                color:              _cameraPhotoMode ? qgcPal.colorGreen : qgcPal.text
                MouseArea {
                    anchors.fill:   parent
                    enabled:        _cameraVideoMode
                    onClicked: {
                        _camera.setPhotoMode()
                    }
                }
            }
        }
    }
    //-- Shutter
    Rectangle {
        color:      Qt.rgba(0,0,0,0)
        width:      ScreenTools.defaultFontPixelWidth * 6
        height:     width
        radius:     width * 0.5
        visible:        _isCamera
        border.color: qgcPal.buttonText
        border.width: 3
        anchors.horizontalCenter: parent.horizontalCenter
        Rectangle {
Gus Grubba's avatar
Gus Grubba committed
142
            width:      parent.width * (_videoRecording ? 0.5 : 0.75)
143
            height:     width
Gus Grubba's avatar
Gus Grubba committed
144
            radius:     _videoRecording ? 0 : width * 0.5
145 146 147 148 149 150 151 152
            color:      _cameraModeUndefined ? qgcPal.colorGrey : qgcPal.colorRed
            anchors.centerIn:   parent
        }
        MouseArea {
            anchors.fill:   parent
            enabled:        !_cameraModeUndefined
            onClicked: {
                if(_cameraVideoMode) {
Gus Grubba's avatar
Gus Grubba committed
153
                    _camera.toggleVideo()
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
                } else {
                    _camera.takePhoto()
                }
            }
        }
    }
    Item { width: 1; height: ScreenTools.defaultFontPixelHeight; visible: _isCamera; }
    Component {
        id: cameraSettings
        QGCViewDialog {
            id: _cameraSettingsDialog
            QGCFlickable {
                anchors.fill:       parent
                contentHeight:      camSettingsCol.height
                flickableDirection: Flickable.VerticalFlick
                clip:               true
                Column {
                    id:             camSettingsCol
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    spacing:        _margins
                    //-------------------------------------------
                    //-- Camera Settings
                    Repeater {
                        model:      _camera ? _camera.activeSettings : []
                        Row {
                            spacing:        ScreenTools.defaultFontPixelWidth
                            anchors.horizontalCenter: parent.horizontalCenter
                            property var    _fact:      _camera.getFact(modelData)
                            property bool   _isBool:    _fact.typeIsBool
                            property bool   _isCombo:   !_isBool && _fact.enumStrings.length > 0
                            property bool   _isSlider:  _fact && !isNaN(_fact.increment)
                            property bool   _isEdit:    !_isBool && !_isSlider && _fact.enumStrings.length < 1
                            QGCLabel {
                                text:       parent._fact.shortDescription
                                width:      _labelFieldWidth
                                anchors.verticalCenter: parent.verticalCenter
                            }
                            FactComboBox {
                                width:      parent._isCombo ? _editFieldWidth : 0
                                fact:       parent._fact
                                indexModel: false
                                visible:    parent._isCombo
                                anchors.verticalCenter: parent.verticalCenter
                            }
                            FactTextField {
                                width:      parent._isEdit ? _editFieldWidth : 0
                                fact:       parent._fact
                                visible:    parent._isEdit
                            }
                            QGCSlider {
                                width:          parent._isSlider ? _editFieldWidth : 0
                                maximumValue:   parent._fact.max
                                minimumValue:   parent._fact.min
                                stepSize:       parent._fact.increment
                                visible:        parent._isSlider
                                updateValueWhileDragging:   false
                                anchors.verticalCenter:     parent.verticalCenter
                                Component.onCompleted: {
                                    value = parent._fact.value
                                }
                                onValueChanged: {
                                    parent._fact.value = value
                                }
                            }
                            Item {
                                width:      parent._isBool ? _editFieldWidth : 0
                                height:     factSwitch.height
                                visible:    parent._isBool
                                anchors.verticalCenter: parent.verticalCenter
                                property var _fact: parent._fact
                                Switch {
                                    id: factSwitch
                                    anchors.left:   parent.left
                                    checked:        parent._fact ? parent._fact.value : false
                                    onClicked:      parent._fact.value = checked ? 1 : 0
                                }
                            }
                        }
                    }
                    //-------------------------------------------
                    //-- Reset Camera
                    Row {
                        spacing:        ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        QGCLabel {
                            text:       qsTr("Reset Camera Defaults")
                            width:      _labelFieldWidth
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCButton {
                            text:       qsTr("Reset")
                            onClicked:  resetPrompt.open()
                            width:      _editFieldWidth
                            anchors.verticalCenter: parent.verticalCenter
                            MessageDialog {
                                id:                 resetPrompt
                                title:              qsTr("Reset Camera to Factory Settings")
                                text:               qsTr("Confirm resetting all settings?")
                                standardButtons:    StandardButton.Yes | StandardButton.No
                                onNo: resetPrompt.close()
                                onYes: {
Gus Grubba's avatar
Gus Grubba committed
256
                                    _camera.resetSettings()
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
                                    resetPrompt.close()
                                }
                            }
                        }
                    }
                    //-------------------------------------------
                    //-- Format Storage
                    Row {
                        spacing:        ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter: parent.horizontalCenter
                        QGCLabel {
                            text:       qsTr("Storage")
                            width:      _labelFieldWidth
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCButton {
                            text:       qsTr("Format")
                            onClicked:  formatPrompt.open()
                            width:      _editFieldWidth
                            anchors.verticalCenter: parent.verticalCenter
                            MessageDialog {
                                id:                 formatPrompt
                                title:              qsTr("Format Camera Storage")
                                text:               qsTr("Confirm erasing all files?")
                                standardButtons:    StandardButton.Yes | StandardButton.No
                                onNo: formatPrompt.close()
                                onYes: {
Gus Grubba's avatar
Gus Grubba committed
284
                                    _camera.formatCard()
285 286 287 288 289 290 291 292 293
                                    formatPrompt.close()
                                }
                            }
                        }
                    }
                }
            }
        }
    }
294
}