PlanToolBar.qml 14.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import QtQuick          2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts  1.2
import QtQuick.Dialogs  1.2

import QGroundControl                   1.0
import QGroundControl.ScreenTools       1.0
import QGroundControl.Controls          1.0
import QGroundControl.FactControls      1.0
import QGroundControl.Palette           1.0

// Toolbar for Plan View
Rectangle {
    id:                 _root
    height:             ScreenTools.toolbarHeight
    anchors.left:       parent.left
    anchors.right:      parent.right
    anchors.top:        parent.top
    z:                  toolBar.z + 1
Gus Grubba's avatar
Gus Grubba committed
20
    color:              qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.8) : Qt.rgba(0,0,0,0.75)
21
    visible:            false
22
    anchors.bottomMargin: 1
23 24 25

    signal showFlyView

26
    property var    planMasterController
27 28
    property var    currentMissionItem          ///< Mission item to display status for

29 30 31 32 33
    property var    missionItems:               _controllerValid ? planMasterController.missionController.visualItems : undefined
    property real   missionDistance:            _controllerValid ? planMasterController.missionController.missionDistance : NaN
    property real   missionTime:                _controllerValid ? planMasterController.missionController.missionTime : NaN
    property real   missionMaxTelemetry:        _controllerValid ? planMasterController.missionController.missionMaxTelemetry : NaN
    property bool   missionDirty:               _controllerValid ? planMasterController.missionController.dirty : false
34

35
    property bool   _controllerValid:           planMasterController !== undefined
DonLakeFlyer's avatar
DonLakeFlyer committed
36 37 38
    property bool   _controllerOffline:         _controllerValid ? planMasterController.offline : true
    property var    _controllerDirty:           _controllerValid ? planMasterController.dirty : false
    property var    _controllerSyncInProgress:  _controllerValid ? planMasterController.syncInProgress : false
39

40 41
    property bool   _statusValid:               currentMissionItem !== undefined
    property bool   _missionValid:              missionItems !== undefined
42

43
    property real   _dataFontSize:              ScreenTools.defaultFontPointSize
44
    property real   _largeValueWidth:           ScreenTools.defaultFontPixelWidth * 8
45 46
    property real   _mediumValueWidth:          ScreenTools.defaultFontPixelWidth * 4
    property real   _smallValueWidth:           ScreenTools.defaultFontPixelWidth * 3
47
    property real   _labelToValueSpacing:       ScreenTools.defaultFontPixelWidth
48
    property real   _rowSpacing:                ScreenTools.isMobile ? 1 : 0
49 50 51 52 53
    property real   _distance:                  _statusValid ? currentMissionItem.distance : NaN
    property real   _altDifference:             _statusValid ? currentMissionItem.altDifference : NaN
    property real   _gradient:                  _statusValid && currentMissionItem.distance > 0 ? Math.atan(currentMissionItem.altDifference / currentMissionItem.distance) : NaN
    property real   _gradientPercent:           isNaN(_gradient) ? NaN : _gradient * 100
    property real   _azimuth:                   _statusValid ? currentMissionItem.azimuth : NaN
54
    property real   _heading:                   _statusValid ? currentMissionItem.missionVehicleYaw : NaN
55 56 57
    property real   _missionDistance:           _missionValid ? missionDistance : NaN
    property real   _missionMaxTelemetry:       _missionValid ? missionMaxTelemetry : NaN
    property real   _missionTime:               _missionValid ? missionTime : NaN
58 59
    property int    _batteryChangePoint:        _controllerValid ? planMasterController.missionController.batteryChangePoint : -1
    property int    _batteriesRequired:         _controllerValid ? planMasterController.missionController.batteriesRequired : -1
60
    property bool   _batteryInfoAvailable:      _batteryChangePoint >= 0 || _batteriesRequired >= 0
61 62
    property real   _controllerProgressPct:     _controllerValid ? planMasterController.missionController.progressPct : 0
    property bool   _syncInProgress:            _controllerValid ? planMasterController.missionController.syncInProgress : false
63 64 65

    property string _distanceText:              isNaN(_distance) ?              "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_distance).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
    property string _altDifferenceText:         isNaN(_altDifference) ?         "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_altDifference).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
66
    property string _gradientText:              isNaN(_gradient) ?              "-.-" : _gradientPercent.toFixed(0) + " %"
67 68
    property string _azimuthText:               isNaN(_azimuth) ?               "-.-" : Math.round(_azimuth) % 360
    property string _headingText:               isNaN(_azimuth) ?               "-.-" : Math.round(_heading) % 360
69 70
    property string _missionDistanceText:       isNaN(_missionDistance) ?       "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_missionDistance).toFixed(0) + " " + QGroundControl.appSettingsDistanceUnitsString
    property string _missionMaxTelemetryText:   isNaN(_missionMaxTelemetry) ?   "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_missionMaxTelemetry).toFixed(0) + " " + QGroundControl.appSettingsDistanceUnitsString
