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
Gus Grubba's avatar
Gus Grubba committed
35
    readonly property string    _armedVehicleText:  qsTr("This operation cannot be performed while the vehicle is armed.")
36

Gus Grubba's avatar
Gus Grubba committed
37
    property bool   _vehicleArmed:                  QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.armed : false
Gus Grubba's avatar
Gus Grubba committed
38
    property string _messagePanelText:              qsTr("missing message panel text")
39
    property bool   _fullParameterVehicleAvailable: QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && !QGroundControl.multiVehicleManager.activeVehicle.parameterManager.missingParameters
40
    property var    _corePlugin:                    QGroundControl.corePlugin
41

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

    function showFirmwarePanel()
    {
59
        if (!ScreenTools.isMobile) {
60
            panelLoader.setSource("FirmwareUpgrade.qml")
61 62 63
        }
    }

64 65
    function showJoystickPanel()
    {
66
        panelLoader.setSource("JoystickConfig.qml")
67 68
    }

69 70
    function showParametersPanel()
    {
71
        panelLoader.setSource("SetupParameterEditor.qml")
72 73
    }

dogmaphobic's avatar
dogmaphobic committed
74 75
    function showPX4FlowPanel()
    {
76
        panelLoader.setSource("PX4FlowSensor.qml")
dogmaphobic's avatar
dogmaphobic committed
77 78
    }

Don Gagne's avatar
Don Gagne committed
79
    function showVehicleComponentPanel(vehicleComponent)
80
    {
81 82 83
        var autopilotPlugin = QGroundControl.multiVehicleManager.activeVehicle.autopilot
        var prereq = autopilotPlugin.prerequisiteSetup(vehicleComponent)
        if (prereq !== "") {
Gus Grubba's avatar
Gus Grubba committed
84
            _messagePanelText = qsTr("%1 setup must be completed prior to %2 setup.").arg(prereq).arg(vehicleComponent.name)
85
            panelLoader.setSourceComponent(messagePanelComponent)
86
        } else {
87 88 89 90 91 92
            panelLoader.setSource(vehicleComponent.setupSource, vehicleComponent)
            for(var i = 0; i < componentRepeater.count; i++) {
                var obj = componentRepeater.itemAt(i);
                if (obj.text === vehicleComponent.name) {
                    obj.checked = true;
                    break;
93
                }
Don Gagne's avatar
Don Gagne committed
94
            }
95 96 97
        }
    }

98 99
    Component.onCompleted: showSummaryPanel()

100
    Connections {
101 102 103 104 105 106 107
        target: QGroundControl.corePlugin
        onShowAdvancedUIChanged: {
            if(!QGroundControl.corePlugin.showAdvancedUI) {
                showSummaryPanel()
            }
        }
    }
108

