FlightDisplayView.qml 16.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

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

31
import QGroundControl               1.0
32 33 34 35
import QGroundControl.FlightMap     1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
36
import QGroundControl.Vehicle       1.0
37
import QGroundControl.Controllers   1.0
38 39 40 41 42

/// Flight Display View
Item {
    id: root

43 44 45 46 47 48 49 50 51 52 53
    // Top margin for all widgets. Used to prevent overlap with the toolbar
    property real   topMargin: 0

    // Used by parent to hide widgets when it displays something above in the z order.
    // Prevents z order drawing problems.
    property bool hideWidgets: false

    readonly property alias zOrderTopMost:   flightMap.zOrderTopMost
    readonly property alias zOrderWidgets:   flightMap.zOrderWidgets
    readonly property alias zOrderMapItems:  flightMap.zOrderMapItems

54 55 56 57
    property var __qgcPal: QGCPalette { colorGroupEnabled: enabled }

    property var _activeVehicle: multiVehicleManager.activeVehicle

58 59 60 61 62 63 64 65
    readonly property var  _defaultVehicleCoordinate:   QtPositioning.coordinate(37.803784, -122.462276)
    readonly property real _defaultRoll:                0
    readonly property real _defaultPitch:               0
    readonly property real _defaultHeading:             0
    readonly property real _defaultAltitudeWGS84:       0
    readonly property real _defaultGroundSpeed:         0
    readonly property real _defaultAirSpeed:            0
    readonly property real _defaultClimbRate:           0
66

Don Gagne's avatar
Don Gagne committed
67 68 69
    readonly property string _mapName:              "FlightDisplayView"
    readonly property string _showMapBackgroundKey: "/showMapBackground"

70 71
    property real _roll:            _activeVehicle ? (isNaN(_activeVehicle.roll) ? _defaultRoll : _activeVehicle.roll) : _defaultRoll
    property real _pitch:           _activeVehicle ? (isNaN(_activeVehicle.pitch) ? _defaultPitch : _activeVehicle.pitch) : _defaultPitch
72 73
    property real _heading:         _activeVehicle ? (isNaN(_activeVehicle.heading) ? _defaultHeading : _activeVehicle.heading) : _defaultHeading

74
    property var  _vehicleCoordinate:   _activeVehicle ? _activeVehicle.coordinate : _defaultVehicleCoordinate
75

76 77 78 79 80
    property real _altitudeWGS84:   _activeVehicle ? _activeVehicle.altitudeWGS84 : _defaultAltitudeWGS84
    property real _groundSpeed:     _activeVehicle ? _activeVehicle.groundSpeed : _defaultGroundSpeed
    property real _airSpeed:        _activeVehicle ? _activeVehicle.airSpeed : _defaultAirSpeed
    property real _climbRate:       _activeVehicle ? _activeVehicle.climbRate : _defaultClimbRate

81
    property bool _showMap: getBool(QGroundControl.flightMapSettings.loadMapSetting(flightMap.mapName, _showMapBackgroundKey, "1"))
Don Gagne's avatar
Don Gagne committed
82

83
    FlightDisplayViewController { id: _controller }
84

Don Gagne's avatar
Don Gagne committed
85 86 87 88
    ExclusiveGroup {
        id: _dropButtonsExclusiveGroup
    }

Don Gagne's avatar
Don Gagne committed
89
    // Validate _showMap setting
90 91 92 93 94 95 96
    Component.onCompleted: {
        // We have to be careful to not reference root properties in a function which is in a subcomponent
        // until the root component has completed loading. Otherwise you get undefined references.
        flightMap.rootLoadCompleted = true
        flightMap.updateMapPosition(true /* force */)
        _setShowMap(_showMap)
    }
Don Gagne's avatar
Don Gagne committed
97

98 99 100 101 102 103 104 105
    function getBool(value) {
        return value === '0' ? false : true;
    }

    function setBool(value) {
        return value ? "1" : "0";
    }

Don Gagne's avatar
Don Gagne committed
106
    function _setShowMap(showMap) {
107
        _showMap = _controller.hasVideo ? showMap : true
108
        QGroundControl.flightMapSettings.saveMapSetting(flightMap.mapName, _showMapBackgroundKey, setBool(_showMap))
Don Gagne's avatar
Don Gagne committed
109 110
    }

111

112
    FlightMap {
Don Gagne's avatar
Don Gagne committed
113 114
        id:             flightMap
        anchors.fill:   parent
Don Gagne's avatar
Don Gagne committed
115
        mapName:        _mapName
Don Gagne's avatar
Don Gagne committed
116
        visible:        _showMap
117 118
        latitude:       root._defaultCoordinate.latitude
        longitude:      root._defaultCoordinate.longitude
119

120 121
        property var rootVehicleCoordinate: _vehicleCoordinate
        property bool rootLoadCompleted: false
Don Gagne's avatar
Don Gagne committed
122

123
        onRootVehicleCoordinateChanged: updateMapPosition(false /* force */)
Don Gagne's avatar
Don Gagne committed
124 125

        function updateMapPosition(force) {
126 127 128
            if ((_followVehicle || force) && rootLoadCompleted) {
                flightMap.latitude = root._vehicleCoordinate.latitude
                flightMap.longitude = root._vehicleCoordinate.longitude
Don Gagne's avatar
Don Gagne committed
129 130 131 132 133
            }
        }

        property bool _followVehicle: true

134 135 136 137 138
        // Home position
        MissionItemIndicator {
            label:          "H"
            coordinate:     (_activeVehicle && _activeVehicle.homePositionAvailable) ? _activeVehicle.homePosition : QtPositioning.coordinate(0, 0)
            visible:        _activeVehicle ? _activeVehicle.homePositionAvailable : false
139
            z:              flightMap.zOrderMapItems
140 141
        }

142 143 144 145 146 147 148 149
        // Add trajectory points to the map
        MapItemView {
            model: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.trajectoryPoints : 0
            
            delegate:
                MapPolyline {
                    line.width: 3
                    line.color: "orange"
150 151
                    z:          flightMap.zOrderMapItems - 1

152 153 154 155 156 157 158 159

                    path: [
                        { latitude: object.coordinate1.latitude, longitude: object.coordinate1.longitude },
                        { latitude: object.coordinate2.latitude, longitude: object.coordinate2.longitude },
                    ]
                }
        }

160 161 162 163 164 165
        // Add the vehicles to the map
        MapItemView {
            model: multiVehicleManager.vehicles
            
            delegate:
                VehicleMapItem {
166
                        vehicle:        object
167
                        coordinate:     object.coordinate
168
                        isSatellite:    flightMap.isSatelliteMap
169
                        z:              flightMap.zOrderMapItems
170 171 172 173 174 175 176 177
                }
        }

        // Add the mission items to the map
        MapItemView {
            model: multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.missionItems : 0
            
            delegate:
Don Gagne's avatar
Don Gagne committed
178 179 180 181
                MissionItemIndicator {
                    label:          object.sequenceNumber
                    isCurrentItem:  object.isCurrentItem
                    coordinate:     object.coordinate
182
                    z:              flightMap.zOrderMapItems
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
                }
        }

        // Vehicle GPS lock display
        Column {
            id:     gpsLockColumn
            y:      (parent.height - height) / 2
            width:  parent.width

            Repeater {
                model: multiVehicleManager.vehicles
                
                delegate:
                    QGCLabel {
                        width:                  gpsLockColumn.width
                        horizontalAlignment:    Text.AlignHCenter
                        visible:                object.satelliteLock < 2
                        text:                   "No GPS Lock for Vehicle #" + object.id
201
                        z:                      flightMap.zOrderMapItems - 2
202 203 204 205
                    }
            }
        }

Don Gagne's avatar
Don Gagne committed
206
        QGCCompassWidget {
207 208
            anchors.leftMargin: ScreenTools.defaultFontPixelHeight
            anchors.topMargin:  topMargin
Don Gagne's avatar
Don Gagne committed
209 210 211 212 213
            anchors.left:       parent.left
            anchors.top:        parent.top
            size:               ScreenTools.defaultFontPixelSize * (13.3)
            heading:            _heading
            active:             multiVehicleManager.activeVehicleAvailable
214
            z:                  flightMap.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
215
        }
216

Don Gagne's avatar
Don Gagne committed
217
        QGCAttitudeWidget {
Don Gagne's avatar
Don Gagne committed
218 219 220 221 222 223 224
            anchors.margins:    ScreenTools.defaultFontPixelHeight
            anchors.left:       parent.left
            anchors.bottom:     parent.bottom
            size:               ScreenTools.defaultFontPixelSize * (13.3)
            rollAngle:          _roll
            pitchAngle:         _pitch
            active:             multiVehicleManager.activeVehicleAvailable
225
            z:                  flightMap.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
226 227 228 229 230 231 232 233 234 235 236
        }

        DropButton {
            id:                     centerMapDropButton
            anchors.rightMargin:    ScreenTools.defaultFontPixelHeight
            anchors.right:          mapTypeButton.left
            anchors.top:            mapTypeButton.top
            dropDirection:          dropDown
            buttonImage:            "/qmlimages/MapCenter.svg"
            viewportMargins:        ScreenTools.defaultFontPixelWidth / 2
            exclusiveGroup:         _dropButtonsExclusiveGroup
237
            z:                      flightMap.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269

            dropDownComponent: Component {
                Row {
                    spacing: ScreenTools.defaultFontPixelWidth

                    QGCCheckBox {
                        id:                 followVehicleCheckBox
                        text:               "Follow Vehicle"
                        checked:            flightMap._followVehicle
                        anchors.baseline:   centerMapButton.baseline

                        onClicked: {
                            centerMapDropButton.hideDropDown()
                            flightMap._followVehicle = !flightMap._followVehicle
                        }
                    }

                    QGCButton {
                        id:         centerMapButton
                        text:       "Center map on Vehicle"
                        enabled:    _activeVehicle && !followVehicleCheckBox.checked

                        property var activeVehicle: multiVehicleManager.activeVehicle

                        onClicked: {
                            centerMapDropButton.hideDropDown()
                            flightMap.latitude = activeVehicle.latitude
                            flightMap.longitude = activeVehicle.longitude
                        }
                    }
                }
            }
Don Gagne's avatar
Don Gagne committed
270
        }
271 272

        DropButton {
273 274 275 276 277 278 279 280 281 282
            id:                     mapTypeButton
            anchors.topMargin:      topMargin
            anchors.rightMargin:    ScreenTools.defaultFontPixelHeight
            anchors.top:            parent.top
            anchors.right:          parent.right
            dropDirection:          dropDown
            buttonImage:            "/qmlimages/MapType.svg"
            viewportMargins:        ScreenTools.defaultFontPixelWidth / 2
            exclusiveGroup:         _dropButtonsExclusiveGroup
            z:                      flightMap.zOrderWidgets
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305

            dropDownComponent: Component {
                Row {
                    spacing: ScreenTools.defaultFontPixelWidth

                    Repeater {
                        model: QGroundControl.flightMapSettings.mapTypes

                        QGCButton {
                            checkable:  true
                            checked:    flightMap.mapType == text
                            text:       modelData

                            onClicked: {
                                flightMap.mapType = text
                                mapTypeButton.hideDropDown()
                            }
                        }
                    }
                }
            }
        }

Don Gagne's avatar
Don Gagne committed
306 307 308 309
    } // Flight Map

    QGCVideoBackground {
        anchors.fill:   parent
310 311
        display:        _controller.videoSurface
        receiver:       _controller.videoReceiver
Don Gagne's avatar
Don Gagne committed
312 313 314 315 316 317 318 319
        visible:        !_showMap

        QGCCompassHUD {
            id:                 compassHUD
            y:                  root.height * 0.7
            x:                  root.width  * 0.5 - ScreenTools.defaultFontPixelSize * (5)
            width:              ScreenTools.defaultFontPixelSize * (10)
            height:             ScreenTools.defaultFontPixelSize * (10)
Don Gagne's avatar
Don Gagne committed
320
            heading:            _heading
Don Gagne's avatar
Don Gagne committed
321
            active:             multiVehicleManager.activeVehicleAvailable
322
            z:                  flightMap.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
323
        }
324

Don Gagne's avatar
Don Gagne committed
325 326 327 328 329 330 331
        QGCAttitudeHUD {
            id:                 attitudeHUD
            rollAngle:          _roll
            pitchAngle:         _pitch
            width:              ScreenTools.defaultFontPixelSize * (30)
            height:             ScreenTools.defaultFontPixelSize * (30)
            active:             multiVehicleManager.activeVehicleAvailable
332
            z:                  flightMap.zOrderWidgets
Don Gagne's avatar
Don Gagne committed
333
        }
334 335 336 337 338 339
    }

    QGCAltitudeWidget {
        anchors.right:  parent.right
        height:         parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
        width:          ScreenTools.defaultFontPixelSize * (5)
Don Gagne's avatar
Don Gagne committed
340
        altitude:       _altitudeWGS84
341 342
        z:              flightMap.zOrderWidgets
        visible:        !hideWidgets
343 344 345 346 347 348
    }

    QGCSpeedWidget {
        anchors.left:   parent.left
        width:          ScreenTools.defaultFontPixelSize * (5)
        height:         parent.height * 0.65 > ScreenTools.defaultFontPixelSize * (23.4) ? ScreenTools.defaultFontPixelSize * (23.4) : parent.height * 0.65
Don Gagne's avatar
Don Gagne committed
349
        speed:          _groundSpeed
350 351
        z:              flightMap.zOrderWidgets
        visible:        !hideWidgets
352 353 354 355 356
    }

    QGCCurrentSpeed {
        anchors.left:       parent.left
        width:              ScreenTools.defaultFontPixelSize * (6.25)
Don Gagne's avatar
Don Gagne committed
357 358
        airspeed:           _airSpeed
        groundspeed:        _groundSpeed
359
        active:             multiVehicleManager.activeVehicleAvailable
360 361
        z:                  flightMap.zOrderWidgets
        visible:             !hideWidgets
362 363 364 365 366
    }

    QGCCurrentAltitude {
        anchors.right:      parent.right
        width:              ScreenTools.defaultFontPixelSize * (6.25)
Don Gagne's avatar
Don Gagne committed
367 368
        altitude:           _altitudeWGS84
        vertZ:              _climbRate
369
        active:             multiVehicleManager.activeVehicleAvailable
370 371
        z:                  flightMap.zOrderWidgets
        visible:              !hideWidgets
372
    }
Don Gagne's avatar
Don Gagne committed
373 374 375 376 377 378 379 380 381 382 383 384 385

    // Mission item list
    ListView {
        id:                 missionItemSummaryList
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        anchors.left:       parent.left
        anchors.right:      optionsButton.left
        anchors.bottom:     parent.bottom
        height:             ScreenTools.defaultFontPixelHeight * 7
        spacing:            ScreenTools.defaultFontPixelWidth / 2
        opacity:            0.75
        orientation:        ListView.Horizontal
        model:              multiVehicleManager.activeVehicle ? multiVehicleManager.activeVehicle.missionItems : 0
386 387
        z:                  flightMap.zOrderWidgets
        visible:            !hideWidgets
Don Gagne's avatar
Don Gagne committed
388 389 390 391 392 393 394 395 396 397 398 399

        property real _maxItemHeight: 0

        delegate:
            MissionItemSummary {
                opacity:        0.75
                missionItem:    object
            }
    } // ListView - Mission item list


    QGCButton {
400 401 402 403 404 405 406 407
        id:         optionsButton
        x:          flightMap.mapWidgets.x
        y:          flightMap.mapWidgets.y - height - (ScreenTools.defaultFontPixelHeight / 2)
        z:          flightMap.zOrderWidgets
        width:      flightMap.mapWidgets.width
        text:       "Options"
        menu:       optionsMenu
        visible:    _controller.hasVideo && !hideWidgets
Don Gagne's avatar
Don Gagne committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422

        ExclusiveGroup {
            id: backgroundTypeGroup
        }

        Menu {
            id: optionsMenu

            MenuItem {
                id:             mapBackgroundMenuItem
                exclusiveGroup: backgroundTypeGroup
                checkable:      true
                checked:        _showMap
                text:           "Show map as background"

Don Gagne's avatar
Don Gagne committed
423
                onTriggered:    _setShowMap(true)
Don Gagne's avatar
Don Gagne committed
424 425 426 427 428 429 430 431 432
            }

            MenuItem {
                id:             videoBackgroundMenuItem
                exclusiveGroup: backgroundTypeGroup
                checkable:      true
                checked:        !_showMap
                text:           "Show video as background"

Don Gagne's avatar
Don Gagne committed
433
                onTriggered:    _setShowMap(false)
Don Gagne's avatar
Don Gagne committed
434 435 436
            }
        }
    }
437
}