PlanToolBar.qml 15.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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
Gus Grubba's avatar
Gus Grubba committed
15
    color:              qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.8) : Qt.rgba(0,0,0,0.75)
16

17 18
    property var    _planMasterController:      mainWindow.planMasterControllerPlan
    property var    _currentMissionItem:        mainWindow.currentPlanMissionItem          ///< Mission item to display status for
19

Gus Grubba's avatar
Gus Grubba committed
20 21 22 23 24
    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
25

26
    property bool   _controllerValid:           _planMasterController !== undefined && _planMasterController !== null
Gus Grubba's avatar
Gus Grubba committed
27 28 29
    property bool   _controllerOffline:         _controllerValid ? _planMasterController.offline : true
    property var    _controllerDirty:           _controllerValid ? _planMasterController.dirty : false
    property var    _controllerSyncInProgress:  _controllerValid ? _planMasterController.syncInProgress : false
30

31
    property bool   _statusValid:               _currentMissionItem !== undefined && _currentMissionItem !== null
32
    property bool   _missionValid:              missionItems !== undefined
33

34
    property real   _dataFontSize:              ScreenTools.defaultFontPointSize
35
    property real   _largeValueWidth:           ScreenTools.defaultFontPixelWidth * 8
36 37
    property real   _mediumValueWidth:          ScreenTools.defaultFontPixelWidth * 4
    property real   _smallValueWidth:           ScreenTools.defaultFontPixelWidth * 3
38
    property real   _labelToValueSpacing:       ScreenTools.defaultFontPixelWidth
39
    property real   _rowSpacing:                ScreenTools.isMobile ? 1 : 0
Gus Grubba's avatar
Gus Grubba committed
40 41 42
    property real   _distance:                  _statusValid && _currentMissionItem ? _currentMissionItem.distance : NaN
    property real   _altDifference:             _statusValid && _currentMissionItem ? _currentMissionItem.altDifference : NaN
    property real   _gradient:                  _statusValid && _currentMissionItem && _currentMissionItem.distance > 0 ? Math.atan(_currentMissionItem.altDifference / _currentMissionItem.distance) : NaN
43
    property real   _gradientPercent:           isNaN(_gradient) ? NaN : _gradient * 100
Gus Grubba's avatar
Gus Grubba committed
44 45
    property real   _azimuth:                   _statusValid && _currentMissionItem ? _currentMissionItem.azimuth : NaN
    property real   _heading:                   _statusValid && _currentMissionItem ? _currentMissionItem.missionVehicleYaw : NaN
46 47 48
    property real   _missionDistance:           _missionValid ? missionDistance : NaN
    property real   _missionMaxTelemetry:       _missionValid ? missionMaxTelemetry : NaN
    property real   _missionTime:               _missionValid ? missionTime : NaN
Gus Grubba's avatar
Gus Grubba committed
49 50
    property int    _batteryChangePoint:        _controllerValid ? _planMasterController.missionController.batteryChangePoint : -1
    property int    _batteriesRequired:         _controllerValid ? _planMasterController.missionController.batteriesRequired : -1
51
    property bool   _batteryInfoAvailable:      _batteryChangePoint >= 0 || _batteriesRequired >= 0
Gus Grubba's avatar
Gus Grubba committed
52 53
    property real   _controllerProgressPct:     _controllerValid ? _planMasterController.missionController.progressPct : 0
    property bool   _syncInProgress:            _controllerValid ? _planMasterController.missionController.syncInProgress : false
54 55 56

    property string _distanceText:              isNaN(_distance) ?              "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_distance).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
    property string _altDifferenceText:         isNaN(_altDifference) ?         "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_altDifference).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
57
    property string _gradientText:              isNaN(_gradient) ?              "-.-" : _gradientPercent.toFixed(0) + " %"
58 59
    property string _azimuthText:               isNaN(_azimuth) ?               "-.-" : Math.round(_azimuth) % 360
    property string _headingText:               isNaN(_azimuth) ?               "-.-" : Math.round(_heading) % 360
60 61
    property string _missionDistanceText:       isNaN(_missionDistance) ?       "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_missionDistance).toFixed(0) + " " + QGroundControl.appSettingsDistanceUnitsString
    property string _missionMaxTelemetryText:   isNaN(_missionMaxTelemetry) ?   "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_missionMaxTelemetry).toFixed(0) + " " + QGroundControl.appSettingsDistanceUnitsString
62 63
    property string _batteryChangePointText:    _batteryChangePoint < 0 ?       "N/A" : _batteryChangePoint
    property string _batteriesRequiredText:     _batteriesRequired < 0 ?        "N/A" : _batteriesRequired
64

Donald Gagne's avatar
Donald Gagne committed
65
    readonly property real _margins: ScreenTools.defaultFontPixelWidth
