FlightDisplayViewWidgets.qml 18.6 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
    property alias  guidedModeBar:  _guidedModeBar
    property bool   gotoEnabled:    _activeVehicle && _activeVehicle.guidedMode && _activeVehicle.flying
Don Gagne's avatar
Don Gagne committed
30

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

36
    readonly property real _margins:                ScreenTools.defaultFontPixelHeight / 2
dogmaphobic's avatar
dogmaphobic committed
37

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

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

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

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

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

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

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

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

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

136 137
        property real _fontPointSize: ScreenTools.isMobile ? ScreenTools.largeFontPointSize : ScreenTools.defaultFontPointSize

Don Gagne's avatar
Don Gagne committed
138 139 140 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
        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
174 175 176 177 178
            onTriggered: {
                if (ScreenTools.isShortScreen) {
                    _guidedModeBar.state = "Hidden"
                }
            }
Don Gagne's avatar
Don Gagne committed
179
        }
Don Gagne's avatar
Don Gagne committed
180 181 182 183 184 185 186 187 188

        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
189
        readonly property int confirmRetask:        9
190
        readonly property int confirmOrbit:         10
Don Gagne's avatar
Don Gagne committed
191 192

        property int    confirmActionCode
Don Gagne's avatar
Don Gagne committed
193 194 195
        property real   _showMargin:    _margins
        property real   _hideMargin:    _margins - _guidedModeBar.height
        property real   _barMargin:     _showMargin
Don Gagne's avatar
Don Gagne committed
196 197 198 199 200 201 202 203 204 205

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

243 244
        function rejectGuidedModeConfirm() {
            guidedModeConfirm.visible = false
Don Gagne's avatar
Don Gagne committed
245
            _guidedModeBar.visible = true
246 247
            altitudeSlider.visible = false
            _flightMap._gotoHereCoordinate = QtPositioning.coordinate()
Don Gagne's avatar
Don Gagne committed
248
            guidedModeHideTimer.restart()
249 250
        }

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

Don Gagne's avatar
Don Gagne committed
294 295
        Column {
            id:                 guidedModeColumn
Don Gagne's avatar
Don Gagne committed
296 297 298 299 300
            anchors.margins:    _margins
            anchors.top:        parent.top
            anchors.left:       parent.left
            spacing:            _margins

301 302
            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
Don Gagne's avatar
Don Gagne committed
303
                color:      _lightWidgetBorders ? qgcPal.mapWidgetBorderDark : qgcPal.mapWidgetBorderLight
304
                text:       "Click in map to move vehicle"
305
                visible:    gotoEnabled
306 307
            }

Don Gagne's avatar
Don Gagne committed
308
            Row {
Don Gagne's avatar
Don Gagne committed
309
                spacing: _margins * 2
Don Gagne's avatar
Don Gagne committed
310 311

                QGCButton {
312
                    pointSize:  _guidedModeBar._fontPointSize
313
                    text:       (_activeVehicle && _activeVehicle.armed) ? (_activeVehicle.flying ? qsTr("Emergency Stop") : qsTr("Disarm")) :  qsTr("Arm")
Don Gagne's avatar
Don Gagne committed
314
                    visible:    _activeVehicle
Don Gagne's avatar
Don Gagne committed
315
                    onClicked:  _guidedModeBar.confirmAction(_activeVehicle.armed ? (_activeVehicle.flying ? _guidedModeBar.confirmEmergencyStop : _guidedModeBar.confirmDisarm) : _guidedModeBar.confirmArm)
316
                }
Don Gagne's avatar
Don Gagne committed
317

Don Gagne's avatar
Don Gagne committed
318
                QGCButton {
319
                    pointSize:  _guidedModeBar._fontPointSize
320
                    text:       qsTr("RTL")
321
                    visible:    (_activeVehicle && _activeVehicle.armed) && _activeVehicle.guidedModeSupported && _activeVehicle.flying
Don Gagne's avatar
Don Gagne committed
322
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmHome)
323
                }
Don Gagne's avatar
Don Gagne committed
324

Don Gagne's avatar
Don Gagne committed
325
                QGCButton {
326
                    pointSize:  _guidedModeBar._fontPointSize
327
                    text:       (_activeVehicle && _activeVehicle.flying) ?  qsTr("Land"):  qsTr("Takeoff")
328
                    visible:    _activeVehicle && _activeVehicle.guidedModeSupported && _activeVehicle.armed
Don Gagne's avatar
Don Gagne committed
329
                    onClicked:  _guidedModeBar.confirmAction(_activeVehicle.flying ? _guidedModeBar.confirmLand : _guidedModeBar.confirmTakeoff)
330
                }
