PlanToolBar.qml 14.8 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

Gus Grubba's avatar
Gus Grubba committed
17 18
    property var    _planMasterController:      mainWindow.planMasterController
    property var    _currentMissionItem:        mainWindow.currentMissionItem          ///< 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

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

Gus Grubba's avatar
Gus Grubba committed
31
    property bool   _statusValid:               _currentMissionItem !== undefined
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
    // Progress bar

    on_ControllerProgressPctChanged: {
        if (_controllerProgressPct === 1) {
84 85
            missionStats.visible = false
            uploadCompleteText.visible = true
86
            progressBar.visible = false
87 88 89 90 91 92 93 94
            resetProgressTimer.start()
        } else if (_controllerProgressPct > 0) {
            progressBar.visible = true
        }
    }

    Timer {
        id:             resetProgressTimer
95 96 97 98 99
        interval:       5000
        onTriggered: {
            missionStats.visible = true
            uploadCompleteText.visible = false
        }
100 101
    }

102 103
    QGCLabel {
        id:                     uploadCompleteText
Gus Grubba's avatar
Gus Grubba committed
104
        anchors.fill:           parent
105 106 107 108 109 110 111
        font.pointSize:         ScreenTools.largeFontPointSize
        horizontalAlignment:    Text.AlignHCenter
        verticalAlignment:      Text.AlignVCenter
        text:                   "Done"
        visible:                false
    }

112
    GridLayout {
113 114 115
        id:                     missionStats
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
116 117
        anchors.leftMargin:     _margins
        anchors.rightMargin:    _margins
Gus Grubba's avatar
Gus Grubba committed
118
        anchors.left:           parent.left
119
        anchors.right:          uploadButton.visible ? uploadButton.left : parent.right
120 121
        columnSpacing:          0
        columns:                3
122 123

        GridLayout {
124
            columns:                8
125
            rowSpacing:             _rowSpacing
126
            columnSpacing:          _labelToValueSpacing
127
            Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
128 129

            QGCLabel {
130
                text:               qsTr("Selected Waypoint")
131
                Layout.columnSpan:  8
Donald Gagne's avatar
Donald Gagne committed
132
                font.pointSize:     ScreenTools.smallFontPointSize
133 134
            }

135
            QGCLabel { text: qsTr("Alt diff:"); font.pointSize: _dataFontSize; }
136
            QGCLabel {
137
                text:                   _altDifferenceText
138
                font.pointSize:         _dataFontSize
139
                Layout.minimumWidth:    _mediumValueWidth
140
            }
141

Donald Gagne's avatar
Donald Gagne committed
142 143
            Item { width: 1; height: 1 }

144
            QGCLabel { text: qsTr("Azimuth:"); font.pointSize: _dataFontSize; }
145
            QGCLabel {
146
                text:                   _azimuthText
147
                font.pointSize:         _dataFontSize
148 149
                Layout.minimumWidth:    _smallValueWidth
            }
150

151 152 153
            Item { width: 1; height: 1 }

            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
154
            QGCLabel {
155
                text:                   _distanceText
156
                font.pointSize:         _dataFontSize
157
                Layout.minimumWidth:    _largeValueWidth
158 159 160 161 162 163 164
            }

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

Donald Gagne's avatar
Donald Gagne committed
167 168
            Item { width: 1; height: 1 }

169
            QGCLabel { text: qsTr("Heading:"); font.pointSize: _dataFontSize; }
170
            QGCLabel {
171
                text:                   _headingText
172
                font.pointSize:         _dataFontSize
173 174
                Layout.minimumWidth:    _smallValueWidth
            }
175 176 177
        }

        GridLayout {
178
            columns:                5
179
            rowSpacing:             _rowSpacing
180
            columnSpacing:          _labelToValueSpacing
181
            Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
182 183

            QGCLabel {
184
                text:               qsTr("Total Mission")
Donald Gagne's avatar
Donald Gagne committed
185 186
                Layout.columnSpan:  5
                font.pointSize:     ScreenTools.smallFontPointSize
187 188
            }

189
            QGCLabel { text: qsTr("Distance:"); font.pointSize: _dataFontSize; }
190 191
            QGCLabel {
                text:                   _missionDistanceText
192
                font.pointSize:         _dataFontSize
193 194
                Layout.minimumWidth:    _largeValueWidth
            }
195

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

198
            QGCLabel { text: qsTr("Max telem dist:"); font.pointSize: _dataFontSize; }
199 200
            QGCLabel {
                text:                   _missionMaxTelemetryText
201
                font.pointSize:         _dataFontSize
202 203
                Layout.minimumWidth:    _largeValueWidth
            }
204

205
            QGCLabel { text: qsTr("Time:"); font.pointSize: _dataFontSize; }
206
            QGCLabel {
207 208
                text:                   getMissionTime()
                font.pointSize:         _dataFontSize
209 210
                Layout.minimumWidth:    _largeValueWidth
            }
211
        }
Donald Gagne's avatar
Donald Gagne committed
212 213

        GridLayout {
214
            columns:                3
215
            rowSpacing:             _rowSpacing
216
            columnSpacing:          _labelToValueSpacing
217
            Layout.alignment:       Qt.AlignVCenter | Qt.AlignHCenter
218
            visible:                _batteryInfoAvailable
Donald Gagne's avatar
Donald Gagne committed
219 220 221 222 223 224 225

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

226
            QGCLabel { text: qsTr("Batteries required:"); font.pointSize: _dataFontSize; }
227 228
            QGCLabel {
                text:                   _batteriesRequiredText
229
                font.pointSize:         _dataFontSize
230
                Layout.minimumWidth:    _mediumValueWidth
231
            }
Donald Gagne's avatar
Donald Gagne committed
232 233

            Item { width: 1; height: 1 }
234 235
/*
            FIXME: Swap point display is currently hidden since the code which calcs it doesn't work correctly
236
            QGCLabel { text: qsTr("Swap waypoint:"); font.pointSize: _dataFontSize; }
237 238
            QGCLabel {
                text:                   _batteryChangePointText
239
                font.pointSize:         _dataFontSize
240
                Layout.minimumWidth:    _mediumValueWidth
241
            }
242
*/
Donald Gagne's avatar
Donald Gagne committed
243
        }
244
    }
245 246 247 248 249 250

    QGCButton {
        id:                     uploadButton
        anchors.rightMargin:    _margins
        anchors.right:          parent.right
        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
251
        text:                   _controllerDirty ? qsTr("Upload Required") : qsTr("Upload")
252
        enabled:                !_controllerSyncInProgress
253 254
        visible:                !_controllerOffline && !_controllerSyncInProgress && !uploadCompleteText.visible
        primary:                _controllerDirty
Gus Grubba's avatar
Gus Grubba committed
255
        onClicked:              _planMasterController.upload()
256 257 258 259 260 261

        PropertyAnimation on opacity {
            easing.type:    Easing.OutQuart
            from:           0.5
            to:             1
            loops:          Animation.Infinite
262
            running:        _controllerDirty && !_controllerSyncInProgress
263 264 265
            alwaysRunToEnd: true
            duration:       2000
        }
266
    }
267 268 269 270 271 272 273 274 275 276

    // 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
277 278 279 280 281 282

        onVisibleChanged: {
            if (visible) {
                largeProgressBar._userHide = false
            }
        }
283 284 285 286 287 288
    }

    /*
    Rectangle {
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
289
        width:          activeVehicle ? activeVehicle.parameterManager.loadProgress * parent.width : 0
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 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
        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
        }
    }
340 341
}