FlightDisplayViewWidgets.qml 20 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.7
import QtQuick.Controls         2.1
13 14
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
Don Gagne's avatar
Don Gagne committed
15
import QtLocation               5.6
16 17
import QtPositioning            5.2

18 19 20 21 22 23
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.FlightMap                 1.0
24 25

Item {
26
    id: _root
27

28 29
    property alias  guidedModeBar:          _guidedModeBar
    property bool   gotoEnabled:            _activeVehicle && _activeVehicle.guidedMode && _activeVehicle.flying
30 31
    property var    qgcView
    property bool   isBackgroundDark
Don Gagne's avatar
Don Gagne committed
32

33 34 35
    property var    _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    property bool   _isSatellite:           _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true
    property bool   _lightWidgetBorders:    _isSatellite
36

37
    readonly property real _margins:        ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
38

39
    QGCMapPalette { id: mapPal; lightColors: isBackgroundDark }
40
    QGCPalette    { id: qgcPal }
41

42
    function getPreferredInstrumentWidth() {
43
        if(ScreenTools.isMobile) {
44
            return ScreenTools.isTinyScreen ? mainWindow.width * 0.2 : mainWindow.width * 0.15
45 46 47 48 49
        }
        var w = mainWindow.width * 0.15
        return Math.min(w, 200)
    }

50
    function _setInstrumentWidget() {
51 52 53 54 55 56 57 58 59 60 61 62 63 64
        if(QGroundControl.corePlugin.options.instrumentWidget.source.toString().length) {
            instrumentsLoader.source = QGroundControl.corePlugin.options.instrumentWidget.source
            switch(QGroundControl.corePlugin.options.instrumentWidget.widgetPosition) {
            case CustomInstrumentWidget.POS_TOP_RIGHT:
                instrumentsLoader.state  = "topMode"
                break;
            case CustomInstrumentWidget.POS_BOTTOM_RIGHT:
                instrumentsLoader.state  = "bottomMode"
                break;
            case CustomInstrumentWidget.POS_CENTER_RIGHT:
            default:
                instrumentsLoader.state  = "centerMode"
                break;
            }
65
        } else {
66
            var useAlternateInstruments = QGroundControl.settingsManager.appSettings.virtualJoystick.value || ScreenTools.isTinyScreen
67 68 69 70 71 72 73
            if(useAlternateInstruments) {
                instrumentsLoader.source = "qrc:/qml/QGCInstrumentWidgetAlternate.qml"
                instrumentsLoader.state  = "topMode"
            } else {
                instrumentsLoader.source = "qrc:/qml/QGCInstrumentWidget.qml"
                instrumentsLoader.state  = "centerMode"
            }
74 75 76 77
        }
    }

    Connections {
78 79
        target:         QGroundControl.settingsManager.appSettings.virtualJoystick
        onValueChanged: _setInstrumentWidget()
80 81 82 83 84 85
    }

    Component.onCompleted: {
        _setInstrumentWidget()
    }

Don Gagne's avatar
Don Gagne committed
86
    //-- Map warnings
87
    Column {
Don Gagne's avatar
Don Gagne committed
88 89 90 91 92 93
        anchors.horizontalCenter:   parent.horizontalCenter
        anchors.verticalCenter:     parent.verticalCenter
        spacing:                    ScreenTools.defaultFontPixelHeight

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
94
            visible:                    _activeVehicle && !_activeVehicle.coordinateValid && _mainIsMap
Don Gagne's avatar
Don Gagne committed
95 96
            z:                          QGroundControl.zOrderTopMost
            color:                      mapPal.text
97
            font.pointSize:             ScreenTools.largeFontPointSize
98
            text:                       qsTr("No GPS Lock for Vehicle")
Don Gagne's avatar
Don Gagne committed
99 100 101 102
        }

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
103
            visible:                    _activeVehicle && _activeVehicle.prearmError
Don Gagne's avatar
Don Gagne committed
104 105
            z:                          QGroundControl.zOrderTopMost
            color:                      mapPal.text
106
            font.pointSize:             ScreenTools.largeFontPointSize
Don Gagne's avatar
Don Gagne committed
107
            text:                       _activeVehicle ? _activeVehicle.prearmError : ""
108 109 110
        }
    }

dogmaphobic's avatar
dogmaphobic committed
111
    //-- Instrument Panel
