SetupView.qml 12.3 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.3
16 17
import QtQuick.Controls 1.2

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 {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
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
    readonly property real      _margin:            Math.round(_defaultTextHeight / 2)
    readonly property real      _buttonWidth:       Math.round(_defaultTextWidth * 18)
38
    readonly property string    _armedVehicleText:  qsTr("This operation cannot be performed while vehicle is armed.")
39

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

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

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

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

80 81 82 83 84
    function showParametersPanel()
    {
        panelLoader.source = "SetupParameterEditor.qml";
    }

dogmaphobic's avatar
dogmaphobic committed
85 86 87 88 89
    function showPX4FlowPanel()
    {
        panelLoader.source = "PX4FlowSensor.qml";
    }

Don Gagne's avatar
Don Gagne committed
90
    function showVehicleComponentPanel(vehicleComponent)
91
    {
92
        if (QGroundControl.multiVehicleManager.activeVehicle.armed && !vehicleComponent.allowSetupWhileArmed) {
Don Gagne's avatar
Don Gagne committed
93
            _messagePanelText = _armedVehicleText
94 95
            panelLoader.sourceComponent = messagePanelComponent
        } else {
Don Gagne's avatar
Don Gagne committed
96
            if (vehicleComponent.prerequisiteSetup != "") {
Don Gagne's avatar
Don Gagne committed
97
                _messagePanelText = vehicleComponent.prerequisiteSetup + " setup must be completed prior to " + vehicleComponent.name + " setup."
Don Gagne's avatar
Don Gagne committed
98 99 100
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = vehicleComponent.setupSource
101 102 103 104 105 106 107
                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
108
            }
109 110 111
        }
    }

112 113
    Component.onCompleted: showSummaryPanel()

114
    Connections {
115
        target: QGroundControl.multiVehicleManager
116

117
        onParameterReadyVehicleAvailableChanged: {
118 119 120 121 122
            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.
123 124 125
                summaryButton.checked = true
                showSummaryPanel()
            }
126 127 128 129
        }
    }

    Component {
130
        id: noComponentsVehicleSummaryComponent
131 132

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

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

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

        Rectangle {
            color: qgcPal.windowShade

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

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

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

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

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

191 192 193 194 195
    Component {
        id: messagePanelComponent

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

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

217 218 219 220
        Column {
            id:         buttonColumn
            width:      _maxButtonWidth
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed
221

222
            property real _maxButtonWidth: 0
dogmaphobic's avatar
dogmaphobic committed
223

224
            Component.onCompleted: reflowWidths()
225

226 227 228 229
            Connections {
                target: componentRepeater
                onModelChanged: buttonColumn.reflowWidths()
            }
230

231 232 233 234 235 236
            // I don't know why this does not work
            Connections {
                target: QGroundControl
                onBaseFontPointSizeChanged: buttonColumn.reflowWidths()
            }

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

247 248 249 250 251 252 253
            SubMenuButton {
                id:             summaryButton
                imageResource: "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator: false
                checked:        true
                exclusiveGroup: setupButtonGroup
                text:           "Summary"
dogmaphobic's avatar
dogmaphobic committed
254

255 256
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
257

258 259 260 261 262 263 264
            SubMenuButton {
                id:             firmwareButton
                imageResource:  "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                visible:        !ScreenTools.isMobile
                text:           "Firmware"
dogmaphobic's avatar
dogmaphobic committed
265

266 267
                onClicked: showFirmwarePanel()
            }
dogmaphobic's avatar
dogmaphobic committed
268

269 270 271 272 273 274 275 276
            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
277

278 279 280 281 282 283 284
            SubMenuButton {
                id:             joystickButton
                setupIndicator: true
                setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup: setupButtonGroup
                visible:        _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
                text:           "Joystick"
285

286 287
                onClicked: showJoystickPanel()
            }
Don Gagne's avatar
Don Gagne committed
288

289 290 291
            Repeater {
                id:     componentRepeater
                model:  _fullParameterVehicleAvailable ? QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents : 0
Don Gagne's avatar
Don Gagne committed
292

dogmaphobic's avatar
dogmaphobic committed
293
                SubMenuButton {
294 295 296
                    imageResource:  modelData.iconResource
                    setupIndicator: modelData.requiresSetup
                    setupComplete:  modelData.setupComplete
dogmaphobic's avatar
dogmaphobic committed
297
                    exclusiveGroup: setupButtonGroup
298 299 300 301
                    text:           modelData.name
                    visible:        modelData.setupSource.toString() != ""

                    onClicked: showVehicleComponentPanel(modelData)
dogmaphobic's avatar
dogmaphobic committed
302
                }
303 304 305 306 307 308 309
            }

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

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

        }
315
    }
316 317 318 319 320 321 322 323 324 325 326 327

    Loader {
        id:                     panelLoader
        anchors.topMargin:      _margin
        anchors.bottomMargin:   _margin
        anchors.leftMargin:     _defaultTextWidth
        anchors.rightMargin:    _defaultTextWidth
        anchors.left:           buttonScroll.right
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
    }
328
}