SetupView.qml 12.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

QGROUNDCONTROL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

QGROUNDCONTROL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

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

28
import QtQuick          2.3
29 30
import QtQuick.Controls 1.2

Gus Grubba's avatar
Gus Grubba committed
31
import QGroundControl                       1.0
32 33 34 35 36
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
37

38
Rectangle {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
39
    id: setupView
40 41
    color:  qgcPal.window
    z:      QGroundControl.zOrderTopMost
42

Don Gagne's avatar
Don Gagne committed
43
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
44 45 46

    ExclusiveGroup { id: setupButtonGroup }

Don Gagne's avatar
Don Gagne committed
47 48
    readonly property real      _defaultTextHeight: ScreenTools.defaultFontPixelHeight
    readonly property real      _defaultTextWidth:  ScreenTools.defaultFontPixelWidth
49 50
    readonly property real      _margin:            Math.round(_defaultTextHeight / 2)
    readonly property real      _buttonWidth:       Math.round(_defaultTextWidth * 18)
51
    readonly property string    _armedVehicleText:  qsTr("This operation cannot be performed while vehicle is armed.")
52

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

56 57
    function showSummaryPanel()
    {
Don Gagne's avatar
Don Gagne committed
58
        if (_fullParameterVehicleAvailable) {
59
            if (QGroundControl.multiVehicleManager.activeVehicle.autopilot.vehicleComponents.length == 0) {
60 61 62 63
                panelLoader.sourceComponent = noComponentsVehicleSummaryComponent
            } else {
                panelLoader.source = "VehicleSummary.qml";
            }
64
        } else if (QGroundControl.multiVehicleManager.parameterReadyVehicleAvailable) {
65
            panelLoader.sourceComponent = missingParametersVehicleSummaryComponent
66 67 68 69 70 71 72
        } else {
            panelLoader.sourceComponent = disconnectedVehicleSummaryComponent
        }
    }

    function showFirmwarePanel()
    {
73
        if (!ScreenTools.isMobile) {
74
            if (QGroundControl.multiVehicleManager.activeVehicleAvailable && QGroundControl.multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
75
                _messagePanelText = _armedVehicleText
76 77 78 79 80 81 82
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = "FirmwareUpgrade.qml";
            }
        }
    }

83 84
    function showJoystickPanel()
    {
85
        if (QGroundControl.multiVehicleManager.activeVehicleAvailable && QGroundControl.multiVehicleManager.activeVehicle.armed) {
Don Gagne's avatar
Don Gagne committed
86
            _messagePanelText = _armedVehicleText
87 88 89 90 91 92
            panelLoader.sourceComponent = messagePanelComponent
        } else {
            panelLoader.source = "JoystickConfig.qml";
        }
    }

93 94 95 96 97
    function showParametersPanel()
    {
        panelLoader.source = "SetupParameterEditor.qml";
    }

dogmaphobic's avatar
dogmaphobic committed
98 99 100 101 102
    function showPX4FlowPanel()
    {
        panelLoader.source = "PX4FlowSensor.qml";
    }

Don Gagne's avatar
Don Gagne committed
103
    function showVehicleComponentPanel(vehicleComponent)
104
    {
105
        if (QGroundControl.multiVehicleManager.activeVehicle.armed && !vehicleComponent.allowSetupWhileArmed) {
Don Gagne's avatar
Don Gagne committed
106
            _messagePanelText = _armedVehicleText
107 108
            panelLoader.sourceComponent = messagePanelComponent
        } else {
Don Gagne's avatar
Don Gagne committed
109
            if (vehicleComponent.prerequisiteSetup != "") {
Don Gagne's avatar
Don Gagne committed
110
                _messagePanelText = vehicleComponent.prerequisiteSetup + " setup must be completed prior to " + vehicleComponent.name + " setup."
Don Gagne's avatar
Don Gagne committed
111 112 113
                panelLoader.sourceComponent = messagePanelComponent
            } else {
                panelLoader.source = vehicleComponent.setupSource
114 115 116 117 118 119 120
                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
121
            }
122 123 124
        }
    }

125 126
    Component.onCompleted: showSummaryPanel()

127
    Connections {
128
        target: QGroundControl.multiVehicleManager
129

130
        onParameterReadyVehicleAvailableChanged: {
131 132 133 134 135
            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.
136 137 138
                summaryButton.checked = true
                showSummaryPanel()
            }
139 140 141 142
        }
    }

    Component {
143
        id: noComponentsVehicleSummaryComponent
144 145

        Rectangle {
Don Gagne's avatar
Don Gagne committed
146
            color: qgcPal.windowShade
147 148

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
149
                anchors.margins:        _defaultTextWidth * 2
150 151 152 153
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
154
                font.pixelSize:         ScreenTools.mediumFontPixelSize
155
                text:                   "QGroundControl does not currently support setup of your vehicle type. " +
156
                                        "If your vehicle is already configured you can still Fly."
157 158 159 160 161 162

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

163 164 165 166 167 168 169 170 171 172 173 174 175
    Component {
        id: disconnectedVehicleSummaryComponent

        Rectangle {
            color: qgcPal.windowShade

            QGCLabel {
                anchors.margins:        _defaultTextWidth * 2
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
                font.pixelSize:         ScreenTools.largeFontPixelSize
Don Gagne's avatar
Don Gagne committed
176
                text:                   "Connect vehicle to your device and QGroundControl will automatically detect it." +
177
                                        (ScreenTools.isMobile ? "" : " Click Firmware on the left to upgrade your vehicle.")
178 179 180 181 182

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }
183 184 185 186
    Component {
        id: missingParametersVehicleSummaryComponent

        Rectangle {
Don Gagne's avatar
Don Gagne committed
187
            color: qgcPal.windowShade
188 189

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
190
                anchors.margins:        _defaultTextWidth * 2
191 192 193 194 195 196
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
                font.pixelSize:         ScreenTools.mediumFontPixelSize
                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
197
                                        "Because of this the full set of vehicle setup options are not available."
198 199 200 201 202 203

                onLinkActivated: Qt.openUrlExternally(link)
            }
        }
    }

204 205 206 207 208
    Component {
        id: messagePanelComponent

        Item {
            QGCLabel {
Don Gagne's avatar
Don Gagne committed
209
                anchors.margins:        _defaultTextWidth * 2
Don Gagne's avatar
Don Gagne committed
210 211 212 213
                anchors.fill:           parent
                verticalAlignment:      Text.AlignVCenter
                horizontalAlignment:    Text.AlignHCenter
                wrapMode:               Text.WordWrap
214
                font.pixelSize:         ScreenTools.mediumFontPixelSize
Don Gagne's avatar
Don Gagne committed
215
                text:                   _messagePanelText
216 217 218 219
            }
        }
    }

220 221 222 223 224
    QGCFlickable {
        id:                 buttonScroll
        width:              buttonColumn.width
        anchors.topMargin:  _defaultTextHeight / 2
        anchors.top:        parent.top
dogmaphobic's avatar
dogmaphobic committed
225
        anchors.bottom:     parent.bottom
226 227
        contentHeight:      buttonColumn.height
        flickableDirection: Flickable.VerticalFlick
dogmaphobic's avatar
dogmaphobic committed
228

229 230 231 232
        Column {
            id:         buttonColumn
            width:      _maxButtonWidth
            spacing:    _defaultTextHeight / 2
dogmaphobic's avatar
dogmaphobic committed
233

234
            property real _maxButtonWidth: 0
dogmaphobic's avatar
dogmaphobic committed
235

236
            Component.onCompleted: reflowWidths()
237

238 239
            Connections {
                target: componentRepeater
240

241 242
                onModelChanged: buttonColumn.reflowWidths()
            }
243

244 245 246
            function reflowWidths() {
                for (var i=0; i<children.length; i++) {
                    _maxButtonWidth = Math.max(_maxButtonWidth, children[i].width)
247
                }
248 249
                for (var i=0; i<children.length; i++) {
                    children[i].width = _maxButtonWidth
dogmaphobic's avatar
dogmaphobic committed
250
                }
251
            }
dogmaphobic's avatar
dogmaphobic committed
252

253 254 255 256 257 258 259
            SubMenuButton {
                id:             summaryButton
                imageResource: "/qmlimages/VehicleSummaryIcon.png"
                setupIndicator: false
                checked:        true
                exclusiveGroup: setupButtonGroup
                text:           "Summary"
dogmaphobic's avatar
dogmaphobic committed
260

261 262
                onClicked: showSummaryPanel()
            }
dogmaphobic's avatar
dogmaphobic committed
263

264 265 266 267 268 269 270
            SubMenuButton {
                id:             firmwareButton
                imageResource:  "/qmlimages/FirmwareUpgradeIcon.png"
                setupIndicator: false
                exclusiveGroup: setupButtonGroup
                visible:        !ScreenTools.isMobile
                text:           "Firmware"
dogmaphobic's avatar
dogmaphobic committed
271

272 273
                onClicked: showFirmwarePanel()
            }
dogmaphobic's avatar
dogmaphobic committed
274

275 276 277 278 279 280 281 282
            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
283

284 285 286 287 288 289 290
            SubMenuButton {
                id:             joystickButton
                setupIndicator: true
                setupComplete:  joystickManager.activeJoystick ? joystickManager.activeJoystick.calibrated : false
                exclusiveGroup: setupButtonGroup
                visible:        _fullParameterVehicleAvailable && joystickManager.joysticks.length != 0
                text:           "Joystick"
291

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

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

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

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

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

317
                onClicked: showParametersPanel()
Don Gagne's avatar
Don Gagne committed
318
            }
dogmaphobic's avatar
dogmaphobic committed
319 320

        }
321
    }
322 323 324 325 326 327 328 329 330 331 332 333

    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
    }
334
}