MainToolBar.qml 17.8 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

Don Gagne's avatar
Don Gagne committed
10 11 12
import QtQuick              2.5
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)
dogmaphobic's avatar
dogmaphobic committed
24

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

27
    property var  activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
dogmaphobic's avatar
dogmaphobic committed
28
    property var  mainWindow:           null
dogmaphobic's avatar
dogmaphobic committed
29 30
    property bool isMessageImportant:   activeVehicle ? !activeVehicle.messageTypeNormal && !activeVehicle.messageTypeNone : false
    property bool isBackgroundDark:     true
dogmaphobic's avatar
dogmaphobic committed
31
    property bool opaqueBackground:     false
32

dogmaphobic's avatar
dogmaphobic committed
33 34 35 36 37 38
    readonly property var   colorGreen:     "#05f068"
    readonly property var   colorOrange:    "#f0ab06"
    readonly property var   colorRed:       "#fc4638"
    readonly property var   colorGrey:      "#7f7f7f"
    readonly property var   colorBlue:      "#636efe"
    readonly property var   colorWhite:     "#ffffff"
39

Don Gagne's avatar
Don Gagne committed
40 41 42 43 44
    signal showSettingsView
    signal showSetupView
    signal showPlanView
    signal showFlyView
    signal showAnalyzeView
Don Gagne's avatar
Don Gagne committed
45

46
    MainToolBarController { id: _controller }
dogmaphobic's avatar
dogmaphobic committed
47

48
    function checkSettingsButton() {
49
        settingsButton.checked = true
50 51
    }

Don Gagne's avatar
Don Gagne committed
52 53 54 55 56 57 58 59 60 61 62 63
    function checkSetupButton() {
        setupButton.checked = true
    }

    function checkPlanButton() {
        planButton.checked = true
    }

    function checkFlyButton() {
        flyButton.checked = true
    }

Don Gagne's avatar
Don Gagne committed
64 65 66 67
    function checkAnalyzeButton() {
        analyzeButton.checked = true
    }

68 69
    function getBatteryColor() {
        if(activeVehicle) {
Don Gagne's avatar
Don Gagne committed
70
            if(activeVehicle.battery.percentRemaining.value > 75) {
71
                return qgcPal.text
72
            }
Don Gagne's avatar
Don Gagne committed
73
            if(activeVehicle.battery.percentRemaining.value > 50) {
74 75
                return colorOrange
            }
Don Gagne's avatar
Don Gagne committed
76
            if(activeVehicle.battery.percentRemaining.value > 0.1) {
77 78 79 80 81 82
                return colorRed
            }
        }
        return colorGrey
    }

dogmaphobic's avatar
dogmaphobic committed
83 84 85 86 87 88 89 90 91 92
    function getRSSIColor(value) {
        if(value >= 0)
            return colorGrey;
        if(value > -60)
            return colorGreen;
        if(value > -90)
            return colorOrange;
        return colorRed;
    }

dogmaphobic's avatar
dogmaphobic committed
93 94 95 96
    Component.onCompleted: {
        //-- TODO: Get this from the actual state
        flyButton.checked = true
    }
97

