SetupView.qml 14.4 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 string _messagePanelText:              qsTr("missing message panel text")
38
    property bool   _fullParameterVehicleAvailable: QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && !QGroundControl.multiVehicleManager.activeVehicle.parameterManager.missingParameters
39
    property var    _corePlugin:                    QGroundControl.corePlugin
40

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

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

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

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

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

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

113 114
    Component.onCompleted: showSummaryPanel()

115
    Connections {
116
        target: QGroundControl.multiVehicleManager
117

118
        onParameterReadyVehicleAvailableChanged: {
119 120 121 122 123 124 125 126 127
            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()
                }
128
            }
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.pointSize:         ScreenTools.mediumFontPointSize
Gus Grubba's avatar
Gus Grubba committed
145
                text:                   qsTr("%1 does not currently support setup of your vehicle type. ").arg(QGroundControl.appName) +
146
                                        "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
    Component {
        id: disconnectedVehicleSummaryComponent

        Rectangle {
            color: qgcPal.windowShade

            QGCLabel {
                anchors.margins:        _defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
165
                font.pointSize:         ScreenTools.largeFontPointSize
Gus Grubba's avatar
Gus Grubba committed
166
                text:                   qsTr("Vehicle settings and info will display after connecting your vehicle.") +
167
                                        (ScreenTools.isMobile ? "" : " Click Firmware on the left to upgrade your vehicle.")
168 169 170 171 172

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

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

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
180
                anchors.margins:        _defaultTextWidth * 2
181 182 183 184
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
185
                font.pointSize:         ScreenTools.mediumFontPointSize
Gus Grubba's avatar
Gus Grubba committed
186 187
                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.")
188 189 190 191 192 193

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

194 195 196 197 198
    Component {
        id: messagePanelComponent

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

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

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

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

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

249
            SubMenuButton {
250 251 252 253 254
                id:                 summaryButton
                imageResource:      "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator:     false
                checked:            true
                exclusiveGroup:     setupButtonGroup
Gus Grubba's avatar
Gus Grubba committed
255
                text:               qsTr("Summary")
256
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
257

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

261
            SubMenuButton {
262 263 264 265
                id:                 firmwareButton
                imageResource:      "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
266
                visible:            !ScreenTools.isMobile && _corePlugin.options.showFirmwareUpgrade
Gus Grubba's avatar
Gus Grubba committed
267
                text:               qsTr("Firmware")
268
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
269

270 271
                onClicked: showFirmwarePanel()
            }
dogmaphobic's avatar
dogmaphobic committed
272

273
            SubMenuButton {
274 275 276 277
                id:                 px4FlowButton
                exclusiveGroup:     setupButtonGroup
                visible:            QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.genericFirmware : false
                setupIndicator:     false
Gus Grubba's avatar
Gus Grubba committed
278
                text:               qsTr("PX4Flow")
279 280
                Layout.fillWidth:   true

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

284
            SubMenuButton {
285 286 287 288 289
                id:                 joystickButton
                setupIndicator:     true
                setupComplete:      joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup:     setupButtonGroup
                visible:            _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
Gus Grubba's avatar
Gus Grubba committed
290
                text:               qsTr("Joystick")
291
                Layout.fillWidth:   true
292

293 294
                onClicked: showJoystickPanel()
            }
Don Gagne's avatar
Don Gagne committed
295

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

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

                    onClicked: showVehicleComponentPanel(modelData)
dogmaphobic's avatar
dogmaphobic committed
310
                }
311 312 313
            }

            SubMenuButton {
314 315
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
316
                visible:            QGroundControl.multiVehicleManager && QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && _corePlugin.showAdvancedUI
Gus Grubba's avatar
Gus Grubba committed
317
                text:               qsTr("Parameters")
318
                Layout.fillWidth:   true
319

320
                onClicked: showParametersPanel()
Don Gagne's avatar
Don Gagne committed
321
            }
dogmaphobic's avatar
dogmaphobic committed
322 323

        }
324
    }
325

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

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

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