112 113
    Loader {
        id:                     instrumentsLoader
114
        anchors.margins:        ScreenTools.defaultFontPixelHeight / 2
Don Gagne's avatar
Don Gagne committed
115
        anchors.right:          altitudeSlider.visible ? altitudeSlider.left : parent.right
116
        z:                      QGroundControl.zOrderWidgets
117 118 119 120 121 122 123 124
        property var  qgcView:  _root.qgcView
        property real maxHeight:parent.height - (anchors.margins * 2)
        states: [
            State {
                name:   "topMode"
                AnchorChanges {
                    target:                 instrumentsLoader
                    anchors.verticalCenter: undefined
125
                    anchors.bottom:         undefined
126 127 128 129 130 131 132 133
                    anchors.top:            _root ? _root.top : undefined
                }
            },
            State {
                name:   "centerMode"
                AnchorChanges {
                    target:                 instrumentsLoader
                    anchors.top:            undefined
134
                    anchors.bottom:         undefined
135 136
                    anchors.verticalCenter: _root ? _root.verticalCenter : undefined
                }
137 138 139 140 141 142 143 144 145
            },
            State {
                name:   "bottomMode"
                AnchorChanges {
                    target:                 instrumentsLoader
                    anchors.top:            undefined
                    anchors.verticalCenter: undefined
                    anchors.bottom:         _root ? _root.bottom : undefined
                }
146 147
            }
        ]
148 149
    }

