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()
    {
44
        if (mainWindow.preventViewSwitch()) {
45 46
            return
        }
Don Gagne's avatar
Don Gagne committed
47
        if (_fullParameterVehicleAvailable) {
Gus Grubba's avatar
Gus Grubba committed
48
            if (QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length === 0) {
49
                panelLoader.setSourceComponent(noComponentsVehicleSummaryComponent)
50
            } else {
51
                panelLoader.setSource("VehicleSummary.qml")
52
            }
53
        } else if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable) {
54
            panelLoader.setSourceComponent(missingParametersVehicleSummaryComponent)
55
        } else {
56
            panelLoader.setSourceComponent(disconnectedVehicleSummaryComponent)
57 58 59
        }
    }

60
    function showPanel(button, qmlSource) {
61
        if (mainWindow.preventViewSwitch()) {
62
            return
63
        }
64 65
        button.checked = true
        panelLoader.setSource(qmlSource)
dogmaphobic's avatar
dogmaphobic committed
66 67
    }

Don Gagne's avatar
Don Gagne committed
68
    function showVehicleComponentPanel(vehicleComponent)
69
    {
70
        if (mainWindow.preventViewSwitch()) {
71 72
            return
        }
73 74 75
        var autopilotPlugin = QGroundControl.multiVehicleManager.activeVehicle.autopilot
        var prereq = autopilotPlugin.prerequisiteSetup(vehicleComponent)
        if (prereq !== "") {
Gus Grubba's avatar
Gus Grubba committed
76
            _messagePanelText = qsTr("%1 setup must be completed prior to %2 setup.").arg(prereq).arg(vehicleComponent.name)
77
            panelLoader.setSourceComponent(messagePanelComponent)
78
        } else {
79 80 81 82 83 84
            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;
85
                }
Don Gagne's avatar
Don Gagne committed
86
            }
87 88 89
        }
    }

90 91
    Component.onCompleted: showSummaryPanel()

92
    Connections {
93 94 95 96 97 98 99
        target: QGroundControl.corePlugin
        onShowAdvancedUIChanged: {
            if(!QGroundControl.corePlugin.showAdvancedUI) {
                showSummaryPanel()
            }
        }
    }
100

101 102
    Connections {
        target: QGroundControl.multiVehicleManager
103
        onParameterReadyVehicleAvailableChanged: {
104
            if(!QGroundControl.skipSetupPage) {
Gus Grubba's avatar
Gus Grubba committed
105
                if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable || summaryButton.checked || setupButtonGroup.current != firmwareButton) {
106 107 108 109 110 111 112
                    // 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()
                }
113
            }
114 115 116 117
        }
    }

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

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

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

154 155 156 157
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
158
            color: qgcPal.windowShade
159 160

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
161
                anchors.margins:        _defaultTextWidth * 2
162 163 164 165
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
166
                font.pointSize:         ScreenTools.mediumFontPointSize
Gus Grubba's avatar
Gus Grubba committed
167 168
                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.")
169 170 171 172 173 174

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

175 176 177 178 179
    Component {
        id: messagePanelComponent

        Item {
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
180
                anchors.margins:        _defaultTextWidth * 2
Don Gagne's avatar
Don Gagne committed
181 182 183 184
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
185
                font.pointSize:         ScreenTools.mediumFontPointSize
Don Gagne's avatar
Don Gagne committed
186
                text:                   _messagePanelText
187 188 189 190
            }
        }
    }

