PlanToolBar.qml 13 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 61
    property real   _controllerProgressPct:     _controllerValid ? planMasterController.missionController.progressPct : 0
    property bool   _syncInProgress:            _controllerValid ? planMasterController.missionController.syncInProgress : false
62 63 64

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

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

    QGCPalette { id: qgcPal }

77 78 79 80 81 82 83 84
    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
85 86 87 88 89 90 91 92
    //-- 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; }
    }

93 94
    //-- 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.
95
    Row {
96
        id:                     logoRow
97 98 99 100
        anchors.bottomMargin:   1
        anchors.left:           parent.left
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
101 102 103 104 105 106 107 108 109
        QGCToolBarButton {
            id:                 settingsButton
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            source:             "/qmlimages/PaperPlane.svg"
            logo:               true
            checked:            false
            onClicked: {
                checked = false
110
                showFlyView()
111 112
            }
        }
113 114
    }

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    // Progress bar

    on_ControllerProgressPctChanged: {
        if (_controllerProgressPct === 1) {
            resetProgressTimer.start()
        } else if (_controllerProgressPct > 0) {
            progressBar.visible = true
        }
    }

    Timer {
        id:             resetProgressTimer
        interval:       1000
        onTriggered:    progressBar.visible = false
    }

    Rectangle {
        id:             progressBar
        anchors.left:   parent.left
        anchors.bottom: parent.bottom
135
        height:         4
136 137 138 139 140
        width:          _controllerProgressPct * parent.width
        color:          qgcPal.colorGreen
        visible:        false
    }

141 142 143 144 145
    GridLayout {
        anchors.top:                parent.top
        anchors.bottom:             parent.bottom
        anchors.leftMargin:     _margins
        anchors.rightMargin:    _margins
146 147
        anchors.left:           logoRow.right
        anchors.right:          uploadButton.visible ? uploadButton.left : parent.right
148 149
        columnSpacing:              0//_margins
        columns:                    3
150 151

        GridLayout {
152
            anchors.verticalCenter: parent.verticalCenter
153
            columns:                8
154
            rowSpacing:             _rowSpacing
155
            columnSpacing:          _labelToValueSpacing
156
            Layout.alignment:       Qt.AlignHCenter
157 158

            QGCLabel {
159
                text:               qsTr("Selected Waypoint")
160
                Layout.columnSpan:  8
Donald Gagne's avatar
Donald Gagne committed
161
                font.pointSize:     ScreenTools.smallFontPointSize
162 163
            }

164
            QGCLabel { text: qsTr("Alt diff:"); font.pointSize: _dataFontSize; }
165
            QGCLabel {
166
                text:                   _altDifferenceText
167
                font.pointSize:         _dataFontSize
168
                Layout.minimumWidth:    _mediumValueWidth
169
            }
170

Donald Gagne's avatar
Donald Gagne committed
171 172
            Item { width: 1; height: 1 }

173
            QGCLabel { text: qsTr("Azimuth:"); font.pointSize: _dataFontSize; }
174
            QGCLabel {
175
                text:                   _azimuthText
176
                font.pointSize:         _dataFontSize
177 178
                Layout.minimumWidth:    _smallValueWidth
            }
179

180 181 182
            Item { width: 1; height: 1 }

            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
183
            QGCLabel {
184
                text:                   _distanceText
185
                font.pointSize:         _dataFontSize
186
                Layout.minimumWidth:    _largeValueWidth
187 188 189 190 191 192 193
            }

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

Donald Gagne's avatar
Donald Gagne committed
196 197
            Item { width: 1; height: 1 }

198
            QGCLabel { text: qsTr("Heading:"); font.pointSize: _dataFontSize; }
199
            QGCLabel {
200
                text:                   _headingText
201
                font.pointSize:         _dataFontSize
202 203
                Layout.minimumWidth:    _smallValueWidth
            }
204 205 206
        }

        GridLayout {
207 208
            anchors.verticalCenter: parent.verticalCenter
            columns:                5
209
            rowSpacing:             _rowSpacing
210
            columnSpacing:          _labelToValueSpacing
211
            Layout.alignment:       Qt.AlignHCenter
212 213

            QGCLabel {
214
                text:               qsTr("Total Mission")
Donald Gagne's avatar
Donald Gagne committed
215 216
                Layout.columnSpan:  5
                font.pointSize:     ScreenTools.smallFontPointSize
217 218
            }

219
            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
220 221
            QGCLabel {
                text:                   _missionDistanceText
222
                font.pointSize:         _dataFontSize
223 224
                Layout.minimumWidth:    _largeValueWidth
            }
225

Donald Gagne's avatar
Donald Gagne committed
226 227
            Item { width: 1; height: 1 }

228
            QGCLabel { text: qsTr("Max telem dist:"); font.pointSize: _dataFontSize; }
229 230
            QGCLabel {
                text:                   _missionMaxTelemetryText
231
                font.pointSize:         _dataFontSize
232 233
                Layout.minimumWidth:    _largeValueWidth
            }
234

235
            QGCLabel { text: qsTr("Time:"); font.pointSize: _dataFontSize; }
236
            QGCLabel {
237 238
                text:                   getMissionTime()
                font.pointSize:         _dataFontSize
239 240
                Layout.minimumWidth:    _largeValueWidth
            }
241
        }
Donald Gagne's avatar
Donald Gagne committed
242 243

        GridLayout {
244 245
            anchors.verticalCenter: parent.verticalCenter
            columns:                3
246
            rowSpacing:             _rowSpacing
247
            columnSpacing:          _labelToValueSpacing
248
            Layout.alignment:       Qt.AlignHCenter
Donald Gagne's avatar
Donald Gagne committed
249 250 251 252 253 254 255

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

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

            Item { width: 1; height: 1 }

265
            QGCLabel { text: qsTr("Swap waypoint:"); font.pointSize: _dataFontSize; }
266 267
            QGCLabel {
                text:                   _batteryChangePointText
268
                font.pointSize:         _dataFontSize
269
                Layout.minimumWidth:    _mediumValueWidth
270
            }
Donald Gagne's avatar
Donald Gagne committed
271
        }
272
    }
273 274 275 276 277 278

    QGCButton {
        id:                     uploadButton
        anchors.rightMargin:    _margins
        anchors.right:          parent.right
        anchors.verticalCenter: parent.verticalCenter
279
        text:                   _controllerDirty ? qsTr("Upload Required") : qsTr("Upload")
280
        enabled:                !_controllerSyncInProgress
DonLakeFlyer's avatar
DonLakeFlyer committed
281
        visible:                !_controllerOffline
282
        onClicked:              planMasterController.upload()
283 284 285 286 287 288

        PropertyAnimation on opacity {
            easing.type:    Easing.OutQuart
            from:           0.5
            to:             1
            loops:          Animation.Infinite
289
            running:        _controllerDirty
290 291 292
            alwaysRunToEnd: true
            duration:       2000
        }
293
    }
294 295
}