MainToolBar.qml 17.5 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 13 14 15 16


/**
 * @file
 *   @brief QGC Main Tool Bar
 *   @author Gus Grubba <mavlink@grubba.com>
 */

dogmaphobic's avatar
dogmaphobic committed
17
import QtQuick 2.5
18
import QtQuick.Layouts 1.2
dogmaphobic's avatar
dogmaphobic committed
19 20 21
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

Don Gagne's avatar
Don Gagne committed
22
import QGroundControl                       1.0
23 24 25 26
import QGroundControl.Controls              1.0
import QGroundControl.Palette               1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
27
import QGroundControl.Controllers           1.0
dogmaphobic's avatar
dogmaphobic committed
28

29
Rectangle {
30
    id:         toolBar
31
    color:      qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.8) : Qt.rgba(0,0,0,0.75)
dogmaphobic's avatar
dogmaphobic committed
32

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

35
    property var  activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
dogmaphobic's avatar
dogmaphobic committed
36
    property var  mainWindow:           null
dogmaphobic's avatar
dogmaphobic committed
37 38
    property bool isMessageImportant:   activeVehicle ? !activeVehicle.messageTypeNormal && !activeVehicle.messageTypeNone : false
    property bool isBackgroundDark:     true
dogmaphobic's avatar
dogmaphobic committed
39
    property bool opaqueBackground:     false
40

dogmaphobic's avatar
dogmaphobic committed
41 42 43 44 45 46
    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"
47

Don Gagne's avatar
Don Gagne committed
48 49 50 51 52
    signal showSettingsView
    signal showSetupView
    signal showPlanView
    signal showFlyView
    signal showAnalyzeView
Don Gagne's avatar
Don Gagne committed
53

54
    MainToolBarController { id: _controller }
dogmaphobic's avatar
dogmaphobic committed
55

56
    function checkSettingsButton() {
57
        settingsButton.checked = true
58 59
    }

Don Gagne's avatar
Don Gagne committed
60 61 62 63 64 65 66 67 68 69 70 71
    function checkSetupButton() {
        setupButton.checked = true
    }

    function checkPlanButton() {
        planButton.checked = true
    }

    function checkFlyButton() {
        flyButton.checked = true
    }

Don Gagne's avatar
Don Gagne committed
72 73 74 75
    function checkAnalyzeButton() {
        analyzeButton.checked = true
    }

76 77
    function getBatteryColor() {
        if(activeVehicle) {
Don Gagne's avatar
Don Gagne committed
78
            if(activeVehicle.battery.percentRemaining.value > 75) {
79
                return qgcPal.text
80
            }
Don Gagne's avatar
Don Gagne committed
81
            if(activeVehicle.battery.percentRemaining.value > 50) {
82 83
                return colorOrange
            }
Don Gagne's avatar
Don Gagne committed
84
            if(activeVehicle.battery.percentRemaining.value > 0.1) {
85 86 87 88 89 90
                return colorRed
            }
        }
        return colorGrey
    }

dogmaphobic's avatar
dogmaphobic committed
91 92 93 94 95 96 97 98 99 100
    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
101 102 103 104
    Component.onCompleted: {
        //-- TODO: Get this from the actual state
        flyButton.checked = true
    }
105

