MainToolBar.qml 9.72 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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9

10 11 12
import QtQuick              2.3
import QtQuick.Layouts      1.2
import QtQuick.Controls     1.2
dogmaphobic's avatar
dogmaphobic committed
13

Don Gagne's avatar
Don Gagne committed
14
import QGroundControl                       1.0
15 16 17 18
import QGroundControl.Controls              1.0
import QGroundControl.Palette               1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
19
import QGroundControl.Controllers           1.0
dogmaphobic's avatar
dogmaphobic committed
20

21
Rectangle {
22
    id:         toolBar
23
    color:      qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.8) : Qt.rgba(0,0,0,0.75)
24
    visible:    !QGroundControl.videoManager.fullScreen
dogmaphobic's avatar
dogmaphobic committed
25

Don Gagne's avatar
Don Gagne committed
26
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
27

28
    property var  _activeVehicle:  QGroundControl.multiVehicleManager.activeVehicle
29

Don Gagne's avatar
Don Gagne committed
30 31 32
    signal showSettingsView
    signal showSetupView
    signal showPlanView
Valentin Platzgummer's avatar
Valentin Platzgummer committed
33
    signal showWimaView
Don Gagne's avatar
Don Gagne committed
34 35
    signal showFlyView
    signal showAnalyzeView
36 37
    signal armVehicle
    signal disarmVehicle
38 39
    signal vtolTransitionToFwdFlight
    signal vtolTransitionToMRFlight
Don Gagne's avatar
Don Gagne committed
40

41
    function checkSettingsButton() {
42
        settingsButton.checked = true
43 44
    }

Don Gagne's avatar
Don Gagne committed
45 46 47 48 49 50 51 52
    function checkSetupButton() {
        setupButton.checked = true
    }

    function checkPlanButton() {
        planButton.checked = true
    }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
53 54
    function checkWimaButton() {
        wimaButton.checked = true
Valentin Platzgummer's avatar
Valentin Platzgummer committed
55 56
    }

Don Gagne's avatar
Don Gagne committed
57 58 59 60
    function checkFlyButton() {
        flyButton.checked = true
    }

Don Gagne's avatar
Don Gagne committed
61 62 63 64
    function checkAnalyzeButton() {
        analyzeButton.checked = true
    }

dogmaphobic's avatar
dogmaphobic committed
65 66
    Component.onCompleted: {
        //-- TODO: Get this from the actual state
67
        flyButton.checked = true
dogmaphobic's avatar
dogmaphobic committed
68
    }
69

70 71 72 73 74
    // Prevent all clicks from going through to lower layers
    DeadMouseArea {
        anchors.fill: parent
    }

Don Gagne's avatar
Don Gagne committed
75
    /// Bottom single pixel divider
76 77 78 79 80 81
    Rectangle {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
        height:         1
        color:          "black"
82
        visible:        qgcPal.globalTheme === QGCPalette.Light
dogmaphobic's avatar
dogmaphobic committed
83 84
    }