Don Gagne's avatar
Don Gagne committed
150 151 152
    //-- Guided mode buttons
    Rectangle {
        id:                         _guidedModeBar
Don Gagne's avatar
Don Gagne committed
153
        anchors.margins:            _barMargin
Don Gagne's avatar
Don Gagne committed
154 155
        anchors.bottom:             parent.bottom
        anchors.horizontalCenter:   parent.horizontalCenter
156
        width:                      guidedModeColumn.width  + (_margins * 2)
Don Gagne's avatar
Don Gagne committed
157
        height:                     guidedModeColumn.height + (_margins * 2)
158
        radius:                     ScreenTools.defaultFontPixelHeight * 0.25
159
        color:                      _isSatellite ? Qt.rgba(qgcPal.mapWidgetBorderLight.r, qgcPal.mapWidgetBorderLight.g, qgcPal.mapWidgetBorderLight.b, 0.8) : Qt.rgba(qgcPal.mapWidgetBorderDark.r, qgcPal.mapWidgetBorderDark.g, qgcPal.mapWidgetBorderDark.b, 0.75)
Don Gagne's avatar
Don Gagne committed
160 161
        visible:                    _activeVehicle
        z:                          QGroundControl.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
162 163
        state:                      "Shown"

164 165
        property real _fontPointSize: ScreenTools.isMobile ? ScreenTools.largeFontPointSize : ScreenTools.defaultFontPointSize

Don Gagne's avatar
Don Gagne committed
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
        states: [
            State {
                name: "Shown"
                PropertyChanges { target: showAnimation; running: true  }
                PropertyChanges { target: guidedModeHideTimer; running: true }
            },
            State {
                name: "Hidden"
                PropertyChanges { target: hideAnimation; running: true  }
            }
        ]

        PropertyAnimation {
            id:             hideAnimation
            target:         _guidedModeBar
            property:       "_barMargin"
            duration:       1000
            easing.type:    Easing.InOutQuad
            from:           _guidedModeBar._showMargin
            to:             _guidedModeBar._hideMargin
        }

        PropertyAnimation {
            id:             showAnimation
            target:         _guidedModeBar
            property:       "_barMargin"
            duration:       250
            easing.type:    Easing.InOutQuad
            from:           _guidedModeBar._hideMargin
            to:             _guidedModeBar._showMargin
        }

        Timer {
            id:             guidedModeHideTimer
            interval:       7000
            running:        true
202
            onTriggered: {
Don Gagne's avatar
Don Gagne committed
203
                if (ScreenTools.isTinyScreen) {
204 205 206
                    _guidedModeBar.state = "Hidden"
                }
            }
Don Gagne's avatar
Don Gagne committed
207
        }
Don Gagne's avatar
Don Gagne committed
208 209 210 211 212 213 214 215 216

        readonly property int confirmHome:          1
        readonly property int confirmLand:          2
        readonly property int confirmTakeoff:       3
        readonly property int confirmArm:           4
        readonly property int confirmDisarm:        5
        readonly property int confirmEmergencyStop: 6
        readonly property int confirmChangeAlt:     7
        readonly property int confirmGoTo:          8
217
        readonly property int confirmRetask:        9
218
        readonly property int confirmOrbit:         10
219
        readonly property int confirmAbort:         11
Don Gagne's avatar
Don Gagne committed
220 221

        property int    confirmActionCode
Don Gagne's avatar
Don Gagne committed
222 223 224
        property real   _showMargin:    _margins
        property real   _hideMargin:    _margins - _guidedModeBar.height
        property real   _barMargin:     _showMargin
Don Gagne's avatar
Don Gagne committed
225 226 227 228 229 230 231 232 233 234

        function actionConfirmed() {
            switch (confirmActionCode) {
            case confirmHome:
                _activeVehicle.guidedModeRTL()
                break;
            case confirmLand:
                _activeVehicle.guidedModeLand()
                break;
            case confirmTakeoff:
235 236 237
                var altitude1 = altitudeSlider.getValue()
                if (!isNaN(altitude1)) {
                    _activeVehicle.guidedModeTakeoff(altitude1)
Don Gagne's avatar
Don Gagne committed
238 239 240 241 242 243 244 245 246 247 248 249
                }
                break;
            case confirmArm:
                _activeVehicle.armed = true
                break;
            case confirmDisarm:
                _activeVehicle.armed = false
                break;
            case confirmEmergencyStop:
                _activeVehicle.emergencyStop()
                break;
            case confirmChangeAlt:
250 251 252
                var altitude2 = altitudeSlider.getValue()
                if (!isNaN(altitude2)) {
                    _activeVehicle.guidedModeChangeAltitude(altitude2)
Don Gagne's avatar
Don Gagne committed
253 254 255 256 257
                }
                break;
            case confirmGoTo:
                _activeVehicle.guidedModeGotoLocation(_flightMap._gotoHereCoordinate)
                break;
258 259 260
            case confirmRetask:
                _activeVehicle.setCurrentMissionSequence(_flightMap._retaskSequence)
                break;
261 262 263 264 265 266
            case confirmOrbit:
                //-- All parameters controlled by RC
                _activeVehicle.guidedModeOrbit()
                //-- Center on current flight map position and orbit with a 50m radius (velocity/direction controlled by the RC)
                //_activeVehicle.guidedModeOrbit(QGroundControl.flightMapPosition, 50.0)
                break;
267
            case confirmAbort:
268
                _activeVehicle.abortLanding(50)     // hardcoded value for climbOutAltitude that is currently ignored
269
                break;
Don Gagne's avatar
Don Gagne committed
270
            default:
271
                console.warn(qsTr("Internal error: unknown confirmActionCode"), confirmActionCode)
Don Gagne's avatar
Don Gagne committed
272 273 274
            }
        }

275 276
        function rejectGuidedModeConfirm() {
            guidedModeConfirm.visible = false
Don Gagne's avatar
Don Gagne committed
277
            _guidedModeBar.visible = true
278 279
            altitudeSlider.visible = false
            _flightMap._gotoHereCoordinate = QtPositioning.coordinate()
Don Gagne's avatar
Don Gagne committed
280
            guidedModeHideTimer.restart()
281 282
        }

Don Gagne's avatar
Don Gagne committed
283
        function confirmAction(actionCode) {
Don Gagne's avatar
Don Gagne committed
284
            guidedModeHideTimer.stop()
Don Gagne's avatar
Don Gagne committed
285 286 287
            confirmActionCode = actionCode
            switch (confirmActionCode) {
            case confirmArm:
288
                guidedModeConfirm.confirmText = qsTr("arm")
Don Gagne's avatar
Don Gagne committed
289 290
                break;
            case confirmDisarm:
291
                guidedModeConfirm.confirmText = qsTr("disarm")
Don Gagne's avatar
Don Gagne committed
292 293
                break;
            case confirmEmergencyStop:
294
                guidedModeConfirm.confirmText = qsTr("STOP ALL MOTORS!")
Don Gagne's avatar
Don Gagne committed
295 296 297
                break;
            case confirmTakeoff:
                altitudeSlider.visible = true
298
                altitudeSlider.setInitialValueMeters(3)
299
                guidedModeConfirm.confirmText = qsTr("takeoff")
Don Gagne's avatar
Don Gagne committed
300 301
                break;
            case confirmLand:
302
                guidedModeConfirm.confirmText = qsTr("land")
Don Gagne's avatar
Don Gagne committed
303
                break;
Don Gagne's avatar
Don Gagne committed
304
            case confirmHome:
305
                guidedModeConfirm.confirmText = qsTr("return to land")
Don Gagne's avatar
Don Gagne committed
306
                break;
Don Gagne's avatar
Don Gagne committed
307 308
            case confirmChangeAlt:
                altitudeSlider.visible = true
309
                altitudeSlider.setInitialValueAppSettingsDistanceUnits(_activeVehicle.altitudeRelative.value)
310
                guidedModeConfirm.confirmText = qsTr("change altitude")
Don Gagne's avatar
Don Gagne committed
311 312
                break;
            case confirmGoTo:
313
                guidedModeConfirm.confirmText = qsTr("move vehicle")
Don Gagne's avatar
Don Gagne committed
314
                break;
315
            case confirmRetask:
316
                guidedModeConfirm.confirmText = qsTr("active waypoint change")
317
                break;
318 319 320
            case confirmOrbit:
                guidedModeConfirm.confirmText = qsTr("enter orbit mode")
                break;
321 322 323
            case confirmAbort:
                guidedModeConfirm.confirmText = qsTr("abort landing")
                break;
Don Gagne's avatar
Don Gagne committed
324
            }
Don Gagne's avatar
Don Gagne committed
325
            _guidedModeBar.visible = false
Don Gagne's avatar
Don Gagne committed
326 327 328
            guidedModeConfirm.visible = true
        }

Don Gagne's avatar
Don Gagne committed
329 330
        Column {
            id:                 guidedModeColumn
Don Gagne's avatar
Don Gagne committed
331 332 333 334 335
            anchors.margins:    _margins
            anchors.top:        parent.top
            anchors.left:       parent.left
            spacing:            _margins

336 337
            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
338
                color:      _isSatellite ? qgcPal.mapWidgetBorderDark : qgcPal.mapWidgetBorderLight
339
                text:       "Click in map to move vehicle"
340
                visible:    gotoEnabled
341 342
            }

Don Gagne's avatar
Don Gagne committed
343
            Row {
Don Gagne's avatar
Don Gagne committed
344
                spacing: _margins * 2
Don Gagne's avatar
Don Gagne committed
345 346

                QGCButton {
347
                    pointSize:  _guidedModeBar._fontPointSize
348
                    text:       (_activeVehicle && _activeVehicle.armed) ? (_activeVehicle.flying ? qsTr("Emergency Stop") : qsTr("Disarm")) :  qsTr("Arm")
Don Gagne's avatar
Don Gagne committed
349
                    visible:    _activeVehicle
Don Gagne's avatar
Don Gagne committed
350
                    onClicked:  _guidedModeBar.confirmAction(_activeVehicle.armed ? (_activeVehicle.flying ? _guidedModeBar.confirmEmergencyStop : _guidedModeBar.confirmDisarm) : _guidedModeBar.confirmArm)
351
                }
Don Gagne's avatar
Don Gagne committed
352

Don Gagne's avatar
Don Gagne committed
353
                QGCButton {
354
                    pointSize:  _guidedModeBar._fontPointSize
355
                    text:       qsTr("RTL")
356
                    visible:    (_activeVehicle && _activeVehicle.armed) && _activeVehicle.guidedModeSupported && _activeVehicle.flying
Don Gagne's avatar
Don Gagne committed
357
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmHome)
358
                }
Don Gagne's avatar
Don Gagne committed
359

Don Gagne's avatar
Don Gagne committed
360
                QGCButton {
361
                    pointSize:  _guidedModeBar._fontPointSize
362
                    text:       (_activeVehicle && _activeVehicle.flying) ?  qsTr("Land"):  qsTr("Takeoff")
363
                    visible:    _activeVehicle && _activeVehicle.guidedModeSupported && _activeVehicle.armed
Don Gagne's avatar
Don Gagne committed
364
                    onClicked:  _guidedModeBar.confirmAction(_activeVehicle.flying ? _guidedModeBar.confirmLand : _guidedModeBar.confirmTakeoff)
365
                }
Don Gagne's avatar
Don Gagne committed
366

Don Gagne's avatar
Don Gagne committed
367
                QGCButton {
368
                    pointSize:  _guidedModeBar._fontPointSize
369
                    text:       qsTr("Pause")
370
                    visible:    (_activeVehicle && _activeVehicle.armed) && _activeVehicle.pauseVehicleSupported && _activeVehicle.flying
Don Gagne's avatar
Don Gagne committed
371 372
                    onClicked:  {
                        guidedModeHideTimer.restart()
373 374 375
                        _activeVehicle.pauseVehicle()
                    }
                }
Don Gagne's avatar
Don Gagne committed
376

Don Gagne's avatar
Don Gagne committed
377
                QGCButton {
378
                    pointSize:  _guidedModeBar._fontPointSize
379
                    text:       qsTr("Change Altitude")
380
                    visible:    (_activeVehicle && _activeVehicle.flying) && _activeVehicle.guidedModeSupported && _activeVehicle.armed
Don Gagne's avatar
Don Gagne committed
381
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmChangeAlt)
382
                }
