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 12 13 14


/// @file
///     @brief Setup View
///     @author Don Gagne <don@thegagnes.com>

15
import QtQuick          2.7
16
import QtQuick.Controls 1.4
17

Gus Grubba's avatar
Gus Grubba committed
18
import QGroundControl                       1.0
19 20 21 22 23
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
24

25
Rectangle {
26
    id:     setupView
27 28
    color:  qgcPal.window
    z:      QGroundControl.zOrderTopMost
29

Don Gagne's avatar
Don Gagne committed
30
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
31 32 33

    ExclusiveGroup { id: setupButtonGroup }

Don Gagne's avatar
Don Gagne committed
34 35
    readonly property real      _defaultTextHeight: ScreenTools.defaultFontPixelHeight
    readonly property real      _defaultTextWidth:  ScreenTools.defaultFontPixelWidth
36 37 38
    readonly property real      _horizontalMargin:  _defaultTextWidth / 2
    readonly property real      _verticalMargin:    _defaultTextHeight / 2
    readonly property real      _buttonWidth:       _defaultTextWidth * 18
39
    readonly property string    _armedVehicleText:  qsTr("This operation cannot be performed while vehicle is armed.")
40

Don Gagne's avatar
Don Gagne committed
41
    property string _messagePanelText:              "missing message panel text"
42
    property bool   _fullParameterVehicleAvailable: QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable && !QGroundControl.multiVehicleManager.activeVehicle.parameterManager.missingParameters
43

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

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

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

81 82
    function showParametersPanel()
    {
83
        panelLoader.setSource("SetupParameterEditor.qml")
84 85
    }

dogmaphobic's avatar
dogmaphobic committed
86 87
    function showPX4FlowPanel()
    {
88
        panelLoader.setSource("PX4FlowSensor.qml")
dogmaphobic's avatar
dogmaphobic committed
89 90
    }

Don Gagne's avatar
Don Gagne committed
91
    function showVehicleComponentPanel(vehicleComponent)
92
    {
93
        if (QGroundControl.multiVehicleManager.activeVehicle.armed && !vehicleComponent.allowSetupWhileArmed) {
Don Gagne's avatar
Don Gagne committed
94
            _messagePanelText = _armedVehicleText
95
            panelLoader.setSourceComponent(messagePanelComponent)
96
        } else {
Don Gagne's avatar
Don Gagne committed
97
            if (vehicleComponent.prerequisiteSetup != "") {
Don Gagne's avatar
Don Gagne committed
98
                _messagePanelText = vehicleComponent.prerequisiteSetup + " 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
            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.
124 125 126
                summaryButton.checked = true
                showSummaryPanel()
            }
127 128 129 130
        }
    }

    Component {
131
        id: noComponentsVehicleSummaryComponent
132 133

        Rectangle {
Don Gagne's avatar
Don Gagne committed
134
            color: qgcPal.windowShade
135 136

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

151 152 153 154 155 156 157 158 159 160 161 162
    Component {
        id: disconnectedVehicleSummaryComponent

        Rectangle {
            color: qgcPal.windowShade

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }
171 172 173 174
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
175
            color: qgcPal.windowShade
176 177

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

192 193 194 195 196
    Component {
        id: messagePanelComponent

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

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

220 221 222 223
        Column {
            id:         buttonColumn
            width:      _maxButtonWidth
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed
224

225
            property real _maxButtonWidth: 0
dogmaphobic's avatar
dogmaphobic committed
226

227
            Component.onCompleted: reflowWidths()
228

229 230 231 232
            Connections {
                target: componentRepeater
                onModelChanged: buttonColumn.reflowWidths()
            }
233

234 235
            // I don't know why this does not work
            Connections {
236 237
                target:         QGroundControl.settingsManager.appSettings.appFontPointSize
                onValueChanged: buttonColumn.reflowWidths()
238 239
            }

240
            function reflowWidths() {
241 242 243
                buttonColumn._maxButtonWidth = 0
                for (var i = 0; i < children.length; i++) {
                    buttonColumn._maxButtonWidth = Math.max(buttonColumn._maxButtonWidth, children[i].width)
244
                }
245 246
                for (var j = 0; j < children.length; j++) {
                    children[j].width = buttonColumn._maxButtonWidth
dogmaphobic's avatar
dogmaphobic committed
247
                }
248
            }
dogmaphobic's avatar
dogmaphobic committed
249

250 251 252 253 254 255 256 257 258
            QGCLabel {
                anchors.left:           parent.left
                anchors.right:          parent.right
                text:                   qsTr("Vehicle Setup")
                wrapMode:               Text.WordWrap
                horizontalAlignment:    Text.AlignHCenter
                visible:                !ScreenTools.isShortScreen
            }

259 260 261 262 263 264 265 266 267 268 269
            Repeater {
                model:              QGroundControl.corePlugin.settings
                visible:            QGroundControl.corePlugin.options.combineSettingsAndSetup
                SubMenuButton {
                    imageResource:  modelData.icon
                    setupIndicator: false
                    exclusiveGroup: setupButtonGroup
                    text:           modelData.title
                    visible:        QGroundControl.corePlugin.options.combineSettingsAndSetup
                    onClicked:      panelLoader.setSource(modelData.url)
                }
Gus Grubba's avatar
Gus Grubba committed
270 271
            }

272 273 274 275 276 277 278
            SubMenuButton {
                id:             summaryButton
                imageResource: "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator: false
                checked:        true
                exclusiveGroup: setupButtonGroup
                text:           "Summary"
dogmaphobic's avatar
dogmaphobic committed
279

280 281
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
282

283 284 285 286 287 288 289
            SubMenuButton {
                id:             firmwareButton
                imageResource:  "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                visible:        !ScreenTools.isMobile
                text:           "Firmware"
dogmaphobic's avatar
dogmaphobic committed
290

291 292
                onClicked: showFirmwarePanel()
            }
dogmaphobic's avatar
dogmaphobic committed
293

294 295 296 297 298 299 300 301
            SubMenuButton {
                id:             px4FlowButton
                exclusiveGroup: setupButtonGroup
                visible:        QGroundControl.multiVehicleManager.activeVehicle ? QGroundControl.multiVehicleManager.activeVehicle.genericFirmware : false
                setupIndicator: false
                text:           "PX4Flow"
                onClicked:      showPX4FlowPanel()
            }
Don Gagne's avatar
Don Gagne committed
302

303 304 305 306 307 308 309
            SubMenuButton {
                id:             joystickButton
                setupIndicator: true
                setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup: setupButtonGroup
                visible:        _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
                text:           "Joystick"
310

311 312
                onClicked: showJoystickPanel()
            }
Don Gagne's avatar
Don Gagne committed
313

314 315 316
            Repeater {
                id:     componentRepeater
                model:  _fullParameterVehicleAvailable ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
Don Gagne's avatar
Don Gagne committed
317

dogmaphobic's avatar
dogmaphobic committed
318
                SubMenuButton {
319 320 321
                    imageResource:  modelData.iconResource
                    setupIndicator: modelData.requiresSetup
                    setupComplete:  modelData.setupComplete
dogmaphobic's avatar
dogmaphobic committed
322
                    exclusiveGroup: setupButtonGroup
323 324 325 326
                    text:           modelData.name
                    visible:        modelData.setupSource.toString() != ""

                    onClicked: showVehicleComponentPanel(modelData)
dogmaphobic's avatar
dogmaphobic committed
327
                }
328 329 330 331 332 333 334
            }

            SubMenuButton {
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                visible:        QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable
                text:           "Parameters"
335

336
                onClicked: showParametersPanel()
Don Gagne's avatar
Don Gagne committed
337
            }
dogmaphobic's avatar
dogmaphobic committed
338 339

        }
340
    }
341

342 343 344 345 346 347 348 349 350 351 352 353
    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
    }

354 355
    Loader {
        id:                     panelLoader
356 357 358 359 360
        anchors.topMargin:      _verticalMargin
        anchors.bottomMargin:   _verticalMargin
        anchors.leftMargin:     _horizontalMargin
        anchors.rightMargin:    _horizontalMargin
        anchors.left:           divider.right
361 362 363
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
Don Gagne's avatar
Don Gagne committed
364

365 366 367 368 369 370 371 372 373 374
        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
375
        property var vehicleComponent
376
    }
377
}