109 110
    Connections {
        target: QGroundControl.multiVehicleManager
111
        onParameterReadyVehicleAvailableChanged: {
112
            if(!QGroundControl.skipSetupPage) {
Gus Grubba's avatar
Gus Grubba committed
113
                if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable || summaryButton.checked || setupButtonGroup.current != firmwareButton) {
114 115 116 117 118 119 120
                    // 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()
                }
121
            }
122 123 124 125
        }
    }

    Component {
126
        id: noComponentsVehicleSummaryComponent
127
        Rectangle {
Don Gagne's avatar
Don Gagne committed
128
            color: qgcPal.windowShade
129
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
130
                anchors.margins:        _defaultTextWidth * 2
131 132 133 134
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
135
                font.pointSize:         ScreenTools.mediumFontPointSize
Gus Grubba's avatar
Gus Grubba committed
136
                text:                   qsTr("%1 does not currently support setup of your vehicle type. ").arg(QGroundControl.appName) +
137
                                        "If your vehicle is already configured you can still Fly."
138 139 140 141 142
                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

143 144 145 146 147 148 149 150 151 152
    Component {
        id: disconnectedVehicleSummaryComponent
        Rectangle {
            color: qgcPal.windowShade
            QGCLabel {
                anchors.margins:        _defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
153
                font.pointSize:         ScreenTools.largeFontPointSize
Gus Grubba's avatar
Gus Grubba committed
154
                text:                   qsTr("Vehicle settings and info will display after connecting your vehicle.") +
155
                                        (ScreenTools.isMobile || !_corePlugin.options.showFirmwareUpgrade ? "" : " Click Firmware on the left to upgrade your vehicle.")
156 157 158 159 160

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }
161

162 163 164 165
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
166
            color: qgcPal.windowShade
167 168

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
169
                anchors.margins:        _defaultTextWidth * 2
170 171 172 173
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
174
                font.pointSize:         ScreenTools.mediumFontPointSize
Gus Grubba's avatar
Gus Grubba committed
175 176
                text:                   qsTr("You are currently connected to a vehicle but it did not return the full parameter list. ") +
                                        qsTr("As a result, the full set of vehicle setup options are not available.")
177 178 179 180 181 182

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

183 184 185 186 187
    Component {
        id: messagePanelComponent

        Item {
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
188
                anchors.margins:        _defaultTextWidth * 2
Don Gagne's avatar
Don Gagne committed
189 190 191 192
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
193
                font.pointSize:         ScreenTools.mediumFontPointSize
Don Gagne's avatar
Don Gagne committed
194
                text:                   _messagePanelText
195 196 197 198
            }
        }
    }

199 200 201 202 203
    QGCFlickable {
        id:                 buttonScroll
        width:              buttonColumn.width
        anchors.topMargin:  _defaultTextHeight / 2
        anchors.top:        parent.top
dogmaphobic's avatar
dogmaphobic committed
204
        anchors.bottom:     parent.bottom
205 206
        anchors.leftMargin: _horizontalMargin
        anchors.left:       parent.left
207 208
        contentHeight:      buttonColumn.height
        flickableDirection: Flickable.VerticalFlick
dogmaphobic's avatar
dogmaphobic committed
209
        clip:               true
dogmaphobic's avatar
dogmaphobic committed
210

211
        ColumnLayout {
212 213
            id:         buttonColumn
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed
214

215
            QGCLabel {
216
                Layout.fillWidth:       true
217 218 219 220 221 222
                text:                   qsTr("Vehicle Setup")
                wrapMode:               Text.WordWrap
                horizontalAlignment:    Text.AlignHCenter
                visible:                !ScreenTools.isShortScreen
            }

223
            Repeater {
224 225
                model:                  _corePlugin ? _corePlugin.settingsPages : []
                visible:                _corePlugin && _corePlugin.options.combineSettingsAndSetup
226
                SubMenuButton {
227 228 229 230
                    imageResource:      modelData.icon
                    setupIndicator:     false
                    exclusiveGroup:     setupButtonGroup
                    text:               modelData.title
231
                    visible:            _corePlugin && _corePlugin.options.combineSettingsAndSetup
232 233
                    onClicked:          panelLoader.setSource(modelData.url)
                    Layout.fillWidth:   true
234
                }
Gus Grubba's avatar
Gus Grubba committed
235 236
            }

237
            SubMenuButton {
238 239 240 241 242
                id:                 summaryButton
                imageResource:      "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator:     false
                checked:            true
                exclusiveGroup:     setupButtonGroup
Gus Grubba's avatar
Gus Grubba committed
243
                text:               qsTr("Summary")
244
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
245

246 247
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
248

249
            SubMenuButton {
250 251 252 253
                id:                 firmwareButton
                imageResource:      "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
254
                visible:            !ScreenTools.isMobile && _corePlugin.options.showFirmwareUpgrade
Gus Grubba's avatar
Gus Grubba committed
255
                text:               qsTr("Firmware")
256
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
257

258 259
                onClicked: showFirmwarePanel()
            }
dogmaphobic's avatar
dogmaphobic committed
260

261
            SubMenuButton {
262 263
                id:                 px4FlowButton
                exclusiveGroup:     setupButtonGroup
264
                visible:            QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.priorityLink.isPX4Flow : false
265
                setupIndicator:     false
Gus Grubba's avatar
Gus Grubba committed
266
                text:               qsTr("PX4Flow")
267 268
                Layout.fillWidth:   true

269 270
                onClicked:      showPX4FlowPanel()
            }
Don Gagne's avatar
Don Gagne committed
271

272
            SubMenuButton {
273 274 275 276
                id:                 joystickButton
                setupIndicator:     true
                setupComplete:      joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup:     setupButtonGroup
Gus Grubba's avatar
Gus Grubba committed
277
                visible:            _fullParameterVehicleAvailable && joystickManager.joysticks.length !== 0
Gus Grubba's avatar
Gus Grubba committed
278
                text:               qsTr("Joystick")
279
                Layout.fillWidth:   true
280

281 282
                onClicked: showJoystickPanel()
            }
Don Gagne's avatar
Don Gagne committed
283

284 285 286
            Repeater {
                id:     componentRepeater
                model:  _fullParameterVehicleAvailable ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
Don Gagne's avatar
Don Gagne committed
287

dogmaphobic's avatar
dogmaphobic committed
288
                SubMenuButton {
289 290 291 292 293
                    imageResource:      modelData.iconResource
                    setupIndicator:     modelData.requiresSetup
                    setupComplete:      modelData.setupComplete
                    exclusiveGroup:     setupButtonGroup
                    text:               modelData.name
Gus Grubba's avatar
Gus Grubba committed
294
                    visible:            modelData.setupSource.toString() !== ""
295
                    Layout.fillWidth:   true
296 297

                    onClicked: showVehicleComponentPanel(modelData)
dogmaphobic's avatar
dogmaphobic committed
298
                }
299 300 301
            }

            SubMenuButton {
302 303
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
304 305 306
                visible:            QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable &&
                                    !QGroundControl.multiVehicleManager.activeVehicle.highLatencyLink &&
                                    _corePlugin.showAdvancedUI
Gus Grubba's avatar
Gus Grubba committed
307
                text:               qsTr("Parameters")
308
                Layout.fillWidth:   true
309

310
                onClicked: showParametersPanel()
Don Gagne's avatar
Don Gagne committed
311
            }
dogmaphobic's avatar
dogmaphobic committed
312 313

        }
314
    }
315

316 317 318 319 320 321 322 323 324 325 326 327
    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
    }

328 329
    Loader {
        id:                     panelLoader
330 331 332 333 334
        anchors.topMargin:      _verticalMargin
        anchors.bottomMargin:   _verticalMargin
        anchors.leftMargin:     _horizontalMargin
        anchors.rightMargin:    _horizontalMargin
        anchors.left:           divider.right
335 336 337
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
Don Gagne's avatar
Don Gagne committed
338

339
        function setSource(source, vehicleComponent) {
340
            panelLoader.source = ""
341 342 343 344 345
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.source = source
        }

        function setSourceComponent(sourceComponent, vehicleComponent) {
346
            panelLoader.sourceComponent = undefined
347 348 349 350
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.sourceComponent = sourceComponent
        }

Don Gagne's avatar
Don Gagne committed
351
        property var vehicleComponent
352
    }
353
}