FlightDisplayWimaMenu.qml 12.2 KB
Newer Older
1 2 3 4 5
import QtQuick                  2.3
import QtQuick.Controls.Styles  1.4
import QtQuick.Dialogs          1.2
import QtLocation               5.3
import QtPositioning            5.3
Valentin Platzgummer's avatar
Valentin Platzgummer committed
6
import QtQuick.Controls         2.4
7 8 9 10 11 12 13 14
import QtQuick.Layouts          1.2

import QGroundControl               1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.Vehicle       1.0
import QGroundControl.FlightMap     1.0
Valentin Platzgummer's avatar
Valentin Platzgummer committed
15
import QGroundControl.FlightDisplay 1.0
16 17
import QGroundControl.Airspace      1.0
import QGroundControl.Airmap        1.0
18 19
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
20

Valentin Platzgummer's avatar
Valentin Platzgummer committed
21 22 23

import Qt.labs.settings             1.0

24
Item {
25
    id:     _root
Valentin Platzgummer's avatar
Valentin Platzgummer committed
26 27
    height: mainFrame.height
    width:  mainFrame.width
28
    clip:   true
29 30 31 32

    property int maxHeight: 500
    property int maxWidth:  300

33
    property var wimaController // must be provided by the user
34
    property var planMasterController // must be provided by the user
35
    property var missionController // must be provided by the user
36 37 38

    property bool   _controllerValid:           planMasterController !== undefined
    property real   _controllerProgressPct:     _controllerValid ? planMasterController.missionController.progressPct : 0
39
    property real   _margins:                   ScreenTools.defaultFontPixelWidth / 2
40

41

Valentin Platzgummer's avatar
Valentin Platzgummer committed
42
    // Disabels map scrolling when cursor on this menu.
43 44 45 46
    DeadMouseArea {
        anchors.fill: parent
    }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
47 48 49 50 51 52
    // Use Settings to store menu appearance through different sessions.
    Settings {
        property alias vehicleHeaderChecker:    vehicleHeader.checked
        property alias statsHeaderChecker:      statsHeader.checked
    }

53 54 55
    // Progress bar visibility
    on_ControllerProgressPctChanged: {
        if (_controllerProgressPct === 1) {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
56 57
            uploadCompleteText.visible      = true
            progressBar.visible             = false
58
        } else if (_controllerProgressPct > 0) {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
59 60
            progressBar.visible             = true
            uploadCompleteText.visible      = false
61 62
        }
    }
63

64 65 66 67 68 69 70 71 72
    function getTime(time) {
        // time is a double
        if(isNaN(time)) {
            return "00:00:00"
        }
        var t = new Date(0, 0, 0, 0, 0, Number(time))
        return Qt.formatTime(t, 'hh:mm:ss')
    }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
73 74 75

    QGCPalette { id: qgcPal }

76
    // box containing all items
Valentin Platzgummer's avatar
Valentin Platzgummer committed
77
    Rectangle { // maybe replace with column and remove anchors => dynamic height:
78
        id: mainFrame
79
        height:     enableWima.height + flickable.height + _margins*2
80 81 82 83 84 85
        width:      Math.max(enableWima.width, flickable.width)
        color:      enableWima.enableWimaBoolean ? qgcPal.window : "transparent"
        radius:     Math.min(height, width)/50
        clip:       true

        property real _margins:       _root._margins
Valentin Platzgummer's avatar
Valentin Platzgummer committed
86

87
        // checkbox to enable/ disable wima
88
        SliderSwitch {
89
            id: enableWima
90 91
            anchors.horizontalCenter:   flickable.horizontalCenter
            anchors.bottom:             flickable.top
92
            anchors.bottomMargin:       _margins
93
            confirmText:                enableWimaBoolean ? qsTr("disable WiMA") : qsTr("enable WiMA")
94

Valentin Platzgummer's avatar
Valentin Platzgummer committed
95

96 97
            property var enableWimaFact:        wimaController.enableWimaController
            property bool enableWimaBoolean:    enableWimaFact.value
98

99 100 101
            onAccept: {
                if (enableWimaBoolean) {
                    enableWimaFact.value = false
102 103
                    enableWimaMouseArea.enabled = true
                    timer.start()
104 105
                } else {
                    enableWimaFact.value = true
106 107
                    enableWimaMouseArea.enabled = false
                    timer.stop()
108 109
                }
            }
110 111
        }

112 113
        MouseArea {
            id: enableWimaMouseArea
Valentin Platzgummer's avatar
Valentin Platzgummer committed
114 115 116 117 118 119 120 121
            anchors.fill: enableWima

            hoverEnabled: true

            property var  enableWimaFact:        wimaController.enableWimaController
            property bool enableWimaBoolean:    enableWimaFact.value
            onEntered: {
                enableWima.visible = true
122 123
                enabled = false
                timer.start()
Valentin Platzgummer's avatar
Valentin Platzgummer committed
124 125 126 127 128 129
            }

        }

        Timer {
                id: timer
130
                interval: 3000
Valentin Platzgummer's avatar
Valentin Platzgummer committed
131 132
                running: false
                repeat: false
133 134 135 136 137 138 139 140 141 142 143 144 145
                onTriggered: triggerHandler()

                function triggerHandler() {
                    if (enableWima.enableWimaBoolean === false) {
                        enableWima.visible = false
                        enableWimaMouseArea.enabled = true
                    }
                }

                Component.onCompleted: {
                        start()
                }
        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
146 147 148 149


        QGCFlickable {
            id: flickable
150 151
            clip:               true
            visible:            enableWima.enableWimaBoolean
152
            anchors.left:       parent.left
153
            anchors.bottom:     parent.bottom
154 155 156 157 158 159
            width:              enableWima.enableWimaBoolean ?
                                    Math.min(contentWidth, maxWidth)
                                  : enableWima.width
            height:             enableWima.enableWimaBoolean ?
                                    Math.min(contentHeight, maxHeight)
                                  : 0
160 161
            contentHeight:      columnWrapper.height
            contentWidth:       columnWrapper.width
Valentin Platzgummer's avatar
Valentin Platzgummer committed
162

163 164 165 166 167
            Row {
                id: columnWrapper
                Item{ // spacer
                    width: 6
                    height: 1
Valentin Platzgummer's avatar
Valentin Platzgummer committed
168 169
                }

170
                Column {
171 172
                    id:         mainColumn
                    spacing:    ScreenTools.defaultFontPixelHeight * 0.3
Valentin Platzgummer's avatar
Valentin Platzgummer committed
173

174

175 176 177
                    SectionHeader{
                        id: vehicleHeader
                        text: qsTr("Vehicle")
Valentin Platzgummer's avatar
Valentin Platzgummer committed
178
                    }
179 180 181 182 183 184 185
                    GridLayout {
                        columns: 2
                        rowSpacing:         ScreenTools.defaultFontPixelHeight * 0.5
                        columnSpacing:      ScreenTools.defaultFontPixelHeight * 0.5
                        visible:            vehicleHeader.checked
                        width:              parent.width

186 187 188 189 190 191 192 193 194 195 196
                        QGCButton {
                            id: buttonUpload
                            text:               qsTr("Upload")
                            onClicked: {
                                if (!planMasterController.offline) {
                                    wimaController.upload()
                                }
                            }
                            Layout.fillWidth: true
                        }

197 198 199 200 201 202 203 204 205 206
                        QGCButton {
                            id: buttonRemoveFromVehicle
                            text:               qsTr("Remove")
                            onClicked:          wimaController.removeFromVehicle()
                            Layout.fillWidth: true
                        }

                        QGCButton {
                            id: buttonSmartRTL
                            text:               qsTr("Smart RTL")
207
                            onClicked:          wimaController.requestSmartRTL();
208
                            Layout.columnSpan:  2
209
                            Layout.fillWidth: true
210 211 212 213 214 215 216 217
                        }

                        QGCButton {
                            id: buttonRemoveTrajectoryHistory
                            text:               qsTr("Clear Trajectory")
                            onClicked:          wimaController.removeVehicleTrajectoryHistory()
                            Layout.columnSpan:  2
                            Layout.fillWidth: true
218
                        }
219
                    }
220

221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
                    GridLayout {
                        columns: 2
                        rowSpacing:         ScreenTools.defaultFontPixelHeight * 0.5
                        columnSpacing:      ScreenTools.defaultFontPixelHeight * 0.5
                        visible:            vehicleHeader.checked
                        width:              parent.width

                        QGCLabel {
                            text:                   qsTr("Speed")
                            Layout.fillWidth: true
                        }
                        FactTextField {
                            fact:               wimaController.flightSpeed
                            Layout.fillWidth: true
                        }

                        QGCLabel {
                            text: qsTr("Altitude")
                            Layout.fillWidth: true
                        }
                        FactTextField {
                            fact:               wimaController.altitude
                            Layout.fillWidth: true
                        }
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262

                        // progess bar
                        Rectangle {
                            id:                 progressBar
                            height:             4
                            width:              _controllerProgressPct * parent.width
                            color:              qgcPal.colorGreen
                            visible:            false
                            Layout.columnSpan:  2
                            Layout.fillWidth:   true
                        }

                        QGCLabel {
                            id:                     uploadCompleteText
                            font.pointSize:         ScreenTools.largeFontPointSize
                            Layout.columnSpan:      2
                            horizontalAlignment:    Text.AlignHCenter
                            verticalAlignment:      Text.AlignVCenter
263
                            text:                   "Done"
264 265 266
                            visible:                false
                            Layout.fillWidth:       true
                        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
267 268
                    }

269 270 271
                    SectionHeader {
                        id: statsHeader
                        text: qsTr("Statistics")
Valentin Platzgummer's avatar
Valentin Platzgummer committed
272
                    }
273
                    GridLayout {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
274
                        columns: 3
275 276 277 278
                        rowSpacing: ScreenTools.defaultFontPixelHeight * 0.5
                        anchors.topMargin: ScreenTools.defaultFontPixelHeight * 0.5
                        visible: statsHeader.checked

Valentin Platzgummer's avatar
Valentin Platzgummer committed
279 280 281 282 283 284
                        Item {
                            id: widthItem

                            Layout.fillWidth:   true
                            Layout.columnSpan:  parent.columns
                            height:             0
285
                        }
286

Valentin Platzgummer's avatar
Valentin Platzgummer committed
287
                        SmallValue {
288 289
                            property var currentMissionIndex:   missionController.currentMissionIndex

Valentin Platzgummer's avatar
Valentin Platzgummer committed
290 291 292 293
                            shortDescription: qsTr("Current Waypoint")
                            value:               currentMissionIndex > 0 ? currentMissionIndex : "-.-"
                            //unit:             "m"
                            //width:            widthItem.width*0.49
294 295
                        }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
296
                        SmallValue {
297 298
                            property var remainingDistance:     missionController.remainingDistance

Valentin Platzgummer's avatar
Valentin Platzgummer committed
299 300 301 302
                            shortDescription: qsTr("Remaining Distance")
                            value:            remainingDistance >= 0 ? remainingDistance.toFixed(2) : "-.-"
                            unit:             "m"
                            //width:            widthItem.width*0.49
303 304
                        }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
305
                        SmallValue {
306 307
                            property var remainingTime:         missionController.remainingTime

Valentin Platzgummer's avatar
Valentin Platzgummer committed
308 309 310 311
                            shortDescription: qsTr("Remaining Time")
                            value:               remainingTime >= 0 ? getTime(remainingTime) : "-.-"
                            //unit:             "m"
                            //width:            widthItem.width*0.49
312
                        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
313 314 315 316

                        Item { // spacer
                            height: 5
                            Layout.columnSpan:  parent.columns
317
                        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
318
                    } // GridLayout
319
                } // settingsColumn
Valentin Platzgummer's avatar
Valentin Platzgummer committed
320

321 322
                Item { // spacer
                    width: 6
323
                    height: 5
Valentin Platzgummer's avatar
Valentin Platzgummer committed
324
                }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
325
            } //  Row
Valentin Platzgummer's avatar
Valentin Platzgummer committed
326 327 328


        } // QGCFlickable
329 330
    }
}