SetupView.qml 14.1 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/
9

10 11
import QtQuick          2.3
import QtQuick.Controls 1.2
12
import QtQuick.Layouts  1.2
13

Gus Grubba's avatar
Gus Grubba committed
14
import QGroundControl                       1.0
15 16 17 18 19
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
20

21
Rectangle {
22
    id:     setupView
23 24
    color:  qgcPal.window
    z:      QGroundControl.zOrderTopMost
25

Don Gagne's avatar
Don Gagne committed
26
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
27 28 29

    ExclusiveGroup { id: setupButtonGroup }

Don Gagne's avatar
Don Gagne committed
30 31
    readonly property real      _defaultTextHeight: ScreenTools.defaultFontPixelHeight
    readonly property real      _defaultTextWidth:  ScreenTools.defaultFontPixelWidth
32 33 34
    readonly property real      _horizontalMargin:  _defaultTextWidth / 2
    readonly property real      _verticalMargin:    _defaultTextHeight / 2
    readonly property real      _buttonWidth:       _defaultTextWidth * 18
35
    readonly property string    _armedVehicleText:  qsTr("This operation cannot be performed while vehicle is armed.")
36

Don Gagne's avatar
Don Gagne committed
37
    property string _messagePanelText:              "missing message panel text"
38
    property bool   _fullParameterVehicleAvailable: QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && !QGroundControl.multiVehicleManager.activeVehicle.parameterManager.missingParameters
39

40 41
    function showSummaryPanel()
    {
Don Gagne's avatar
Don Gagne committed
42
        if (_fullParameterVehicleAvailable) {
43
            if (QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length == 0) {
44
                panelLoader.setSourceComponent(noComponentsVehicleSummaryComponent)
45
            } else {
46
                panelLoader.setSource("VehicleSummary.qml")
47
            }
48
        } else if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable) {
49
            panelLoader.setSourceComponent(missingParametersVehicleSummaryComponent)
50
        } else {
51
            panelLoader.setSourceComponent(disconnectedVehicleSummaryComponent)
52 53 54 55 56
        }
    }

    function showFirmwarePanel()
    {
57
        if (!ScreenTools.isMobile) {
58
            if (QGroundControl.multiVehicleManager.activeVehicleAvailable && QGroundControl.multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
59
                _messagePanelText = _armedVehicleText
60
                panelLoader.setSourceComponent(messagePanelComponent)
61
            } else {
62
                panelLoader.setSource("FirmwareUpgrade.qml")
63 64 65 66
            }
        }
    }

67 68
    function showJoystickPanel()
    {
69
        if (QGroundControl.multiVehicleManager.activeVehicleAvailable && QGroundControl.multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
70
            _messagePanelText = _armedVehicleText
71
            panelLoader.setSourceComponent(messagePanelComponent)
72
        } else {
73
            panelLoader.setSource("JoystickConfig.qml")
74 75 76
        }
    }

77 78
    function showParametersPanel()
    {
79
        panelLoader.setSource("SetupParameterEditor.qml")
80 81
    }

dogmaphobic's avatar
dogmaphobic committed
82 83
    function showPX4FlowPanel()
    {
84
        panelLoader.setSource("PX4FlowSensor.qml")
dogmaphobic's avatar
dogmaphobic committed
85 86
    }

Don Gagne's avatar
Don Gagne committed
87
    function showVehicleComponentPanel(vehicleComponent)
88
    {
89
        if (QGroundControl.multiVehicleManager.activeVehicle.armed && !vehicleComponent.allowSetupWhileArmed) {
Don Gagne's avatar
Don Gagne committed
90
            _messagePanelText = _armedVehicleText
91
            panelLoader.setSourceComponent(messagePanelComponent)
92
        } else {
93 94 95 96
            var autopilotPlugin = QGroundControl.multiVehicleManager.activeVehicle.autopilot
            var prereq = autopilotPlugin.prerequisiteSetup(vehicleComponent)
            if (prereq != "") {
                _messagePanelText = prereq + " setup must be completed prior to " + vehicleComponent.name + " setup."
97
                panelLoader.setSourceComponent(messagePanelComponent)
Don Gagne's avatar
Don Gagne committed
98
            } else {
99
                panelLoader.setSource(vehicleComponent.setupSource, vehicleComponent)
100 101 102 103 104 105 106
                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
107
            }
108 109 110
        }
    }

111 112
    Component.onCompleted: showSummaryPanel()

113
    Connections {
114
        target: QGroundControl.multiVehicleManager
115

116
        onParameterReadyVehicleAvailableChanged: {
117 118 119 120 121 122 123 124 125
            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()
                }
126
            }