383 384 385 386

                QGCButton {
                    pointSize:  _guidedModeBar._fontPointSize
                    text:       qsTr("Orbit")
387
                    visible:    (_activeVehicle && _activeVehicle.flying) && _activeVehicle.orbitModeSupported && _activeVehicle.armed
388 389 390
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmOrbit)
                }

391 392 393
                QGCButton {
                    pointSize:  _guidedModeBar._fontPointSize
                    text:       qsTr("Abort")
394
                    visible:    _activeVehicle && _activeVehicle.flying && _activeVehicle.fixedWing
395 396 397
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmAbort)
                }

Don Gagne's avatar
Don Gagne committed
398 399
            } // Row
        } // Column
400 401
    } // Rectangle - Guided mode buttons

402
    MouseArea {
Don Gagne's avatar
Don Gagne committed
403 404 405
        anchors.fill:   parent
        enabled:        guidedModeConfirm.visible
        onClicked:      _guidedModeBar.rejectGuidedModeConfirm()
406 407
    }

408 409 410
    // Action confirmation control
    SliderSwitch {
        id:                         guidedModeConfirm
Don Gagne's avatar
Don Gagne committed
411 412
        anchors.bottomMargin:       _margins
        anchors.bottom:             parent.bottom
413 414 415
        anchors.horizontalCenter:   parent.horizontalCenter
        visible:                    false
        z:                          QGroundControl.zOrderWidgets
416
        fontPointSize:              _guidedModeBar._fontPointSize
417 418 419

        onAccept: {
            guidedModeConfirm.visible = false
Don Gagne's avatar
Don Gagne committed
420
            _guidedModeBar.visible = true
421 422
            _guidedModeBar.actionConfirmed()
            altitudeSlider.visible = false
Don Gagne's avatar
Don Gagne committed
423
            guidedModeHideTimer.restart()
Don Gagne's avatar
Don Gagne committed
424
        }
425

Don Gagne's avatar
Don Gagne committed
426
        onReject: _guidedModeBar.rejectGuidedModeConfirm()
427
    }