dogmaphobic's avatar
dogmaphobic committed
106 107 108 109
    //---------------------------------------------
    // GPS Info
    Component {
        id: gpsInfo
110

dogmaphobic's avatar
dogmaphobic committed
111
        Rectangle {
112 113 114 115 116
            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
117 118 119 120 121 122
            Column {
                id:                 gpsCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(gpsGrid.width, gpsLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
123

dogmaphobic's avatar
dogmaphobic committed
124
                QGCLabel {
125 126 127
                    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
128 129
                    anchors.horizontalCenter: parent.horizontalCenter
                }
130

dogmaphobic's avatar
dogmaphobic committed
131 132
                GridLayout {
                    id:                 gpsGrid
Don Gagne's avatar
Don Gagne committed
133
                    visible:            (activeVehicle && activeVehicle.gps.count.value >= 0)
dogmaphobic's avatar
dogmaphobic committed
134 135 136 137
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
                    anchors.horizontalCenter: parent.horizontalCenter
                    columns: 2
138

Tomaz Canabrava's avatar
Tomaz Canabrava committed
139 140 141 142 143 144 145 146 147 148
                    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
149 150
                }
            }
151

dogmaphobic's avatar
dogmaphobic committed
152 153 154 155 156 157 158 159
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

160 161 162 163
    //---------------------------------------------
    // Battery Info
    Component {
        id: batteryInfo
Don Gagne's avatar
Don Gagne committed
164

165
        Rectangle {
166 167 168 169
            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
170

171 172 173 174 175 176
            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
177

178
                QGCLabel {
179 180 181
                    id:             battLabel
                    text:           qsTr("Battery Status")
                    font.family:    ScreenTools.demiboldFontFamily
182 183
                    anchors.horizontalCenter: parent.horizontalCenter
                }
184

185 186 187 188
                GridLayout {
                    id:                 battGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
189
                    columns:            2
190
                    anchors.horizontalCenter: parent.horizontalCenter
191

Tomaz Canabrava's avatar
Tomaz Canabrava committed
192
                    QGCLabel { text: qsTr("Voltage:") }
193
                    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
194
                    QGCLabel { text: qsTr("Accumulated Consumption:") }
195
                    QGCLabel { text: (activeVehicle && activeVehicle.battery.mahConsumed.value != -1) ? (activeVehicle.battery.mahConsumed.valueString + " " + activeVehicle.battery.mahConsumed.units) : "N/A" }
196 197
                }
            }
Don Gagne's avatar
Don Gagne committed
198

199 200 201 202 203 204 205 206 207 208 209 210
            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
211

212
        Rectangle {
213 214 215 216 217
            width:  rcrssiCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: rcrssiCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

218
            Column {
dogmaphobic's avatar
dogmaphobic committed
219
                id:                 rcrssiCol
220
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
221
                width:              Math.max(rcrssiGrid.width, rssiLabel.width)
222 223
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
224

225
                QGCLabel {
226
                    id:             rssiLabel
Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
227
                    text:           activeVehicle ? (activeVehicle.rcRSSI != 255 ? qsTr("RC RSSI Status") : qsTr("RC RSSI Data Unavailable")) : qsTr("N/A", "No data available")
228
                    font.family:    ScreenTools.demiboldFontFamily
229 230
                    anchors.horizontalCenter: parent.horizontalCenter
                }
231

232
                GridLayout {
dogmaphobic's avatar
dogmaphobic committed
233
                    id:                 rcrssiGrid
234
                    visible:            activeVehicle && activeVehicle.rcRSSI != 255
235 236
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
237
                    columns:            2
238
                    anchors.horizontalCenter: parent.horizontalCenter
239

Tomaz Canabrava's avatar
Tomaz Canabrava committed
240
                    QGCLabel { text: qsTr("RSSI:") }
241
                    QGCLabel { text: activeVehicle ? (activeVehicle.rcRSSI + "%") : 0 }
242 243
                }
            }
244

245 246 247 248 249 250 251 252
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

dogmaphobic's avatar
dogmaphobic committed
253 254 255 256
    //---------------------------------------------
    // Telemetry RSSI Info
    Component {
        id: telemRSSIInfo
257

dogmaphobic's avatar
dogmaphobic committed
258
        Rectangle {
259 260 261 262 263
            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
264 265 266 267 268 269
            Column {
                id:                 telemCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(telemGrid.width, telemLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
270

dogmaphobic's avatar
dogmaphobic committed
271
                QGCLabel {
272
                    id:             telemLabel
Tomaz Canabrava's avatar
Tomaz Canabrava committed
273
                    text:           qsTr("Telemetry RSSI Status")
274
                    font.family:    ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
275 276
                    anchors.horizontalCenter: parent.horizontalCenter
                }
277

dogmaphobic's avatar
dogmaphobic committed
278 279 280 281
                GridLayout {
                    id:                 telemGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
282
                    columns:            2
dogmaphobic's avatar
dogmaphobic committed
283
                    anchors.horizontalCenter: parent.horizontalCenter
284

Tomaz Canabrava's avatar
Tomaz Canabrava committed
285
                    QGCLabel { text: qsTr("Local RSSI:") }
286
                    QGCLabel { text: _controller.telemetryLRSSI + " dBm" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
287
                    QGCLabel { text: qsTr("Remote RSSI:") }
288
                    QGCLabel { text: _controller.telemetryRRSSI + " dBm" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
289
                    QGCLabel { text: qsTr("RX Errors:") }
290
                    QGCLabel { text: _controller.telemetryRXErrors }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
291
                    QGCLabel { text: qsTr("Errors Fixed:") }
292
                    QGCLabel { text: _controller.telemetryFixed }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
293
                    QGCLabel { text: qsTr("TX Buffer:") }
294
                    QGCLabel { text: _controller.telemetryTXBuffer }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
295
                    QGCLabel { text: qsTr("Local Noise:") }
296
                    QGCLabel { text: _controller.telemetryLNoise }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
297
                    QGCLabel { text: qsTr("Remote Noise:") }
298
                    QGCLabel { text: _controller.telemetryRNoise }
dogmaphobic's avatar
dogmaphobic committed
299 300
                }
            }
301

dogmaphobic's avatar
dogmaphobic committed
302 303 304 305 306 307 308 309
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

310 311 312 313 314 315
    Rectangle {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
        height:         1
        color:          "black"
dogmaphobic's avatar
dogmaphobic committed
316 317 318
        visible:        qgcPal.globalTheme == QGCPalette.Light
    }

319 320
    //---------------------------------------------
    // Toolbar Row
dogmaphobic's avatar
dogmaphobic committed
321
    Row {
322 323 324
        id:                     viewRow
        height:                 mainWindow.tbCellHeight
        spacing:                mainWindow.tbSpacing
325
        anchors.left:           parent.left
326 327 328
        anchors.bottomMargin:   1
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
dogmaphobic's avatar
dogmaphobic committed
329 330 331

        ExclusiveGroup { id: mainActionGroup }

332
        QGCToolBarButton {
Don Gagne's avatar
Don Gagne committed
333
            id:                 settingsButton
334 335 336 337 338 339
            width:              mainWindow.tbButtonWidth
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            exclusiveGroup:     mainActionGroup
            source:             "/res/QGCLogoWhite"
            logo:               true
340
            onClicked:          toolBar.showSettingsView()
Gus Grubba's avatar
Gus Grubba committed
341
            visible:            !QGroundControl.colapseSettings
342 343
        }

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

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

dogmaphobic's avatar
dogmaphobic committed
364 365
        QGCToolBarButton {
            id:                 flyButton
dogmaphobic's avatar
dogmaphobic committed
366
            width:              mainWindow.tbButtonWidth
367 368
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
369
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
370
            source:             "/qmlimages/PaperPlane.svg"
Don Gagne's avatar
Don Gagne committed
371
            onClicked:          toolBar.showFlyView()
Don Gagne's avatar
Don Gagne committed
372
        }
Don Gagne's avatar
Don Gagne committed
373 374 375 376 377 378 379 380 381 382 383

        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()
        }
dogmaphobic's avatar
dogmaphobic committed
384
    }
385

dogmaphobic's avatar
dogmaphobic committed
386
    Item {
dogmaphobic's avatar
dogmaphobic committed
387
        id:                     vehicleIndicators
dogmaphobic's avatar
dogmaphobic committed
388 389
        height:                 mainWindow.tbCellHeight
        anchors.leftMargin:     mainWindow.tbSpacing * 2
Don Gagne's avatar
Don Gagne committed
390 391
        anchors.left:           viewRow.right
        anchors.right:          parent.right
dogmaphobic's avatar
dogmaphobic committed
392
        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
393

394
        property bool vehicleConnectionLost: activeVehicle ? activeVehicle.connectionLost : false
Don Gagne's avatar
Don Gagne committed
395

dogmaphobic's avatar
dogmaphobic committed
396
        Loader {
397
            id:                     indicatorLoader
398
            source:                 activeVehicle && !parent.vehicleConnectionLost ? "MainToolBarIndicators.qml" : ""
Don Gagne's avatar
Don Gagne committed
399 400
            anchors.left:           parent.left
            anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
401
        }
dogmaphobic's avatar
dogmaphobic committed
402

Don Gagne's avatar
Don Gagne committed
403 404
        QGCLabel {
            id:                     connectionLost
Tomaz Canabrava's avatar
Tomaz Canabrava committed
405
            text:                   qsTr("COMMUNICATION LOST")
dogmaphobic's avatar
dogmaphobic committed
406
            font.pointSize:         ScreenTools.largeFontPointSize
407
            font.family:            ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
408
            color:                  colorRed
409 410
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.right:          disconnectButton.left
Don Gagne's avatar
Don Gagne committed
411
            anchors.verticalCenter: parent.verticalCenter
412
            visible:                parent.vehicleConnectionLost
Don Gagne's avatar
Don Gagne committed
413 414 415
        }

        QGCButton {
416
            id:                     disconnectButton
Don Gagne's avatar
Don Gagne committed
417 418 419
            anchors.rightMargin:     mainWindow.tbSpacing * 2
            anchors.right:          parent.right
            anchors.verticalCenter: parent.verticalCenter
Tomaz Canabrava's avatar
Tomaz Canabrava committed
420
            text:                   qsTr("Disconnect")
421
            visible:                parent.vehicleConnectionLost
422
            primary:                true
Don Gagne's avatar
Don Gagne committed
423 424
            onClicked:              activeVehicle.disconnectInactiveVehicle()
        }
425 426 427 428 429 430

        Image {
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth / 2
            anchors.right:          parent.right
            anchors.top:            parent.top
            anchors.bottom:         parent.bottom
431
            visible:                x > indicatorLoader.x + indicatorLoader.width && !disconnectButton.visible && source != ""
432 433 434 435
            fillMode:               Image.PreserveAspectFit
            source:                 activeVehicle ? activeVehicle.brandImage : ""
        }

dogmaphobic's avatar
dogmaphobic committed
436
    }
dogmaphobic's avatar
dogmaphobic committed
437

438 439
    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
440
        id:             progressBar
dogmaphobic's avatar
dogmaphobic committed
441 442
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
443
        width:          activeVehicle ? activeVehicle.parameterManager.loadProgress * parent.width : 0
dogmaphobic's avatar
dogmaphobic committed
444
        color:          colorGreen
445
    }
dogmaphobic's avatar
dogmaphobic committed
446

447
}