MainToolBar.qml 32.7 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief QGC Main Tool Bar
 *   @author Gus Grubba <mavlink@grubba.com>
 */

import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

34 35 36 37 38
import QGroundControl.Controls              1.0
import QGroundControl.FactControls          1.0
import QGroundControl.Palette               1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
39
import QGroundControl.Controllers           1.0
dogmaphobic's avatar
dogmaphobic committed
40

41 42 43
Item {
    id:     toolBarHolder
    height: toolBarHeight
dogmaphobic's avatar
dogmaphobic committed
44 45

    property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true }
46

47 48
    property var activeVehicle: multiVehicleManager.activeVehicle

Don Gagne's avatar
Don Gagne committed
49 50
    readonly property real toolBarHeight:   ScreenTools.defaultFontPixelHeight * 3
    property int cellSpacerSize:            ScreenTools.isMobile ? getProportionalDimmension(6) : getProportionalDimmension(4)
Don Gagne's avatar
Don Gagne committed
51 52 53 54
    readonly property int cellHeight:       toolBarHeight * 0.75

    readonly property real horizontalMargins:   ScreenTools.defaultFontPixelWidth / 2
    readonly property real verticalMargins:     ScreenTools.defaultFontPixelHeight / 4
dogmaphobic's avatar
dogmaphobic committed
55

Don Gagne's avatar
Don Gagne committed
56 57 58 59 60
    readonly property var colorBlue:    "#1a6eaa"
    readonly property var colorGreen:   "#329147"
    readonly property var colorRed:     "#942324"
    readonly property var colorOrange:  "#a76f26"
    readonly property var colorWhite:   "#f0f0f0"
dogmaphobic's avatar
dogmaphobic committed
61

62 63 64 65 66
    property var colorOrangeText: (qgcPal.globalTheme === QGCPalette.Light) ? "#b75711" : "#ea8225"
    property var colorRedText:    (qgcPal.globalTheme === QGCPalette.Light) ? "#ee1112" : "#ef2526"
    property var colorGreenText:  (qgcPal.globalTheme === QGCPalette.Light) ? "#046b1b" : "#00d930"
    property var colorWhiteText:  (qgcPal.globalTheme === QGCPalette.Light) ? "#343333" : "#f0f0f0"

67
    MainToolBarController { id: _controller }
dogmaphobic's avatar
dogmaphobic committed
68

69 70 71
    function showToolbarMessage(message) {
        toolBarMessage.text = message
        if (toolBarMessage.contentHeight > toolBarMessageCloseButton.height) {
Don Gagne's avatar
Don Gagne committed
72
            toolBarHolder.height = toolBarHeight + toolBarMessage.contentHeight + (verticalMargins * 2)
73
        } else {
Don Gagne's avatar
Don Gagne committed
74
            toolBarHolder.height = toolBarHeight + toolBarMessageCloseButton.height + (verticalMargins * 2)
Don Gagne's avatar
Don Gagne committed
75
        }
76
        toolBarMessageArea.visible = true
Don Gagne's avatar
Don Gagne committed
77 78
    }

dogmaphobic's avatar
dogmaphobic committed
79
    function getProportionalDimmension(val) {
Don Gagne's avatar
Don Gagne committed
80
        return toolBarHeight * val / 40
dogmaphobic's avatar
dogmaphobic committed
81 82
    }

dogmaphobic's avatar
dogmaphobic committed
83
    function getMessageColor() {
84
        if (activeVehicle.messageTypeNone)
dogmaphobic's avatar
dogmaphobic committed
85
            return qgcPal.button;
86
        if (activeVehicle.messageTypeNorma)
dogmaphobic's avatar
dogmaphobic committed
87
            return colorBlue;
88
        if (activeVehicle.messageTypeWarning)
dogmaphobic's avatar
dogmaphobic committed
89
            return colorOrange;
90
        if (activeVehicle.messageTypeError)
dogmaphobic's avatar
dogmaphobic committed
91 92 93 94 95 96
            return colorRed;
        // Cannot be so make make it obnoxious to show error
        return "purple";
    }

    function getMessageIcon() {
97
        if (activeVehicle.messageTypeNormal || activeVehicle.messageTypeNone)
Don Gagne's avatar
Don Gagne committed
98
            return "qrc:/res/Megaphone";
dogmaphobic's avatar
dogmaphobic committed
99
        else
Don Gagne's avatar
Don Gagne committed
100
            return "qrc:/res/Yield";
dogmaphobic's avatar
dogmaphobic committed
101 102 103
    }

    function getBatteryIcon() {
104
        if(activeVehicle.batteryPercent < 20.0)
Don Gagne's avatar
Don Gagne committed
105
            return "qrc:/res/Battery_0";
106
        else if(activeVehicle.batteryPercent < 40.0)
Don Gagne's avatar
Don Gagne committed
107
            return "qrc:/res/Battery_20";
108
        else if(activeVehicle.batteryPercent < 60.0)
Don Gagne's avatar
Don Gagne committed
109
            return "qrc:/res/Battery_40";
110
        else if(activeVehicle.batteryPercent < 80.0)
Don Gagne's avatar
Don Gagne committed
111
            return "qrc:/res/Battery_60";
112
        else if(activeVehicle.batteryPercent < 90.0)
Don Gagne's avatar
Don Gagne committed
113
            return "qrc:/res/Battery_80";
dogmaphobic's avatar
dogmaphobic committed
114
        else
Don Gagne's avatar
Don Gagne committed
115
            return "qrc:/res/Battery_100";
dogmaphobic's avatar
dogmaphobic committed
116 117
    }