127 128 129 130
        }
    }

    Component {
131
        id: noComponentsVehicleSummaryComponent
132 133

        Rectangle {
Don Gagne's avatar
Don Gagne committed
134
            color: qgcPal.windowShade
135 136

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

151 152 153 154 155 156 157 158 159 160 161 162
    Component {
        id: disconnectedVehicleSummaryComponent

        Rectangle {
            color: qgcPal.windowShade

            QGCLabel {
                anchors.margins:        _defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
163
                font.pointSize:         ScreenTools.largeFontPointSize
Don Gagne's avatar
Don Gagne committed
164
                text:                   "Connect vehicle to your device and QGroundControl will automatically detect it." +
165
                                        (ScreenTools.isMobile ? "" : " Click Firmware on the left to upgrade your vehicle.")
166 167 168 169 170

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

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

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
178
                anchors.margins:        _defaultTextWidth * 2
179 180 181 182
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
183
                font.pointSize:         ScreenTools.mediumFontPointSize
184
                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
185
                                        "Because of this the full set of vehicle setup options are not available."
186 187 188 189 190 191

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

192 193 194 195 196
    Component {
        id: messagePanelComponent

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

208 209 210 211 212
    QGCFlickable {
        id:                 buttonScroll
        width:              buttonColumn.width
        anchors.topMargin:  _defaultTextHeight / 2
        anchors.top:        parent.top
dogmaphobic's avatar
dogmaphobic committed
213
        anchors.bottom:     parent.bottom
214 215
        anchors.leftMargin: _horizontalMargin
        anchors.left:       parent.left
216 217
        contentHeight:      buttonColumn.height
        flickableDirection: Flickable.VerticalFlick
dogmaphobic's avatar
dogmaphobic committed
218
        clip:               true
dogmaphobic's avatar
dogmaphobic committed
219

220
        ColumnLayout {
221 222
            id:         buttonColumn
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed
223

224 225 226 227 228 229 230 231 232
            QGCLabel {
                anchors.left:           parent.left
                anchors.right:          parent.right
                text:                   qsTr("Vehicle Setup")
                wrapMode:               Text.WordWrap
                horizontalAlignment:    Text.AlignHCenter
                visible:                !ScreenTools.isShortScreen
            }

233
            Repeater {
234
                model:              QGroundControl.corePlugin.settingsPages
235 236
                visible:            QGroundControl.corePlugin.options.combineSettingsAndSetup
                SubMenuButton {
237 238 239 240 241 242 243
                    imageResource:      modelData.icon
                    setupIndicator:     false
                    exclusiveGroup:     setupButtonGroup
                    text:               modelData.title
                    visible:            QGroundControl.corePlugin.options.combineSettingsAndSetup
                    onClicked:          panelLoader.setSource(modelData.url)
                    Layout.fillWidth:   true
244
                }
Gus Grubba's avatar
Gus Grubba committed
245 246
            }

247
            SubMenuButton {
248 249 250 251 252 253 254
                id:                 summaryButton
                imageResource:      "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator:     false
                checked:            true
                exclusiveGroup:     setupButtonGroup
                text:               "Summary"
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
255

256 257
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
258

259
            SubMenuButton {
260 261 262 263 264 265 266
                id:                 firmwareButton
                imageResource:      "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
                visible:            !ScreenTools.isMobile
                text:               "Firmware"
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
267

268 269
                onClicked: showFirmwarePanel()
            }
dogmaphobic's avatar
dogmaphobic committed
270

271
            SubMenuButton {
272 273 274 275 276 277 278
                id:                 px4FlowButton
                exclusiveGroup:     setupButtonGroup
                visible:            QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.genericFirmware : false
                setupIndicator:     false
                text:               "PX4Flow"
                Layout.fillWidth:   true

279 280
                onClicked:      showPX4FlowPanel()
            }
Don Gagne's avatar
Don Gagne committed
281

282
            SubMenuButton {
283 284 285 286 287 288 289
                id:                 joystickButton
                setupIndicator:     true
                setupComplete:      joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup:     setupButtonGroup
                visible:            _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
                text:               "Joystick"
                Layout.fillWidth:   true
290

291 292
                onClicked: showJoystickPanel()
            }
Don Gagne's avatar
Don Gagne committed
293

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

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

                    onClicked: showVehicleComponentPanel(modelData)
dogmaphobic's avatar
dogmaphobic committed
308
                }
309 310 311
            }

            SubMenuButton {
312 313
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
314
                visible:            QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && QGroundControl.corePlugin.showAdvancedUI
315 316
                text:               "Parameters"
                Layout.fillWidth:   true
317

318
                onClicked: showParametersPanel()
Don Gagne's avatar
Don Gagne committed
319
            }
dogmaphobic's avatar
dogmaphobic committed
320 321

        }
322
    }
323

324 325 326 327 328 329 330 331 332 333 334 335
    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
    }

336 337
    Loader {
        id:                     panelLoader
338 339 340 341 342
        anchors.topMargin:      _verticalMargin
        anchors.bottomMargin:   _verticalMargin
        anchors.leftMargin:     _horizontalMargin
        anchors.rightMargin:    _horizontalMargin
        anchors.left:           divider.right
343 344 345
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
Don Gagne's avatar
Don Gagne committed
346

347 348 349 350 351 352 353 354 355 356
        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
357
        property var vehicleComponent
358
    }
359
}