MainToolBar.qml 16.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 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() {
Don Gagne's avatar
Don Gagne committed
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()
341 342
        }

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

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

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

        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
383
    }
384

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

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

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

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

        }

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

426 427
    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
428
        id:             progressBar
dogmaphobic's avatar
dogmaphobic committed
429 430
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
431
        width:          parent.width * _controller.progressBarValue
dogmaphobic's avatar
dogmaphobic committed
432
        color:          colorGreen
433
    }
dogmaphobic's avatar
dogmaphobic committed
434

435
}