PlanToolBar.qml 11.9 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
36
    property var    _activeVehicle:             QGroundControl.multiVehicleManager.activeVehicle
37 38
    property var    _controllerDirty:           planMasterController ? planMasterController.dirty : false
    property var    _controllerSyncInProgress:  planMasterController ? 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 62

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

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

    QGCPalette { id: qgcPal }

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

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

113 114 115 116 117 118 119 120
    RowLayout {
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
        spacing:                _margins * 2
        anchors.left:           logoRow.right
        anchors.leftMargin:     _margins * 4
        anchors.right:          uploadButton.visible ? uploadButton.left : parent.right
        anchors.rightMargin:    _margins
121 122

        GridLayout {
123
            anchors.verticalCenter: parent.verticalCenter
124
            columns:                8
125
            rowSpacing:             _rowSpacing
126
            columnSpacing:          _labelToValueSpacing
127 128

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

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

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

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

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

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

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

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

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

        GridLayout {
177 178
            anchors.verticalCenter: parent.verticalCenter
            columns:                5
179
            rowSpacing:             _rowSpacing
180
            columnSpacing:          _labelToValueSpacing
181 182

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

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

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

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

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

        GridLayout {
213 214
            anchors.verticalCenter: parent.verticalCenter
            columns:                3
215
            rowSpacing:             _rowSpacing
216
            columnSpacing:          _labelToValueSpacing
Donald Gagne's avatar
Donald Gagne committed
217 218 219 220 221 222 223

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

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

            Item { width: 1; height: 1 }

233
            QGCLabel { text: qsTr("Swap waypoint:"); font.pointSize: _dataFontSize; }
234 235
            QGCLabel {
                text:                   _batteryChangePointText
236
                font.pointSize:         _dataFontSize
237
                Layout.minimumWidth:    _mediumValueWidth
238
            }
Donald Gagne's avatar
Donald Gagne committed
239
        }
240
    }
241 242 243 244 245 246

    QGCButton {
        id:                     uploadButton
        anchors.rightMargin:    _margins
        anchors.right:          parent.right
        anchors.verticalCenter: parent.verticalCenter
247 248 249 250
        text:                   _controllerDirty ? qsTr("Upload Required") : qsTr("Upload")
        enabled:                _activeVehicle && !_controllerSyncInProgress
        visible:                _activeVehicle
        onClicked:              planMasterController.upload()
251 252 253 254 255 256

        PropertyAnimation on opacity {
            easing.type:    Easing.OutQuart
            from:           0.5
            to:             1
            loops:          Animation.Infinite
257
            running:        _controllerDirty
258 259 260
            alwaysRunToEnd: true
            duration:       2000
        }
261
    }
262 263
}