FlightDisplayView.qml 13.3 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10
import QtQuick                  2.12
11 12
import QtQuick.Controls         2.4
import QtQuick.Dialogs          1.3
13
import QtQuick.Layouts          1.12
14

15 16
import QtLocation               5.3
import QtPositioning            5.3
Patrick José Pereira's avatar
Patrick José Pereira committed
17
import QtQuick.Window           2.2
18
import QtQml.Models             2.1
19

20
import QGroundControl               1.0
21 22 23 24
import QGroundControl.Airspace      1.0
import QGroundControl.Controllers   1.0
import QGroundControl.Controls      1.0
import QGroundControl.FactSystem    1.0
Don Gagne's avatar
Don Gagne committed
25
import QGroundControl.FlightDisplay 1.0
26 27
import QGroundControl.FlightMap     1.0
import QGroundControl.Palette       1.0
28
import QGroundControl.ScreenTools   1.0
29
import QGroundControl.Vehicle       1.0
30 31

/// Flight Display View
32
Item {
33

Gus Grubba's avatar
Gus Grubba committed
34
    PlanMasterController {
Gus Grubba's avatar
Gus Grubba committed
35 36 37 38 39
        id: _planController
        Component.onCompleted: {
            start(true /* flyView */)
            mainWindow.planMasterControllerView = _planController
        }
Gus Grubba's avatar
Gus Grubba committed
40 41
    }

42 43 44 45 46 47 48 49 50 51 52 53
    property bool   _mainWindowIsMap:       mapControl.pipState.state === mapControl.pipState.fullState
    property bool   _isMapDark:             _mainWindowIsMap ? mapControl.isSatelliteMap : true
    property var    _activeVehicle:         QGroundControl.multiVehicleManager.activeVehicle
    property var    _missionController:     _planController.missionController
    property var    _geoFenceController:    _planController.geoFenceController
    property var    _rallyPointController:  _planController.rallyPointController
    property real   _margins:               ScreenTools.defaultFontPixelWidth / 2
    property alias  _guidedController:      guidedActionsController
    property alias  _guidedConfirm:         guidedActionConfirm
    property alias  _guidedList:            guidedActionList
    property alias  _guidedSlider:          altitudeSlider
    property real   _toolsMargin:           ScreenTools.defaultFontPixelWidth * 0.75
54

55
    readonly property string _mapName:              "FlightDisplayView"
Don Gagne's avatar
Don Gagne committed
56

57 58 59
    function setPipVisibility(state) {
        _isPipVisible = state;
        QGroundControl.saveBoolGlobalSetting(_PIPVisibleKey, state)
60 61
    }

Gus Grubba's avatar
Gus Grubba committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75
    function isInstrumentRight() {
        if(QGroundControl.corePlugin.options.instrumentWidget) {
            if(QGroundControl.corePlugin.options.instrumentWidget.source.toString().length) {
                switch(QGroundControl.corePlugin.options.instrumentWidget.widgetPosition) {
                case CustomInstrumentWidget.POS_TOP_LEFT:
                case CustomInstrumentWidget.POS_BOTTOM_LEFT:
                case CustomInstrumentWidget.POS_CENTER_LEFT:
                    return false;
                }
            }
        }
        return true;
    }

76
    Component.onCompleted: {
77 78 79
        if(QGroundControl.corePlugin.options.flyViewOverlay.toString().length) {
            flyViewOverlay.source = QGroundControl.corePlugin.options.flyViewOverlay
        }
80 81
    }

82 83 84 85 86
    FlyViewMissionCompleteDialog {
        missionController:      _missionController
        geoFenceController:     _geoFenceController
        rallyPointController:   _rallyPointController
        guidedController:       _guidedController
87 88
    }

89
    QGCMapPalette { id: mapPal; lightColors: _mainWindowIsMap ? mapControl.isSatelliteMap : true }
90

91
    Item {
92
        id:             _mapAndVideo
93
        anchors.fill:   parent
94

95 96 97 98 99 100 101 102 103 104 105 106 107 108
        FlightDisplayViewMap {
            id:                         mapControl
            guidedActionsController:    _guidedController
            planMasterController:       _planController
            flightWidgets:              flightDisplayViewWidgets
            rightPanelWidth:            ScreenTools.defaultFontPixelHeight * 9
            scaleState:                 (_mainWindowIsMap && flyViewOverlay.item) ? (flyViewOverlay.item.scaleState ? flyViewOverlay.item.scaleState : "bottomMode") : "bottomMode"
            mainWindowIsMap:            _mainWindowIsMap

            property var pipState: mapPipState
            QGCPipState {
                id:         mapPipState
                pipOverlay: _pipOverlay
                isDark:     _isMapDark
109
            }
110
        }
111

112
        //-- Video View
113
        Item {
114 115 116 117 118 119 120 121 122 123 124 125 126
            id:         videoControl
            visible:    QGroundControl.videoManager.hasVideo

            property var pipState: videoPipState
            QGCPipState {
                id:         videoPipState
                pipOverlay: _pipOverlay
                isDark:     true

                onWindowAboutToOpen: {
                    console.log("about to open")
                    QGroundControl.videoManager.stopVideo()
                    videoStartDelay.start()
127 128
                }

129 130 131 132
                onWindowAboutToClose: {
                    console.log("about to close")
                    QGroundControl.videoManager.stopVideo()
                    videoStartDelay.start()
133
                }
134 135 136 137 138 139 140 141 142 143
            }

            Timer {
              id:           videoStartDelay
              interval:     2000;
              running:      false
              repeat:       false
              onTriggered:  QGroundControl.videoManager.startVideo()
            }

144
            //-- Video Streaming
145
            FlightDisplayViewVideo {
Patrick José Pereira's avatar
Patrick José Pereira committed
146
                id:             videoStreaming
147
                anchors.fill:   parent
148
                useSmallFont:   videoControl.pipState.state !== videoControl.pipState.fullState
149 150 151
                visible:        QGroundControl.videoManager.isGStreamer
            }
            //-- UVC Video (USB Camera or Video Device)
152 153
            Loader {
                id:             cameraLoader
154 155
                anchors.fill:   parent
                visible:        !QGroundControl.videoManager.isGStreamer
156
                source:         visible ? (QGroundControl.videoManager.uvcEnabled ? "qrc:/qml/FlightDisplayViewUVC.qml" : "qrc:/qml/FlightDisplayViewDummy.qml") : ""
157
            }
dogmaphobic's avatar
dogmaphobic committed
158
        }
159

160 161 162 163 164 165 166 167 168 169
        QGCPipOverlay {
            id:                     _pipOverlay
            anchors.left:           parent.left
            anchors.bottom:         parent.bottom
            anchors.margins:        ScreenTools.defaultFontPixelHeight
            item1IsFullSettingsKey: "MainFlyWindowIsMap"
            item1:                  mapControl
            item2:                  QGroundControl.videoManager.hasVideo ? videoControl : null
            fullZOrder:             0
            pipZOrder:              QGroundControl.zOrderWidgets
dogmaphobic's avatar
dogmaphobic committed
170
        }
Don Gagne's avatar
Don Gagne committed
171

172 173 174 175 176
        MultiVehiclePanel {
            id:                         singleMultiSelector
            anchors.margins:            _toolsMargin
            anchors.top:                parent.top
            anchors.right:              parent.right
177
            z:                          QGroundControl.zOrderWidgets
178 179
            availableHeight:            mainWindow.availableHeight - (anchors.margins * 2)
            guidedActionsController:    _guidedController
180 181
        }

182
        FlightDisplayViewWidgets {
183
            id:                 flightDisplayViewWidgets
184
            z:                  QGroundControl.zOrderWidgets
185
            height:             availableHeight - (singleMultiSelector.visible ? singleMultiSelector.height + _toolsMargin : 0) - _toolsMargin
186
            anchors.left:       parent.left
187
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
188
            anchors.bottom:     parent.bottom
189
            anchors.top:        singleMultiSelector.visible? singleMultiSelector.bottom : undefined
190
            useLightColors:     _isMapDark
191
            missionController:  _missionController
192
            visible:            singleMultiSelector.singleVehiclePanel && !QGroundControl.videoManager.fullScreen
193 194
        }

195 196 197 198
        //-------------------------------------------------------------------------
        //-- Loader helper for plugins to overlay elements over the fly view
        Loader {
            id:                 flyViewOverlay
199
            z:                  QGroundControl.zOrderWidgets
200
            visible:            !QGroundControl.videoManager.fullScreen
201
            height:             mainWindow.height - mainWindow.header.height
202 203 204 205 206
            anchors.left:       parent.left
            anchors.right:      altitudeSlider.visible ? altitudeSlider.left : parent.right
            anchors.bottom:     parent.bottom
        }

207
        //-- Virtual Joystick
208
        Loader {
209
            id:                         virtualJoystickMultiTouch
210 211
            z:                          QGroundControl.zOrderTopMost + 1
            width:                      parent.width  - (_pipOverlay.width / 2)
212
            height:                     Math.min(mainWindow.height * 0.25, ScreenTools.defaultFontPixelWidth * 16)
213
            visible:                    (_virtualJoystick ? _virtualJoystick.value : false) && !QGroundControl.videoManager.fullScreen && !(_activeVehicle ? _activeVehicle.highLatencyLink : false)
214
            anchors.bottom:             _pipOverlay.top
215
            anchors.bottomMargin:       ScreenTools.defaultFontPixelHeight * 2
216
            anchors.horizontalCenter:   flightDisplayViewWidgets.horizontalCenter
217
            source:                     "qrc:/qml/VirtualJoystick.qml"
218
            active:                     (_virtualJoystick ? _virtualJoystick.value : false) && !(_activeVehicle ? _activeVehicle.highLatencyLink : false)
Don Gagne's avatar
Don Gagne committed
219

220
            property bool useLightColors: _isMapDark
221 222
            // The default behaviour is not centralized throttle
            property bool centralizeThrottle: _virtualJoystickCentralized ? _virtualJoystickCentralized.value : false
223

224 225
            property Fact _virtualJoystick:             QGroundControl.settingsManager.appSettings.virtualJoystick
            property Fact _virtualJoystickCentralized:  QGroundControl.settingsManager.appSettings.virtualJoystickCentralized
Don Gagne's avatar
Don Gagne committed
226
        }
227

228 229 230 231 232 233 234 235
        FlyViewToolStrip {
            id:                         toolStrip
            anchors.leftMargin:         isInstrumentRight() ? _toolsMargin : undefined
            anchors.left:               isInstrumentRight() ? _mapAndVideo.left : undefined
            anchors.rightMargin:        isInstrumentRight() ? undefined : ScreenTools.defaultFontPixelWidth
            anchors.right:              isInstrumentRight() ? undefined : _mapAndVideo.right
            anchors.topMargin:          _toolsMargin
            anchors.top:                parent.top
236 237
            z:                          QGroundControl.zOrderWidgets
            maxHeight:                  parent.height - toolStrip.y + (_pipOverlay.visible ? (_pipOverlay.y - parent.height) : 0)
238 239
            guidedActionsController:    _guidedController
            guidedActionList:           _guidedList
240 241 242 243
            usePreFlightChecklist:      preFlightChecklistPopup.useChecklist
            visible:                    (_activeVehicle ? _activeVehicle.guidedModeSupported : true) && !QGroundControl.videoManager.fullScreen

            onDisplayPreFlightChecklist: preFlightChecklistPopup.open()
244 245 246
        }

        GuidedActionsController {
247
            id:                 guidedActionsController
248
            missionController:  _missionController
249 250 251
            confirmDialog:      _guidedConfirm
            actionList:         _guidedList
            altitudeSlider:     _guidedSlider
252 253
        }

254
        GuidedActionConfirm {
255 256 257 258
            id:                         guidedActionConfirm
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
259
            z:                          QGroundControl.zOrderTopMost
260
            guidedController:           _guidedController
261
            altitudeSlider:             _guidedSlider
262 263
        }

264
        GuidedActionList {
265 266 267 268
            id:                         guidedActionList
            anchors.margins:            _margins
            anchors.bottom:             parent.bottom
            anchors.horizontalCenter:   parent.horizontalCenter
269
            z:                          QGroundControl.zOrderTopMost
270
            guidedController:           _guidedController
271 272 273
        }

        //-- Altitude slider
DonLakeFlyer's avatar
DonLakeFlyer committed
274
        GuidedAltitudeSlider {
275 276 277 278 279 280
            id:                 altitudeSlider
            anchors.margins:    _margins
            anchors.right:      parent.right
            anchors.topMargin:  ScreenTools.toolbarHeight + _margins
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
281
            z:                  QGroundControl.zOrderTopMost
282 283 284 285 286
            radius:             ScreenTools.defaultFontPixelWidth / 2
            width:              ScreenTools.defaultFontPixelWidth * 10
            color:              qgcPal.window
            visible:            false
        }
Don Gagne's avatar
Don Gagne committed
287
    }
288

289 290 291 292
    FlyViewAirspaceIndicator {
        anchors.top:                parent.top
        anchors.topMargin:          ScreenTools.defaultFontPixelHeight * 0.25
        anchors.horizontalCenter:   parent.horizontalCenter
293
        show:                       _mainWindowIsMap
294 295
    }

296 297 298 299
    FlyViewPreFlightChecklistPopup {
        id: preFlightChecklistPopup
        x:  toolStrip.x + toolStrip.width + (ScreenTools.defaultFontPixelWidth * 2)
        y:  toolStrip.y
300
    }
301
}