MainToolBar.qml 16.4 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

Don Gagne's avatar
Don Gagne committed
45
    QGCPalette { id: qgcPal; 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
    //-------------------------------------------------------------------------
    //-- Main menu for Mobile Devices
    Menu {
Don Gagne's avatar
Don Gagne committed
156
        id: mobileMenu
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

Don Gagne's avatar
Don Gagne committed
207
    /*
208 209 210 211
    Row {
        id:         toolRow
        height:     cellHeight
        spacing:    getProportionalDimmension(4)
Don Gagne's avatar
Don Gagne committed
212 213 214 215 216 217 218 219 220 221
    }
    */

    Loader {
        id:                 desktopToolsLoader
        height:             cellHeight
        x:                  horizontalMargins
        y:                  (toolBarHeight - cellHeight) / 2
        sourceComponent:    ScreenTools.isMobile ? undefined : desktopTools
    }
222

Don Gagne's avatar
Don Gagne committed
223 224 225 226
    //---------------------------------------------------------------------
    //-- Indicators
    Row {
        id:                     row12
227
        x:                      horizontalMargins + (ScreenTools.isMobile ? 0: desktopToolsLoader.item.width)
Don Gagne's avatar
Don Gagne committed
228 229 230 231
        height:                 cellHeight
        spacing:                cellSpacerSize
        anchors.top:            desktopToolsLoader.top
        anchors.verticalCenter: desktopToolsLoader.verticalCenter
232

Don Gagne's avatar
Don Gagne committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246
        //-- "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
247
            }
Don Gagne's avatar
Don Gagne committed
248 249 250
            MouseArea {
                anchors.fill: parent
                acceptedButtons: Qt.LeftButton
251
                onClicked: {
Don Gagne's avatar
Don Gagne committed
252 253 254
                    if (mouse.button == Qt.LeftButton)
                    {
                        mobileMenu.popup();
255 256 257
                    }
                }
            }
Don Gagne's avatar
Don Gagne committed
258
        }
259

Don Gagne's avatar
Don Gagne committed
260 261 262 263 264 265 266 267
        //-- Separator if Hamburger menu is visible
        Rectangle {
            visible:    actionButton.visible
            height:     cellHeight
            width:      cellHeight
            color:      "#00000000"
            anchors.verticalCenter: parent.verticalCenter
        }
268

Don Gagne's avatar
Don Gagne committed
269 270 271 272
        Loader {
            id:         activeVehicleLoader
            visible:    showMavStatus()
            source:     multiVehicleManager.activeVehicleAvailable ? "MainToolBarActiveVehicleComponent.qml" : ""
273

Don Gagne's avatar
Don Gagne committed
274 275 276
            property real cellHeight:       toolBarHolder.cellHeight
            property real cellSpacerSize:   toolBarHolder.cellSpacerSize
        }
dogmaphobic's avatar
dogmaphobic committed
277

Don Gagne's avatar
Don Gagne committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
        Rectangle {
            id: connectionStatus
            width: getProportionalDimmension(160)
            height: cellHeight
            visible: (_controller.connectionCount > 0 && multiVehicleManager.activeVehicleAvailable && activeVehicle.heartbeatTimeout != 0)
            anchors.verticalCenter: parent.verticalCenter
            color: "#00000000"
            border.color: "#00000000"
            border.width: 0

            QGCLabel {
                id: connectionStatusText
                text: qsTr("CONNECTION LOST")
                font.pixelSize: ScreenTools.defaultFontPixelSize
                font.weight: Font.DemiBold
293
                anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
294 295
                anchors.horizontalCenter: parent.horizontalCenter
                color: colorRedText
dogmaphobic's avatar
dogmaphobic committed
296
            }
Don Gagne's avatar
Don Gagne committed
297
        }
Don Gagne's avatar
Don Gagne committed
298
    } // Row
