MainToolBar.qml 16.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 44 45 46
Rectangle {
    id:             toolBarHolder
    anchors.left:   parent.left
    anchors.right:  parent.right
    height:         toolBarHeight
    color:          qgcPal.window
dogmaphobic's avatar
dogmaphobic committed
47

Don Gagne's avatar
Don Gagne committed
48
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
49

50 51
    property var activeVehicle: multiVehicleManager.activeVehicle

Don Gagne's avatar
Don Gagne committed
52 53
    readonly property real toolBarHeight:   ScreenTools.defaultFontPixelHeight * 3
    property int cellSpacerSize:            ScreenTools.isMobile ? getProportionalDimmension(6) : getProportionalDimmension(4)
Don Gagne's avatar
Don Gagne committed
54 55 56 57
    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
58

Don Gagne's avatar
Don Gagne committed
59 60 61 62 63
    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
64

65 66 67 68 69
    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"

70
    MainToolBarController { id: _controller }
dogmaphobic's avatar
dogmaphobic committed
71

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

dogmaphobic's avatar
dogmaphobic committed
82
    function getProportionalDimmension(val) {
Don Gagne's avatar
Don Gagne committed
83
        return toolBarHeight * val / 40
dogmaphobic's avatar
dogmaphobic committed
84 85
    }

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

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

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

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

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

144 145 146 147 148 149
    function getRSSIColor(value) {
        if(value < 10)
            return colorRed;
        if(value < 50)
            return colorOrange;
        return colorGreen;
150 151
    }

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

dogmaphobic's avatar
dogmaphobic committed
156 157 158
    //-------------------------------------------------------------------------
    //-- Main menu for Mobile Devices
    Menu {
Don Gagne's avatar
Don Gagne committed
159
        id: mobileMenu
160

dogmaphobic's avatar
dogmaphobic committed
161
        ExclusiveGroup { id: mainMenuGroup }
162

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

            onTriggered: {
                checked = true
                _controller.onFlyView();
dogmaphobic's avatar
dogmaphobic committed
173 174
            }
        }
175

dogmaphobic's avatar
dogmaphobic committed
176
        MenuItem {
177 178 179
            id:             setupViewShowing
            text:           "Setup"
            checkable:      true
dogmaphobic's avatar
dogmaphobic committed
180
            exclusiveGroup: mainMenuGroup
181 182 183 184

            onTriggered: {
                checked = true
                _controller.onSetupView();
dogmaphobic's avatar
dogmaphobic committed
185 186
            }
        }
187

dogmaphobic's avatar
dogmaphobic committed
188
        MenuItem {
189 190 191
            id:             planViewShowing
            text:           "Plan"
            checkable:      true
dogmaphobic's avatar
dogmaphobic committed
192
            exclusiveGroup: mainMenuGroup
193 194 195 196

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

        MenuSeparator { }


        MenuItem {
            text:           "QGroundControl Settings"

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

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

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

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

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

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

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

Don Gagne's avatar
Don Gagne committed
277 278 279
            property real cellHeight:       toolBarHolder.cellHeight
            property real cellSpacerSize:   toolBarHolder.cellSpacerSize
        }
dogmaphobic's avatar
dogmaphobic committed
280

Don Gagne's avatar
Don Gagne committed
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
        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
296
                anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
297 298
                anchors.horizontalCenter: parent.horizontalCenter
                color: colorRedText
dogmaphobic's avatar
dogmaphobic committed
299
            }
Don Gagne's avatar
Don Gagne committed
300
        }
Don Gagne's avatar
Don Gagne committed
301
    } // Row
dogmaphobic's avatar
dogmaphobic committed
302 303

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

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

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

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

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

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

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

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

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

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

            onClicked: {
                parent.visible = false
Don Gagne's avatar
Don Gagne committed
424
                toolBarHolder.height = toolBarHeight
425
                _controller.onToolBarMessageClosed()
Don Gagne's avatar
Don Gagne committed
426 427 428
            }
        }
    }
Don Gagne's avatar
Don Gagne committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447

    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;
                }
            }
448 449 450 451 452 453 454
            Connections {
                target:controller
                onShowFlyView:  { flyButton.checked   = true }
                onShowPlanView: { planButton.checked  = true }
                onShowSetupView:{ setupButton.checked = true }
            }

Don Gagne's avatar
Don Gagne committed
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 492 493 494 495 496 497 498 499 500 501

            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
502
} // Rectangle