dogmaphobic's avatar
dogmaphobic committed
118
    function getBatteryColor() {
119
        if (activeVehicle.batteryPercent > 40.0)
dogmaphobic's avatar
dogmaphobic committed
120
            return colorGreen;
121
        if(activeVehicle.batteryPercent > 0.01)
dogmaphobic's avatar
dogmaphobic committed
122 123 124 125 126 127 128
            return colorRed;
        // This means there is no battery level data
        return colorBlue;
    }

    function getSatelliteColor() {
        // No GPS data
129
        if (activeVehicle.satelliteCount < 0)
dogmaphobic's avatar
dogmaphobic committed
130 131
            return qgcPal.button
        // No Lock
132
        if(activeVehicle.satelliteLock < 2)
dogmaphobic's avatar
dogmaphobic committed
133 134
            return colorRed;
        // 2D Lock
135
        if(activeVehicle.satelliteLock === 2)
dogmaphobic's avatar
dogmaphobic committed
136 137 138 139 140
            return colorBlue;
        // Lock is 3D or more
        return colorGreen;
    }

141 142 143 144 145 146
    function getRSSIColor(value) {
        if(value < 10)
            return colorRed;
        if(value < 50)
            return colorOrange;
        return colorGreen;
147 148
    }

dogmaphobic's avatar
dogmaphobic committed
149
    function showMavStatus() {
150
         return (multiVehicleManager.activeVehicleAvailable && activeVehicle.heartbeatTimeout === 0 && _controller.connectionCount > 0);
dogmaphobic's avatar
dogmaphobic committed
151 152
    }

dogmaphobic's avatar
dogmaphobic committed
153 154 155 156
    //-------------------------------------------------------------------------
    //-- Main menu for Mobile Devices
    Menu {
        id: maintMenu
157

dogmaphobic's avatar
dogmaphobic committed
158
        ExclusiveGroup { id: mainMenuGroup }
159

dogmaphobic's avatar
dogmaphobic committed
160
        MenuItem {
161 162 163 164
            id:             flyViewShowing
            text:           "Fly"
            checkable:      true
            checked:        true
dogmaphobic's avatar
dogmaphobic committed
165
            exclusiveGroup: mainMenuGroup
166 167 168 169

            onTriggered: {
                checked = true
                _controller.onFlyView();
dogmaphobic's avatar
dogmaphobic committed
170 171
            }
        }
172

dogmaphobic's avatar
dogmaphobic committed
173
        MenuItem {
174 175 176
            id:             setupViewShowing
            text:           "Setup"
            checkable:      true
dogmaphobic's avatar
dogmaphobic committed
177
            exclusiveGroup: mainMenuGroup
178 179 180 181

            onTriggered: {
                checked = true
                _controller.onSetupView();
dogmaphobic's avatar
dogmaphobic committed
182 183
            }
        }
184

dogmaphobic's avatar
dogmaphobic committed
185
        MenuItem {
186 187 188
            id:             planViewShowing
            text:           "Plan"
            checkable:      true
dogmaphobic's avatar
dogmaphobic committed
189
            exclusiveGroup: mainMenuGroup
190 191 192 193

            onTriggered: {
                checked = true
                _controller.onPlanView();
dogmaphobic's avatar
dogmaphobic committed
194 195
            }
        }
Don Gagne's avatar
Don Gagne committed
196 197 198 199 200 201 202 203 204

        MenuSeparator { }


        MenuItem {
            text:           "QGroundControl Settings"

            onTriggered: controller.showSettings()
        }
Don Gagne's avatar
Don Gagne committed
205
    } // Menu
dogmaphobic's avatar
dogmaphobic committed
206