dogmaphobic's avatar
dogmaphobic committed
299 300

    Row {
Don Gagne's avatar
Don Gagne committed
301 302 303
        id:                     connectRow
        anchors.rightMargin:    verticalMargins
        anchors.right:          parent.right
Don Gagne's avatar
Don Gagne committed
304 305 306
        anchors.top:            desktopToolsLoader.top
        anchors.verticalCenter: desktopToolsLoader.verticalCenter
        height:                 desktopToolsLoader.height
Don Gagne's avatar
Don Gagne committed
307
        spacing:                cellSpacerSize
dogmaphobic's avatar
dogmaphobic committed
308

dogmaphobic's avatar
dogmaphobic committed
309 310
        Menu {
            id: connectMenu
dogmaphobic's avatar
dogmaphobic committed
311
            Component.onCompleted: {
312
                _controller.configListChanged.connect(connectMenu.updateConnectionList);
dogmaphobic's avatar
dogmaphobic committed
313
                connectMenu.updateConnectionList();
dogmaphobic's avatar
dogmaphobic committed
314
            }
dogmaphobic's avatar
dogmaphobic committed
315 316 317 318 319
            function addMenuEntry(name) {
                var label = "Add Connection"
                if(name !== "")
                    label = name;
                var mItem = connectMenu.addItem(label);
320
                var menuSlot = function() {_controller.onConnect(name)};
dogmaphobic's avatar
dogmaphobic committed
321 322 323 324
                mItem.triggered.connect(menuSlot);
            }
            function updateConnectionList() {
                connectMenu.clear();
325 326
                for(var i = 0; i < _controller.configList.length; i++) {
                    connectMenu.addMenuEntry(_controller.configList[i]);
dogmaphobic's avatar
dogmaphobic committed
327
                }
328
                if(_controller.configList.length > 0) {
dogmaphobic's avatar
dogmaphobic committed
329 330 331 332
                    connectMenu.addSeparator();
                }
                // Add "Add Connection" to the list
                connectMenu.addMenuEntry("");
dogmaphobic's avatar
dogmaphobic committed
333 334 335 336
            }
        }

        QGCButton {
dogmaphobic's avatar
dogmaphobic committed
337
            id:         connectButton
dogmaphobic's avatar
dogmaphobic committed
338
            width:      getProportionalDimmension(100)
339
            visible:    _controller.connectionCount === 0
dogmaphobic's avatar
dogmaphobic committed
340 341 342 343 344 345
            text:       qsTr("Connect")
            menu:       connectMenu
        }

        QGCButton {
            id:         disconnectButton
dogmaphobic's avatar
dogmaphobic committed
346
            width:      getProportionalDimmension(100)
347
            visible:    _controller.connectionCount === 1
dogmaphobic's avatar
dogmaphobic committed
348
            text:       qsTr("Disconnect")
dogmaphobic's avatar
dogmaphobic committed
349
            onClicked: {
350
                _controller.onDisconnect("");
dogmaphobic's avatar
dogmaphobic committed
351 352 353 354 355 356
            }
        }

        Menu {
            id: disconnectMenu
            Component.onCompleted: {
357
                _controller.connectedListChanged.connect(disconnectMenu.onConnectedListChanged)
dogmaphobic's avatar
dogmaphobic committed
358
            }
dogmaphobic's avatar
dogmaphobic committed
359 360
            function addMenuEntry(name) {
                var mItem = disconnectMenu.addItem(name);
361
                var menuSlot = function() {_controller.onDisconnect(name)};
dogmaphobic's avatar
dogmaphobic committed
362 363
                mItem.triggered.connect(menuSlot);
            }
dogmaphobic's avatar
dogmaphobic committed
364 365 366
            function onConnectedListChanged(conList) {
                disconnectMenu.clear();
                for(var i = 0; i < conList.length; i++) {
dogmaphobic's avatar
dogmaphobic committed
367
                    disconnectMenu.addMenuEntry(conList[i]);
dogmaphobic's avatar
dogmaphobic committed
368 369 370 371 372
                }
            }
        }

        QGCButton {
dogmaphobic's avatar
dogmaphobic committed
373
            id:         multidisconnectButton
dogmaphobic's avatar
dogmaphobic committed
374
            width:      getProportionalDimmension(100)
dogmaphobic's avatar
dogmaphobic committed
375
            text:       "Disconnect"
376
            visible:    _controller.connectionCount > 1
dogmaphobic's avatar
dogmaphobic committed
377
            menu:       disconnectMenu
dogmaphobic's avatar
dogmaphobic committed
378
        }
Don Gagne's avatar
Don Gagne committed
379
    } // Row
380 381 382

    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
383
        id:             progressBar
Don Gagne's avatar
Don Gagne committed
384
        anchors.top:    desktopToolsLoader.bottom
Don Gagne's avatar
Don Gagne committed
385
        height:         getProportionalDimmension(3)
386
        width:          parent.width * _controller.progressBarValue
Don Gagne's avatar
Don Gagne committed
387
        color:          qgcPal.text
388
    }
dogmaphobic's avatar
dogmaphobic committed
389

Don Gagne's avatar
Don Gagne committed
390 391
    // Toolbar message area
    Rectangle {
392 393 394 395 396 397 398 399 400 401 402
        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
403 404 405 406 407

        QGCLabel {
            id:             toolBarMessage
            anchors.fill:   parent
            wrapMode:       Text.WordWrap
408
			color:			qgcPal.warningText
Don Gagne's avatar
Don Gagne committed
409 410 411 412 413 414 415
        }

        QGCButton {
            id:                     toolBarMessageCloseButton
            anchors.rightMargin:    horizontalMargins
            anchors.top:            parent.top
            anchors.right:          parent.right
416
			primary:				true
Don Gagne's avatar
Don Gagne committed
417 418 419 420
            text:                   "Close Message"

            onClicked: {
                parent.visible = false
Don Gagne's avatar
Don Gagne committed
421
                toolBarHolder.height = toolBarHeight
422
                _controller.onToolBarMessageClosed()
Don Gagne's avatar
Don Gagne committed
423 424 425
            }
        }
    }
Don Gagne's avatar
Don Gagne committed
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 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

    Component {
        id: desktopTools

        //---------------------------------------------------------------------
        //-- Main menu for Non Mobile Devices (Chevron Buttons)
        Row {
            id:             row11
            height:         cellHeight
            spacing:        -getProportionalDimmension(12)

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

            ExclusiveGroup { id: mainActionGroup }

            QGCToolBarButton {
                id:             setupButton
                width:          getProportionalDimmension(90)
                height:         cellHeight
                exclusiveGroup: mainActionGroup
                text:           "Setup"

                onClicked: {
                    checked = true
                    _controller.onSetupView();
                }
                z: 1000
            }

            QGCToolBarButton {
                id:             planButton
                width:          getProportionalDimmension(90)
                height:         cellHeight
                exclusiveGroup: mainActionGroup
                text:           "Plan"

                onClicked: {
                    checked = true
                    _controller.onPlanView();
                }
                z: 900
            }

            QGCToolBarButton {
                id:             flyButton
                width:          getProportionalDimmension(90)
                height:         cellHeight
                exclusiveGroup: mainActionGroup
                text:           "Fly"
                checked:        true

                onClicked: {
                    checked = true
                    _controller.onFlyView();
                }
                z: 800
            }
        } // Row
    } // Component - desktopTools
Don Gagne's avatar
Don Gagne committed
492
} // Rectangle