FlightDisplayViewWidgets.qml 19.3 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 13 14 15 16 17 18 19 20 21 22 23 24 25


import QtQuick                  2.4
import QtQuick.Controls         1.3
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.2
import QtLocation               5.3
import QtPositioning            5.2

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

Item {
26
    id: _root
27

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

33 34
    property var    _activeVehicle:             QGroundControl.multiVehicleManager.activeVehicle
    property bool   _isSatellite:               _mainIsMap ? (_flightMap ? _flightMap.isSatelliteMap : true) : true
35
    property bool   _lightWidgetBorders:        _isSatellite
36 37
    property bool   _useAlternateInstruments:   QGroundControl.virtualTabletJoystick || ScreenTools.isTinyScreen

38
    readonly property real _margins:                ScreenTools.defaultFontPixelHeight / 2
dogmaphobic's avatar
dogmaphobic committed
39

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

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

Don Gagne's avatar
Don Gagne committed
51
    //-- Map warnings
52
    Column {
Don Gagne's avatar
Don Gagne committed
53 54 55 56 57 58
        anchors.horizontalCenter:   parent.horizontalCenter
        anchors.verticalCenter:     parent.verticalCenter
        spacing:                    ScreenTools.defaultFontPixelHeight

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
59
            visible:                    _activeVehicle && !_activeVehicle.coordinateValid && _mainIsMap
Don Gagne's avatar
Don Gagne committed
60 61
            z:                          QGroundControl.zOrderTopMost
            color:                      mapPal.text
62
            font.pointSize:             ScreenTools.largeFontPointSize
63
            text:                       qsTr("No GPS Lock for Vehicle")
Don Gagne's avatar
Don Gagne committed
64 65 66 67
        }

        QGCLabel {
            anchors.horizontalCenter:   parent.horizontalCenter
68
            visible:                    _activeVehicle && _activeVehicle.prearmError
Don Gagne's avatar
Don Gagne committed
69 70
            z:                          QGroundControl.zOrderTopMost
            color:                      mapPal.text
71
            font.pointSize:             ScreenTools.largeFontPointSize
Don Gagne's avatar
Don Gagne committed
72
            text:                       _activeVehicle ? _activeVehicle.prearmError : ""
73 74 75
        }
    }

dogmaphobic's avatar
dogmaphobic committed
76
    //-- Instrument Panel
77
    QGCInstrumentWidget {
78
        id:                     instrumentGadget
79
        anchors.margins:        ScreenTools.defaultFontPixelHeight / 2
Don Gagne's avatar
Don Gagne committed
80
        anchors.right:          altitudeSlider.visible ? altitudeSlider.left : parent.right
81
        anchors.verticalCenter: parent.verticalCenter
82
        visible:                !_useAlternateInstruments
83
        size:                   getGadgetWidth()
84 85 86
        heading:                _heading
        rollAngle:              _roll
        pitchAngle:             _pitch
Don Gagne's avatar
Don Gagne committed
87 88
        groundSpeedFact:        _groundSpeedFact
        airSpeedFact:           _airSpeedFact
89
        lightBorders:           _lightWidgetBorders
90
        z:                      QGroundControl.zOrderWidgets
91
        qgcView:                _root.qgcView
92
        maxHeight:              parent.height - (anchors.margins * 2)
dogmaphobic's avatar
dogmaphobic committed
93 94
    }

95 96
    QGCInstrumentWidgetAlternate {
        id:                     instrumentGadgetAlternate
97
        anchors.margins:        ScreenTools.defaultFontPixelHeight / 2
98
        anchors.top:            parent.top
Don Gagne's avatar
Don Gagne committed
99
        anchors.right:          altitudeSlider.visible ? altitudeSlider.left : parent.right
100 101
        visible:                _useAlternateInstruments
        width:                  ScreenTools.isTinyScreen ? getGadgetWidth() * 1.5 : getGadgetWidth()
102 103 104 105 106
        heading:                _heading
        rollAngle:              _roll
        pitchAngle:             _pitch
        groundSpeedFact:        _groundSpeedFact
        airSpeedFact:           _airSpeedFact
Don Gagne's avatar
Don Gagne committed
107 108 109
        lightBorders:           _lightWidgetBorders
        qgcView:                _root.qgcView
        maxHeight:              parent.height - (anchors.margins * 2)
110 111 112
        z:                      QGroundControl.zOrderWidgets
    }

