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

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

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

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

    function checkPlanButton() {
        planButton.checked = true
    }

    function checkFlyButton() {
        flyButton.checked = true
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        ExclusiveGroup { id: mainActionGroup }

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

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

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

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

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

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

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

        }

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

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

450
}