dogmaphobic's avatar
dogmaphobic committed
98 99 100 101
    //---------------------------------------------
    // GPS Info
    Component {
        id: gpsInfo
102

dogmaphobic's avatar
dogmaphobic committed
103
        Rectangle {
104 105 106 107 108
            width:  gpsCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: gpsCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

dogmaphobic's avatar
dogmaphobic committed
109 110 111 112 113 114
            Column {
                id:                 gpsCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(gpsGrid.width, gpsLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
115

dogmaphobic's avatar
dogmaphobic committed
116
                QGCLabel {
117 118 119
                    id:             gpsLabel
                    text:           (activeVehicle && activeVehicle.gps.count.value >= 0) ? qsTr("GPS Status") : qsTr("GPS Data Unavailable")
                    font.family:    ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
120 121
                    anchors.horizontalCenter: parent.horizontalCenter
                }
122

dogmaphobic's avatar
dogmaphobic committed
123 124
                GridLayout {
                    id:                 gpsGrid
Don Gagne's avatar
Don Gagne committed
125
                    visible:            (activeVehicle && activeVehicle.gps.count.value >= 0)
dogmaphobic's avatar
dogmaphobic committed
126 127 128 129
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
                    anchors.horizontalCenter: parent.horizontalCenter
                    columns: 2
130

Tomaz Canabrava's avatar
Tomaz Canabrava committed
131 132 133 134 135 136 137 138 139 140
                    QGCLabel { text: qsTr("GPS Count:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.count.valueString : qsTr("N/A", "No data to display") }
                    QGCLabel { text: qsTr("GPS Lock:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.lock.enumStringValue : qsTr("N/A", "No data to display") }
                    QGCLabel { text: qsTr("HDOP:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.hdop.valueString : qsTr("--.--", "No data to display") }
                    QGCLabel { text: qsTr("VDOP:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.vdop.valueString : qsTr("--.--", "No data to display") }
                    QGCLabel { text: qsTr("Course Over Ground:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.courseOverGround.valueString : qsTr("--.--", "No data to display") }
dogmaphobic's avatar
dogmaphobic committed
141 142
                }
            }
143

dogmaphobic's avatar
dogmaphobic committed
144 145 146 147 148 149 150 151
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

152 153 154 155
    //---------------------------------------------
    // Battery Info
    Component {
        id: batteryInfo
Don Gagne's avatar
Don Gagne committed
156

157
        Rectangle {
158 159 160 161
            width:  battCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: battCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window
Don Gagne's avatar
Don Gagne committed
162

163 164 165 166 167 168
            Column {
                id:                 battCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(battGrid.width, battLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
Don Gagne's avatar
Don Gagne committed
169

170
                QGCLabel {
171 172 173
                    id:             battLabel
                    text:           qsTr("Battery Status")
                    font.family:    ScreenTools.demiboldFontFamily
174 175
                    anchors.horizontalCenter: parent.horizontalCenter
                }
176

177 178 179 180
                GridLayout {
                    id:                 battGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
181
                    columns:            2
182
                    anchors.horizontalCenter: parent.horizontalCenter
183

Tomaz Canabrava's avatar
Tomaz Canabrava committed
184
                    QGCLabel { text: qsTr("Voltage:") }
185
                    QGCLabel { text: (activeVehicle && activeVehicle.battery.voltage.value != -1) ? (activeVehicle.battery.voltage.valueString + " " + activeVehicle.battery.voltage.units) : "N/A" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
186
                    QGCLabel { text: qsTr("Accumulated Consumption:") }
187
                    QGCLabel { text: (activeVehicle && activeVehicle.battery.mahConsumed.value != -1) ? (activeVehicle.battery.mahConsumed.valueString + " " + activeVehicle.battery.mahConsumed.units) : "N/A" }
188 189
                }
            }
Don Gagne's avatar
Don Gagne committed
190

191 192 193 194 195 196 197 198 199 200 201 202
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

    //---------------------------------------------
    // RC RSSI Info
    Component {
        id: rcRSSIInfo
203

204
        Rectangle {
205 206 207 208 209
            width:  rcrssiCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: rcrssiCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

210
            Column {
dogmaphobic's avatar
dogmaphobic committed
211
                id:                 rcrssiCol
212
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
213
                width:              Math.max(rcrssiGrid.width, rssiLabel.width)
214 215
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
216

217
                QGCLabel {
218
                    id:             rssiLabel
Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
219
                    text:           activeVehicle ? (activeVehicle.rcRSSI != 255 ? qsTr("RC RSSI Status") : qsTr("RC RSSI Data Unavailable")) : qsTr("N/A", "No data available")
220
                    font.family:    ScreenTools.demiboldFontFamily
221 222
                    anchors.horizontalCenter: parent.horizontalCenter
                }
223

224
                GridLayout {
dogmaphobic's avatar
dogmaphobic committed
225
                    id:                 rcrssiGrid
226
                    visible:            activeVehicle && activeVehicle.rcRSSI != 255
227 228
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
229
                    columns:            2
230
                    anchors.horizontalCenter: parent.horizontalCenter
231

Tomaz Canabrava's avatar
Tomaz Canabrava committed
232
                    QGCLabel { text: qsTr("RSSI:") }
233
                    QGCLabel { text: activeVehicle ? (activeVehicle.rcRSSI + "%") : 0 }
234 235
                }
            }
236

237 238 239 240 241 242 243 244
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

dogmaphobic's avatar
dogmaphobic committed
245 246 247 248
    //---------------------------------------------
    // Telemetry RSSI Info
    Component {
        id: telemRSSIInfo
249

dogmaphobic's avatar
dogmaphobic committed
250
        Rectangle {
251 252 253 254 255
            width:  telemCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: telemCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

dogmaphobic's avatar
dogmaphobic committed
256 257 258 259 260 261
            Column {
                id:                 telemCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(telemGrid.width, telemLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
262

dogmaphobic's avatar
dogmaphobic committed
263
                QGCLabel {
264
                    id:             telemLabel
Tomaz Canabrava's avatar
Tomaz Canabrava committed
265
                    text:           qsTr("Telemetry RSSI Status")
266
                    font.family:    ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
267 268
                    anchors.horizontalCenter: parent.horizontalCenter
                }
269

dogmaphobic's avatar
dogmaphobic committed
270 271 272 273
                GridLayout {
                    id:                 telemGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
274
                    columns:            2
dogmaphobic's avatar
dogmaphobic committed
275
                    anchors.horizontalCenter: parent.horizontalCenter
276

Tomaz Canabrava's avatar
Tomaz Canabrava committed
277
                    QGCLabel { text: qsTr("Local RSSI:") }
278
                    QGCLabel { text: _controller.telemetryLRSSI + " dBm" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
279
                    QGCLabel { text: qsTr("Remote RSSI:") }
280
                    QGCLabel { text: _controller.telemetryRRSSI + " dBm" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
281
                    QGCLabel { text: qsTr("RX Errors:") }
282
                    QGCLabel { text: _controller.telemetryRXErrors }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
283
                    QGCLabel { text: qsTr("Errors Fixed:") }
284
                    QGCLabel { text: _controller.telemetryFixed }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
285
                    QGCLabel { text: qsTr("TX Buffer:") }
286
                    QGCLabel { text: _controller.telemetryTXBuffer }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
287
                    QGCLabel { text: qsTr("Local Noise:") }
288
                    QGCLabel { text: _controller.telemetryLNoise }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
289
                    QGCLabel { text: qsTr("Remote Noise:") }
290
                    QGCLabel { text: _controller.telemetryRNoise }
dogmaphobic's avatar
dogmaphobic committed
291 292
                }
            }
293

dogmaphobic's avatar
dogmaphobic committed
294 295 296 297 298 299 300 301
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

302 303 304 305 306 307
    Rectangle {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
        height:         1
        color:          "black"
dogmaphobic's avatar
dogmaphobic committed
308 309 310
        visible:        qgcPal.globalTheme == QGCPalette.Light
    }

Don Gagne's avatar
Don Gagne committed
311
    RowLayout {
312
        anchors.bottomMargin:   1
Don Gagne's avatar
Don Gagne committed
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
        anchors.rightMargin:    ScreenTools.defaultFontPixelWidth / 2
        anchors.fill:           parent
        spacing:                mainWindow.tbSpacing * 2

        //---------------------------------------------
        // Toolbar Row
        Row {
            id:             viewRow
            height:         mainWindow.tbCellHeight
            spacing:        mainWindow.tbSpacing
            anchors.top:    parent.top
            anchors.bottom: parent.bottom

            ExclusiveGroup { id: mainActionGroup }

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

Don Gagne's avatar
Don Gagne committed
340 341 342 343 344 345 346 347 348
            QGCToolBarButton {
                id:                 setupButton
                width:              mainWindow.tbButtonWidth
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Gears.svg"
                onClicked:          toolBar.showSetupView()
            }
349

Don Gagne's avatar
Don Gagne committed
350 351 352 353 354 355 356 357 358
            QGCToolBarButton {
                id:                 planButton
                width:              mainWindow.tbButtonWidth
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Plan.svg"
                onClicked:          toolBar.showPlanView()
            }
Don Gagne's avatar
Don Gagne committed
359

Don Gagne's avatar
Don Gagne committed
360 361 362 363 364 365 366 367 368
            QGCToolBarButton {
                id:                 flyButton
                width:              mainWindow.tbButtonWidth
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/PaperPlane.svg"
                onClicked:          toolBar.showFlyView()
            }
Don Gagne's avatar
Don Gagne committed
369

Don Gagne's avatar
Don Gagne committed
370 371 372 373 374 375 376 377 378 379
            QGCToolBarButton {
                id:                 analyzeButton
                width:              mainWindow.tbButtonWidth
                anchors.top:        parent.top
                anchors.bottom:     parent.bottom
                exclusiveGroup:     mainActionGroup
                source:             "/qmlimages/Analyze.svg"
                visible:            !ScreenTools.isMobile
                onClicked:          toolBar.showAnalyzeView()
            }
Don Gagne's avatar
Don Gagne committed
380
        }
381

Don Gagne's avatar
Don Gagne committed
382 383 384 385 386 387 388 389
        //-------------------------------------------------------------------------
        //-- Vehicle Selector
        QGCButton {
            id:                     vehicleSelectorButton
            width:                  ScreenTools.defaultFontPixelHeight * 8
            text:                   "Vehicle " + (activeVehicle ? activeVehicle.id : "None")
            visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
            anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
390

Don Gagne's avatar
Don Gagne committed
391
            menu: vehicleMenu
Don Gagne's avatar
Don Gagne committed
392

Don Gagne's avatar
Don Gagne committed
393 394 395
            Menu {
                id: vehicleMenu
            }
dogmaphobic's avatar
dogmaphobic committed
396

Don Gagne's avatar
Don Gagne committed
397 398
            Component {
                id: vehicleMenuItemComponent
Don Gagne's avatar
Don Gagne committed
399

Don Gagne's avatar
Don Gagne committed
400 401 402 403 404 405 406 407 408 409
                MenuItem {
                    checkable:      true
                    onTriggered:    QGroundControl.multiVehicleManager.activeVehicle = vehicle

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

            property var vehicleMenuItems: []
410

Don Gagne's avatar
Don Gagne committed
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
            function updateVehicleMenu() {
                // Remove old menu items
                for (var i = 0; i < vehicleMenuItems.length; i++) {
                    vehicleMenu.removeItem(vehicleMenuItems[i])
                }
                vehicleMenuItems.length = 0

                // Add new items
                for (var i=0; i<QGroundControl.multiVehicleManager.vehicles.count; i++) {
                    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()
            }
433 434
        }

Don Gagne's avatar
Don Gagne committed
435 436 437 438 439 440
        MainToolBarIndicators {
            height:                 mainWindow.tbCellHeight
            Layout.fillWidth:       true
            anchors.verticalCenter: parent.verticalCenter
            visible:                activeVehicle
        }
dogmaphobic's avatar
dogmaphobic committed
441
    }
dogmaphobic's avatar
dogmaphobic committed
442

443 444
    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
445
        id:             progressBar
dogmaphobic's avatar
dogmaphobic committed
446 447
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
448
        width:          activeVehicle ? activeVehicle.parameterManager.loadProgress * parent.width : 0
dogmaphobic's avatar
dogmaphobic committed
449
        color:          colorGreen
450
    }
dogmaphobic's avatar
dogmaphobic committed
451

452
}