Don Gagne's avatar
Don Gagne committed
428 429 430 431 432 433 434 435 436 437 438 439 440

    //-- Altitude slider
    Rectangle {
        id:                 altitudeSlider
        anchors.margins:    _margins
        anchors.right:      parent.right
        anchors.top:        parent.top
        anchors.bottom:     parent.bottom
        color:              qgcPal.window
        width:              ScreenTools.defaultFontPixelWidth * 10
        opacity:            0.8
        visible:            false

441 442 443 444 445 446 447
        function setInitialValueMeters(meters) {
            altSlider.value = QGroundControl.metersToAppSettingsDistanceUnits(meters)
        }

        function setInitialValueAppSettingsDistanceUnits(height) {
            altSlider.value = height
        }
Don Gagne's avatar
Don Gagne committed
448 449 450

        /// Returns NaN for bad value
        function getValue() {
451 452 453 454 455 456
            var value =  parseFloat(altField.text)
            if (!isNaN(value)) {
                return QGroundControl.appSettingsDistanceUnitsToMeters(value);
            } else {
                return value;
            }
Don Gagne's avatar
Don Gagne committed
457 458 459 460 461 462 463 464 465 466 467
        }

        Column {
            id:                 headerColumn
            anchors.margins:    _margins
            anchors.top:        parent.top
            anchors.left:       parent.left
            anchors.right:      parent.right

            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
468
                text: qsTr("Alt (rel)")
Don Gagne's avatar
Don Gagne committed
469 470 471 472
            }

            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
473
                text: QGroundControl.appSettingsDistanceUnitsString
Don Gagne's avatar
Don Gagne committed
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
            }

            QGCTextField {
                id:             altField
                anchors.left:   parent.left
                anchors.right:  parent.right
                text:           altSlider.value.toFixed(1)
            }
        }

        Slider {
            id:                 altSlider
            anchors.margins:    _margins
            anchors.top:        headerColumn.bottom
            anchors.bottom:     parent.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
            orientation:        Qt.Vertical
492 493
            minimumValue:       QGroundControl.metersToAppSettingsDistanceUnits(0)
            maximumValue:       QGroundControl.metersToAppSettingsDistanceUnits((_activeVehicle && _activeVehicle.flying) ? Math.round((_activeVehicle.altitudeRelative.value + 100) / 100) * 100 : 10)
Don Gagne's avatar
Don Gagne committed
494 495
        }
    }
496
}