Skip to content
SetupView.qml 14.4 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.Controls 1.2
import QtQuick.Layouts  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 {
    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      _horizontalMargin:  _defaultTextWidth / 2
    readonly property real      _verticalMargin:    _defaultTextHeight / 2
    readonly property real      _buttonWidth:       _defaultTextWidth * 18
Gus Grubba's avatar
Gus Grubba committed
    readonly property string    _armedVehicleText:  qsTr("This operation cannot be performed while the vehicle is armed.")
Gus Grubba's avatar
Gus Grubba committed
    property string _messagePanelText:              qsTr("missing message panel text")
    property bool   _fullParameterVehicleAvailable: QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && !QGroundControl.multiVehicleManager.activeVehicle.parameterManager.missingParameters
    property var    _corePlugin:                    QGroundControl.corePlugin
    function showSummaryPanel()
    {
Don Gagne's avatar
Don Gagne committed
        if (_fullParameterVehicleAvailable) {
            if (QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length == 0) {
                panelLoader.setSourceComponent(noComponentsVehicleSummaryComponent)
                panelLoader.setSource("VehicleSummary.qml")
        } else if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable) {
            panelLoader.setSourceComponent(missingParametersVehicleSummaryComponent)
        } else {
            panelLoader.setSourceComponent(disconnectedVehicleSummaryComponent)
        }
    }

    function showFirmwarePanel()
    {
        if (!ScreenTools.isMobile) {
            if (QGroundControl.multiVehicleManager.activeVehicleAvailable && QGroundControl.multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
                _messagePanelText = _armedVehicleText
                panelLoader.setSourceComponent(messagePanelComponent)
            } else {
                panelLoader.setSource("FirmwareUpgrade.qml")
    function showJoystickPanel()
    {
        if (QGroundControl.multiVehicleManager.activeVehicleAvailable && QGroundControl.multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
            _messagePanelText = _armedVehicleText
            panelLoader.setSourceComponent(messagePanelComponent)
            panelLoader.setSource("JoystickConfig.qml")
    function showParametersPanel()
    {
        panelLoader.setSource("SetupParameterEditor.qml")
dogmaphobic's avatar
dogmaphobic committed
    function showPX4FlowPanel()
    {
        panelLoader.setSource("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.setSourceComponent(messagePanelComponent)
        } else {
            var autopilotPlugin = QGroundControl.multiVehicleManager.activeVehicle.autopilot
            var prereq = autopilotPlugin.prerequisiteSetup(vehicleComponent)
Gus Grubba's avatar
Gus Grubba committed
            if (prereq !== "") {
                //-- TODO: This cannot be trasnlated when built this way.
                _messagePanelText = prereq + " setup must be completed prior to " + vehicleComponent.name + " setup."
                panelLoader.setSourceComponent(messagePanelComponent)
Don Gagne's avatar
Don Gagne committed
            } else {
                panelLoader.setSource(vehicleComponent.setupSource, vehicleComponent)
                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(!QGroundControl.skipSetupPage) {
                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
Gus Grubba's avatar
Gus Grubba committed
                text:                   qsTr("%1 does not currently support setup of your vehicle type. ").arg(QGroundControl.appName) +
                                        "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
Gus Grubba's avatar
Gus Grubba committed
                text:                   qsTr("Vehicle settings and info will display after connecting your vehicle.") +
                                        (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
Gus Grubba's avatar
Gus Grubba committed
                text:                   qsTr("You are currently connected to a vehicle but it did not return the full parameter list. ") +
                                        qsTr("As a result, 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
        anchors.leftMargin: _horizontalMargin
        anchors.left:       parent.left
        contentHeight:      buttonColumn.height
        flickableDirection: Flickable.VerticalFlick
dogmaphobic's avatar
dogmaphobic committed
        clip:               true
dogmaphobic's avatar
dogmaphobic committed

            id:         buttonColumn
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed

            QGCLabel {
                anchors.left:           parent.left
                anchors.right:          parent.right
                text:                   qsTr("Vehicle Setup")
                wrapMode:               Text.WordWrap
                horizontalAlignment:    Text.AlignHCenter
                visible:                !ScreenTools.isShortScreen
            }

                model:                  _corePlugin ? _corePlugin.settingsPages : []
                visible:                _corePlugin && _corePlugin.options.combineSettingsAndSetup
                    imageResource:      modelData.icon
                    setupIndicator:     false
                    exclusiveGroup:     setupButtonGroup
                    text:               modelData.title
                    visible:            _corePlugin && _corePlugin.options.combineSettingsAndSetup
                    onClicked:          panelLoader.setSource(modelData.url)
                    Layout.fillWidth:   true
Gus Grubba's avatar
Gus Grubba committed
            }

            SubMenuButton {
                id:                 summaryButton
                imageResource:      "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator:     false
                checked:            true
                exclusiveGroup:     setupButtonGroup
Gus Grubba's avatar
Gus Grubba committed
                text:               qsTr("Summary")
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed

                onClicked: showSummaryPanel()
            }
            SubMenuButton {
                id:                 firmwareButton
                imageResource:      "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
                visible:            !ScreenTools.isMobile && _corePlugin.options.showFirmwareUpgrade
Gus Grubba's avatar
Gus Grubba committed
                text:               qsTr("Firmware")
                Layout.fillWidth:   true
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
Gus Grubba's avatar
Gus Grubba committed
                text:               qsTr("PX4Flow")
                Layout.fillWidth:   true

                onClicked:      showPX4FlowPanel()
            }
            SubMenuButton {
                id:                 joystickButton
                setupIndicator:     true
                setupComplete:      joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup:     setupButtonGroup
                visible:            _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
Gus Grubba's avatar
Gus Grubba committed
                text:               qsTr("Joystick")
                Layout.fillWidth:   true
                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
                    exclusiveGroup:     setupButtonGroup
                    text:               modelData.name
                    visible:            modelData.setupSource.toString() != ""
                    Layout.fillWidth:   true

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

            SubMenuButton {
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
                visible:            QGroundControl.multiVehicleManager && QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && _corePlugin.showAdvancedUI
Gus Grubba's avatar
Gus Grubba committed
                text:               qsTr("Parameters")
                Layout.fillWidth:   true
                onClicked: showParametersPanel()
dogmaphobic's avatar
dogmaphobic committed

        }
    Rectangle {
        id:                     divider
        anchors.topMargin:      _verticalMargin
        anchors.bottomMargin:   _verticalMargin
        anchors.leftMargin:     _horizontalMargin
        anchors.left:           buttonScroll.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
        width:                  1
        color:                  qgcPal.windowShade
    }

    Loader {
        id:                     panelLoader
        anchors.topMargin:      _verticalMargin
        anchors.bottomMargin:   _verticalMargin
        anchors.leftMargin:     _horizontalMargin
        anchors.rightMargin:    _horizontalMargin
        anchors.left:           divider.right
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
        function setSource(source, vehicleComponent) {
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.source = source
        }

        function setSourceComponent(sourceComponent, vehicleComponent) {
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.sourceComponent = sourceComponent
        }

Don Gagne's avatar
Don Gagne committed
        property var vehicleComponent