207 208
    Component {
        id: activeVehicleComponent
dogmaphobic's avatar
dogmaphobic committed
209

210
        Row {
211 212
            height:     cellHeight
            spacing:    cellSpacerSize
dogmaphobic's avatar
dogmaphobic committed
213

dogmaphobic's avatar
dogmaphobic committed
214
            Rectangle {
215
                id: messages
216
                width: (activeVehicle.messageCount > 99) ? getProportionalDimmension(65) : getProportionalDimmension(60)
217
                height: cellHeight
dogmaphobic's avatar
dogmaphobic committed
218
                anchors.verticalCenter: parent.verticalCenter
219 220 221 222 223 224 225 226
                color:  getMessageColor()
                border.color: "#00000000"
                border.width: 0
                property bool showTriangle: false

                Image {
                    id: messageIcon
                    source: getMessageIcon();
dogmaphobic's avatar
dogmaphobic committed
227
                    height: getProportionalDimmension(16)
228
                    fillMode: Image.PreserveAspectFit
dogmaphobic's avatar
dogmaphobic committed
229
                    anchors.verticalCenter: parent.verticalCenter
230
                    anchors.left: parent.left
231
                    anchors.leftMargin: getProportionalDimmension(8)
dogmaphobic's avatar
dogmaphobic committed
232 233
                }

dogmaphobic's avatar
dogmaphobic committed
234
                Item {
235 236 237 238
                    id: messageTextRect
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    width: messages.width - messageIcon.width
239
                    QGCLabel {
240
                        id: messageText
241
                        text: (activeVehicle.messageCount > 0) ? activeVehicle.messageCount : ''
Don Gagne's avatar
Don Gagne committed
242
                        font.pixelSize: ScreenTools.smallFontPixelSize
243 244 245 246 247 248 249
                        font.weight: Font.DemiBold
                        anchors.verticalCenter: parent.verticalCenter
                        anchors.horizontalCenter: parent.horizontalCenter
                        horizontalAlignment: Text.AlignHCenter
                        color: colorWhite
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
250

251 252
                Image {
                    id: dropDown
253
                    source: "/qmlimages/arrow-down.png"
254
                    visible: (messages.showTriangle) && (activeVehicle.messageCount > 0)
255 256
                    anchors.bottom: parent.bottom
                    anchors.right: parent.right
dogmaphobic's avatar
dogmaphobic committed
257 258
                    anchors.bottomMargin: getProportionalDimmension(3)
                    anchors.rightMargin:  getProportionalDimmension(3)
dogmaphobic's avatar
dogmaphobic committed
259 260
                }

261 262 263 264 265 266 267 268
                Timer {
                    id: mouseOffTimer
                    interval: 2000;
                    running: false;
                    repeat: false
                    onTriggered: {
                        messages.showTriangle = false;
                    }
dogmaphobic's avatar
dogmaphobic committed
269
                }
270 271 272 273 274 275 276 277 278

                MouseArea {
                    anchors.fill: parent
                    hoverEnabled: true
                    onEntered: {
                        messages.showTriangle = true;
                        mouseOffTimer.start();
                    }
                    onClicked: {
dogmaphobic's avatar
dogmaphobic committed
279
                        var p = mapToItem(toolBarHolder, mouseX, mouseY);
280
                        _controller.onEnterMessageArea(p.x, p.y);
dogmaphobic's avatar
dogmaphobic committed
281
                    }
dogmaphobic's avatar
dogmaphobic committed
282 283 284 285
                }

            }

Don Gagne's avatar
Don Gagne committed
286 287 288
            QGCButton {
                width:                  ScreenTools.defaultFontPixelWidth * 12
                height:                 cellHeight
dogmaphobic's avatar
dogmaphobic committed
289
                anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
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
                text:                   "Vehicle " + activeVehicle.id

                menu: vehicleMenu

                Menu {
                    id: vehicleMenu
                }

                Component {
                    id: vehicleMenuItemComponent

                    MenuItem {
                        checkable:      true
                        checked:        vehicle.active
                        onTriggered:    multiVehicleManager.activeVehicle = vehicle

                        property int vehicleId: Number(text.split(" ")[1])
                        property var vehicle:   multiVehicleManager.getVehicleById(vehicleId)
                    }
                }

                property var vehicleMenuItems: []

                function updateVehicleMenu() {
                    // Remove old menu items
                    for (var i=0; i<vehicleMenuItems.length; i++) {
                        vehicleMenu.removeItem(vehicleMenuItems[i])
                    }
                    vehicleMenuItems.length = 0

                    // Add new items
                    for (var i=0; i<multiVehicleManager.vehicles.count; i++) {
                        var vehicle = multiVehicleManager.vehicles.get(i)
                        var menuItem = vehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id })
                        vehicleMenuItems.push(menuItem)
                        vehicleMenu.insertItem(i, menuItem)
                    }
                }

                Component.onCompleted: updateVehicleMenu()

                Connections {
                    target:         multiVehicleManager.vehicles
                    onCountChanged: parent.updateVehicleMenu
334
                }
dogmaphobic's avatar
dogmaphobic committed
335 336
            }

Don Gagne's avatar
Don Gagne committed
337

338 339
            Rectangle {
                id: satelitte
340
                width:  getProportionalDimmension(55)
341
                height: cellHeight
dogmaphobic's avatar
dogmaphobic committed
342
                anchors.verticalCenter: parent.verticalCenter
343 344 345 346 347
                color:  getSatelliteColor();
                border.color: "#00000000"
                border.width: 0

                Image {
Don Gagne's avatar
Don Gagne committed
348
                    source: "qrc:/res/Gps";
dogmaphobic's avatar
dogmaphobic committed
349
                    height: getProportionalDimmension(24)
350 351 352
                    fillMode: Image.PreserveAspectFit
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
353
                    anchors.leftMargin: getProportionalDimmension(6)
354 355 356 357
                    mipmap: true
                    smooth: true
                }

358
                QGCLabel {
359
                    id: satelitteText
360 361
                    text: activeVehicle.satelliteCount >= 0 ? activeVehicle.satelliteCount : 'NA'
                    font.pixelSize: activeVehicle.satelliteCount >= 0 ? ScreenTools.defaultFontPixelSize : ScreenTools.smallFontPixelSize
362 363 364
                    font.weight: Font.DemiBold
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
365
                    anchors.rightMargin: getProportionalDimmension(6)
366 367 368
                    horizontalAlignment: Text.AlignRight
                    color: colorWhite
                }
dogmaphobic's avatar
dogmaphobic committed
369 370
            }

371
            Rectangle {
372 373
                id: rssiRC
                width:  getProportionalDimmension(55)
374
                height: cellHeight
375
                visible: _controller.remoteRSSI <= 100
376
                anchors.verticalCenter: parent.verticalCenter
377
                color:  getRSSIColor(_controller.remoteRSSI);
378 379 380
                border.color: "#00000000"
                border.width: 0
                Image {
381 382
                    source: "qrc:/res/AntennaRC";
                    width: cellHeight * 0.7
383 384 385 386 387 388 389
                    fillMode: Image.PreserveAspectFit
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: getProportionalDimmension(6)
                    mipmap: true
                    smooth: true
                }
390
                QGCLabel {
391
                    text: _controller.remoteRSSI
392 393 394 395
                    anchors.right: parent.right
                    anchors.rightMargin: getProportionalDimmension(6)
                    anchors.verticalCenter: parent.verticalCenter
                    horizontalAlignment: Text.AlignRight
Don Gagne's avatar
Don Gagne committed
396
                    font.pixelSize: ScreenTools.smallFontPixelSize
397 398 399 400
                    font.weight: Font.DemiBold
                    color: colorWhite
                }
            }
401

402 403 404 405
            Rectangle {
                id: rssiTelemetry
                width:  getProportionalDimmension(80)
                height: cellHeight
406
                visible: (_controller.telemetryRRSSI > 0) && (_controller.telemetryLRSSI > 0)
407
                anchors.verticalCenter: parent.verticalCenter
408
                color:  getRSSIColor(Math.min(_controller.telemetryRRSSI,_controller.telemetryLRSSI));
409 410 411 412 413 414 415 416 417 418 419 420
                border.color: "#00000000"
                border.width: 0
                Image {
                    source: "qrc:/res/AntennaT";
                    width: cellHeight * 0.7
                    fillMode: Image.PreserveAspectFit
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: getProportionalDimmension(6)
                    mipmap: true
                    smooth: true
                }
421 422 423 424 425 426 427 428
                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right:          parent.right
                    anchors.rightMargin:    getProportionalDimmension(6)
                    Row {
                        anchors.right: parent.right
                        QGCLabel {
                            text: 'R '
Don Gagne's avatar
Don Gagne committed
429
                            font.pixelSize: ScreenTools.smallFontPixelSize
430 431 432 433
                            font.weight: Font.DemiBold
                            color: colorWhite
                        }
                        QGCLabel {
434
                            text: _controller.telemetryRRSSI + 'dB'
435
                            width: getProportionalDimmension(30)
436
                            horizontalAlignment: Text.AlignRight
Don Gagne's avatar
Don Gagne committed
437
                            font.pixelSize: ScreenTools.smallFontPixelSize
438 439 440 441 442 443 444
                            font.weight: Font.DemiBold
                            color: colorWhite
                        }
                    }
                    Row {
                        anchors.right: parent.right
                        QGCLabel {
445
                            text: 'L '
Don Gagne's avatar
Don Gagne committed
446
                            font.pixelSize: ScreenTools.smallFontPixelSize
447 448 449 450
                            font.weight: Font.DemiBold
                            color: colorWhite
                        }
                        QGCLabel {
451
                            text: _controller.telemetryLRSSI + 'dB'
452
                            width: getProportionalDimmension(30)
453
                            horizontalAlignment: Text.AlignRight
Don Gagne's avatar
Don Gagne committed
454
                            font.pixelSize: ScreenTools.smallFontPixelSize
455 456 457 458 459 460 461
                            font.weight: Font.DemiBold
                            color: colorWhite
                        }
                    }
                }
            }

462
            Rectangle {
463
                id: batteryStatus
464
                width:  activeVehicle.batteryConsumed < 0.0 ? getProportionalDimmension(60) : getProportionalDimmension(80)
465
                height: cellHeight
dogmaphobic's avatar
dogmaphobic committed
466
                anchors.verticalCenter: parent.verticalCenter
dogmaphobic's avatar
dogmaphobic committed
467
                color:  getBatteryColor();
468 469 470 471
                border.color: "#00000000"
                border.width: 0
                Image {
                    source: getBatteryIcon();
dogmaphobic's avatar
dogmaphobic committed
472
                    height: getProportionalDimmension(20)
473 474 475
                    fillMode: Image.PreserveAspectFit
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
dogmaphobic's avatar
dogmaphobic committed
476
                    anchors.leftMargin: getProportionalDimmension(6)
477 478 479 480
                    mipmap: true
                    smooth: true
                }

481
                QGCLabel {
482
                    visible: batteryStatus.visible && activeVehicle.batteryConsumed < 0.0
483
                    text: (activeVehicle.batteryVoltage > 0) ? activeVehicle.batteryVoltage.toFixed(1) + 'V' : '---';
Don Gagne's avatar
Don Gagne committed
484
                    font.pixelSize: ScreenTools.smallFontPixelSize
485 486
                    font.weight: Font.DemiBold
                    anchors.right: parent.right
487
                    anchors.rightMargin: getProportionalDimmension(6)
dogmaphobic's avatar
dogmaphobic committed
488
                    anchors.verticalCenter: parent.verticalCenter
489 490 491
                    horizontalAlignment: Text.AlignRight
                    color: colorWhite
                }
492 493 494 495 496

                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right:          parent.right
                    anchors.rightMargin:    getProportionalDimmension(6)
497
                    visible: batteryStatus.visible && activeVehicle.batteryConsumed >= 0.0
498
                    QGCLabel {
499
                        text: (activeVehicle.batteryVoltage > 0) ? activeVehicle.batteryVoltage.toFixed(1) + 'V' : '---';
500 501
                        width: getProportionalDimmension(30)
                        horizontalAlignment: Text.AlignRight
Don Gagne's avatar
Don Gagne committed
502
                        font.pixelSize: ScreenTools.smallFontPixelSize
503 504 505 506
                        font.weight: Font.DemiBold
                        color: colorWhite
                    }
                    QGCLabel {
507
                        text: (activeVehicle.batteryConsumed > 0) ? activeVehicle.batteryConsumed.toFixed(0) + 'mAh' : '---';
508 509
                        width: getProportionalDimmension(30)
                        horizontalAlignment: Text.AlignRight
Don Gagne's avatar
Don Gagne committed
510
                        font.pixelSize: ScreenTools.smallFontPixelSize
511 512 513 514
                        font.weight: Font.DemiBold
                        color: colorWhite
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
515 516
            }

Don Gagne's avatar
Don Gagne committed
517 518 519
            QGCButton {
                width:                  ScreenTools.defaultFontPixelWidth * 11
                height:                 cellHeight
dogmaphobic's avatar
dogmaphobic committed
520
                anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
521
                text:                   activeVehicle.armed ? "Armed" : "Disarmed"
dogmaphobic's avatar
dogmaphobic committed
522

Don Gagne's avatar
Don Gagne committed
523 524 525 526
                menu: Menu {
                    MenuItem {
                        enabled: !activeVehicle.armed
                        text: "Arm"
527

Don Gagne's avatar
Don Gagne committed
528 529 530 531 532 533 534 535
                        onTriggered: activeVehicle.armed = true
                    }

                    MenuItem {
                        enabled: activeVehicle.armed
                        text: "Disarm"

                        onTriggered: activeVehicle.armed = false
536 537
                    }
                }
Don Gagne's avatar
Don Gagne committed
538
            }
539

Don Gagne's avatar
Don Gagne committed
540 541 542 543 544
            QGCButton {
                width:                  ScreenTools.defaultFontPixelWidth * 15
                height:                 cellHeight
                anchors.verticalCenter: parent.verticalCenter
                text:                   activeVehicle.flightMode
545

546
                menu: activeVehicle.flightModeSetAvailable ? flightModesMenu : null
Don Gagne's avatar
Don Gagne committed
547 548 549 550 551 552 553 554 555 556 557 558

                Menu {
                    id: flightModesMenu
                }

                Component {
                    id: flightModeMenuItemComponent

                    MenuItem {
                        checkable:      true
                        checked:        activeVehicle.flightMode == text
                        onTriggered:    activeVehicle.flightMode = text
559 560 561
                    }
                }

Don Gagne's avatar
Don Gagne committed
562 563 564
                property var flightModesMenuItems: []

                function updateFlightModesMenu() {
565 566 567 568 569 570 571 572 573 574 575 576 577
                    if (activeVehicle.flightModeSetAvailable) {
                        // Remove old menu items
                        for (var i=0; i<flightModesMenuItems.length; i++) {
                            flightModesMenu.removeItem(flightModesMenuItems[i])
                        }
                        flightModesMenuItems.length = 0

                            // Add new items
                            for (var i=0; i<activeVehicle.flightModes.length; i++) {
                                var menuItem = flightModeMenuItemComponent.createObject(null, { "text": activeVehicle.flightModes[i] })
                                flightModesMenuItems.push(menuItem)
                                flightModesMenu.insertItem(i, menuItem)
                            }
Don Gagne's avatar
Don Gagne committed
578 579 580 581 582 583 584 585 586
                    }
                }

                Component.onCompleted: updateFlightModesMenu()

                Connections {
                    target:                 multiVehicleManager
                    onActiveVehicleChanged: parent.updateFlightModesMenu
                }
587
            }
dogmaphobic's avatar
dogmaphobic committed
588 589

            Rectangle {
Don Gagne's avatar
Don Gagne committed
590 591 592 593 594 595
                width:                  ScreenTools.defaultFontPixelWidth * 4
                height:                 cellHeight
                anchors.verticalCenter: parent.verticalCenter
                color:                  colorBlue
                border.width:           0
                visible:                activeVehicle.hilMode
dogmaphobic's avatar
dogmaphobic committed
596

597
                QGCLabel {
Don Gagne's avatar
Don Gagne committed
598 599 600 601
                    anchors.fill:           parent
                    horizontalAlignment:    Text.AlignHCenter
                    verticalAlignment:      Text.AlignVCenter
                    text:                   "HIL"
dogmaphobic's avatar
dogmaphobic committed
602 603
                }
            }
Don Gagne's avatar
Don Gagne committed
604

605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
        } // Row
    } // Component - activeVehicleComponent

    Row {
        id:         toolRow
        x:          horizontalMargins
        y:          (toolBarHeight - cellHeight) / 2
        height:     cellHeight
        spacing:    getProportionalDimmension(4)

        //---------------------------------------------------------------------
        //-- Main menu for Non Mobile Devices (Chevron Buttons)
        Row {
            id:             row11
            height:         cellHeight
            spacing:        -getProportionalDimmension(12)
            anchors.top:    parent.top
            visible:        !ScreenTools.isMobile

            Connections {
                target: ScreenTools
                onRepaintRequested: {
                    setupButton.repaintChevron   = true;
                    planButton.repaintChevron    = true;
                    flyButton.repaintChevron     = true;
                }
            }

            ExclusiveGroup { id: mainActionGroup }

            QGCToolBarButton {
636 637 638
                id:             setupButton
                width:          getProportionalDimmension(90)
                height:         cellHeight
639
                exclusiveGroup: mainActionGroup
640 641
                text:           "Setup"

642
                onClicked: {
643 644
                    checked = true
                    _controller.onSetupView();
645 646 647 648 649
                }
                z: 1000
            }

            QGCToolBarButton {
650 651 652
                id:             planButton
                width:          getProportionalDimmension(90)
                height:         cellHeight
653
                exclusiveGroup: mainActionGroup
654 655
                text:           "Plan"

656
                onClicked: {
657 658
                    checked = true
                    _controller.onPlanView();
659 660 661 662 663
                }
                z: 900
            }

            QGCToolBarButton {
664 665 666
                id:             flyButton
                width:          getProportionalDimmension(90)
                height:         cellHeight
667
                exclusiveGroup: mainActionGroup
668 669 670
                text:           "Fly"
                checked:        true

671
                onClicked: {
672 673
                    checked = true
                    _controller.onFlyView();
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
                }
                z: 800
            }
        } // Row

        //---------------------------------------------------------------------
        //-- Indicators
        Row {
            id:                     row12
            height:                 cellHeight
            spacing:                cellSpacerSize
            anchors.verticalCenter: parent.verticalCenter

            //-- "Hamburger" menu for Mobile Devices
            Item {
                id:         actionButton
                visible:    ScreenTools.isMobile
                height:     cellHeight
                width:      cellHeight
                Image {
                    id:             buttomImg
                    anchors.fill:   parent
                    source:         "/qmlimages/buttonMore.svg"
                    mipmap:         true
                    smooth:         true
                    antialiasing:   true
                    fillMode:       Image.PreserveAspectFit
                }
                MouseArea {
                    anchors.fill: parent
                    acceptedButtons: Qt.LeftButton
                    onClicked: {
                        if (mouse.button == Qt.LeftButton)
                        {
                            maintMenu.popup();
                        }
                    }
                }
            }

            //-- Separator if Hamburger menu is visible
            Rectangle {
                visible:    actionButton.visible
                height:     cellHeight
                width:      cellHeight
                color:      "#00000000"
                anchors.verticalCenter: parent.verticalCenter
            }

            Loader {
                id:                 activeVehicleLoader
                visible:            showMavStatus()
                sourceComponent:    multiVehicleManager.activeVehicleAvailable ? activeVehicleComponent : undefined

                property real cellHeight:       toolBarHolder.cellHeight
                property real cellSpacerSize:   toolBarHolder.cellSpacerSize
            }
dogmaphobic's avatar
dogmaphobic committed
731 732

            Rectangle {
733
                id: connectionStatus
dogmaphobic's avatar
dogmaphobic committed
734
                width: getProportionalDimmension(160)
735
                height: cellHeight
736
                visible: (_controller.connectionCount > 0 && multiVehicleManager.activeVehicleAvailable && activeVehicle.heartbeatTimeout != 0)
737
                anchors.verticalCenter: parent.verticalCenter
dogmaphobic's avatar
dogmaphobic committed
738 739 740 741
                color: "#00000000"
                border.color: "#00000000"
                border.width: 0

742
                QGCLabel {
743 744
                    id: connectionStatusText
                    text: qsTr("CONNECTION LOST")
Don Gagne's avatar
Don Gagne committed
745
                    font.pixelSize: ScreenTools.defaultFontPixelSize
dogmaphobic's avatar
dogmaphobic committed
746
                    font.weight: Font.DemiBold
747 748
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.horizontalCenter: parent.horizontalCenter
749
                    color: colorRedText
dogmaphobic's avatar
dogmaphobic committed
750 751
                }
            }
Don Gagne's avatar
Don Gagne committed
752 753
        } // Row
    } // Row