Don Gagne's avatar
Don Gagne committed
85
    RowLayout {
86
        anchors.bottomMargin:   1
Don Gagne's avatar
Don Gagne committed
87 88
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth / 2
        anchors.fill:           parent
Don Gagne's avatar
Don Gagne committed
89
        spacing:                ScreenTools.defaultFontPixelWidth * 2
Don Gagne's avatar
Don Gagne committed
90 91 92 93

        //---------------------------------------------
        // Toolbar Row
        Row {
94 95 96
            id:                 viewRow
            Layout.fillHeight:  true
            spacing:            ScreenTools.defaultFontPixelWidth / 2
Don Gagne's avatar
Don Gagne committed
97 98 99 100 101 102 103 104 105 106 107 108 109

            ExclusiveGroup { id: mainActionGroup }

            QGCToolBarButton {
                id:                 settingsButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/res/QGCLogoWhite"
                logo:               true
                onClicked:          toolBar.showSettingsView()
                visible:            !QGroundControl.corePlugin.options.combineSettingsAndSetup
            }
110

Don Gagne's avatar
Don Gagne committed
111 112 113 114 115 116 117 118
            QGCToolBarButton {
                id:                 setupButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Gears.svg"
                onClicked:          toolBar.showSetupView()
            }
119

Don Gagne's avatar
Don Gagne committed
120 121 122 123 124 125 126 127
            QGCToolBarButton {
                id:                 planButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Plan.svg"
                onClicked:          toolBar.showPlanView()
            }
Don Gagne's avatar
Don Gagne committed
128

129 130 131 132 133 134 135 136 137
            QGCToolBarButton {
                id:                 flyButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/PaperPlane.svg"
                onClicked:          toolBar.showFlyView()
            }

Valentin Platzgummer's avatar
Valentin Platzgummer committed
138
            QGCToolBarButton {
Valentin Platzgummer's avatar
Valentin Platzgummer committed
139
                id:                 wimaButton
Valentin Platzgummer's avatar
Valentin Platzgummer committed
140 141 142 143
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/res/waves.svg"
Valentin Platzgummer's avatar
Valentin Platzgummer committed
144
                onClicked:          toolBar.showWimaView()
Valentin Platzgummer's avatar
Valentin Platzgummer committed
145 146
            }

Don Gagne's avatar
Don Gagne committed
147 148 149 150 151 152
            QGCToolBarButton {
                id:                 analyzeButton
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Analyze.svg"
153
                visible:            !ScreenTools.isMobile && QGroundControl.corePlugin.showAdvancedUI
Don Gagne's avatar
Don Gagne committed
154 155
                onClicked:          toolBar.showAnalyzeView()
            }
Don Gagne's avatar
Don Gagne committed
156 157 158 159 160 161 162 163 164

            Rectangle {
                anchors.margins:    ScreenTools.defaultFontPixelHeight / 2
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                width:              1
                color:              qgcPal.text
                visible:            _activeVehicle
            }
Don Gagne's avatar
Don Gagne committed
165
        }
166

Don Gagne's avatar
Don Gagne committed
167 168 169 170 171
        //-------------------------------------------------------------------------
        //-- Vehicle Selector
        QGCButton {
            id:                     vehicleSelectorButton
            width:                  ScreenTools.defaultFontPixelHeight * 8
Don Gagne's avatar
Don Gagne committed
172
            text:                   "Vehicle " + (_activeVehicle ? _activeVehicle.id : "None")
Don Gagne's avatar
Don Gagne committed
173
            visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
174
            Layout.alignment:       Qt.AlignVCenter
Don Gagne's avatar
Don Gagne committed
175

Don Gagne's avatar
Don Gagne committed
176
            menu: vehicleMenu
Don Gagne's avatar
Don Gagne committed
177

Don Gagne's avatar
Don Gagne committed
178 179 180
            Menu {
                id: vehicleMenu
            }
dogmaphobic's avatar
dogmaphobic committed
181

Don Gagne's avatar
Don Gagne committed
182 183
            Component {
                id: vehicleMenuItemComponent
Don Gagne's avatar
Don Gagne committed
184

Don Gagne's avatar
Don Gagne committed
185
                MenuItem {
Don Gagne's avatar
Don Gagne committed
186
                    onTriggered: QGroundControl.multiVehicleManager.activeVehicle = vehicle
Don Gagne's avatar
Don Gagne committed
187 188 189 190 191 192 193

                    property int vehicleId: Number(text.split(" ")[1])
                    property var vehicle:   QGroundControl.multiVehicleManager.getVehicleById(vehicleId)
                }
            }

            property var vehicleMenuItems: []
194

Don Gagne's avatar
Don Gagne committed
195
            function updateVehicleMenu() {
196
                var i;
Don Gagne's avatar
Don Gagne committed
197
                // Remove old menu items
198
                for (i = 0; i < vehicleMenuItems.length; i++) {
Don Gagne's avatar
Don Gagne committed
199 200 201 202 203
                    vehicleMenu.removeItem(vehicleMenuItems[i])
                }
                vehicleMenuItems.length = 0

                // Add new items
204
                for (i = 0; i < QGroundControl.multiVehicleManager.vehicles.count; i++) {
Don Gagne's avatar
Don Gagne committed
205 206 207 208 209 210 211 212 213 214 215 216 217
                    var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i)
                    var menuItem = vehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id })
                    vehicleMenuItems.push(menuItem)
                    vehicleMenu.insertItem(i, menuItem)
                }
            }

            Component.onCompleted: updateVehicleMenu()

            Connections {
                target:         QGroundControl.multiVehicleManager.vehicles
                onCountChanged: vehicleSelectorButton.updateVehicleMenu()
            }
218 219
        }

Don Gagne's avatar
Don Gagne committed
220
        MainToolBarIndicators {
Don Gagne's avatar
Don Gagne committed
221
            Layout.fillWidth:   true
222 223
            Layout.fillHeight:  true
            Layout.margins:     ScreenTools.defaultFontPixelHeight * 0.66
224
        }
dogmaphobic's avatar
dogmaphobic committed
225
    }
dogmaphobic's avatar
dogmaphobic committed
226

227
    // Small parameter download progress bar
228
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
229 230
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
Don Gagne's avatar
Don Gagne committed
231
        width:          _activeVehicle ? _activeVehicle.parameterManager.loadProgress * parent.width : 0
232
        color:          qgcPal.colorGreen
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
        visible:        !largeProgressBar.visible
    }

    // Large parameter download progress bar
    Rectangle {
        id:             largeProgressBar
        anchors.bottom: parent.bottom
        anchors.left:   parent.left
        anchors.right:  parent.right
        height:         parent.height
        color:          qgcPal.window
        visible:        _showLargeProgress

        property bool _initialDownloadComplete: _activeVehicle ? _activeVehicle.parameterManager.parametersReady : true
        property bool _userHide:                false
        property bool _showLargeProgress:       !_initialDownloadComplete && !_userHide && qgcPal.globalTheme === QGCPalette.Light

        Connections {
            target:                 QGroundControl.multiVehicleManager
            onActiveVehicleChanged: largeProgressBar._userHide = false
        }

        Rectangle {
            anchors.top:    parent.top
            anchors.bottom: parent.bottom
            width:          _activeVehicle ? _activeVehicle.parameterManager.loadProgress * parent.width : 0
            color:          qgcPal.colorGreen
        }

        QGCLabel {
            anchors.centerIn:   parent
            text:               qsTr("Downloading Parameters")
            font.pointSize:     ScreenTools.largeFontPointSize
        }

        QGCLabel {
            anchors.margins:    _margin
            anchors.right:      parent.right
            anchors.bottom:     parent.bottom
            text:               qsTr("Click anywhere to hide")

            property real _margin: ScreenTools.defaultFontPixelWidth / 2
        }

        MouseArea {
            anchors.fill:   parent
            onClicked:      largeProgressBar._userHide = true
        }
281
    }
282
}