MainToolBar.qml 17.7 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

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

dogmaphobic's avatar
dogmaphobic committed
30
import QtQuick 2.5
31
import QtQuick.Layouts 1.2
dogmaphobic's avatar
dogmaphobic committed
32 33 34
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

Don Gagne's avatar
Don Gagne committed
35
import QGroundControl                       1.0
36 37 38 39
import QGroundControl.Controls              1.0
import QGroundControl.Palette               1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
40
import QGroundControl.Controllers           1.0
dogmaphobic's avatar
dogmaphobic committed
41

42
Rectangle {
43
    id:         toolBar
44
    color:      qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.8) : Qt.rgba(0,0,0,0.75)
dogmaphobic's avatar
dogmaphobic committed
45

Don Gagne's avatar
Don Gagne committed
46
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
47

48
    property var  activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
dogmaphobic's avatar
dogmaphobic committed
49
    property var  mainWindow:           null
dogmaphobic's avatar
dogmaphobic committed
50 51
    property bool isMessageImportant:   activeVehicle ? !activeVehicle.messageTypeNormal && !activeVehicle.messageTypeNone : false
    property bool isBackgroundDark:     true
dogmaphobic's avatar
dogmaphobic committed
52
    property bool opaqueBackground:     false
53

dogmaphobic's avatar
dogmaphobic committed
54 55 56 57 58 59
    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"
60

61
    signal showPreferences()
Don Gagne's avatar
Don Gagne committed
62 63 64 65
    signal showSetupView()
    signal showPlanView()
    signal showFlyView()

66
    MainToolBarController { id: _controller }
dogmaphobic's avatar
dogmaphobic committed
67

Don Gagne's avatar
Don Gagne committed
68 69 70 71 72 73 74 75 76 77 78 79
    function checkSetupButton() {
        setupButton.checked = true
    }

    function checkPlanButton() {
        planButton.checked = true
    }

    function checkFlyButton() {
        flyButton.checked = true
    }

80 81
    function getBatteryColor() {
        if(activeVehicle) {
Don Gagne's avatar
Don Gagne committed
82
            if(activeVehicle.battery.percentRemaining.value > 75) {
83 84
                return colorGreen
            }
Don Gagne's avatar
Don Gagne committed
85
            if(activeVehicle.battery.percentRemaining.value > 50) {
86 87
                return colorOrange
            }
Don Gagne's avatar
Don Gagne committed
88
            if(activeVehicle.battery.percentRemaining.value > 0.1) {
89 90 91 92 93 94
                return colorRed
            }
        }
        return colorGrey
    }

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

dogmaphobic's avatar
dogmaphobic committed
110 111 112 113
    //---------------------------------------------
    // GPS Info
    Component {
        id: gpsInfo
114

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

dogmaphobic's avatar
dogmaphobic committed
128
                QGCLabel {
129 130 131
                    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
132 133
                    anchors.horizontalCenter: parent.horizontalCenter
                }
134

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

Tomaz Canabrava's avatar
Tomaz Canabrava committed
143 144 145 146 147 148 149 150 151 152
                    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
153 154
                }
            }
155

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