66

67 68 69 70 71 72 73 74
    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
75
    //-- Eat mouse events, preventing them from reaching toolbar, which is underneath us.
76 77
    DeadMouseArea {
        anchors.fill: parent
Gus Grubba's avatar
Gus Grubba committed
78 79
    }

80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    //-- 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.
    Row {
        id:                     logoRow
        anchors.bottomMargin:   1
        anchors.left:           parent.left
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
        QGCToolBarButton {
            id:                 settingsButton
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            icon.source:        "/qmlimages/PaperPlane.svg"
            logo:               true
            checked:            false
            onClicked: {
                checked = false
                mainWindow.showFlyView()
            }
        }
    }

102 103 104 105
    // Progress bar

    on_ControllerProgressPctChanged: {
        if (_controllerProgressPct === 1) {
106 107
            missionStats.visible = false
            uploadCompleteText.visible = true
108
            progressBar.visible = false
109 110 111 112 113 114 115 116
            resetProgressTimer.start()
        } else if (_controllerProgressPct > 0) {
            progressBar.visible = true
        }
    }

    Timer {
        id:             resetProgressTimer
117 118 119 120 121
        interval:       5000
        onTriggered: {
            missionStats.visible = true
            uploadCompleteText.visible = false
        }
122 123
    }

124 125
    QGCLabel {
        id:                     uploadCompleteText
Gus Grubba's avatar
Gus Grubba committed
126
        anchors.fill:           parent
127 128 129 130 131 132 133
        font.pointSize:         ScreenTools.largeFontPointSize
        horizontalAlignment:    Text.AlignHCenter
        verticalAlignment:      Text.AlignVCenter
        text:                   "Done"
        visible:                false
    }

134
    GridLayout {
135 136 137
        id:                     missionStats
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
138 139
        anchors.leftMargin:     _margins
        anchors.rightMargin:    _margins
Gus Grubba's avatar
Gus Grubba committed
140
        anchors.left:           parent.left
141
        anchors.right:          uploadButton.visible ? uploadButton.left : parent.right
142 143
        columnSpacing:          0
        columns:                3
144 145

        GridLayout {
146
            columns:                8
147
            rowSpacing:             _rowSpacing
148
            columnSpacing:          _labelToValueSpacing
149
            Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
150 151

            QGCLabel {
152
                text:               qsTr("Selected Waypoint")
153
                Layout.columnSpan:  8
Donald Gagne's avatar
Donald Gagne committed
154
                font.pointSize:     ScreenTools.smallFontPointSize
155 156
            }

157
            QGCLabel { text: qsTr("Alt diff:"); font.pointSize: _dataFontSize; }
158
            QGCLabel {
159
                text:                   _altDifferenceText
160
                font.pointSize:         _dataFontSize
161
                Layout.minimumWidth:    _mediumValueWidth
162
            }
163

Donald Gagne's avatar
Donald Gagne committed
164 165
            Item { width: 1; height: 1 }

166
            QGCLabel { text: qsTr("Azimuth:"); font.pointSize: _dataFontSize; }
167
            QGCLabel {
168
                text:                   _azimuthText
169
                font.pointSize:         _dataFontSize
170 171
                Layout.minimumWidth:    _smallValueWidth
            }
172

173 174 175
            Item { width: 1; height: 1 }

            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
176
            QGCLabel {
177
                text:                   _distanceText
178
                font.pointSize:         _dataFontSize
179
                Layout.minimumWidth:    _largeValueWidth
180 181 182 183 184 185 186
            }

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

Donald Gagne's avatar
Donald Gagne committed
189 190
            Item { width: 1; height: 1 }

191
            QGCLabel { text: qsTr("Heading:"); font.pointSize: _dataFontSize; }
192
            QGCLabel {
193
                text:                   _headingText
194
                font.pointSize:         _dataFontSize
195 196
                Layout.minimumWidth:    _smallValueWidth
            }
197 198 199
        }

        GridLayout {
200
            columns:                5
201
            rowSpacing:             _rowSpacing
202
            columnSpacing:          _labelToValueSpacing
203
            Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
204 205

            QGCLabel {
206
                text:               qsTr("Total Mission")
Donald Gagne's avatar
Donald Gagne committed
207 208
                Layout.columnSpan:  5
                font.pointSize:     ScreenTools.smallFontPointSize
209 210
            }

211
            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
212 213
            QGCLabel {
                text:                   _missionDistanceText
214
                font.pointSize:         _dataFontSize
215 216
                Layout.minimumWidth:    _largeValueWidth
            }
217

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

220
            QGCLabel { text: qsTr("Max telem dist:"); font.pointSize: _dataFontSize; }
221 222
            QGCLabel {
                text:                   _missionMaxTelemetryText
223
                font.pointSize:         _dataFontSize
224 225
                Layout.minimumWidth:    _largeValueWidth
            }
226

227
            QGCLabel { text: qsTr("Time:"); font.pointSize: _dataFontSize; }
228
            QGCLabel {
229 230
                text:                   getMissionTime()
                font.pointSize:         _dataFontSize
231 232
                Layout.minimumWidth:    _largeValueWidth
            }
233
        }
Donald Gagne's avatar
Donald Gagne committed
234 235

        GridLayout {
236
            columns:                3
237
            rowSpacing:             _rowSpacing
238
            columnSpacing:          _labelToValueSpacing
239
            Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
240
            visible:                _batteryInfoAvailable
Donald Gagne's avatar
Donald Gagne committed
241 242 243 244 245 246 247

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

248
            QGCLabel { text: qsTr("Batteries required:"); font.pointSize: _dataFontSize; }
249 250
            QGCLabel {
                text:                   _batteriesRequiredText
251
                font.pointSize:         _dataFontSize
252
                Layout.minimumWidth:    _mediumValueWidth
253
            }
Donald Gagne's avatar
Donald Gagne committed
254 255

            Item { width: 1; height: 1 }
256 257
/*
            FIXME: Swap point display is currently hidden since the code which calcs it doesn't work correctly
258
            QGCLabel { text: qsTr("Swap waypoint:"); font.pointSize: _dataFontSize; }
259 260
            QGCLabel {
                text:                   _batteryChangePointText
261
                font.pointSize:         _dataFontSize
262
                Layout.minimumWidth:    _mediumValueWidth
263
            }
264
*/
Donald Gagne's avatar
Donald Gagne committed
265
        }
266
    }
