SetupView.qml 9.9 KB
Newer Older
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
/*=====================================================================

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>

28
import QtQuick          2.3
29 30
import QtQuick.Controls 1.2

31 32 33 34 35
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
36 37 38 39

Rectangle {
    id:     topLevel
    color:  palette.window
40
    z:      zOrder   // zOrder comes from the Loader in MainWindow.qml
41 42 43 44 45 46 47 48 49 50 51 52 53 54

    QGCPalette { id: palette; colorGroupEnabled: true }

    ExclusiveGroup { id: setupButtonGroup }

    QGCLabel { id: _textMeasure; text: "X"; visible: false }

    readonly property real defaultTextHeight:   _textMeasure.contentHeight
    readonly property real defaultTextWidth:    _textMeasure.contentWidth
    readonly property real buttonWidth:         defaultTextWidth * 15

    property string messagePanelText:           "missing message panel text"
    readonly property string armedVehicleText:  "This operation cannot be performed while vehicle is armed."

55 56
    property bool fullParameterVehicleAvailable: multiVehicleManager.parameterReadyVehicleAvailable && !multiVehicleManager.activeVehicle.missingParameters

57 58
    function showSummaryPanel()
    {
59
        if (fullParameterVehicleAvailable) {
60
            panelLoader.source = "VehicleSummary.qml";
61 62
        } else if (multiVehicleManager.parameterReadyVehicleAvailable) {
            panelLoader.sourceComponent = missingParametersVehicleSummaryComponent
63 64 65 66 67 68 69
        } else {
            panelLoader.sourceComponent = disconnectedVehicleSummaryComponent
        }
    }

    function showFirmwarePanel()
    {
70
        if (!ScreenTools.isMobile) {
Don Gagne's avatar
Don Gagne committed
71
            if (multiVehicleManager.activeVehicleAvailable && multiVehicleManager.activeVehicle.armed) {
72 73 74 75 76 77 78 79
                messagePanelText = armedVehicleText
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = "FirmwareUpgrade.qml";
            }
        }
    }

80 81
    function showJoystickPanel()
    {
Don Gagne's avatar
Don Gagne committed
82
        if (multiVehicleManager.activeVehicleAvailable && multiVehicleManager.activeVehicle.armed) {
83 84 85 86 87 88 89
            messagePanelText = armedVehicleText
            panelLoader.sourceComponent = messagePanelComponent
        } else {
            panelLoader.source = "JoystickConfig.qml";
        }
    }

90 91 92 93 94
    function showParametersPanel()
    {
        panelLoader.source = "SetupParameterEditor.qml";
    }

Don Gagne's avatar
Don Gagne committed
95
    function showVehicleComponentPanel(vehicleComponent)
96
    {
Don Gagne's avatar
Don Gagne committed
97
        if (multiVehicleManager.activeVehicle.armed) {
98 99 100
            messagePanelText = armedVehicleText
            panelLoader.sourceComponent = messagePanelComponent
        } else {
Don Gagne's avatar
Don Gagne committed
101 102 103 104 105 106
            if (vehicleComponent.prerequisiteSetup != "") {
                messagePanelText = vehicleComponent.prerequisiteSetup + " setup must be completed prior to " + vehicleComponent.name + " setup."
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = vehicleComponent.setupSource
            }
107 108 109
        }
    }

110 111
    Component.onCompleted: showSummaryPanel()

112
    Connections {
113
        target: multiVehicleManager
114

115
        onParameterReadyVehicleAvailableChanged: {
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
            summaryButton.checked = true
            showSummaryPanel()
        }
    }

    Component {
        id: disconnectedVehicleSummaryComponent

        Rectangle {
            color: palette.windowShade

            QGCLabel {
                anchors.margins:        defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
133
                font.pixelSize:         ScreenTools.mediumFontPixelSize
134 135 136 137 138 139 140 141 142 143 144
                text:                   "Welcome to QGroundControl. " +
                                            "QGroundControl supports any <font color=\"orange\"><a href=\"http://www.qgroundcontrol.org/mavlink/start\">mavlink</a></font> enabled vehicle. " +
                                            "If you are using the <font color=\"orange\"><a href=\"https://pixhawk.org/choice\">PX4 Flight Stack</a></font>, you also get full support for setting up and calibrating your vehicle. "+
                                            "Otherwise you will only get support for flying a vehicle which has been setup and calibrated using other means. " +
                                            "Use the Connect button above to connect to your vehicle."

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
            color: palette.windowShade

            QGCLabel {
                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. " +
                                            "Because of this the full set of vehicle setup options are not available."

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

166 167 168 169 170
    Component {
        id: messagePanelComponent

        Item {
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
171 172 173 174 175
                anchors.margins:        defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
176
                font.pixelSize:         ScreenTools.mediumFontPixelSize
Don Gagne's avatar
Don Gagne committed
177
                text:                   messagePanelText
178 179 180 181
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
182 183 184 185 186 187 188 189 190 191 192
    Flickable {
        id:                 buttonFlickable
        width:              buttonWidth
        height:             parent.height
        contentWidth:       buttonWidth
        contentHeight:      buttonColumn.height
        flickableDirection: Flickable.VerticalFlick

        Column {
            id:     buttonColumn
            width:  buttonWidth
193

Don Gagne's avatar
Don Gagne committed
194 195 196 197 198 199 200
            SubMenuButton {
                id:             summaryButton
                width:          buttonWidth
                imageResource: "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                text:           "SUMMARY"
201

Don Gagne's avatar
Don Gagne committed
202 203
                onClicked: showSummaryPanel()
            }
204

Don Gagne's avatar
Don Gagne committed
205 206 207 208 209 210 211 212
            SubMenuButton {
                id:             firmwareButton
                width:          buttonWidth
                imageResource:  "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                visible:        !ScreenTools.isMobile
                text:           "FIRMWARE"
213

Don Gagne's avatar
Don Gagne committed
214 215
                onClicked: showFirmwarePanel()
            }
216 217

            SubMenuButton {
Don Gagne's avatar
Don Gagne committed
218
                id:             joystickButton
219
                width:          buttonWidth
Don Gagne's avatar
Don Gagne committed
220 221
                setupIndicator: true
                setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
222
                exclusiveGroup: setupButtonGroup
223
                visible:        fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
Don Gagne's avatar
Don Gagne committed
224
                text:           "JOYSTICK"
225

Don Gagne's avatar
Don Gagne committed
226
                onClicked: showJoystickPanel()
227 228
            }

Don Gagne's avatar
Don Gagne committed
229
            Repeater {
230
                model: fullParameterVehicleAvailable ? multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
231

Don Gagne's avatar
Don Gagne committed
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
                SubMenuButton {
                    width:          buttonWidth
                    imageResource:  modelData.iconResource
                    setupIndicator: modelData.requiresSetup
                    setupComplete:  modelData.setupComplete
                    exclusiveGroup: setupButtonGroup
                    text:           modelData.name.toUpperCase()

                    onClicked: showVehicleComponentPanel(modelData)
                }
            }

            SubMenuButton {
                width:          buttonWidth
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                visible:        multiVehicleManager.parameterReadyVehicleAvailable
                text:           "PARAMETERS"

                onClicked: showParametersPanel()
            }
        } // Column
    } // Flickable
255 256 257 258 259

    Loader {
        id:                     panelLoader
        anchors.leftMargin:     defaultTextWidth
        anchors.rightMargin:    defaultTextWidth
Don Gagne's avatar
Don Gagne committed
260
        anchors.left:           buttonFlickable.right
261 262 263 264 265
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
    }
}