164 165 166 167
    //---------------------------------------------
    // Battery Info
    Component {
        id: batteryInfo
Don Gagne's avatar
Don Gagne committed
168

169
        Rectangle {
170 171 172 173
            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
174

175 176 177 178 179 180
            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
181

182
                QGCLabel {
183 184 185
                    id:             battLabel
                    text:           qsTr("Battery Status")
                    font.family:    ScreenTools.demiboldFontFamily
186 187
                    anchors.horizontalCenter: parent.horizontalCenter
                }
188

189 190 191 192
                GridLayout {
                    id:                 battGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
193
                    columns:            2
194
                    anchors.horizontalCenter: parent.horizontalCenter
195

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

203 204 205 206 207 208 209 210 211 212 213 214
            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
215

216
        Rectangle {
217 218 219 220 221
            width:  rcrssiCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: rcrssiCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

222
            Column {
dogmaphobic's avatar
dogmaphobic committed
223
                id:                 rcrssiCol
224
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
225
                width:              Math.max(rcrssiGrid.width, rssiLabel.width)
226 227
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
228

229
                QGCLabel {
230 231 232
                    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
233 234
                    anchors.horizontalCenter: parent.horizontalCenter
                }
235

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

Tomaz Canabrava's avatar
Tomaz Canabrava committed
244
                    QGCLabel { text: qsTr("RSSI:") }
245
                    QGCLabel { text: activeVehicle ? (activeVehicle.rcRSSI + "%") : 0 }
246 247
                }
            }
248

249 250 251 252 253 254 255 256
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

dogmaphobic's avatar
dogmaphobic committed
257 258 259 260
    //---------------------------------------------
    // Telemetry RSSI Info
    Component {
        id: telemRSSIInfo
261

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

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

dogmaphobic's avatar
dogmaphobic committed
282 283 284 285
                GridLayout {
                    id:                 telemGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
286
                    columns:            2
dogmaphobic's avatar
dogmaphobic committed
287
                    anchors.horizontalCenter: parent.horizontalCenter
288

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

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

314 315 316 317 318 319
    Rectangle {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
        height:         1
        color:          "black"
dogmaphobic's avatar
dogmaphobic committed
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
        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
        }
341 342 343 344 345 346 347 348 349
        /* 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
350
        MouseArea {
351 352
            anchors.fill:   parent
            onClicked:      toolBar.showPreferences()
dogmaphobic's avatar
dogmaphobic committed
353
        }
354 355
    }

356 357
    //---------------------------------------------
    // Toolbar Row
dogmaphobic's avatar
dogmaphobic committed
358
    Row {
359 360 361
        id:                     viewRow
        height:                 mainWindow.tbCellHeight
        spacing:                mainWindow.tbSpacing
dogmaphobic's avatar
dogmaphobic committed
362
        anchors.left:           preferencesButton.right
dogmaphobic's avatar
dogmaphobic committed
363
        anchors.leftMargin:     mainWindow.tbSpacing
364 365 366
        anchors.bottomMargin:   1
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
dogmaphobic's avatar
dogmaphobic committed
367 368 369 370 371

        ExclusiveGroup { id: mainActionGroup }

        QGCToolBarButton {
            id:                 setupButton
dogmaphobic's avatar
dogmaphobic committed
372
            width:              mainWindow.tbButtonWidth
373 374
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
375
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
376
            source:             "/qmlimages/Gears.svg"
Don Gagne's avatar
Don Gagne committed
377
            onClicked:          toolBar.showSetupView()
dogmaphobic's avatar
dogmaphobic committed
378
        }
379

dogmaphobic's avatar
dogmaphobic committed
380 381
        QGCToolBarButton {
            id:                 planButton
dogmaphobic's avatar
dogmaphobic committed
382
            width:              mainWindow.tbButtonWidth
383 384
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
385
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
386
            source:             "/qmlimages/Plan.svg"
Don Gagne's avatar
Don Gagne committed
387
            onClicked:          toolBar.showPlanView()
dogmaphobic's avatar
dogmaphobic committed
388
        }
Don Gagne's avatar
Don Gagne committed
389

dogmaphobic's avatar
dogmaphobic committed
390 391
        QGCToolBarButton {
            id:                 flyButton
dogmaphobic's avatar
dogmaphobic committed
392
            width:              mainWindow.tbButtonWidth
393 394
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
395
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
396
            source:             "/qmlimages/PaperPlane.svg"
Don Gagne's avatar
Don Gagne committed
397
            onClicked:          toolBar.showFlyView()
Don Gagne's avatar
Don Gagne committed
398
        }
dogmaphobic's avatar
dogmaphobic committed
399
    }
400

dogmaphobic's avatar
dogmaphobic committed
401
    Item {
dogmaphobic's avatar
dogmaphobic committed
402
        id:                     vehicleIndicators
dogmaphobic's avatar
dogmaphobic committed
403 404
        height:                 mainWindow.tbCellHeight
        anchors.leftMargin:     mainWindow.tbSpacing * 2
Don Gagne's avatar
Don Gagne committed
405 406
        anchors.left:           viewRow.right
        anchors.right:          parent.right
dogmaphobic's avatar
dogmaphobic committed
407
        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
408

409
        property bool vehicleConnectionLost: activeVehicle ? activeVehicle.connectionLost : false
Don Gagne's avatar
Don Gagne committed
410

dogmaphobic's avatar
dogmaphobic committed
411
        Loader {
412
            source:                 activeVehicle && !parent.vehicleConnectionLost ? "MainToolBarIndicators.qml" : ""
Don Gagne's avatar
Don Gagne committed
413 414
            anchors.left:           parent.left
            anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
415
        }
dogmaphobic's avatar
dogmaphobic committed
416

Don Gagne's avatar
Don Gagne committed
417 418
        QGCLabel {
            id:                     connectionLost
Tomaz Canabrava's avatar
Tomaz Canabrava committed
419
            text:                   qsTr("COMMUNICATION LOST")
dogmaphobic's avatar
dogmaphobic committed
420
            font.pointSize:         ScreenTools.largeFontPointSize
421
            font.family:            ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
422
            color:                  colorRed
423 424
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.right:          disconnectButton.left
Don Gagne's avatar
Don Gagne committed
425
            anchors.verticalCenter: parent.verticalCenter
426
            visible:                parent.vehicleConnectionLost
Don Gagne's avatar
Don Gagne committed
427 428 429 430

        }

        QGCButton {
431
            id:                     disconnectButton
Don Gagne's avatar
Don Gagne committed
432 433 434
            anchors.rightMargin:     mainWindow.tbSpacing * 2
            anchors.right:          parent.right
            anchors.verticalCenter: parent.verticalCenter
Tomaz Canabrava's avatar
Tomaz Canabrava committed
435
            text:                   qsTr("Disconnect")
436
            visible:                parent.vehicleConnectionLost
437
            primary:                true
Don Gagne's avatar
Don Gagne committed
438 439
            onClicked:              activeVehicle.disconnectInactiveVehicle()
        }
dogmaphobic's avatar
dogmaphobic committed
440
    }
dogmaphobic's avatar
dogmaphobic committed
441

442 443
    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
444
        id:             progressBar
dogmaphobic's avatar
dogmaphobic committed
445 446
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
447
        width:          parent.width * _controller.progressBarValue
dogmaphobic's avatar
dogmaphobic committed
448
        color:          colorGreen
449
    }
dogmaphobic's avatar
dogmaphobic committed
450

451
}