191 192 193 194 195
    QGCFlickable {
        id:                 buttonScroll
        width:              buttonColumn.width
        anchors.topMargin:  _defaultTextHeight / 2
        anchors.top:        parent.top
dogmaphobic's avatar
dogmaphobic committed
196
        anchors.bottom:     parent.bottom
197 198
        anchors.leftMargin: _horizontalMargin
        anchors.left:       parent.left
199 200
        contentHeight:      buttonColumn.height
        flickableDirection: Flickable.VerticalFlick
dogmaphobic's avatar
dogmaphobic committed
201
        clip:               true
dogmaphobic's avatar
dogmaphobic committed
202

203
        ColumnLayout {
204 205
            id:         buttonColumn
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed
206

207
            QGCLabel {
208
                Layout.fillWidth:       true
209 210 211 212 213 214
                text:                   qsTr("Vehicle Setup")
                wrapMode:               Text.WordWrap
                horizontalAlignment:    Text.AlignHCenter
                visible:                !ScreenTools.isShortScreen
            }

215
            Repeater {
216 217
                model:                  _corePlugin ? _corePlugin.settingsPages : []
                visible:                _corePlugin && _corePlugin.options.combineSettingsAndSetup
218
                SubMenuButton {
219 220 221 222
                    imageResource:      modelData.icon
                    setupIndicator:     false
                    exclusiveGroup:     setupButtonGroup
                    text:               modelData.title
223
                    visible:            _corePlugin && _corePlugin.options.combineSettingsAndSetup
224
                    onClicked:          showPanel(this, modelData.url)
225
                    Layout.fillWidth:   true
226
                }
Gus Grubba's avatar
Gus Grubba committed
227 228
            }

229
            SubMenuButton {
230 231 232 233 234
                id:                 summaryButton
                imageResource:      "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator:     false
                checked:            true
                exclusiveGroup:     setupButtonGroup
Gus Grubba's avatar
Gus Grubba committed
235
                text:               qsTr("Summary")
236
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
237

238 239
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
240

241
            SubMenuButton {
242 243 244 245
                id:                 firmwareButton
                imageResource:      "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
246
                visible:            !ScreenTools.isMobile && _corePlugin.options.showFirmwareUpgrade
Gus Grubba's avatar
Gus Grubba committed
247
                text:               qsTr("Firmware")
248
                Layout.fillWidth:   true
dogmaphobic's avatar
dogmaphobic committed
249

250
                onClicked: showPanel(this, "FirmwareUpgrade.qml")
251
            }
dogmaphobic's avatar
dogmaphobic committed
252

253
            SubMenuButton {
254 255
                id:                 px4FlowButton
                exclusiveGroup:     setupButtonGroup
256
                visible:            QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.priorityLink.isPX4Flow : false
257
                setupIndicator:     false
Gus Grubba's avatar
Gus Grubba committed
258
                text:               qsTr("PX4Flow")
259
                Layout.fillWidth:   true
260
                onClicked:          showPX4FlowPanel(this, "PX4FlowSensor.qml")
261
            }
Don Gagne's avatar
Don Gagne committed
262

263
            SubMenuButton {
264 265 266 267
                id:                 joystickButton
                setupIndicator:     true
                setupComplete:      joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup:     setupButtonGroup
Gus Grubba's avatar
Gus Grubba committed
268
                visible:            _fullParameterVehicleAvailable && joystickManager.joysticks.length !== 0
Gus Grubba's avatar
Gus Grubba committed
269
                text:               qsTr("Joystick")
270
                Layout.fillWidth:   true
271
                onClicked:          showJoystickPanel(this, "JoystickConfig.qml")
272
            }
Don Gagne's avatar
Don Gagne committed
273

274 275 276
            Repeater {
                id:     componentRepeater
                model:  _fullParameterVehicleAvailable ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
Don Gagne's avatar
Don Gagne committed
277

dogmaphobic's avatar
dogmaphobic committed
278
                SubMenuButton {
279 280 281 282 283
                    imageResource:      modelData.iconResource
                    setupIndicator:     modelData.requiresSetup
                    setupComplete:      modelData.setupComplete
                    exclusiveGroup:     setupButtonGroup
                    text:               modelData.name
Gus Grubba's avatar
Gus Grubba committed
284
                    visible:            modelData.setupSource.toString() !== ""
285
                    Layout.fillWidth:   true
286
                    onClicked:          showVehicleComponentPanel(modelData)
dogmaphobic's avatar
dogmaphobic committed
287
                }
288 289 290
            }

            SubMenuButton {
291 292
                setupIndicator:     false
                exclusiveGroup:     setupButtonGroup
293 294 295
                visible:            QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable &&
                                    !QGroundControl.multiVehicleManager.activeVehicle.highLatencyLink &&
                                    _corePlugin.showAdvancedUI
Gus Grubba's avatar
Gus Grubba committed
296
                text:               qsTr("Parameters")
297
                Layout.fillWidth:   true
298
                onClicked:          showPanel(this, "SetupParameterEditor.qml")
Don Gagne's avatar
Don Gagne committed
299
            }
dogmaphobic's avatar
dogmaphobic committed
300 301

        }
302
    }
303

304 305 306 307 308 309 310 311 312 313 314 315
    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
    }

316 317
    Loader {
        id:                     panelLoader
318 319 320 321 322
        anchors.topMargin:      _verticalMargin
        anchors.bottomMargin:   _verticalMargin
        anchors.leftMargin:     _horizontalMargin
        anchors.rightMargin:    _horizontalMargin
        anchors.left:           divider.right
323 324 325
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
Don Gagne's avatar
Don Gagne committed
326

327
        function setSource(source, vehicleComponent) {
328
            panelLoader.source = ""
329 330 331 332 333
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.source = source
        }

        function setSourceComponent(sourceComponent, vehicleComponent) {
334
            panelLoader.sourceComponent = undefined
335 336 337 338
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.sourceComponent = sourceComponent
        }

Don Gagne's avatar
Don Gagne committed
339
        property var vehicleComponent
340
    }
341
}