71 72
    property string _batteryChangePointText:    _batteryChangePoint < 0 ?       "N/A" : _batteryChangePoint
    property string _batteriesRequiredText:     _batteriesRequired < 0 ?        "N/A" : _batteriesRequired
73

Donald Gagne's avatar
Donald Gagne committed
74
    readonly property real _margins: ScreenTools.defaultFontPixelWidth
75 76 77

    QGCPalette { id: qgcPal }

78 79 80 81 82 83 84 85
    function getMissionTime() {
        if(isNaN(_missionTime)) {
            return "00:00:00"
        }
        var t = new Date(0, 0, 0, 0, 0, Number(_missionTime))
        return Qt.formatTime(t, 'hh:mm:ss')
    }

Gus Grubba's avatar
Gus Grubba committed
86 87 88 89 90 91 92 93
    //-- Eat mouse events, preventing them from reaching toolbar, which is underneath us.
    MouseArea {
        anchors.fill:   parent
        onWheel:        { wheel.accepted = true; }
        onPressed:      { mouse.accepted = true; }
        onReleased:     { mouse.accepted = true; }
    }

94 95
    //-- The reason for this Row to be here is so the Logo (Home) button is in the same
    //   location as the one in the main toolbar.
96
    Row {
97
        id:                     logoRow
98 99 100 101
        anchors.bottomMargin:   1
        anchors.left:           parent.left
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
102 103 104 105 106 107 108 109 110
        QGCToolBarButton {
            id:                 settingsButton
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            source:             "/qmlimages/PaperPlane.svg"
            logo:               true
            checked:            false
            onClicked: {
                checked = false
111
                showFlyView()
112 113
            }
        }
114 115
    }

116 117 118 119
    // Progress bar

    on_ControllerProgressPctChanged: {
        if (_controllerProgressPct === 1) {
120 121
            missionStats.visible = false
            uploadCompleteText.visible = true
122 123 124 125 126 127 128 129
            resetProgressTimer.start()
        } else if (_controllerProgressPct > 0) {
            progressBar.visible = true
        }
    }

    Timer {
        id:             resetProgressTimer
130 131 132 133 134 135
        interval:       5000
        onTriggered: {
            missionStats.visible = true
            uploadCompleteText.visible = false
            progressBar.visible = false
        }
136 137 138 139 140 141
    }

    Rectangle {
        id:             progressBar
        anchors.left:   parent.left
        anchors.bottom: parent.bottom
142
        height:         4
143 144 145 146 147
        width:          _controllerProgressPct * parent.width
        color:          qgcPal.colorGreen
        visible:        false
    }

148 149 150 151 152 153 154 155 156 157 158 159 160
    QGCLabel {
        id:                     uploadCompleteText
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
        anchors.left:           logoRow.right
        anchors.right:          uploadButton.left
        font.pointSize:         ScreenTools.largeFontPointSize
        horizontalAlignment:    Text.AlignHCenter
        verticalAlignment:      Text.AlignVCenter
        text:                   "Done"
        visible:                false
    }

