FlightDisplayWimaMenu.qml 16.3 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 15 16
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
import QGroundControl.Airspace      1.0
import QGroundControl.Airmap        1.0
17 18
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
19 20

Item {
21
    id:     _root
Valentin Platzgummer's avatar
Valentin Platzgummer committed
22 23
    height: mainFrame.height
    width:  mainFrame.width
24 25 26 27

    property int maxHeight: 500
    property int maxWidth:  300

28
    property var wimaController // must be provided by the user
29 30 31 32
    property var planMasterController // must be provided by the user

    property bool   _controllerValid:           planMasterController !== undefined
    property real   _controllerProgressPct:     _controllerValid ? planMasterController.missionController.progressPct : 0
33
    property real   _margins:                   ScreenTools.defaultPixelWidth*0.3
34

35 36
    signal initSmartRTL();

37 38 39 40 41 42 43 44 45 46
    // Progress bar visibility
    on_ControllerProgressPctChanged: {
        if (_controllerProgressPct === 1) {
            uploadCompleteText.visible  = true
            progressBar.visible         = false
        } else if (_controllerProgressPct > 0) {
            progressBar.visible         = true
            uploadCompleteText.visible  = false
        }
    }
47

48 49 50 51 52 53 54 55 56
    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
57 58 59

    QGCPalette { id: qgcPal }

60
    // box containing all items
Valentin Platzgummer's avatar
Valentin Platzgummer committed
61
    Rectangle { // maybe replace with column and remove anchors => dynamic height:
62 63 64 65 66 67 68 69
        id: mainFrame
        height:     enableWima.height + flickable.height
        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
70 71 72 73 74 75 76

        Component.onCompleted: {
            console.log('onCompleted')
            console.log('height')
            console.log(height)
            console.log('width')
            console.log(width)
77 78 79 80 81 82 83
            console.log(enableWima.width)
            console.log(enableWima.height)
            console.log(flickable.contentWidth)
            console.log(flickable.contentHeight)
            width = enableWima.width + flickable.contentWidth + 2*_margins
            console.log('width')
            console.log(width)
Valentin Platzgummer's avatar
Valentin Platzgummer committed
84 85 86 87 88
        }

        onHeightChanged: {
            console.log('height')
            console.log(height)
89
            //_root.height = mainFrame.height
Valentin Platzgummer's avatar
Valentin Platzgummer committed
90 91 92 93 94
        }

        onWidthChanged: {
            console.log('width')
            console.log(width)
95
            //_root.width = mainFrame.width
Valentin Platzgummer's avatar
Valentin Platzgummer committed
96
        }
97

98
        // checkbox to enable/ disable wima
99
        SliderSwitch {
100
            id: enableWima
101 102
            anchors.horizontalCenter:   flickable.horizontalCenter
            anchors.bottom:             flickable.top
103
            confirmText:                enableWimaBoolean ? qsTr("disable WiMA") : qsTr("enable WiMA")
104

Valentin Platzgummer's avatar
Valentin Platzgummer committed
105

106 107
            property var enableWimaFact:        wimaController.enableWimaController
            property bool enableWimaBoolean:    enableWimaFact.value
108

109 110 111 112 113 114
            /*onXChanged: {
                console.log('x')
            }

            onYChanged: {
                console.log('y')
Valentin Platzgummer's avatar
Valentin Platzgummer committed
115 116
            }

117 118 119 120
            Component.onCompleted: {
                enableWimaFact.value = true
            }*/

121 122 123
            onAccept: {
                if (enableWimaBoolean) {
                    enableWimaFact.value = false
124 125
                    enableWimaMouseArea.enabled = true
                    timer.start()
126 127
                } else {
                    enableWimaFact.value = true
128 129
                    enableWimaMouseArea.enabled = false
                    timer.stop()
130 131
                }
            }
132 133
        }

134 135
        MouseArea {
            id: enableWimaMouseArea
Valentin Platzgummer's avatar
Valentin Platzgummer committed
136 137 138 139 140 141 142 143
            anchors.fill: enableWima

            hoverEnabled: true

            property var  enableWimaFact:        wimaController.enableWimaController
            property bool enableWimaBoolean:    enableWimaFact.value
            onEntered: {
                enableWima.visible = true
144 145
                enabled = false
                timer.start()
Valentin Platzgummer's avatar
Valentin Platzgummer committed
146 147
            }

148 149

            onExited: timer.start()
Valentin Platzgummer's avatar
Valentin Platzgummer committed
150 151 152 153
        }

        Timer {
                id: timer
154
                interval: 3000
Valentin Platzgummer's avatar
Valentin Platzgummer committed
155 156
                running: false
                repeat: false
157 158 159 160 161 162 163 164 165 166 167 168 169
                onTriggered: triggerHandler()

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

                Component.onCompleted: {
                        start()
                }
        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
170 171 172 173


        QGCFlickable {
            id: flickable
174 175
            clip:               true
            visible:            enableWima.enableWimaBoolean
176
            anchors.left:       parent.left
177 178 179 180 181
            anchors.bottom:     parent.bottom
            width:              enableWima.enableWimaBoolean ? Math.min(contentWidth, maxWidth) : enableWima.width
            height:             enableWima.enableWimaBoolean ? Math.min(contentHeight, maxHeight) : 0
            contentHeight:      columnWrapper.height
            contentWidth:       columnWrapper.width
Valentin Platzgummer's avatar
Valentin Platzgummer committed
182

183 184

           onContentHeightChanged: {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
185 186
                console.log('contentHeight')
                console.log(contentHeight)
187
                //mainFrame.height = enableWima.enableWimaBoolean ? Math.min(parent.maxHeight, enableWima.height + flickable.contentHeight + 2*_margins) : enableWima.height + _margins
Valentin Platzgummer's avatar
Valentin Platzgummer committed
188 189 190 191 192
            }

            onContentWidthChanged: {
                console.log('contentWidth')
                console.log(contentWidth)
193
                //mainFrame.width =  enableWima.enableWimaBoolean ? Math.min(parent.maxWidth, flickable.contentWidth + 2*_margins) : enableWima.width
Valentin Platzgummer's avatar
Valentin Platzgummer committed
194 195
            }

196 197 198 199 200
            Row {
                id: columnWrapper
                Item{ // spacer
                    width: 6
                    height: 1
Valentin Platzgummer's avatar
Valentin Platzgummer committed
201 202
                }

203 204 205
                Column {
                    id:                         mainColumn
                    spacing:                    ScreenTools.defaultFontPixelHeight * 0.3
Valentin Platzgummer's avatar
Valentin Platzgummer committed
206

207 208 209
                    SectionHeader{
                        id: settingsHeader
                        text: qsTr("Settings")
Valentin Platzgummer's avatar
Valentin Platzgummer committed
210
                    }
211 212 213 214 215 216 217 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
                    GridLayout {
                        columns: 2
                        rowSpacing:         ScreenTools.defaultFontPixelHeight * 0.5
                        columnSpacing:      ScreenTools.defaultFontPixelHeight * 0.5
                        visible:            settingsHeader.checked

                        QGCLabel {
                            text: qsTr("Next Waypoint")
                            Layout.fillWidth: true
                        }
                        FactTextField {
                            fact:               wimaController.startWaypointIndex
                            Layout.fillWidth:   true
                        }

                        QGCLabel {
                            text: qsTr("Max Waypoints")
                            Layout.fillWidth: true
                        }
                        FactTextField {
                            fact:               wimaController.maxWaypointsPerPhase
                            Layout.fillWidth: true
                        }

                        QGCLabel {
                            text: qsTr("Overlap")
                            Layout.fillWidth: true
                        }
                        FactTextField {
                            fact:               wimaController.overlapWaypoints
                            Layout.fillWidth: true
                        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
243
                    }
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
                    GridLayout {
                        columns: 2
                        rowSpacing:         ScreenTools.defaultFontPixelHeight * 0.5
                        columnSpacing:      ScreenTools.defaultFontPixelHeight * 0.5
                        visible:            settingsHeader.checked

                        FactCheckBox {
                            text:       qsTr("Show All")
                            fact:       wimaController.showAllMissionItems
                            Layout.fillWidth: true
                        }

                        FactCheckBox {
                            text:       qsTr("Show Current")
                            fact:       wimaController.showCurrentMissionItems
                            Layout.fillWidth: true
                        }

                        FactCheckBox {
                            text:       qsTr("Reverse")
                            fact:       wimaController.reverse
                            Layout.fillWidth: true
                        }
                    } // Grid

                    SectionHeader{
                        id: missionHeader
                        text: qsTr("Mission")
Valentin Platzgummer's avatar
Valentin Platzgummer committed
272
                    }
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
                    GridLayout {
                        columns:            2
                        rowSpacing:         ScreenTools.defaultFontPixelHeight * 0.5
                        columnSpacing:      ScreenTools.defaultFontPixelHeight * 0.5
                        visible:            missionHeader.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
                        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
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
                    GridLayout {
                        columns:            2
                        rowSpacing:         ScreenTools.defaultFontPixelHeight * 0.5
                        columnSpacing:      ScreenTools.defaultFontPixelHeight * 0.5
                        visible:            missionHeader.checked
                        width:              parent.width

                        // Buttons
                        QGCButton {
                            id: buttonPreviousMissionPhase
                            text:                   qsTr("Reverse")
                            onClicked:              wimaController.previousPhase()
                            Layout.fillWidth: true
                        }

                        QGCButton {
                            id: buttonNextMissionPhase
                            text:               qsTr("Forward")
                            onClicked:          wimaController.nextPhase()
                            Layout.fillWidth: true
                        }

                        QGCButton {
                            id: buttonResetPhase
                            text:               qsTr("Reset Phase")
                            onClicked:          wimaController.resetPhase();
                            Layout.columnSpan:  2
                            Layout.fillWidth: true
                        }
                    } // Grid

                    SectionHeader{
                        id: vehicleHeader
                        text: qsTr("Vehicle")
Valentin Platzgummer's avatar
Valentin Platzgummer committed
334
                    }
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
                    GridLayout {
                        columns: 2
                        rowSpacing:         ScreenTools.defaultFontPixelHeight * 0.5
                        columnSpacing:      ScreenTools.defaultFontPixelHeight * 0.5
                        visible:            vehicleHeader.checked
                        width:              parent.width

                        QGCButton {
                            id: buttonUpload
                            text:               qsTr("Upload")
                            onClicked:          wimaController.uploadToVehicle()
                            Layout.fillWidth: true
                        }

                        QGCButton {
                            id: buttonRemoveFromVehicle
                            text:               qsTr("Remove")
                            onClicked:          wimaController.removeFromVehicle()
                            Layout.fillWidth: true
                        }

                        QGCButton {
                            id: buttonSmartRTL
                            text:               qsTr("Smart RTL")
                            onClicked:          initSmartRTL()
                            Layout.columnSpan:  2
                            Layout.fillWidth: true
                        }


                        // 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
                            text:                   "Done"
                            visible:                false
                            Layout.fillWidth:       true
                        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
386 387
                    }

388 389 390
                    SectionHeader {
                        id: statsHeader
                        text: qsTr("Statistics")
Valentin Platzgummer's avatar
Valentin Platzgummer committed
391
                    }
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
                    GridLayout {
                        columns: 2
                        rowSpacing: ScreenTools.defaultFontPixelHeight * 0.5
                        anchors.topMargin: ScreenTools.defaultFontPixelHeight * 0.5
                        visible: statsHeader.checked

                        QGCLabel {
                            text:               qsTr("Phase Length: ")
                            wrapMode:           Text.WordWrap
                            Layout.fillWidth: true
                        }
                        QGCLabel {
                            text:               wimaController.phaseDistance >= 0 ? wimaController.phaseDistance.toFixed(2) + " m": ""
                            wrapMode:           Text.WordWrap
                            Layout.fillWidth:   true
                        }

                        QGCLabel {
                            text:               qsTr("Phase Duration: ")
                            wrapMode:           Text.WordWrap
                            Layout.fillWidth: true
                        }
                        QGCLabel {
                            text:               wimaController.phaseDuration >= 0 ? getTime(wimaController.phaseDuration) : ""
                            wrapMode:           Text.WordWrap
                            Layout.fillWidth: true
                        }
                        QGCLabel {
                            text:               ""
                            Layout.columnSpan:  2
                        }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
423
                    }
424
                } // settingsColumn
Valentin Platzgummer's avatar
Valentin Platzgummer committed
425

426 427 428
                Item { // spacer
                    width: 6
                    height: 1
Valentin Platzgummer's avatar
Valentin Platzgummer committed
429
                }
430
            }
Valentin Platzgummer's avatar
Valentin Platzgummer committed
431 432 433


        } // QGCFlickable
434 435
    }
}