SetupView.qml 14 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
            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.
122 123 124
                summaryButton.checked = true
                showSummaryPanel()
            }
125 126 127 128
        }
    }

    Component {
129
        id: noComponentsVehicleSummaryComponent
130 131

        Rectangle {
Don Gagne's avatar
Don Gagne committed
132
            color: qgcPal.windowShade
133 134

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

149 150 151 152 153 154 155 156 157 158 159 160
    Component {
        id: disconnectedVehicleSummaryComponent

        Rectangle {
            color: qgcPal.windowShade

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }
169 170 171 172
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
173
            color: qgcPal.windowShade
174 175

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

190 191 192 193 194
    Component {
        id: messagePanelComponent

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

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

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

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

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

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

254 255
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
256

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

266 267
                onClicked: showFirmwarePanel()
            }
dogmaphobic's avatar
dogmaphobic committed
268

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

277 278
                onClicked:      showPX4FlowPanel()
            }
Don Gagne's avatar
Don Gagne committed
279

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

289 290
                onClicked: showJoystickPanel()
            }
Don Gagne's avatar
Don Gagne committed
291

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

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

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

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

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

        }
320
    }
321

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

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

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