Skip to content
MainToolBar.qml 7.53 KiB
Newer Older
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
import QtQuick              2.3
import QtQuick.Layouts      1.2
import QtQuick.Controls     1.2
Don Gagne's avatar
Don Gagne committed
import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.Palette               1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Controllers           1.0
Rectangle {
    id:         toolBar
    color:      qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.8) : Qt.rgba(0,0,0,0.75)
    visible:    !QGroundControl.videoManager.fullScreen
Don Gagne's avatar
Don Gagne committed
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
    property var  _activeVehicle:  QGroundControl.multiVehicleManager.activeVehicle
Don Gagne's avatar
Don Gagne committed
    signal showSettingsView
    signal showSetupView
    signal showPlanView
    signal showFlyView
    signal showAnalyzeView
    signal armVehicle
    signal disarmVehicle
    signal vtolTransitionToFwdFlight
    signal vtolTransitionToMRFlight
Don Gagne's avatar
Don Gagne committed

    function checkSettingsButton() {
        settingsButton.checked = true
Don Gagne's avatar
Don Gagne committed
    function checkSetupButton() {
        setupButton.checked = true
    }

    function checkPlanButton() {
        planButton.checked = true
    }

    function checkFlyButton() {
        flyButton.checked = true
    }

Don Gagne's avatar
Don Gagne committed
    function checkAnalyzeButton() {
        analyzeButton.checked = true
    }

dogmaphobic's avatar
dogmaphobic committed
    Component.onCompleted: {
        //-- TODO: Get this from the actual state
        flyButton.checked = true
    }
Don Gagne's avatar
Don Gagne committed
    /// Bottom single pixel divider
    Rectangle {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
        height:         1
        color:          "black"
        visible:        qgcPal.globalTheme === QGCPalette.Light
Don Gagne's avatar
Don Gagne committed
    RowLayout {
        anchors.bottomMargin:   1
Don Gagne's avatar
Don Gagne committed
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth / 2
        anchors.fill:           parent
Don Gagne's avatar
Don Gagne committed
        spacing:                ScreenTools.defaultFontPixelWidth * 2
Don Gagne's avatar
Don Gagne committed

        //---------------------------------------------
        // Toolbar Row
        Row {
            id:             viewRow
            anchors.top:    parent.top
            anchors.bottom: parent.bottom
Don Gagne's avatar
Don Gagne committed
            spacing:        ScreenTools.defaultFontPixelWidth / 2
Don Gagne's avatar
Don Gagne committed

            ExclusiveGroup { id: mainActionGroup }

            QGCToolBarButton {
                id:                 settingsButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/res/QGCLogoWhite"
                logo:               true
                onClicked:          toolBar.showSettingsView()
                visible:            !QGroundControl.corePlugin.options.combineSettingsAndSetup
            }
Don Gagne's avatar
Don Gagne committed
            QGCToolBarButton {
                id:                 setupButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Gears.svg"
                onClicked:          toolBar.showSetupView()
            }
Don Gagne's avatar
Don Gagne committed
            QGCToolBarButton {
                id:                 planButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Plan.svg"
                onClicked:          toolBar.showPlanView()
            }
Don Gagne's avatar
Don Gagne committed
            QGCToolBarButton {
                id:                 flyButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/PaperPlane.svg"
                onClicked:          toolBar.showFlyView()
            }
Don Gagne's avatar
Don Gagne committed

Don Gagne's avatar
Don Gagne committed
            QGCToolBarButton {
                id:                 analyzeButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Analyze.svg"
                visible:            !ScreenTools.isMobile && QGroundControl.corePlugin.showAdvancedUI
Don Gagne's avatar
Don Gagne committed
                onClicked:          toolBar.showAnalyzeView()
            }
Don Gagne's avatar
Don Gagne committed

            Rectangle {
                anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                width:              1
                color:              qgcPal.text
                visible:            _activeVehicle
            }
Don Gagne's avatar
Don Gagne committed
        }
Don Gagne's avatar
Don Gagne committed
        //-------------------------------------------------------------------------
        //-- Vehicle Selector
        QGCButton {
            id:                     vehicleSelectorButton
            width:                  ScreenTools.defaultFontPixelHeight * 8
Don Gagne's avatar
Don Gagne committed
            text:                   "Vehicle " + (_activeVehicle ? _activeVehicle.id : "None")
Don Gagne's avatar
Don Gagne committed
            visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
            anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
            menu: vehicleMenu
Don Gagne's avatar
Don Gagne committed
            Menu {
                id: vehicleMenu
            }
Don Gagne's avatar
Don Gagne committed
            Component {
                id: vehicleMenuItemComponent
Don Gagne's avatar
Don Gagne committed
                MenuItem {
Don Gagne's avatar
Don Gagne committed
                    onTriggered: QGroundControl.multiVehicleManager.activeVehicle = vehicle
Don Gagne's avatar
Don Gagne committed

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

            property var vehicleMenuItems: []
Don Gagne's avatar
Don Gagne committed
            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<QGroundControl.multiVehicleManager.vehicles.count; i++) {
                    var vehicle = QGroundControl.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:         QGroundControl.multiVehicleManager.vehicles
                onCountChanged: vehicleSelectorButton.updateVehicleMenu()
            }
Don Gagne's avatar
Don Gagne committed
        MainToolBarIndicators {
Don Gagne's avatar
Don Gagne committed
            anchors.margins:    ScreenTools.defaultFontPixelHeight * 0.66
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
    }
    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
        id:             progressBar
dogmaphobic's avatar
dogmaphobic committed
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
Don Gagne's avatar
Don Gagne committed
        width:          _activeVehicle ? _activeVehicle.parameterManager.loadProgress * parent.width : 0
        color:          qgcPal.colorGreen