dogmaphobic's avatar
dogmaphobic committed
754 755

    Row {
Don Gagne's avatar
Don Gagne committed
756 757 758 759 760 761 762
        id:                     connectRow
        anchors.rightMargin:    verticalMargins
        anchors.right:          parent.right
        anchors.top:            toolRow.top
        anchors.verticalCenter: toolRow.verticalCenter
        height:                 toolRow.height
        spacing:                cellSpacerSize
dogmaphobic's avatar
dogmaphobic committed
763

dogmaphobic's avatar
dogmaphobic committed
764 765
        Menu {
            id: connectMenu
dogmaphobic's avatar
dogmaphobic committed
766
            Component.onCompleted: {
767
                _controller.configListChanged.connect(connectMenu.updateConnectionList);
dogmaphobic's avatar
dogmaphobic committed
768
                connectMenu.updateConnectionList();
dogmaphobic's avatar
dogmaphobic committed
769
            }
dogmaphobic's avatar
dogmaphobic committed
770 771 772 773 774
            function addMenuEntry(name) {
                var label = "Add Connection"
                if(name !== "")
                    label = name;
                var mItem = connectMenu.addItem(label);
775
                var menuSlot = function() {_controller.onConnect(name)};
dogmaphobic's avatar
dogmaphobic committed
776 777 778 779
                mItem.triggered.connect(menuSlot);
            }
            function updateConnectionList() {
                connectMenu.clear();
780 781
                for(var i = 0; i < _controller.configList.length; i++) {
                    connectMenu.addMenuEntry(_controller.configList[i]);
dogmaphobic's avatar
dogmaphobic committed
782
                }
783
                if(_controller.configList.length > 0) {
dogmaphobic's avatar
dogmaphobic committed
784 785 786 787
                    connectMenu.addSeparator();
                }
                // Add "Add Connection" to the list
                connectMenu.addMenuEntry("");
dogmaphobic's avatar
dogmaphobic committed
788 789 790 791
            }
        }

        QGCButton {
dogmaphobic's avatar
dogmaphobic committed
792
            id:         connectButton
dogmaphobic's avatar
dogmaphobic committed
793
            width:      getProportionalDimmension(100)
794
            visible:    _controller.connectionCount === 0
dogmaphobic's avatar
dogmaphobic committed
795 796 797 798 799 800
            text:       qsTr("Connect")
            menu:       connectMenu
        }

        QGCButton {
            id:         disconnectButton
dogmaphobic's avatar
dogmaphobic committed
801
            width:      getProportionalDimmension(100)
802
            visible:    _controller.connectionCount === 1
dogmaphobic's avatar
dogmaphobic committed
803
            text:       qsTr("Disconnect")
dogmaphobic's avatar
dogmaphobic committed
804
            onClicked: {
805
                _controller.onDisconnect("");
dogmaphobic's avatar
dogmaphobic committed
806 807 808 809 810 811
            }
        }

        Menu {
            id: disconnectMenu
            Component.onCompleted: {
812
                _controller.connectedListChanged.connect(disconnectMenu.onConnectedListChanged)
dogmaphobic's avatar
dogmaphobic committed
813
            }
dogmaphobic's avatar
dogmaphobic committed
814 815
            function addMenuEntry(name) {
                var mItem = disconnectMenu.addItem(name);
816
                var menuSlot = function() {_controller.onDisconnect(name)};
dogmaphobic's avatar
dogmaphobic committed
817 818
                mItem.triggered.connect(menuSlot);
            }
dogmaphobic's avatar
dogmaphobic committed
819 820 821
            function onConnectedListChanged(conList) {
                disconnectMenu.clear();
                for(var i = 0; i < conList.length; i++) {
dogmaphobic's avatar
dogmaphobic committed
822
                    disconnectMenu.addMenuEntry(conList[i]);
dogmaphobic's avatar
dogmaphobic committed
823 824 825 826 827
                }
            }
        }

        QGCButton {
dogmaphobic's avatar
dogmaphobic committed
828
            id:         multidisconnectButton
dogmaphobic's avatar
dogmaphobic committed
829
            width:      getProportionalDimmension(100)
dogmaphobic's avatar
dogmaphobic committed
830
            text:       "Disconnect"
831
            visible:    _controller.connectionCount > 1
dogmaphobic's avatar
dogmaphobic committed
832
            menu:       disconnectMenu
dogmaphobic's avatar
dogmaphobic committed
833
        }
Don Gagne's avatar
Don Gagne committed
834
    } // Row
