Skip to content
SetupView.qml 12.3 KiB
Newer Older
/*=====================================================================

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 Setup View
///     @author Don Gagne <don@thegagnes.com>

import QtQuick          2.3
import QtQuick.Controls 1.2

Gus Grubba's avatar
Gus Grubba committed
import QGroundControl                       1.0
import QGroundControl.AutoPilotPlugin       1.0
import QGroundControl.Palette               1.0
import QGroundControl.Controls              1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.MultiVehicleManager   1.0
Rectangle {
    color:          qgcPal.window
Gus Grubba's avatar
Gus Grubba committed
    z:              QGroundControl.zOrderTopMost
Don Gagne's avatar
Don Gagne committed
    QGCPalette { id: qgcPal; colorGroupEnabled: true }

    ExclusiveGroup { id: setupButtonGroup }

Don Gagne's avatar
Don Gagne committed
    readonly property real      _defaultTextHeight: ScreenTools.defaultFontPixelHeight
    readonly property real      _defaultTextWidth:  ScreenTools.defaultFontPixelWidth
    readonly property real      _margin:            _defaultTextHeight / 2
    readonly property real      _buttonWidth:       _defaultTextWidth * 18
Don Gagne's avatar
Don Gagne committed
    readonly property string    _armedVehicleText:  "This operation cannot be performed while vehicle is armed."
Don Gagne's avatar
Don Gagne committed
    property string _messagePanelText:              "missing message panel text"
    property bool   _fullParameterVehicleAvailable: multiVehicleManager.parameterReadyVehicleAvailable && !multiVehicleManager.activeVehicle.missingParameters
    function showSummaryPanel()
    {
Don Gagne's avatar
Don Gagne committed
        if (_fullParameterVehicleAvailable) {
            if (multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length == 0) {
                panelLoader.sourceComponent = noComponentsVehicleSummaryComponent
            } else {
                panelLoader.source = "VehicleSummary.qml";
            }
        } else if (multiVehicleManager.parameterReadyVehicleAvailable) {
            panelLoader.sourceComponent = missingParametersVehicleSummaryComponent
        } else {
            panelLoader.sourceComponent = disconnectedVehicleSummaryComponent
        }
    }

    function showFirmwarePanel()
    {
        if (!ScreenTools.isMobile) {
Don Gagne's avatar
Don Gagne committed
            if (multiVehicleManager.activeVehicleAvailable && multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
                _messagePanelText = _armedVehicleText
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = "FirmwareUpgrade.qml";
            }
        }
    }

    function showJoystickPanel()
    {
Don Gagne's avatar
Don Gagne committed
        if (multiVehicleManager.activeVehicleAvailable && multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
            _messagePanelText = _armedVehicleText
            panelLoader.sourceComponent = messagePanelComponent
        } else {
            panelLoader.source = "JoystickConfig.qml";
        }
    }

    function showParametersPanel()
    {
        panelLoader.source = "SetupParameterEditor.qml";
    }

dogmaphobic's avatar
dogmaphobic committed
    function showPX4FlowPanel()
    {
        panelLoader.source = "PX4FlowSensor.qml";
    }

Don Gagne's avatar
Don Gagne committed
    function showVehicleComponentPanel(vehicleComponent)
Don Gagne's avatar
Don Gagne committed
        if (multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
            _messagePanelText = _armedVehicleText
            panelLoader.sourceComponent = messagePanelComponent
        } else {
Don Gagne's avatar
Don Gagne committed
            if (vehicleComponent.prerequisiteSetup != "") {
Don Gagne's avatar
Don Gagne committed
                _messagePanelText = vehicleComponent.prerequisiteSetup + " setup must be completed prior to " + vehicleComponent.name + " setup."
Don Gagne's avatar
Don Gagne committed
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = vehicleComponent.setupSource
            }
    Component.onCompleted: showSummaryPanel()

    Connections {
        target: multiVehicleManager
        onParameterReadyVehicleAvailableChanged: {
            summaryButton.checked = true
            showSummaryPanel()
        }
    }

    Component {
        id: noComponentsVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
            color: qgcPal.windowShade

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
                anchors.margins:        _defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
                font.pixelSize:         ScreenTools.mediumFontPixelSize
                text:                   "QGroundControl does not currently support setup of your vehicle type. " +
                                            "If your vehicle is already configured you can still Fly."

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

    Component {
        id: disconnectedVehicleSummaryComponent

        Rectangle {
            color: qgcPal.windowShade

            QGCLabel {
                anchors.margins:        _defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
                font.pixelSize:         ScreenTools.largeFontPixelSize
                text:                   "Connect vehicle to your device and QGroundControl will automatically detect to it. Click Firmware on the left to upgrade your vehicle."

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
            color: qgcPal.windowShade
Don Gagne's avatar
Don Gagne committed
                anchors.margins:        _defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
                font.pixelSize:         ScreenTools.mediumFontPixelSize
                text:                   "You are currently connected to a vehicle, but that vehicle did not return back the full parameter list. " +
Don Gagne's avatar
Don Gagne committed
                                        "Because of this the full set of vehicle setup options are not available."

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

    Component {
        id: messagePanelComponent

        Item {
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
                anchors.margins:        _defaultTextWidth * 2
Don Gagne's avatar
Don Gagne committed
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
                font.pixelSize:         ScreenTools.mediumFontPixelSize
Don Gagne's avatar
Don Gagne committed
                text:                   _messagePanelText
Don Gagne's avatar
Don Gagne committed
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
        //-- Limit height to available height (below tool bar)
        anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
        height:             mainWindow.availableHeight
dogmaphobic's avatar
dogmaphobic committed
        anchors.bottom:     parent.bottom
        anchors.left:       parent.left
        anchors.right:      parent.right
        color:              qgcPal.window

        Flickable {
            id:                 buttonScroll
            width:              buttonColumn.width
dogmaphobic's avatar
dogmaphobic committed
            anchors.topMargin:  _defaultTextHeight / 2
            anchors.top:        parent.top
Don Gagne's avatar
Don Gagne committed
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
            clip:               true
            contentHeight:      buttonColumn.height
            contentWidth:       buttonColumn.width
dogmaphobic's avatar
dogmaphobic committed
            boundsBehavior:     Flickable.StopAtBounds
            flickableDirection: Flickable.VerticalFlick

            Column {
                id:         buttonColumn
                width:      _maxButtonWidth
dogmaphobic's avatar
dogmaphobic committed
                spacing:    _defaultTextHeight / 2

                property real _maxButtonWidth: 0

                Component.onCompleted: reflowWidths()

                Connections {
                    target: componentRepeater

                    onModelChanged: buttonColumn.reflowWidths()
                }

                function reflowWidths() {
                    for (var i=0; i<children.length; i++) {
                        _maxButtonWidth = Math.max(_maxButtonWidth, children[i].width)
                    }
                    for (var i=0; i<children.length; i++) {
                        children[i].width = _maxButtonWidth
                    }
                }

dogmaphobic's avatar
dogmaphobic committed
                SubMenuButton {
                    id:             summaryButton
                    imageResource: "/qmlimages/VehicleSummaryIcon.png"
                    setupIndicator: false
                    checked:        true
                    exclusiveGroup: setupButtonGroup
                    text:           "Summary"
dogmaphobic's avatar
dogmaphobic committed

                    onClicked: showSummaryPanel()
                }

                SubMenuButton {
                    id:             firmwareButton
                    imageResource:  "/qmlimages/FirmwareUpgradeIcon.png"
                    setupIndicator: false
                    exclusiveGroup: setupButtonGroup
                    visible:        !ScreenTools.isMobile
                    text:           "Firmware"
dogmaphobic's avatar
dogmaphobic committed

                    onClicked: showFirmwarePanel()
                }

dogmaphobic's avatar
dogmaphobic committed
                SubMenuButton {
                    id:             px4FlowButton
                    exclusiveGroup: setupButtonGroup
                    visible:        QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.genericFirmware : false
dogmaphobic's avatar
dogmaphobic committed
                    setupIndicator: false
                    text:           "PX4Flow"
dogmaphobic's avatar
dogmaphobic committed
                    onClicked:      showPX4FlowPanel()
                }

dogmaphobic's avatar
dogmaphobic committed
                SubMenuButton {
                    id:             joystickButton
                    setupIndicator: true
                    setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                    exclusiveGroup: setupButtonGroup
                    visible:        _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
                    text:           "Joystick"
dogmaphobic's avatar
dogmaphobic committed

                    onClicked: showJoystickPanel()
                }

                Repeater {
                    id:     componentRepeater
                    model:  _fullParameterVehicleAvailable ? multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
Don Gagne's avatar
Don Gagne committed

                    SubMenuButton {
dogmaphobic's avatar
dogmaphobic committed
                        imageResource:  modelData.iconResource
                        setupIndicator: modelData.requiresSetup
                        setupComplete:  modelData.setupComplete
Don Gagne's avatar
Don Gagne committed
                        exclusiveGroup: setupButtonGroup
                        text:           modelData.name
dogmaphobic's avatar
dogmaphobic committed
                        onClicked: showVehicleComponentPanel(modelData)
Don Gagne's avatar
Don Gagne committed
                    }
dogmaphobic's avatar
dogmaphobic committed
                }
dogmaphobic's avatar
dogmaphobic committed
                SubMenuButton {
                    setupIndicator: false
                    exclusiveGroup: setupButtonGroup
                    visible:        multiVehicleManager.parameterReadyVehicleAvailable
                    text:           "Parameters"
dogmaphobic's avatar
dogmaphobic committed
                    onClicked: showParametersPanel()
                }
Don Gagne's avatar
Don Gagne committed
        }
dogmaphobic's avatar
dogmaphobic committed

        Loader {
            id:                     panelLoader
            anchors.topMargin:      _margin
            anchors.bottomMargin:   _margin
            anchors.leftMargin:     _defaultTextWidth
            anchors.rightMargin:    _defaultTextWidth
            anchors.left:           buttonScroll.right
            anchors.right:          parent.right
            anchors.top:            parent.top
            anchors.bottom:         parent.bottom
        }