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

Gus Grubba's avatar
Gus Grubba committed
31
import QGroundControl                       1.0
32 33 34 35 36
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
37

38 39
Rectangle {
    color:          qgcPal.window
Gus Grubba's avatar
Gus Grubba committed
40
    z:              QGroundControl.zOrderTopMost
41

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

    ExclusiveGroup { id: setupButtonGroup }

Don Gagne's avatar
Don Gagne committed
46 47
    readonly property real      _defaultTextHeight: ScreenTools.defaultFontPixelHeight
    readonly property real      _defaultTextWidth:  ScreenTools.defaultFontPixelWidth
48 49
    readonly property real      _margin:            Math.round(_defaultTextHeight / 2)
    readonly property real      _buttonWidth:       Math.round(_defaultTextWidth * 18)
Don Gagne's avatar
Don Gagne committed
50
    readonly property string    _armedVehicleText:  "This operation cannot be performed while vehicle is armed."
51

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

55 56
    function showSummaryPanel()
    {
Don Gagne's avatar
Don Gagne committed
57
        if (_fullParameterVehicleAvailable) {
58 59 60 61 62
            if (multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length == 0) {
                panelLoader.sourceComponent = noComponentsVehicleSummaryComponent
            } else {
                panelLoader.source = "VehicleSummary.qml";
            }
63 64
        } else if (multiVehicleManager.parameterReadyVehicleAvailable) {
            panelLoader.sourceComponent = missingParametersVehicleSummaryComponent
65 66 67 68 69 70 71
        } else {
            panelLoader.sourceComponent = disconnectedVehicleSummaryComponent
        }
    }

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

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

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

dogmaphobic's avatar
dogmaphobic committed
97 98 99 100 101
    function showPX4FlowPanel()
    {
        panelLoader.source = "PX4FlowSensor.qml";
    }

Don Gagne's avatar
Don Gagne committed
102
    function showVehicleComponentPanel(vehicleComponent)
103
    {
Don Gagne's avatar
Don Gagne committed
104
        if (multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
105
            _messagePanelText = _armedVehicleText
106 107
            panelLoader.sourceComponent = messagePanelComponent
        } else {
Don Gagne's avatar
Don Gagne committed
108
            if (vehicleComponent.prerequisiteSetup != "") {
Don Gagne's avatar
Don Gagne committed
109
                _messagePanelText = vehicleComponent.prerequisiteSetup + " setup must be completed prior to " + vehicleComponent.name + " setup."
Don Gagne's avatar
Don Gagne committed
110 111 112 113
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = vehicleComponent.setupSource
            }
114 115 116
        }
    }

117 118
    Component.onCompleted: showSummaryPanel()

119
    Connections {
120
        target: multiVehicleManager
121

122
        onParameterReadyVehicleAvailableChanged: {
123 124 125
            if (parameterReadyVehicleAvailable || summaryButton.checked) {
                // When a new vehicle shows up we switch to the Summary View. If the Summary View is already showing
                // and a vehicle goes away, we must reload it to show new disconnected Qml
126 127 128
                summaryButton.checked = true
                showSummaryPanel()
            }
129 130 131 132
        }
    }

    Component {
133
        id: noComponentsVehicleSummaryComponent
134 135

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

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
139
                anchors.margins:        _defaultTextWidth * 2
140 141 142 143
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
144
                font.pixelSize:         ScreenTools.mediumFontPixelSize
145 146
                text:                   "QGroundControl does not currently support setup of your vehicle type. " +
                                            "If your vehicle is already configured you can still Fly."
147 148 149 150 151 152

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

153 154 155 156 157 158 159 160 161 162 163 164 165
    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
166
                text:                   "Connect vehicle to your device and QGroundControl will automatically detect to it. Click Firmware on the left to upgrade your vehicle."
167 168 169 170 171

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }
172 173 174 175
    Component {
        id: missingParametersVehicleSummaryComponent

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

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
179
                anchors.margins:        _defaultTextWidth * 2
180 181 182 183 184 185
                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
186
                                        "Because of this the full set of vehicle setup options are not available."
187 188 189 190 191 192

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

193 194 195 196 197
    Component {
        id: messagePanelComponent

        Item {
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
198
                anchors.margins:        _defaultTextWidth * 2
Don Gagne's avatar
Don Gagne committed
199 200 201 202
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
203
                font.pixelSize:         ScreenTools.mediumFontPixelSize
Don Gagne's avatar
Don Gagne committed
204
                text:                   _messagePanelText
205 206 207 208
            }
        }
    }

Don Gagne's avatar
Don Gagne committed
209
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
210 211
        //-- Limit height to available height (below tool bar)
        anchors.topMargin:  _margin
Don Gagne's avatar
Don Gagne committed
212
        height:             mainWindow.availableHeight
dogmaphobic's avatar
dogmaphobic committed
213 214 215 216 217
        anchors.bottom:     parent.bottom
        anchors.left:       parent.left
        anchors.right:      parent.right
        color:              qgcPal.window

Don Gagne's avatar
Don Gagne committed
218
        QGCFlickable {
dogmaphobic's avatar
dogmaphobic committed
219
            id:                 buttonScroll
220
            width:              buttonColumn.width
dogmaphobic's avatar
dogmaphobic committed
221 222
            anchors.topMargin:  _defaultTextHeight / 2
            anchors.top:        parent.top
Don Gagne's avatar
Don Gagne committed
223
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
224 225 226 227 228
            contentHeight:      buttonColumn.height
            flickableDirection: Flickable.VerticalFlick

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

232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
                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
251 252 253 254 255 256
                SubMenuButton {
                    id:             summaryButton
                    imageResource: "/qmlimages/VehicleSummaryIcon.png"
                    setupIndicator: false
                    checked:        true
                    exclusiveGroup: setupButtonGroup
257
                    text:           "Summary"
dogmaphobic's avatar
dogmaphobic committed
258 259 260 261 262 263 264 265 266 267

                    onClicked: showSummaryPanel()
                }

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

                    onClicked: showFirmwarePanel()
                }

dogmaphobic's avatar
dogmaphobic committed
273 274 275
                SubMenuButton {
                    id:             px4FlowButton
                    exclusiveGroup: setupButtonGroup
276
                    visible:        QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.genericFirmware : false
dogmaphobic's avatar
dogmaphobic committed
277
                    setupIndicator: false
278
                    text:           "PX4Flow"
dogmaphobic's avatar
dogmaphobic committed
279 280 281
                    onClicked:      showPX4FlowPanel()
                }

dogmaphobic's avatar
dogmaphobic committed
282 283 284 285 286 287
                SubMenuButton {
                    id:             joystickButton
                    setupIndicator: true
                    setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                    exclusiveGroup: setupButtonGroup
                    visible:        _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
288
                    text:           "Joystick"
dogmaphobic's avatar
dogmaphobic committed
289 290 291 292 293

                    onClicked: showJoystickPanel()
                }

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

                    SubMenuButton {
dogmaphobic's avatar
dogmaphobic committed
298 299 300
                        imageResource:  modelData.iconResource
                        setupIndicator: modelData.requiresSetup
                        setupComplete:  modelData.setupComplete
Don Gagne's avatar
Don Gagne committed
301
                        exclusiveGroup: setupButtonGroup
302
                        text:           modelData.name
303 304
                        visible:        modelData.setupSource.toString() != ""

Don Gagne's avatar
Don Gagne committed
305

dogmaphobic's avatar
dogmaphobic committed
306
                        onClicked: showVehicleComponentPanel(modelData)
Don Gagne's avatar
Don Gagne committed
307
                    }
dogmaphobic's avatar
dogmaphobic committed
308
                }
Don Gagne's avatar
Don Gagne committed
309

dogmaphobic's avatar
dogmaphobic committed
310 311 312 313
                SubMenuButton {
                    setupIndicator: false
                    exclusiveGroup: setupButtonGroup
                    visible:        multiVehicleManager.parameterReadyVehicleAvailable
314
                    text:           "Parameters"
Don Gagne's avatar
Don Gagne committed
315

dogmaphobic's avatar
dogmaphobic committed
316 317
                    onClicked: showParametersPanel()
                }
318

Don Gagne's avatar
Don Gagne committed
319
            }
Don Gagne's avatar
Don Gagne committed
320
        }
dogmaphobic's avatar
dogmaphobic committed
321 322 323 324 325 326 327 328 329 330 331 332

        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
        }
333 334
    }
}