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

48
    signal showPreferences()
Don Gagne's avatar
Don Gagne committed
49 50 51 52
    signal showSetupView()
    signal showPlanView()
    signal showFlyView()

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

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

    function checkPlanButton() {
        planButton.checked = true
    }

    function checkFlyButton() {
        flyButton.checked = true
    }

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

dogmaphobic's avatar
dogmaphobic committed
82 83 84 85 86 87 88 89 90 91
    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
92 93 94 95
    Component.onCompleted: {
        //-- TODO: Get this from the actual state
        flyButton.checked = true
    }
96

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

dogmaphobic's avatar
dogmaphobic committed
102
        Rectangle {
103 104 105 106 107
            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
108 109 110 111 112 113
            Column {
                id:                 gpsCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(gpsGrid.width, gpsLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
114

dogmaphobic's avatar
dogmaphobic committed
115
                QGCLabel {
116 117 118
                    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
119 120
                    anchors.horizontalCenter: parent.horizontalCenter
                }
121

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

Tomaz Canabrava's avatar
Tomaz Canabrava committed
130 131 132 133 134 135 136 137 138 139
                    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
140 141
                }
            }
142

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

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

156
        Rectangle {
157 158 159 160
            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
161

162 163 164 165 166 167
            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
168

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

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

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

190 191 192 193 194 195 196 197 198 199 200 201
            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
202

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

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

216
                QGCLabel {
217 218 219
                    id:             rssiLabel
                    text:           activeVehicle ? (activeVehicle.rcRSSI != 255 ? qsTr("RC RSSI Status") : qsTr("RC RSSI Data Unavailable")) : qsTr("N/A", "No data avaliable")
                    font.family:    ScreenTools.demiboldFontFamily
220 221
                    anchors.horizontalCenter: parent.horizontalCenter
                }
222

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

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

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

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

dogmaphobic's avatar
dogmaphobic committed
249
        Rectangle {
250 251 252 253 254
            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
255 256 257 258 259 260
            Column {
                id:                 telemCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(telemGrid.width, telemLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
261

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

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

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

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

301 302 303 304 305 306
    Rectangle {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
        height:         1
        color:          "black"
dogmaphobic's avatar
dogmaphobic committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
        visible:        qgcPal.globalTheme == QGCPalette.Light
    }

    //---------------------------------------------
    // Logo (Preferences Button)
    Rectangle {
        id:                     preferencesButton
        width:                  mainWindow.tbButtonWidth * 1.25
        height:                 parent.height
        anchors.top:            parent.top
        anchors.left:           parent.left
        color:                  "#4A2C6D"
        Image {
            height:                 mainWindow.tbCellHeight
            anchors.centerIn:       parent
            source:                 "/res/QGCLogoWhite"
            fillMode:               Image.PreserveAspectFit
            smooth:                 true
            mipmap:                 true
            antialiasing:           true
        }
328 329 330 331 332 333 334 335 336
        /* Experimenting with a white/black divider
        Rectangle {
            color:      qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(0,0,0,0.15) : Qt.rgba(1,1,1,0.15)
            height: parent.height
            width:  1
            anchors.right:  parent.right
            anchors.top:    parent.top
        }
        */
dogmaphobic's avatar
dogmaphobic committed
337
        MouseArea {
338 339
            anchors.fill:   parent
            onClicked:      toolBar.showPreferences()
dogmaphobic's avatar
dogmaphobic committed
340
        }
341 342
    }

343 344
    //---------------------------------------------
    // Toolbar Row
dogmaphobic's avatar
dogmaphobic committed
345
    Row {
346 347 348
        id:                     viewRow
        height:                 mainWindow.tbCellHeight
        spacing:                mainWindow.tbSpacing
dogmaphobic's avatar
dogmaphobic committed
349
        anchors.left:           preferencesButton.right
dogmaphobic's avatar
dogmaphobic committed
350
        anchors.leftMargin:     mainWindow.tbSpacing
351 352 353
        anchors.bottomMargin:   1
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
dogmaphobic's avatar
dogmaphobic committed
354 355 356 357 358

        ExclusiveGroup { id: mainActionGroup }

        QGCToolBarButton {
            id:                 setupButton
dogmaphobic's avatar
dogmaphobic committed
359
            width:              mainWindow.tbButtonWidth
360 361
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
362
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
363
            source:             "/qmlimages/Gears.svg"
Don Gagne's avatar
Don Gagne committed
364
            onClicked:          toolBar.showSetupView()
dogmaphobic's avatar
dogmaphobic committed
365
        }
366

dogmaphobic's avatar
dogmaphobic committed
367 368
        QGCToolBarButton {
            id:                 planButton
dogmaphobic's avatar
dogmaphobic committed
369
            width:              mainWindow.tbButtonWidth
370 371
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
372
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
373
            source:             "/qmlimages/Plan.svg"
Don Gagne's avatar
Don Gagne committed
374
            onClicked:          toolBar.showPlanView()
dogmaphobic's avatar
dogmaphobic committed
375
        }
Don Gagne's avatar
Don Gagne committed
376

dogmaphobic's avatar
dogmaphobic committed
377 378
        QGCToolBarButton {
            id:                 flyButton
dogmaphobic's avatar
dogmaphobic committed
379
            width:              mainWindow.tbButtonWidth
380 381
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
382
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
383
            source:             "/qmlimages/PaperPlane.svg"
Don Gagne's avatar
Don Gagne committed
384
            onClicked:          toolBar.showFlyView()
Don Gagne's avatar
Don Gagne committed
385
        }
dogmaphobic's avatar
dogmaphobic committed
386
    }
387

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

396
        property bool vehicleConnectionLost: activeVehicle ? activeVehicle.connectionLost : false
Don Gagne's avatar
Don Gagne committed
397

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

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

        }

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

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

438
}