MainToolBar.qml 19.1 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 34 35 36 37 38 39 40 41 42
/*=====================================================================

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

import QGroundControl.Controls 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.MainToolBar 1.0

Rectangle {

    property var qgcPal: QGCPalette { id: palette; colorGroupEnabled: true }
    property int cellSpacerSize: 4
43 44
    property int cellHeight:     30
    property int cellRadius:     3
dogmaphobic's avatar
dogmaphobic committed
45 46
    property double dpiFactor: (72.0 / mainToolBar.dotsPerInch);

dogmaphobic's avatar
dogmaphobic committed
47 48 49 50 51
    property var colorBlue:       "#1a6eaa"
    property var colorGreen:      "#079527"
    property var colorRed:        "#a81a1b"
    property var colorOrange:     "#a76f26"
    property var colorWhite:      "#f0f0f0"
dogmaphobic's avatar
dogmaphobic committed
52

53 54 55 56 57
    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"

dogmaphobic's avatar
dogmaphobic committed
58 59 60 61 62 63 64 65 66 67 68 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
    id: toolBarHolder
    color: qgcPal.windowShade

    function getMessageColor() {
        if(mainToolBar.messageType === MainToolBar.MessageNone)
            return qgcPal.button;
        if(mainToolBar.messageType === MainToolBar.MessageNormal)
            return colorBlue;
        if(mainToolBar.messageType === MainToolBar.MessageWarning)
            return colorOrange;
        if(mainToolBar.messageType === MainToolBar.MessageError)
            return colorRed;
        // Cannot be so make make it obnoxious to show error
        return "purple";
    }

    function getMessageIcon() {
        if(mainToolBar.messageType === MainToolBar.MessageNormal || mainToolBar.messageType === MainToolBar.MessageNone)
            return "qrc:/files/images/status/message_megaphone.png";
        else
            return "qrc:/files/images/status/message_triangle.png";
    }

    function getBatteryIcon() {
        if(mainToolBar.batteryPercent < 20.0)
            return "qrc:/files/images/status/battery_0.svg";
        else if(mainToolBar.batteryPercent < 40.0)
            return "qrc:/files/images/status/battery_20.svg";
        else if(mainToolBar.batteryPercent < 60.0)
            return "qrc:/files/images/status/battery_40.svg";
        else if(mainToolBar.batteryPercent < 80.0)
            return "qrc:/files/images/status/battery_60.svg";
        else if(mainToolBar.batteryPercent < 90.0)
            return "qrc:/files/images/status/battery_80.svg";
        else
            return "qrc:/files/images/status/battery_100.svg";
    }

dogmaphobic's avatar
dogmaphobic committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    function getBatteryColor() {
        if (mainToolBar.batteryPercent > 40.0)
            return colorGreen;
        if(mainToolBar.batteryPercent > 0.01)
            return colorRed;
        // This means there is no battery level data
        return colorBlue;
    }

    function getSatelliteColor() {
        // No GPS data
        if (mainToolBar.satelliteCount < 0)
            return qgcPal.button
        // No Lock
        if(mainToolBar.satelliteLock < 2)
            return colorRed;
        // 2D Lock
        if(mainToolBar.satelliteLock === 2)
            return colorBlue;
        // Lock is 3D or more
        return colorGreen;
    }

dogmaphobic's avatar
dogmaphobic committed
119 120 121 122 123
    function showMavStatus() {
         return (mainToolBar.mavPresent && mainToolBar.heartbeatTimeout === 0 && mainToolBar.connectionCount > 0);
    }

    Row {
124 125 126 127
        id:                     row1
        height:                 cellHeight
        anchors.left:           parent.left
        spacing:                4
dogmaphobic's avatar
dogmaphobic committed
128
        anchors.verticalCenter: parent.verticalCenter
129
        anchors.leftMargin:     10
dogmaphobic's avatar
dogmaphobic committed
130

131 132 133 134
        Row {
            id:                     row11
            height:                 cellHeight
            spacing:                -12
dogmaphobic's avatar
dogmaphobic committed
135
            anchors.verticalCenter: parent.verticalCenter
136 137 138 139 140 141 142 143 144

            Connections {
                target: mainToolBar
                onRepaintRequestedChanged: {
                    setupButton.repaintChevron = true;
                    planButton.repaintChevron = true;
                    flyButton.repaintChevron = true;
                    analyzeButton.repaintChevron = true;
                }
dogmaphobic's avatar
dogmaphobic committed
145 146
            }

147 148 149 150
            ExclusiveGroup { id: mainActionGroup }

            QGCToolBarButton {
                id: setupButton
151
                width: 90
152 153
                height: cellHeight
                exclusiveGroup: mainActionGroup
154
                text: qsTr("Setup")
155 156 157 158 159 160
                anchors.verticalCenter: parent.verticalCenter
                checked: (mainToolBar.currentView === MainToolBar.ViewSetup)
                onClicked: {
                    mainToolBar.onSetupView();
                }
                z: 1000
dogmaphobic's avatar
dogmaphobic committed
161 162
            }

163 164
            QGCToolBarButton {
                id: planButton
165
                width: 90
166 167
                height: cellHeight
                exclusiveGroup: mainActionGroup
168
                text: qsTr("Plan")
169 170 171 172 173 174
                anchors.verticalCenter: parent.verticalCenter
                checked: (mainToolBar.currentView === MainToolBar.ViewPlan)
                onClicked: {
                    mainToolBar.onPlanView();
                }
                z: 900
dogmaphobic's avatar
dogmaphobic committed
175 176
            }

177 178
            QGCToolBarButton {
                id: flyButton
179
                width: 90
180 181
                height: cellHeight
                exclusiveGroup: mainActionGroup
182
                text: qsTr("Fly")
183 184 185 186 187 188 189 190 191 192
                anchors.verticalCenter: parent.verticalCenter
                checked: (mainToolBar.currentView === MainToolBar.ViewFly)
                onClicked: {
                    mainToolBar.onFlyView();
                }
                z: 800
            }

            QGCToolBarButton {
                id: analyzeButton
193
                width: 90
194 195
                height: cellHeight
                exclusiveGroup: mainActionGroup
196
                text: qsTr("Analyze")
197 198 199 200 201 202
                anchors.verticalCenter: parent.verticalCenter
                checked: (mainToolBar.currentView === MainToolBar.ViewAnalyze)
                onClicked: {
                    mainToolBar.onAnalyzeView();
                }
                z: 700
dogmaphobic's avatar
dogmaphobic committed
203 204 205 206
            }

        }

207 208 209 210
        Row {
            id:                     row12
            height:                 cellHeight
            spacing:                cellSpacerSize
dogmaphobic's avatar
dogmaphobic committed
211 212 213
            anchors.verticalCenter: parent.verticalCenter

            Rectangle {
214 215 216 217
                id: messages
                width: (mainToolBar.messageCount > 99) ? 70 : 60
                height: cellHeight
                visible: (mainToolBar.connectionCount > 0) && (mainToolBar.showMessages)
dogmaphobic's avatar
dogmaphobic committed
218
                anchors.verticalCenter: parent.verticalCenter
219 220 221 222 223 224 225 226 227 228 229
                color:  getMessageColor()
                radius: cellRadius
                border.color: "#00000000"
                border.width: 0
                property bool showTriangle: false

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

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
                Rectangle {
                    id: messageTextRect
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    width: messages.width - messageIcon.width
                    Text {
                        id: messageText
                        text: (mainToolBar.messageCount > 0) ? mainToolBar.messageCount : ''
                        font.pointSize: 14 * dpiFactor
                        font.weight: Font.DemiBold
                        anchors.verticalCenter: parent.verticalCenter
                        anchors.horizontalCenter: parent.horizontalCenter
                        horizontalAlignment: Text.AlignHCenter
                        color: colorWhite
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
251

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

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

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

            }

287 288 289 290 291
            Rectangle {
                id: mavIcon
                width: cellHeight
                height: cellHeight
                visible: showMavStatus() &&  (mainToolBar.showMav)
dogmaphobic's avatar
dogmaphobic committed
292
                anchors.verticalCenter: parent.verticalCenter
293 294 295 296 297 298 299 300 301 302 303
                color: colorBlue
                radius: cellRadius
                border.color: "#00000000"
                border.width: 0
                Image {
                    source: mainToolBar.systemPixmap
                    height: cellHeight * 0.75
                    fillMode: Image.PreserveAspectFit
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.horizontalCenter: parent.horizontalCenter
                }
dogmaphobic's avatar
dogmaphobic committed
304 305
            }

306 307 308 309 310
            Rectangle {
                id: satelitte
                width: 60
                height: cellHeight
                visible: showMavStatus() && (mainToolBar.showGPS)
dogmaphobic's avatar
dogmaphobic committed
311
                anchors.verticalCenter: parent.verticalCenter
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
                color:  getSatelliteColor();
                radius: cellRadius
                border.color: "#00000000"
                border.width: 0

                Image {
                    source: "qrc:/files/images/status/gps.svg";
                    height: 24
                    fillMode: Image.PreserveAspectFit
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 10
                    mipmap: true
                    smooth: true
                }

                Text {
                    id: satelitteText
                    text: (mainToolBar.satelliteCount > 0) ? mainToolBar.satelliteCount : ''
                    font.pointSize: 14 * dpiFactor
                    font.weight: Font.DemiBold
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    anchors.rightMargin: 10
                    horizontalAlignment: Text.AlignRight
                    color: colorWhite
                }
dogmaphobic's avatar
dogmaphobic committed
339 340
            }

341 342 343 344 345
            Rectangle {
                id: battery
                width: 80
                height: cellHeight
                visible: showMavStatus() && (mainToolBar.showBattery)
dogmaphobic's avatar
dogmaphobic committed
346
                anchors.verticalCenter: parent.verticalCenter
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
                color:  (mainToolBar.batteryPercent > 40.0 || mainToolBar.batteryPercent < 0.01) ? colorBlue : colorRed
                radius: cellRadius
                border.color: "#00000000"
                border.width: 0

                Image {
                    source: getBatteryIcon();
                    height: 20
                    fillMode: Image.PreserveAspectFit
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.left: parent.left
                    anchors.leftMargin: 6
                    mipmap: true
                    smooth: true
                }

                Text {
                    id: batteryText
                    text: mainToolBar.batteryVoltage.toFixed(1) + ' V';
                    font.pointSize: 14 * dpiFactor
                    font.weight: Font.DemiBold
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    anchors.rightMargin: 8
                    horizontalAlignment: Text.AlignRight
                    color: colorWhite
                }
dogmaphobic's avatar
dogmaphobic committed
374 375
            }

376 377 378 379
            Column {
                visible: showMavStatus()
                height:  cellHeight * 0.85
                width:   80
dogmaphobic's avatar
dogmaphobic committed
380 381
                anchors.verticalCenter: parent.verticalCenter

382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
                Rectangle {
                    id: armedStatus
                    width: parent.width
                    height: parent.height / 2
                    anchors.horizontalCenter: parent.horizontalCenter
                    color: "#00000000"
                    border.color: "#00000000"
                    border.width: 0

                    Text {
                        id: armedStatusText
                        text: (mainToolBar.systemArmed) ? qsTr("ARMED") :  qsTr("DISARMED")
                        font.pointSize: 12 * dpiFactor
                        font.weight: Font.DemiBold
                        anchors.centerIn: parent
397
                        color: (mainToolBar.systemArmed) ? colorOrangeText : colorGreenText
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
                    }
                }

                Rectangle {
                    id: stateStatus
                    width: parent.width
                    height: parent.height / 2
                    anchors.horizontalCenter: parent.horizontalCenter
                    color: "#00000000"
                    border.color: "#00000000"
                    border.width: 0

                    Text {
                        id: stateStatusText
                        text: mainToolBar.currentState
                        font.pointSize: 12 * dpiFactor
                        font.weight: Font.DemiBold
                        anchors.centerIn: parent
416
                        color: (mainToolBar.currentState === "STANDBY") ? colorGreenText : colorRedText
417 418 419 420
                    }
                }

            }
dogmaphobic's avatar
dogmaphobic committed
421 422

            Rectangle {
423 424 425 426
                id: modeStatus
                width: 90
                height: cellHeight
                visible: showMavStatus()
dogmaphobic's avatar
dogmaphobic committed
427 428 429 430 431
                color: "#00000000"
                border.color: "#00000000"
                border.width: 0

                Text {
432 433
                    id: modeStatusText
                    text: mainToolBar.currentMode
dogmaphobic's avatar
dogmaphobic committed
434 435
                    font.pointSize: 12 * dpiFactor
                    font.weight: Font.DemiBold
436 437
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter
438
                    color: colorWhiteText
dogmaphobic's avatar
dogmaphobic committed
439 440 441 442
                }
            }

            Rectangle {
443 444 445 446 447
                id: connectionStatus
                width: 160
                height: cellHeight
                visible: (mainToolBar.connectionCount > 0 && mainToolBar.mavPresent && mainToolBar.heartbeatTimeout != 0)
                anchors.verticalCenter: parent.verticalCenter
dogmaphobic's avatar
dogmaphobic committed
448 449 450 451 452
                color: "#00000000"
                border.color: "#00000000"
                border.width: 0

                Text {
453 454 455
                    id: connectionStatusText
                    text: qsTr("CONNECTION LOST")
                    font.pointSize: 14 * dpiFactor
dogmaphobic's avatar
dogmaphobic committed
456
                    font.weight: Font.DemiBold
457 458
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.horizontalCenter: parent.horizontalCenter
459
                    color: colorRedText
dogmaphobic's avatar
dogmaphobic committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493
                }
            }
        }
    }

    Row {
        id: row2
        height: cellHeight
        spacing: cellSpacerSize
        anchors.right: parent.right
        anchors.verticalCenter: parent.verticalCenter
        anchors.leftMargin:  10
        anchors.rightMargin: 10

        QGCComboBox {
            id: configList
            width: 200
            visible: (mainToolBar.connectionCount === 0 && mainToolBar.configList.length > 0)
            anchors.verticalCenter: parent.verticalCenter
            model: mainToolBar.configList
            onCurrentIndexChanged: {
                mainToolBar.onLinkConfigurationChanged(mainToolBar.configList[currentIndex]);
            }
            Component.onCompleted: {
                mainToolBar.currentConfigChanged.connect(configList.onCurrentConfigChanged)
            }
            function onCurrentConfigChanged(config) {
                var index = configList.find(config);
                configList.currentIndex = index;
            }
        }

        QGCButton {
            id: connectButton
494
            width: 100
dogmaphobic's avatar
dogmaphobic committed
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
            visible: (mainToolBar.connectionCount === 0 || mainToolBar.connectionCount === 1)
            text: (mainToolBar.configList.length > 0) ? (mainToolBar.connectionCount === 0) ? qsTr("Connect") : qsTr("Disconnect") : qsTr("Add Link")
            anchors.verticalCenter: parent.verticalCenter
            onClicked: {
                mainToolBar.onConnect("");
            }
        }

        Menu {
            id: disconnectMenu
            Component.onCompleted: {
                mainToolBar.connectedListChanged.connect(disconnectMenu.onConnectedListChanged)
            }
            function onConnectedListChanged(conList) {
                disconnectMenu.clear();
                for(var i = 0; i < conList.length; i++) {
                    var mItem = disconnectMenu.addItem(conList[i]);
                    var menuSlot = function() {mainToolBar.onConnect(mItem.text)};
                    mItem.triggered.connect(menuSlot);
                }
            }
        }

        QGCButton {
            id: multidisconnectButton
520
            width: 100
dogmaphobic's avatar
dogmaphobic committed
521 522 523 524 525 526 527 528 529
            text: qsTr("Disconnect")
            visible: (mainToolBar.connectionCount > 1)
            anchors.verticalCenter: parent.verticalCenter
            menu: disconnectMenu
        }

    }
}