SetupView.qml 11.4 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

Don Gagne's avatar
Don Gagne committed
37 38
Item {
    z: zOrder   // zOrder comes from the Loader in MainWindow.qml
39

Don Gagne's avatar
Don Gagne committed
40
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
41 42 43

    ExclusiveGroup { id: setupButtonGroup }

Don Gagne's avatar
Don Gagne committed
44 45 46 47 48
    readonly property real      _defaultTextHeight: ScreenTools.defaultFontPixelHeight
    readonly property real      _defaultTextWidth:  ScreenTools.defaultFontPixelWidth
    readonly property real      _margin:            _defaultTextHeight / 2
    readonly property real      _buttonWidth:       _defaultTextWidth * 15
    readonly property string    _armedVehicleText:  "This operation cannot be performed while vehicle is armed."
49

Don Gagne's avatar
Don Gagne committed
50 51
    property string _messagePanelText:              "missing message panel text"
    property bool   _fullParameterVehicleAvailable: multiVehicleManager.parameterReadyVehicleAvailable && !multiVehicleManager.activeVehicle.missingParameters
52

53 54
    function showSummaryPanel()
    {
Don Gagne's avatar
Don Gagne committed
55
        if (_fullParameterVehicleAvailable) {
56
            panelLoader.source = "VehicleSummary.qml";
57 58
        } else if (multiVehicleManager.parameterReadyVehicleAvailable) {
            panelLoader.sourceComponent = missingParametersVehicleSummaryComponent
59 60 61 62 63 64 65
        } else {
            panelLoader.sourceComponent = disconnectedVehicleSummaryComponent
        }
    }

    function showFirmwarePanel()
    {
66
        if (!ScreenTools.isMobile) {
Don Gagne's avatar
Don Gagne committed
67
            if (multiVehicleManager.activeVehicleAvailable && multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
68
                _messagePanelText = _armedVehicleText
69 70 71 72 73 74 75
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = "FirmwareUpgrade.qml";
            }
        }
    }

76 77
    function showJoystickPanel()
    {
Don Gagne's avatar
Don Gagne committed
78
        if (multiVehicleManager.activeVehicleAvailable && multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
79
            _messagePanelText = _armedVehicleText
80 81 82 83 84 85
            panelLoader.sourceComponent = messagePanelComponent
        } else {
            panelLoader.source = "JoystickConfig.qml";
        }
    }

86 87 88 89 90
    function showParametersPanel()
    {
        panelLoader.source = "SetupParameterEditor.qml";
    }

Don Gagne's avatar
Don Gagne committed
91
    function showVehicleComponentPanel(vehicleComponent)
92
    {
Don Gagne's avatar
Don Gagne committed
93
        if (multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
94
            _messagePanelText = _armedVehicleText
95 96
            panelLoader.sourceComponent = messagePanelComponent
        } else {
Don Gagne's avatar
Don Gagne committed
97
            if (vehicleComponent.prerequisiteSetup != "") {
Don Gagne's avatar
Don Gagne committed
98
                _messagePanelText = vehicleComponent.prerequisiteSetup + " setup must be completed prior to " + vehicleComponent.name + " setup."
Don Gagne's avatar
Don Gagne committed
99 100 101 102
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = vehicleComponent.setupSource
            }
103 104 105
        }
    }

106 107
    Component.onCompleted: showSummaryPanel()

108
    Connections {
109
        target: multiVehicleManager
110

111
        onParameterReadyVehicleAvailableChanged: {
112 113 114 115 116 117 118 119 120
            summaryButton.checked = true
            showSummaryPanel()
        }
    }

    Component {
        id: disconnectedVehicleSummaryComponent

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

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
124
                anchors.margins:        _defaultTextWidth * 2
125 126 127 128
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
129
                font.pixelSize:         ScreenTools.mediumFontPixelSize
130
                text:                   "Welcome to QGroundControl. " +
Don Gagne's avatar
Don Gagne committed
131 132 133 134
                                        "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."
135 136 137 138 139 140

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

141 142 143 144
    Component {
        id: missingParametersVehicleSummaryComponent

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

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
148
                anchors.margins:        _defaultTextWidth * 2
149 150 151 152 153 154
                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
155
                                        "Because of this the full set of vehicle setup options are not available."
156 157 158 159 160 161

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

162 163 164 165 166
    Component {
        id: messagePanelComponent

        Item {
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
167
                anchors.margins:        _defaultTextWidth * 2
Don Gagne's avatar
Don Gagne committed
168 169 170 171
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
172
                font.pixelSize:         ScreenTools.mediumFontPixelSize
Don Gagne's avatar
Don Gagne committed
173
                text:                   _messagePanelText
174 175 176 177
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    Rectangle {
        //anchors.margins:    _defaultTextHeight * 2
        anchors.fill:       parent
        color:              qgcPal.window
        opacity:            0.8

        QGCLabel {
            id:                     title
            anchors.topMargin:      _margin
            anchors.top:            parent.top
            anchors.left:           parent.left
            anchors.right:          parent.right
            horizontalAlignment:    Text.AlignHCenter
            font.pixelSize:         ScreenTools.largeFontPixelSize
            text:                   "Vehicle Setup"
        }
Don Gagne's avatar
Don Gagne committed
194

Don Gagne's avatar
Don Gagne committed
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
        Rectangle {
            anchors.topMargin:  _margin
            anchors.top:        title.bottom
            anchors.bottom:     parent.bottom
            anchors.left:       parent.left
            anchors.right:      parent.right
            color:              qgcPal.windowShade

            Flickable {
                id:                 buttonFlickable
                width:              _buttonWidth
                height:             parent.height
                contentWidth:       _buttonWidth
                contentHeight:      buttonColumn.height
                flickableDirection: Flickable.VerticalFlick

                Column {
                    id:         buttonColumn
                    width:      _buttonWidth
                    spacing:    _defaultTextHeight / 2

                    SubMenuButton {
                        id:             summaryButton
                        width:          _buttonWidth
                        imageResource: "/qmlimages/VehicleSummaryIcon.png"
                        setupIndicator: false
                        exclusiveGroup: setupButtonGroup
                        text:           "SUMMARY"

                        onClicked: showSummaryPanel()
                    }

                    SubMenuButton {
                        id:             firmwareButton
                        width:          _buttonWidth
                        imageResource:  "/qmlimages/FirmwareUpgradeIcon.png"
                        setupIndicator: false
                        exclusiveGroup: setupButtonGroup
                        visible:        !ScreenTools.isMobile
                        text:           "FIRMWARE"

                        onClicked: showFirmwarePanel()
                    }

                    SubMenuButton {
                        id:             joystickButton
                        width:          _buttonWidth
                        setupIndicator: true
                        setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                        exclusiveGroup: setupButtonGroup
                        visible:        _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
                        text:           "JOYSTICK"

                        onClicked: showJoystickPanel()
                    }

                    Repeater {
                        model: _fullParameterVehicleAvailable ? multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0

                        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

            Loader {
                id:                     panelLoader
                anchors.leftMargin:     _defaultTextWidth
                anchors.rightMargin:    _defaultTextWidth
                anchors.left:           buttonFlickable.right
                anchors.right:          parent.right
                anchors.top:            parent.top
                anchors.bottom:         parent.bottom
Don Gagne's avatar
Don Gagne committed
286
            }
Don Gagne's avatar
Don Gagne committed
287
        }
288 289
    }
}