267 268 269 270 271 272

    QGCButton {
        id:                     uploadButton
        anchors.rightMargin:    _margins
        anchors.right:          parent.right
        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
273
        text:                   _controllerDirty ? qsTr("Upload Required") : qsTr("Upload")
274
        enabled:                !_controllerSyncInProgress
275 276
        visible:                !_controllerOffline && !_controllerSyncInProgress && !uploadCompleteText.visible
        primary:                _controllerDirty
Gus Grubba's avatar
Gus Grubba committed
277
        onClicked:              _planMasterController.upload()
278 279 280 281 282 283

        PropertyAnimation on opacity {
            easing.type:    Easing.OutQuart
            from:           0.5
            to:             1
            loops:          Animation.Infinite
284
            running:        _controllerDirty && !_controllerSyncInProgress
285 286 287
            alwaysRunToEnd: true
            duration:       2000
        }
288
    }
289 290 291 292 293 294 295 296 297 298

    // Small mission download progress bar
    Rectangle {
        id:             progressBar
        anchors.left:   parent.left
        anchors.bottom: parent.bottom
        height:         4
        width:          _controllerProgressPct * parent.width
        color:          qgcPal.colorGreen
        visible:        false
299 300 301 302 303 304

        onVisibleChanged: {
            if (visible) {
                largeProgressBar._userHide = false
            }
        }
305 306 307 308 309 310
    }

    /*
    Rectangle {
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
311
        width:          activeVehicle ? activeVehicle.parameterManager.loadProgress * parent.width : 0
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
        color:          qgcPal.colorGreen
        visible:        !largeProgressBar.visible
    }
    */

    // Large mission download progress bar
    Rectangle {
        id:             largeProgressBar
        anchors.bottom: parent.bottom
        anchors.left:   parent.left
        anchors.right:  parent.right
        height:         parent.height
        color:          qgcPal.window
        visible:        _showLargeProgress

        property bool _userHide:                false
        property bool _showLargeProgress:       progressBar.visible && !_userHide && qgcPal.globalTheme === QGCPalette.Light

        Connections {
            target:                 QGroundControl.multiVehicleManager
            onActiveVehicleChanged: largeProgressBar._userHide = false
        }

        Rectangle {
            anchors.top:    parent.top
            anchors.bottom: parent.bottom
            width:          _controllerProgressPct * parent.width
            color:          qgcPal.colorGreen
        }

        QGCLabel {
            anchors.centerIn:   parent
            text:               qsTr("Syncing Mission")
            font.pointSize:     ScreenTools.largeFontPointSize
        }

        QGCLabel {
            anchors.margins:    _margin
            anchors.right:      parent.right
            anchors.bottom:     parent.bottom
            text:               qsTr("Click anywhere to hide")

            property real _margin: ScreenTools.defaultFontPixelWidth / 2
        }

        MouseArea {
            anchors.fill:   parent
            onClicked:      largeProgressBar._userHide = true
        }
    }
362 363
}