Don Gagne's avatar
Don Gagne committed
113
    /*
114
    ValuesWidget {
115 116 117 118
        anchors.topMargin:          ScreenTools.defaultFontPixelHeight
        anchors.top:                instrumentGadgetAlternate.bottom
        anchors.horizontalCenter:   instrumentGadgetAlternate.horizontalCenter
        width:                      getGadgetWidth()
119
        qgcView:                    _root.qgcView
120 121 122
        textColor:                  _isSatellite ? "white" : "black"
        visible:                    _useAlternateInstruments
        maxHeight:                  virtualJoystickMultiTouch.visible ? virtualJoystickMultiTouch.y - y : parent.height - anchors.margins - y
Don Gagne's avatar
Don Gagne committed
123
    }*/
dogmaphobic's avatar
dogmaphobic committed
124

Don Gagne's avatar
Don Gagne committed
125 126 127
    //-- Guided mode buttons
    Rectangle {
        id:                         _guidedModeBar
Don Gagne's avatar
Don Gagne committed
128
        anchors.margins:            _barMargin
Don Gagne's avatar
Don Gagne committed
129 130
        anchors.bottom:             parent.bottom
        anchors.horizontalCenter:   parent.horizontalCenter
131
        width:                      guidedModeColumn.width  + (_margins * 2)
Don Gagne's avatar
Don Gagne committed
132
        height:                     guidedModeColumn.height + (_margins * 2)
133 134
        radius:                     ScreenTools.defaultFontPixelHeight * 0.25
        color:                      _lightWidgetBorders ? 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
135 136
        visible:                    _activeVehicle
        z:                          QGroundControl.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
137 138
        state:                      "Shown"

139 140
        property real _fontPointSize: ScreenTools.isMobile ? ScreenTools.largeFontPointSize : ScreenTools.defaultFontPointSize

Don Gagne's avatar
Don Gagne committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
        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
177 178 179 180 181
            onTriggered: {
                if (ScreenTools.isShortScreen) {
                    _guidedModeBar.state = "Hidden"
                }
            }
Don Gagne's avatar
Don Gagne committed
182
        }
Don Gagne's avatar
Don Gagne committed
183 184 185 186 187 188 189 190 191

        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
192
        readonly property int confirmRetask:        9
193
        readonly property int confirmOrbit:         10
194
        readonly property int confirmAbort:         11
Don Gagne's avatar
Don Gagne committed
195 196

        property int    confirmActionCode
Don Gagne's avatar
Don Gagne committed
197 198 199
        property real   _showMargin:    _margins
        property real   _hideMargin:    _margins - _guidedModeBar.height
        property real   _barMargin:     _showMargin
Don Gagne's avatar
Don Gagne committed
200 201 202 203 204 205 206 207 208 209

        function actionConfirmed() {
            switch (confirmActionCode) {
            case confirmHome:
                _activeVehicle.guidedModeRTL()
                break;
            case confirmLand:
                _activeVehicle.guidedModeLand()
                break;
            case confirmTakeoff:
210 211 212
                var altitude1 = altitudeSlider.getValue()
                if (!isNaN(altitude1)) {
                    _activeVehicle.guidedModeTakeoff(altitude1)
Don Gagne's avatar
Don Gagne committed
213 214 215 216 217 218 219 220 221 222 223 224
                }
                break;
            case confirmArm:
                _activeVehicle.armed = true
                break;
            case confirmDisarm:
                _activeVehicle.armed = false
                break;
            case confirmEmergencyStop:
                _activeVehicle.emergencyStop()
                break;
            case confirmChangeAlt:
225 226 227
                var altitude2 = altitudeSlider.getValue()
                if (!isNaN(altitude2)) {
                    _activeVehicle.guidedModeChangeAltitude(altitude2)
Don Gagne's avatar
Don Gagne committed
228 229 230 231 232
                }
                break;
            case confirmGoTo:
                _activeVehicle.guidedModeGotoLocation(_flightMap._gotoHereCoordinate)
                break;
233 234 235
            case confirmRetask:
                _activeVehicle.setCurrentMissionSequence(_flightMap._retaskSequence)
                break;
236 237 238 239 240 241
            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;
242 243 244
            case confirmAbort:
                _activeVehicle.abortLanding()
                break;
Don Gagne's avatar
Don Gagne committed
245
            default:
246
                console.warn(qsTr("Internal error: unknown confirmActionCode"), confirmActionCode)
Don Gagne's avatar
Don Gagne committed
247 248 249
            }
        }

250 251
        function rejectGuidedModeConfirm() {
            guidedModeConfirm.visible = false
Don Gagne's avatar
Don Gagne committed
252
            _guidedModeBar.visible = true
253 254
            altitudeSlider.visible = false
            _flightMap._gotoHereCoordinate = QtPositioning.coordinate()
Don Gagne's avatar
Don Gagne committed
255
            guidedModeHideTimer.restart()
256 257
        }

