SetupView.qml 13.8 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * 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 44 45 46 47 48 49
    function showSummaryPanel() {
        if (mainWindow.preventViewSwitch()) {
            return
        }
        _showSummaryPanel()
    }

    function _showSummaryPanel() {
Don Gagne's avatar
Don Gagne committed
50
        if (_fullParameterVehicleAvailable) {
Gus Grubba's avatar
Gus Grubba committed
51
            if (QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length === 0) {
52
                panelLoader.setSourceComponent(noComponentsVehicleSummaryComponent)
53
            } else {
54
                panelLoader.setSource("VehicleSummary.qml")
55
            }
56
        } else if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable) {
57
            panelLoader.setSourceComponent(missingParametersVehicleSummaryComponent)
58
        } else {
59
            panelLoader.setSourceComponent(disconnectedVehicleSummaryComponent)
60
        }
61
        summaryButton.checked = true
62 63
    }

64 65 66
    function showPanel(button, qmlSource) {
        if (mainWindow.preventViewSwitch()) {
            return
67
        }
68 69
        button.checked = true
        panelLoader.setSource(qmlSource)
dogmaphobic's avatar
dogmaphobic committed
70 71
    }

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

94
    Component.onCompleted: _showSummaryPanel()
95

96
    Connections {
97 98 99 100 101 102 103
        target: QGroundControl.corePlugin
        onShowAdvancedUIChanged: {
            if(!QGroundControl.corePlugin.showAdvancedUI) {
                _showSummaryPanel()
            }
        }
    }
104

105 106
    Connections {
        target: QGroundControl.multiVehicleManager
107
        onParameterReadyVehicleAvailableChanged: {
108
            if(!QGroundControl.skipSetupPage) {
109
                if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable || summaryButton.checked || setupButtonGroup.current != firmwareButton) {
110 111 112 113 114
                    // 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
115
                    _showSummaryPanel()
116
                }
117
            }
118 119 120 121
        }
    }

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

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

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

158 159 160 161
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
162
            color: qgcPal.windowShade
163 164

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

179 180 181 182 183
    Component {
        id: messagePanelComponent

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

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

207
        ColumnLayout {
208 209
            id:         buttonColumn
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed
210

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

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

234 235
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
236

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

246
                onClicked: showPanel(this, "FirmwareUpgrade.qml")
247
            }
dogmaphobic's avatar
dogmaphobic committed
248

249
            SubMenuButton {
250 251
                id:                 px4FlowButton
                exclusiveGroup:     setupButtonGroup
252
                visible:            QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.vehicleLinkManager.primaryLink.isPX4Flow : false
253
                setupIndicator:     false
Gus Grubba's avatar
Gus Grubba committed
254
                text:               qsTr("PX4Flow")
255
                Layout.fillWidth:   true
256
                onClicked:          showPanel(this, "PX4FlowSensor.qml")
257
            }
Don Gagne's avatar
Don Gagne committed
258

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

270 271 272
            Repeater {
                id:     componentRepeater
                model:  _fullParameterVehicleAvailable ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
Don Gagne's avatar
Don Gagne committed
273

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

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

        }
298
    }
299

300 301 302 303 304 305 306 307 308 309 310 311
    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
    }

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

323
        function setSource(source, vehicleComponent) {
324
            panelLoader.source = ""
325 326 327 328 329
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.source = source
        }

        function setSourceComponent(sourceComponent, vehicleComponent) {
330
            panelLoader.sourceComponent = undefined
331 332 333 334
            panelLoader.vehicleComponent = vehicleComponent
            panelLoader.sourceComponent = sourceComponent
        }

Don Gagne's avatar
Don Gagne committed
335
        property var vehicleComponent
336
    }
337
}