Skip to content
SetupView.qml 12.5 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.
 *
 ****************************************************************************/


/// @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 {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
    id: setupView
    color:  qgcPal.window
    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:            Math.round(_defaultTextHeight / 2)
    readonly property real      _buttonWidth:       Math.round(_defaultTextWidth * 18)
    readonly property string    _armedVehicleText:  qsTr("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: QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && !QGroundControl.multiVehicleManager.activeVehicle.missingParameters
    function showSummaryPanel()
    {
Don Gagne's avatar
Don Gagne committed
        if (_fullParameterVehicleAvailable) {
            if (QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length == 0) {
                panelLoader.sourceComponent = noComponentsVehicleSummaryComponent
            } else {
                panelLoader.source = "VehicleSummary.qml";
            }
        } else if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable) {
            panelLoader.sourceComponent = missingParametersVehicleSummaryComponent
        } else {
            panelLoader.sourceComponent = disconnectedVehicleSummaryComponent
        }
    }

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

    function showJoystickPanel()
    {
        if (QGroundControl.multiVehicleManager.activeVehicleAvailable && QGroundControl.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)
        if (QGroundControl.multiVehicleManager.activeVehicle.armed && !vehicleComponent.allowSetupWhileArmed) {
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 {
Don Gagne's avatar
Don Gagne committed
                panelLoader.vehicleComponent = vehicleComponent
Don Gagne's avatar
Don Gagne committed
                panelLoader.source = vehicleComponent.setupSource
                for(var i = 0; i < componentRepeater.count; i++) {
                    var obj = componentRepeater.itemAt(i);
                    if (obj.text === vehicleComponent.name) {
                        obj.checked = true;
                        break;
                    }
                }
Don Gagne's avatar
Don Gagne committed
            }
    Component.onCompleted: showSummaryPanel()

    Connections {
        target: QGroundControl.multiVehicleManager
        onParameterReadyVehicleAvailableChanged: {
            if (parameterReadyVehicleAvailable || summaryButton.checked || setupButtonGroup.current != firmwareButton) {
                // Show/Reload the Summary panel when:
                //      A new vehicle shows up
                //      The summary panel is already showing and the active vehicle goes away
                //      The active vehicle goes away and we are not on the Firmware panel.
                summaryButton.checked = true
                showSummaryPanel()
            }
        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
dogmaphobic's avatar
dogmaphobic committed
                font.pointSize:         ScreenTools.mediumFontPointSize
                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
dogmaphobic's avatar
dogmaphobic committed
                font.pointSize:         ScreenTools.largeFontPointSize
Don Gagne's avatar
Don Gagne committed
                text:                   "Connect vehicle to your device and QGroundControl will automatically detect it." +
                                        (ScreenTools.isMobile ? "" : " 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
dogmaphobic's avatar
dogmaphobic committed
                font.pointSize:         ScreenTools.mediumFontPointSize
                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
dogmaphobic's avatar
dogmaphobic committed
                font.pointSize:         ScreenTools.mediumFontPointSize
Don Gagne's avatar
Don Gagne committed
                text:                   _messagePanelText
    QGCFlickable {
        id:                 buttonScroll
        width:              buttonColumn.width
        anchors.topMargin:  _defaultTextHeight / 2
        anchors.top:        parent.top
dogmaphobic's avatar
dogmaphobic committed
        anchors.bottom:     parent.bottom
        contentHeight:      buttonColumn.height
        flickableDirection: Flickable.VerticalFlick
dogmaphobic's avatar
dogmaphobic committed
        clip:               true
dogmaphobic's avatar
dogmaphobic committed

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

            property real _maxButtonWidth: 0
dogmaphobic's avatar
dogmaphobic committed

            Component.onCompleted: reflowWidths()
            Connections {
                target: componentRepeater
                onModelChanged: buttonColumn.reflowWidths()
            }
            // I don't know why this does not work
            Connections {
                target: QGroundControl
                onBaseFontPointSizeChanged: buttonColumn.reflowWidths()
            }

            function reflowWidths() {
                buttonColumn._maxButtonWidth = 0
                for (var i = 0; i < children.length; i++) {
                    buttonColumn._maxButtonWidth = Math.max(buttonColumn._maxButtonWidth, children[i].width)
                for (var j = 0; j < children.length; j++) {
                    children[j].width = buttonColumn._maxButtonWidth
dogmaphobic's avatar
dogmaphobic committed
                }
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
                setupIndicator: false
                text:           "PX4Flow"
                onClicked:      showPX4FlowPanel()
            }
            SubMenuButton {
                id:             joystickButton
                setupIndicator: true
                setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup: setupButtonGroup
                visible:        _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
                text:           "Joystick"
                onClicked: showJoystickPanel()
            }
            Repeater {
                id:     componentRepeater
                model:  _fullParameterVehicleAvailable ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
dogmaphobic's avatar
dogmaphobic committed
                SubMenuButton {
                    imageResource:  modelData.iconResource
                    setupIndicator: modelData.requiresSetup
                    setupComplete:  modelData.setupComplete
dogmaphobic's avatar
dogmaphobic committed
                    exclusiveGroup: setupButtonGroup
                    text:           modelData.name
                    visible:        modelData.setupSource.toString() != ""

                    onClicked: showVehicleComponentPanel(modelData)
dogmaphobic's avatar
dogmaphobic committed
                }
            }

            SubMenuButton {
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                visible:        QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable
                text:           "Parameters"
                onClicked: showParametersPanel()
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
Don Gagne's avatar
Don Gagne committed

        property var vehicleComponent