Don Gagne's avatar
Don Gagne committed
258
        function confirmAction(actionCode) {
Don Gagne's avatar
Don Gagne committed
259
            guidedModeHideTimer.stop()
Don Gagne's avatar
Don Gagne committed
260 261 262
            confirmActionCode = actionCode
            switch (confirmActionCode) {
            case confirmArm:
263
                guidedModeConfirm.confirmText = qsTr("arm")
Don Gagne's avatar
Don Gagne committed
264 265
                break;
            case confirmDisarm:
266
                guidedModeConfirm.confirmText = qsTr("disarm")
Don Gagne's avatar
Don Gagne committed
267 268
                break;
            case confirmEmergencyStop:
269
                guidedModeConfirm.confirmText = qsTr("STOP ALL MOTORS!")
Don Gagne's avatar
Don Gagne committed
270 271 272
                break;
            case confirmTakeoff:
                altitudeSlider.visible = true
273
                altitudeSlider.setInitialValueMeters(3)
274
                guidedModeConfirm.confirmText = qsTr("takeoff")
Don Gagne's avatar
Don Gagne committed
275 276
                break;
            case confirmLand:
277
                guidedModeConfirm.confirmText = qsTr("land")
Don Gagne's avatar
Don Gagne committed
278
                break;
Don Gagne's avatar
Don Gagne committed
279
            case confirmHome:
280
                guidedModeConfirm.confirmText = qsTr("return to land")
Don Gagne's avatar
Don Gagne committed
281
                break;
Don Gagne's avatar
Don Gagne committed
282 283
            case confirmChangeAlt:
                altitudeSlider.visible = true
284
                altitudeSlider.setInitialValueAppSettingsDistanceUnits(_activeVehicle.altitudeRelative.value)
285
                guidedModeConfirm.confirmText = qsTr("change altitude")
Don Gagne's avatar
Don Gagne committed
286 287
                break;
            case confirmGoTo:
288
                guidedModeConfirm.confirmText = qsTr("move vehicle")
Don Gagne's avatar
Don Gagne committed
289
                break;
290
            case confirmRetask:
291
                guidedModeConfirm.confirmText = qsTr("active waypoint change")
292
                break;
293 294 295
            case confirmOrbit:
                guidedModeConfirm.confirmText = qsTr("enter orbit mode")
                break;
296 297 298
            case confirmAbort:
                guidedModeConfirm.confirmText = qsTr("abort landing")
                break;
Don Gagne's avatar
Don Gagne committed
299
            }
Don Gagne's avatar
Don Gagne committed
300
            _guidedModeBar.visible = false
Don Gagne's avatar
Don Gagne committed
301 302 303
            guidedModeConfirm.visible = true
        }

Don Gagne's avatar
Don Gagne committed
304 305
        Column {
            id:                 guidedModeColumn
Don Gagne's avatar
Don Gagne committed
306 307 308 309 310
            anchors.margins:    _margins
            anchors.top:        parent.top
            anchors.left:       parent.left
            spacing:            _margins

311 312
            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
Don Gagne's avatar
Don Gagne committed
313
                color:      _lightWidgetBorders ? qgcPal.mapWidgetBorderDark : qgcPal.mapWidgetBorderLight
314
                text:       "Click in map to move vehicle"
315
                visible:    gotoEnabled
316 317
            }

Don Gagne's avatar
Don Gagne committed
318
            Row {
Don Gagne's avatar
Don Gagne committed
319
                spacing: _margins * 2
Don Gagne's avatar
Don Gagne committed
320 321

                QGCButton {
322
                    pointSize:  _guidedModeBar._fontPointSize
323
                    text:       (_activeVehicle && _activeVehicle.armed) ? (_activeVehicle.flying ? qsTr("Emergency Stop") : qsTr("Disarm")) :  qsTr("Arm")
Don Gagne's avatar
Don Gagne committed
324
                    visible:    _activeVehicle
Don Gagne's avatar
Don Gagne committed
325
                    onClicked:  _guidedModeBar.confirmAction(_activeVehicle.armed ? (_activeVehicle.flying ? _guidedModeBar.confirmEmergencyStop : _guidedModeBar.confirmDisarm) : _guidedModeBar.confirmArm)
326
                }
Don Gagne's avatar
Don Gagne committed
327

Don Gagne's avatar
Don Gagne committed
328
                QGCButton {
329
                    pointSize:  _guidedModeBar._fontPointSize
330
                    text:       qsTr("RTL")
331
                    visible:    (_activeVehicle && _activeVehicle.armed) && _activeVehicle.guidedModeSupported && _activeVehicle.flying
Don Gagne's avatar
Don Gagne committed
332
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmHome)
333
                }
