PlanToolBar.qml 8.42 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 22 23 24 25 26 27
    visible:            false

    signal showFlyView

    property var    missionController
    property var    currentMissionItem          ///< Mission item to display status for

Donald Gagne's avatar
Donald Gagne committed
28 29 30 31 32
    property var    missionItems:               _controllerValid ? missionController.visualItems : undefined
    property real   missionDistance:            _controllerValid ? missionController.missionDistance : NaN
    property real   missionTime:                _controllerValid ? missionController.missionTime : NaN
    property real   missionMaxTelemetry:        _controllerValid ? missionController.missionMaxTelemetry : NaN
    property bool   missionDirty:               _controllerValid ? missionController.dirty : false
33 34 35 36 37

    property var    _activeVehicle:             QGroundControl.multiVehicleManager.activeVehicle

    property bool   _statusValid:               currentMissionItem != undefined
    property bool   _missionValid:              missionItems != undefined
Donald Gagne's avatar
Donald Gagne committed
38
    property bool   _controllerValid:           missionController != undefined
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

    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
    property real   _missionDistance:           _missionValid ? missionDistance : NaN
    property real   _missionMaxTelemetry:       _missionValid ? missionMaxTelemetry : NaN
    property real   _missionTime:               _missionValid ? missionTime : NaN

    property string _distanceText:              isNaN(_distance) ? "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_distance).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
    property string _altDifferenceText:         isNaN(_altDifference) ? "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_altDifference).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
    property string _gradientText:              isNaN(_gradient) ? "-.-" : _gradientPercent.toFixed(0) + "%"
    property string _azimuthText:               isNaN(_azimuth) ? "-.-" : Math.round(_azimuth)
    property string _missionDistanceText:       isNaN(_missionDistance) ? "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_missionDistance).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString
    property string _missionTimeText:           isNaN(_missionTime) ? "-.-" : Number(_missionTime / 60).toFixed(1) + " min"
    property string _missionMaxTelemetryText:   isNaN(_missionMaxTelemetry) ? "-.-" : QGroundControl.metersToAppSettingsDistanceUnits(_missionMaxTelemetry).toFixed(1) + " " + QGroundControl.appSettingsDistanceUnitsString

Donald Gagne's avatar
Donald Gagne committed
57
    readonly property real _margins: ScreenTools.defaultFontPixelWidth
58 59 60

    QGCPalette { id: qgcPal }

Gus Grubba's avatar
Gus Grubba committed
61 62 63 64 65 66 67 68
    //-- 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; }
    }

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    Row {
        anchors.top:    parent.top
        anchors.bottom: parent.bottom
        spacing:        ScreenTools.defaultFontPixelWidth * 2

        QGCToolBarButton {
            id:                 settingsButton
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            source:             "/qmlimages/PaperPlane.svg"
            logo:               true
            checked:            false

            onClicked: {
                checked = false
                if (missionController.dirty) {
                    uploadPrompt.visible = true
                } else {
                    showFlyView()
                }
            }

            MessageDialog {
                id:                 uploadPrompt
                title:              _activeVehicle ? qsTr("Unsent changes") : qsTr("Unsaved changes")
                text:               qsTr("You have %1 changes to your mission. Are you sure you want to leave before you %2?").arg(_activeVehicle ? qsTr("unsent") : qsTr("unsaved")).arg(_activeVehicle ? qsTr("send the missoin to the vehicle") : qsTr("save the mission to a file"))
                standardButtons:    StandardButton.Yes | StandardButton.No

                onNo: visible = false

                onYes: {
                    visible = false
                    showFlyView()
                }
            }
        }

        GridLayout {
Donald Gagne's avatar
Donald Gagne committed
107 108 109 110 111
            anchors.top:    parent.top
            anchors.bottom: parent.bottom
            columns:        5
            rowSpacing:     0
            columnSpacing:  _margins / 4
112 113

            QGCLabel {
Donald Gagne's avatar
Donald Gagne committed
114 115 116
                text:               qsTr("Selected waypoint")
                Layout.columnSpan:  5
                font.pointSize:     ScreenTools.smallFontPointSize
117 118 119 120 121
            }

            QGCLabel { text: qsTr("Distance:") }
            QGCLabel { text: _distanceText }

Donald Gagne's avatar
Donald Gagne committed
122 123
            Item { width: 1; height: 1 }

124 125 126 127 128 129
            QGCLabel { text: qsTr("Gradient:") }
            QGCLabel { text: _gradientText }

            QGCLabel { text: qsTr("Alt diff:") }
            QGCLabel { text: _altDifferenceText }

Donald Gagne's avatar
Donald Gagne committed
130 131
            Item { width: 1; height: 1 }

132 133 134 135 136
            QGCLabel { text: qsTr("Azimuth:") }
            QGCLabel { text: _azimuthText }
        }

        GridLayout {
Donald Gagne's avatar
Donald Gagne committed
137 138 139 140 141
            anchors.top:    parent.top
            anchors.bottom: parent.bottom
            columns:        5
            rowSpacing:     0
            columnSpacing:  _margins / 4
142 143

            QGCLabel {
Donald Gagne's avatar
Donald Gagne committed
144 145 146
                text:               qsTr("Total mission")
                Layout.columnSpan:  5
                font.pointSize:     ScreenTools.smallFontPointSize
147 148 149 150 151
            }

            QGCLabel { text: qsTr("Distance:") }
            QGCLabel { text: _missionDistanceText }

Donald Gagne's avatar
Donald Gagne committed
152 153
            Item { width: 1; height: 1 }

154 155 156 157 158 159
            QGCLabel { text: qsTr("Max telem dist:") }
            QGCLabel { text: _missionMaxTelemetryText }

            QGCLabel { text: qsTr("Time:") }
            QGCLabel { text: _missionTimeText }
        }
Donald Gagne's avatar
Donald Gagne committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

        GridLayout {
            anchors.top:    parent.top
            anchors.bottom: parent.bottom
            columns:        3
            rowSpacing:     0
            columnSpacing:  _margins / 4

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

            QGCLabel { text: qsTr("Batteries required:") }
            QGCLabel { text: "--.--" }

            Item { width: 1; height: 1 }

            QGCLabel { text: qsTr("Swap waypoint:") }
            QGCLabel { text: "--" }
        }
182 183 184 185 186 187 188
    }

    QGCButton {
        anchors.rightMargin:    _margins
        anchors.right:          parent.right
        anchors.verticalCenter: parent.verticalCenter
        text:                   _activeVehicle ? qsTr("Upload") : qsTr("Save")
Donald Gagne's avatar
Donald Gagne committed
189
        visible:                missionDirty
190 191 192 193 194 195 196 197 198 199 200 201
        primary:                true

        onClicked: {
            if (_activeVehicle) {
                missionController.sendToVehicle()
            } else {
                missionController.saveToSelectedFile()
            }
        }

        NumberAnimation on opacity {
            id:         opacityAnimation
Donald Gagne's avatar
Donald Gagne committed
202
            running:    missionDirty
203 204 205 206 207 208 209 210
            from:       0.5
            to:         1.0
            loops:      Animation.Infinite
            duration:   2000
        }
    }
}