Don Gagne's avatar
Don Gagne committed
331

Don Gagne's avatar
Don Gagne committed
332
                QGCButton {
333
                    pointSize:  _guidedModeBar._fontPointSize
334
                    text:       qsTr("Pause")
335
                    visible:    (_activeVehicle && _activeVehicle.armed) && _activeVehicle.pauseVehicleSupported && _activeVehicle.flying
Don Gagne's avatar
Don Gagne committed
336 337
                    onClicked:  {
                        guidedModeHideTimer.restart()
338 339 340
                        _activeVehicle.pauseVehicle()
                    }
                }
Don Gagne's avatar
Don Gagne committed
341

Don Gagne's avatar
Don Gagne committed
342
                QGCButton {
343
                    pointSize:  _guidedModeBar._fontPointSize
344
                    text:       qsTr("Change Altitude")
345
                    visible:    (_activeVehicle && _activeVehicle.flying) && _activeVehicle.guidedModeSupported && _activeVehicle.armed
Don Gagne's avatar
Don Gagne committed
346
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmChangeAlt)
347
                }
348 349 350 351

                QGCButton {
                    pointSize:  _guidedModeBar._fontPointSize
                    text:       qsTr("Orbit")
352
                    visible:    (_activeVehicle && _activeVehicle.flying) && _activeVehicle.orbitModeSupported && _activeVehicle.armed
353 354 355
                    onClicked:  _guidedModeBar.confirmAction(_guidedModeBar.confirmOrbit)
                }

Don Gagne's avatar
Don Gagne committed
356 357
            } // Row
        } // Column
358 359
    } // Rectangle - Guided mode buttons

360
    MouseArea {
Don Gagne's avatar
Don Gagne committed
361 362 363
        anchors.fill:   parent
        enabled:        guidedModeConfirm.visible
        onClicked:      _guidedModeBar.rejectGuidedModeConfirm()
364 365
    }

366 367 368
    // Action confirmation control
    SliderSwitch {
        id:                         guidedModeConfirm
Don Gagne's avatar
Don Gagne committed
369 370
        anchors.bottomMargin:       _margins
        anchors.bottom:             parent.bottom
371 372 373
        anchors.horizontalCenter:   parent.horizontalCenter
        visible:                    false
        z:                          QGroundControl.zOrderWidgets
374
        fontPointSize:              _guidedModeBar._fontPointSize
375 376 377

        onAccept: {
            guidedModeConfirm.visible = false
Don Gagne's avatar
Don Gagne committed
378
            _guidedModeBar.visible = true
379 380
            _guidedModeBar.actionConfirmed()
            altitudeSlider.visible = false
Don Gagne's avatar
Don Gagne committed
381
            guidedModeHideTimer.restart()
Don Gagne's avatar
Don Gagne committed
382
        }
383

Don Gagne's avatar
Don Gagne committed
384
        onReject: _guidedModeBar.rejectGuidedModeConfirm()
385
    }
Don Gagne's avatar
Don Gagne committed
386 387 388 389 390 391 392 393 394 395 396 397 398

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

399 400 401 402 403 404 405
        function setInitialValueMeters(meters) {
            altSlider.value = QGroundControl.metersToAppSettingsDistanceUnits(meters)
        }

        function setInitialValueAppSettingsDistanceUnits(height) {
            altSlider.value = height
        }
Don Gagne's avatar
Don Gagne committed
406 407 408

        /// Returns NaN for bad value
        function getValue() {
409 410 411 412 413 414
            var value =  parseFloat(altField.text)
            if (!isNaN(value)) {
                return QGroundControl.appSettingsDistanceUnitsToMeters(value);
            } else {
                return value;
            }
Don Gagne's avatar
Don Gagne committed
415 416 417 418 419 420 421 422 423 424 425
        }

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

            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
426
                text: qsTr("Alt (rel)")
Don Gagne's avatar
Don Gagne committed
427 428 429 430
            }

            QGCLabel {
                anchors.horizontalCenter: parent.horizontalCenter
431
                text: QGroundControl.appSettingsDistanceUnitsString
Don Gagne's avatar
Don Gagne committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
            }

            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
Don Gagne's avatar
Don Gagne committed
450 451
            minimumValue:       QGroundControl.metersToAppSettingsDistanceUnits(2)
            maximumValue:       QGroundControl.metersToAppSettingsDistanceUnits((_activeVehicle && _activeVehicle.flying) ? 100 : 10)
Don Gagne's avatar
Don Gagne committed
452 453
        }
    }
454
}