835 836 837

    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
838 839 840
        id:             progressBar
        anchors.top:    toolRow.bottom
        height:         getProportionalDimmension(3)
841
        width:          parent.width * _controller.progressBarValue
Don Gagne's avatar
Don Gagne committed
842
        color:          qgcPal.text
843
    }
dogmaphobic's avatar
dogmaphobic committed
844

Don Gagne's avatar
Don Gagne committed
845 846
    // Toolbar message area
    Rectangle {
847 848 849 850 851 852 853 854 855 856 857
        id:                     toolBarMessageArea
        anchors.leftMargin:     horizontalMargins
        anchors.rightMargin:    horizontalMargins
        anchors.topMargin:      verticalMargins
        anchors.bottomMargin:   verticalMargins
        anchors.top:            progressBar.bottom
        anchors.bottom:         parent.bottom
        anchors.left:           parent.left
        anchors.right:          parent.right
        color:                  qgcPal.windowShadeDark
        visible:                false
Don Gagne's avatar
Don Gagne committed
858 859 860 861 862

        QGCLabel {
            id:             toolBarMessage
            anchors.fill:   parent
            wrapMode:       Text.WordWrap
863
			color:			qgcPal.warningText
Don Gagne's avatar
Don Gagne committed
864 865 866 867 868 869 870
        }

        QGCButton {
            id:                     toolBarMessageCloseButton
            anchors.rightMargin:    horizontalMargins
            anchors.top:            parent.top
            anchors.right:          parent.right
871
			primary:				true
Don Gagne's avatar
Don Gagne committed
872 873 874 875
            text:                   "Close Message"

            onClicked: {
                parent.visible = false
Don Gagne's avatar
Don Gagne committed
876
                toolBarHolder.height = toolBarHeight
877
                _controller.onToolBarMessageClosed()
Don Gagne's avatar
Don Gagne committed
878 879 880 881
            }
        }
    }
} // Rectangle