161
    GridLayout {
162 163 164
        id:                     missionStats
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
165 166
        anchors.leftMargin:     _margins
        anchors.rightMargin:    _margins
167 168
        anchors.left:           logoRow.right
        anchors.right:          uploadButton.visible ? uploadButton.left : parent.right
169 170
        columnSpacing:          0
        columns:                3
171 172

        GridLayout {
173
            anchors.verticalCenter: parent.verticalCenter
174
            columns:                8
175
            rowSpacing:             _rowSpacing
176
            columnSpacing:          _labelToValueSpacing
177
            Layout.alignment:       Qt.AlignHCenter
178 179

            QGCLabel {
180
                text:               qsTr("Selected Waypoint")
181
                Layout.columnSpan:  8
Donald Gagne's avatar
Donald Gagne committed
182
                font.pointSize:     ScreenTools.smallFontPointSize
183 184
            }

185
            QGCLabel { text: qsTr("Alt diff:"); font.pointSize: _dataFontSize; }
186
            QGCLabel {
187
                text:                   _altDifferenceText
188
                font.pointSize:         _dataFontSize
189
                Layout.minimumWidth:    _mediumValueWidth
190
            }
191

Donald Gagne's avatar
Donald Gagne committed
192 193
            Item { width: 1; height: 1 }

194
            QGCLabel { text: qsTr("Azimuth:"); font.pointSize: _dataFontSize; }
195
            QGCLabel {
196
                text:                   _azimuthText
197
                font.pointSize:         _dataFontSize
198 199
                Layout.minimumWidth:    _smallValueWidth
            }
200

201 202 203
            Item { width: 1; height: 1 }

            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
204
            QGCLabel {
205
                text:                   _distanceText
206
                font.pointSize:         _dataFontSize
207
                Layout.minimumWidth:    _largeValueWidth
208 209 210 211 212 213 214
            }

            QGCLabel { text: qsTr("Gradient:"); font.pointSize: _dataFontSize; }
            QGCLabel {
                text:                   _gradientText
                font.pointSize:         _dataFontSize
                Layout.minimumWidth:    _mediumValueWidth
215
            }
216

Donald Gagne's avatar
Donald Gagne committed
217 218
            Item { width: 1; height: 1 }

219
            QGCLabel { text: qsTr("Heading:"); font.pointSize: _dataFontSize; }
220
            QGCLabel {
221
                text:                   _headingText
222
                font.pointSize:         _dataFontSize
223 224
                Layout.minimumWidth:    _smallValueWidth
            }
225 226 227
        }

        GridLayout {
228 229
            anchors.verticalCenter: parent.verticalCenter
            columns:                5
230
            rowSpacing:             _rowSpacing
231
            columnSpacing:          _labelToValueSpacing
232
            Layout.alignment:       Qt.AlignHCenter
233 234

            QGCLabel {
235
                text:               qsTr("Total Mission")
Donald Gagne's avatar
Donald Gagne committed
236 237
                Layout.columnSpan:  5
                font.pointSize:     ScreenTools.smallFontPointSize
238 239
            }

240
            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
241 242
            QGCLabel {
                text:                   _missionDistanceText
243
                font.pointSize:         _dataFontSize
244 245
                Layout.minimumWidth:    _largeValueWidth
            }
246

Donald Gagne's avatar
Donald Gagne committed
247 248
            Item { width: 1; height: 1 }

249
            QGCLabel { text: qsTr("Max telem dist:"); font.pointSize: _dataFontSize; }
250 251
            QGCLabel {
                text:                   _missionMaxTelemetryText
252
                font.pointSize:         _dataFontSize
253 254
                Layout.minimumWidth:    _largeValueWidth
            }
255

256
            QGCLabel { text: qsTr("Time:"); font.pointSize: _dataFontSize; }
257
            QGCLabel {
258 259
                text:                   getMissionTime()
                font.pointSize:         _dataFontSize
260 261
                Layout.minimumWidth:    _largeValueWidth
            }
262
        }
Donald Gagne's avatar
Donald Gagne committed
263 264

        GridLayout {
265 266
            anchors.verticalCenter: parent.verticalCenter
            columns:                3
267
            rowSpacing:             _rowSpacing
268
            columnSpacing:          _labelToValueSpacing
269
            Layout.alignment:       Qt.AlignHCenter
270
            visible:                _batteryInfoAvailable
Donald Gagne's avatar
Donald Gagne committed
271 272 273 274 275 276 277

            QGCLabel {
                text:               qsTr("Battery")
                Layout.columnSpan:  3
                font.pointSize:     ScreenTools.smallFontPointSize
            }

278
            QGCLabel { text: qsTr("Batteries required:"); font.pointSize: _dataFontSize; }
279 280
            QGCLabel {
                text:                   _batteriesRequiredText
281
                font.pointSize:         _dataFontSize
282
                Layout.minimumWidth:    _mediumValueWidth
283
            }
Donald Gagne's avatar
Donald Gagne committed
284 285

            Item { width: 1; height: 1 }
286 287
/*
            FIXME: Swap point display is currently hidden since the code which calcs it doesn't work correctly
288
            QGCLabel { text: qsTr("Swap waypoint:"); font.pointSize: _dataFontSize; }
289 290
            QGCLabel {
                text:                   _batteryChangePointText
291
                font.pointSize:         _dataFontSize
292
                Layout.minimumWidth:    _mediumValueWidth
293
            }
294
*/
Donald Gagne's avatar
Donald Gagne committed
295
        }
296
    }
297 298 299 300 301 302

    QGCButton {
        id:                     uploadButton
        anchors.rightMargin:    _margins
        anchors.right:          parent.right
        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
303
        text:                   _controllerDirty ? qsTr("Upload Required") : qsTr("Upload")
304
        enabled:                !_controllerSyncInProgress
305 306
        visible:                !_controllerOffline && !_controllerSyncInProgress && !uploadCompleteText.visible
        primary:                _controllerDirty
307
        onClicked:              planMasterController.upload()
308 309 310 311 312 313

        PropertyAnimation on opacity {
            easing.type:    Easing.OutQuart
            from:           0.5
            to:             1
            loops:          Animation.Infinite
314
            running:        _controllerDirty && !_controllerSyncInProgress
315 316 317
            alwaysRunToEnd: true
            duration:       2000
        }
318
    }
319 320
}