Don Gagne's avatar
Don Gagne committed
334

Don Gagne's avatar
Don Gagne committed
335
                QGCButton {
336
                    pointSize:  _guidedModeBar._fontPointSize
337
                    text:       (_activeVehicle && _activeVehicle.flying) ?  qsTr("Land"):  qsTr("Takeoff")
338
                    visible:    _activeVehicle && _activeVehicle.guidedModeSupported && _activeVehicle.armed
Don Gagne's avatar
Don Gagne committed
339
                    onClicked:  _guidedModeBar.confirmAction(_activeVehicle.flying ? _guidedModeBar.confirmLand : _guidedModeBar.confirmTakeoff)
340
                }
Don Gagne's avatar
Don Gagne committed
341

Don Gagne's avatar
Don Gagne committed
342
                QGCButton {
343
                    pointSize:  _guidedModeBar._fontPointSize
344
                    text:       qsTr("Pause")
345
                    visible:    (_activeVehicle && _activeVehicle.armed) && _activeVehicle.pauseVehicleSupported && _activeVehicle.flying
Don Gagne's avatar
Don Gagne committed
346 347
                    onClicked:  {
                        guidedModeHideTimer.restart()
348 349 350
                        _activeVehicle.pauseVehicle()
                    }
                }
Don Gagne's avatar
Don Gagne committed
351

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

                QGCButton {
                    pointSize:  _guidedModeBar._fontPointSize
                    text:       qsTr("Orbit")
362
                    visible:    (_activeVehicle && _activeVehicle.flying) && _activeVehicle.orbitModeSupported && _activeVehicle.armed
363 364 365
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmOrbit)
                }

366 367 368 369 370 371 372
                QGCButton {
                    pointSize:  _guidedModeBar._fontPointSize
                    text:       qsTr("Abort")
                    visible:    _activeVehicle && _activeVehicle.flying
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmAbort)
                }

Don Gagne's avatar
Don Gagne committed
373 374
            } // Row
        } // Column
375 376
    } // Rectangle - Guided mode buttons

377
    MouseArea {
Don Gagne's avatar
Don Gagne committed
378 379 380
        anchors.fill:   parent
        enabled:        guidedModeConfirm.visible
        onClicked:      _guidedModeBar.rejectGuidedModeConfirm()
381 382
    }

383 384 385
    // Action confirmation control
    SliderSwitch {
        id:                         guidedModeConfirm
Don Gagne's avatar
Don Gagne committed
386 387
        anchors.bottomMargin:       _margins
        anchors.bottom:             parent.bottom
388 389 390
        anchors.horizontalCenter:   parent.horizontalCenter
        visible:                    false
        z:                          QGroundControl.zOrderWidgets
391
        fontPointSize:              _guidedModeBar._fontPointSize
392 393 394

        onAccept: {
            guidedModeConfirm.visible = false
Don Gagne's avatar
Don Gagne committed
395
            _guidedModeBar.visible = true
396 397
            _guidedModeBar.actionConfirmed()
            altitudeSlider.visible = false
Don Gagne's avatar
Don Gagne committed
398
            guidedModeHideTimer.restart()
Don Gagne's avatar
Don Gagne committed
399
        }
400

Don Gagne's avatar
Don Gagne committed
401
        onReject: _guidedModeBar.rejectGuidedModeConfirm()
402
    }
Don Gagne's avatar
Don Gagne committed
403 404 405 406 407 408 409 410 411 412 413 414 415

    //-- 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

416 417 418 419 420 421 422
        function setInitialValueMeters(meters) {
            altSlider.value = QGroundControl.metersToAppSettingsDistanceUnits(meters)
        }

        function setInitialValueAppSettingsDistanceUnits(height) {
            altSlider.value = height
        }
Don Gagne's avatar
Don Gagne committed
423 424 425

        /// Returns NaN for bad value
        function getValue() {
426 427 428 429 430 431
            var value =  parseFloat(altField.text)
            if (!isNaN(value)) {
                return QGroundControl.appSettingsDistanceUnitsToMeters(value);
            } else {
                return value;
            }
Don Gagne's avatar
Don Gagne committed
432 433 434 435 436 437 438 439 440 441 442
        }

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

            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
443
                text: qsTr("Alt (rel)")
Don Gagne's avatar
Don Gagne committed
444 445 446 447
            }

            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
448
                text: QGroundControl.appSettingsDistanceUnitsString
Don Gagne's avatar
Don Gagne committed
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
            }

            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
467 468
            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
469 470
        }
    }
471
}