MainToolBarIndicators.qml 14.9 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
import QtQuick                  2.5
import QtQuick.Controls         1.2
import QtGraphicalEffects       1.0
import QtQuick.Controls.Styles  1.2
import QtQuick.Dialogs          1.1
dogmaphobic's avatar
dogmaphobic committed
16 17 18 19

import QGroundControl               1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
20
import QGroundControl.Palette       1.0
dogmaphobic's avatar
dogmaphobic committed
21 22 23 24

Row {
    spacing:  tbSpacing * 2

25 26
    QGCPalette { id: qgcPal }

dogmaphobic's avatar
dogmaphobic committed
27
    //-------------------------------------------------------------------------
28
    function getSatStrength(hdop) {
29
        if (hdop <= 1.0)
30
            return 100
31
        if (hdop <= 1.4)
32
            return 75
33
        if (hdop <= 1.8)
34
            return 50
35
        if (hdop <= 3.0)
36 37
            return 25
        return 0
dogmaphobic's avatar
dogmaphobic committed
38 39
    }

dogmaphobic's avatar
dogmaphobic committed
40
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
41
    function getMessageColor() {
42 43 44 45 46 47 48 49 50
        if (activeVehicle) {
            if (activeVehicle.messageTypeNone)
                return colorGrey
            if (activeVehicle.messageTypeNormal)
                return colorBlue;
            if (activeVehicle.messageTypeWarning)
                return colorOrange;
            if (activeVehicle.messageTypeError)
                return colorRed;
51 52 53
            // Cannot be so make make it obnoxious to show error
            console.log("Invalid vehicle message type")
            return "purple";
54
        }
55 56
        //-- It can only get here when closing (vehicle gone while window active)
        return "white";
dogmaphobic's avatar
dogmaphobic committed
57 58
    }

dogmaphobic's avatar
dogmaphobic committed
59
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
60
    function getBatteryVoltageText() {
Don Gagne's avatar
Don Gagne committed
61 62
        if (activeVehicle.battery.voltage.value >= 0) {
            return activeVehicle.battery.voltage.valueString + activeVehicle.battery.voltage.units
dogmaphobic's avatar
dogmaphobic committed
63 64 65 66
        }
        return 'N/A';
    }

dogmaphobic's avatar
dogmaphobic committed
67
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
68
    function getBatteryPercentageText() {
69
        if(activeVehicle) {
Don Gagne's avatar
Don Gagne committed
70
            if(activeVehicle.battery.percentRemaining.value > 98.9) {
71 72
                return "100%"
            }
Don Gagne's avatar
Don Gagne committed
73 74
            if(activeVehicle.battery.percentRemaining.value > 0.1) {
                return activeVehicle.battery.percentRemaining.valueString + activeVehicle.battery.percentRemaining.units
75
            }
Don Gagne's avatar
Don Gagne committed
76 77
            if(activeVehicle.battery.voltage.value >= 0) {
                return activeVehicle.battery.voltage.valueString + activeVehicle.battery.voltage.units
78
            }
dogmaphobic's avatar
dogmaphobic committed
79 80 81 82 83 84 85 86
        }
        return "N/A"
    }

    //-------------------------------------------------------------------------
    //-- Message Indicator
    Item {
        id:         messages
dogmaphobic's avatar
dogmaphobic committed
87 88
        width:      mainWindow.tbCellHeight
        height:     mainWindow.tbCellHeight
89
        visible:    activeVehicle && activeVehicle.messageCount
dogmaphobic's avatar
dogmaphobic committed
90 91 92 93
        anchors.verticalCenter: parent.verticalCenter
        Item {
            id:                 criticalMessage
            anchors.fill:       parent
94
            visible:            activeVehicle && activeVehicle.messageCount > 0 && isMessageImportant
dogmaphobic's avatar
dogmaphobic committed
95
            Image {
dogmaphobic's avatar
dogmaphobic committed
96 97 98 99 100 101
                source:             "/qmlimages/Yield.svg"
                height:             mainWindow.tbCellHeight * 0.75
                sourceSize.height:  height
                fillMode:           Image.PreserveAspectFit
                cache:              false
                visible:            isMessageImportant
dogmaphobic's avatar
dogmaphobic committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
            SequentialAnimation {
                id:    loopAnimation
                loops: Animation.Infinite
                NumberAnimation { target: criticalMessage; property: "opacity"; duration: 1000; from: 0.25; to: 1 }
                NumberAnimation { target: criticalMessage; property: "opacity"; duration: 1000; from: 1; to: 0.25 }
            }
            onVisibleChanged: {
                if(messages.visible) {
                    loopAnimation.start()
                } else {
                    loopAnimation.stop()
                }
            }
        }
        Item {
            anchors.fill:       parent
            visible:            !criticalMessage.visible
122 123 124 125
            QGCColoredImage {
                id:         messageIcon
                source:     "/qmlimages/Megaphone.svg"
                height:     mainWindow.tbCellHeight * 0.5
126
                width:      height
dogmaphobic's avatar
dogmaphobic committed
127
                sourceSize.height: height
128 129
                fillMode:   Image.PreserveAspectFit
                color:      getMessageColor()
dogmaphobic's avatar
dogmaphobic committed
130 131 132 133 134 135 136
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
137
                mainWindow.showMessageArea()
dogmaphobic's avatar
dogmaphobic committed
138 139 140 141 142 143 144 145 146
            }
        }
    }

    //-------------------------------------------------------------------------
    //-- GPS Indicator
    Item {
        id:     satelitte
        width:  gpsRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
147
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
148
        Row {
dogmaphobic's avatar
dogmaphobic committed
149 150 151
            id:         gpsRow
            height:     parent.height
            spacing:    ScreenTools.defaultFontPixelWidth
152
            QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
153 154 155
                id:             gpsIcon
                source:         "/qmlimages/Gps.svg"
                fillMode:       Image.PreserveAspectFit
dogmaphobic's avatar
dogmaphobic committed
156 157
                width:          mainWindow.tbCellHeight * 0.65
                height:         mainWindow.tbCellHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
158
                sourceSize.height: height
Don Gagne's avatar
Don Gagne committed
159
                opacity:        (activeVehicle && activeVehicle.gps.count.value >= 0) ? 1 : 0.5
160
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
161 162 163
                anchors.verticalCenter: parent.verticalCenter
            }
            SignalStrength {
dogmaphobic's avatar
dogmaphobic committed
164
                size:           mainWindow.tbCellHeight * 0.5
Don Gagne's avatar
Don Gagne committed
165
                percent:        activeVehicle ? getSatStrength(activeVehicle.gps.hdop.value) : ""
dogmaphobic's avatar
dogmaphobic committed
166 167 168 169
                anchors.verticalCenter: parent.verticalCenter
            }
        }
        QGCLabel {
170
            anchors.top:        parent.top
dogmaphobic's avatar
dogmaphobic committed
171 172
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
            anchors.horizontalCenter: parent.horizontalCenter
173
            visible:            activeVehicle && !isNaN(activeVehicle.gps.hdop.value)
dogmaphobic's avatar
dogmaphobic committed
174
            font.pointSize:     ScreenTools.smallFontPointSize
175
            color:              qgcPal.buttonText
176
            text:               activeVehicle ? activeVehicle.gps.hdop.value.toFixed(0) : ""
dogmaphobic's avatar
dogmaphobic committed
177
        }
dogmaphobic's avatar
dogmaphobic committed
178 179 180 181 182 183 184
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                mainWindow.showPopUp(gpsInfo, centerX)
            }
        }
dogmaphobic's avatar
dogmaphobic committed
185 186 187 188 189 190 191
    }

    //-------------------------------------------------------------------------
    //-- RC RSSI
    Item {
        id:     rcRssi
        width:  rssiRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
192
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
193
        Row {
dogmaphobic's avatar
dogmaphobic committed
194 195 196
            id:         rssiRow
            height:     parent.height
            spacing:    ScreenTools.defaultFontPixelWidth
197
            QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
198
                width:          mainWindow.tbCellHeight * 0.65
dogmaphobic's avatar
dogmaphobic committed
199 200
                height:         width
                sourceSize.height: height
201 202
                source:         "/qmlimages/RC.svg"
                fillMode:       Image.PreserveAspectFit
203
                opacity:        activeVehicle ? (((activeVehicle.rcRSSI < 0) || (activeVehicle.rcRSSI > 100)) ? 0.5 : 1) : 0.5
204
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
205 206 207
                anchors.verticalCenter: parent.verticalCenter
            }
            SignalStrength {
208
                size:       mainWindow.tbCellHeight * 0.5
209
                percent:    activeVehicle ? ((activeVehicle.rcRSSI > 100) ? 0 : activeVehicle.rcRSSI) : 0
dogmaphobic's avatar
dogmaphobic committed
210 211 212
                anchors.verticalCenter: parent.verticalCenter
            }
        }
213 214 215 216 217 218 219
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                mainWindow.showPopUp(rcRSSIInfo, centerX)
            }
        }
dogmaphobic's avatar
dogmaphobic committed
220 221
    }

dogmaphobic's avatar
dogmaphobic committed
222 223 224 225 226 227 228
    //-------------------------------------------------------------------------
    //-- Telemetry RSSI
    Item {
        id:         telemRssi
        width:      telemIcon.width
        height:     mainWindow.tbCellHeight
        visible:    _controller.telemetryLRSSI < 0
229 230 231
        QGCColoredImage {
            id:         telemIcon
            height:     parent.height * 0.5
dogmaphobic's avatar
dogmaphobic committed
232
            sourceSize.height: height
233 234 235 236
            width:      height * 1.5
            source:     "/qmlimages/TelemRSSI.svg"
            fillMode:   Image.PreserveAspectFit
            color:      qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
237 238 239 240 241 242 243 244 245 246 247
            anchors.verticalCenter: parent.verticalCenter
        }
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                mainWindow.showPopUp(telemRSSIInfo, centerX)
            }
        }
    }

dogmaphobic's avatar
dogmaphobic committed
248 249 250
    //-------------------------------------------------------------------------
    //-- Battery Indicator
    Item {
251 252 253 254
        id:         batteryStatus
        width:      battRow.width * 1.1
        height:     mainWindow.tbCellHeight
        opacity:    (activeVehicle && activeVehicle.battery.voltage.value >= 0) ? 1 : 0.5
dogmaphobic's avatar
dogmaphobic committed
255
        Row {
256 257
            id:     battRow
            height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
258
            anchors.horizontalCenter: parent.horizontalCenter
259 260
            QGCColoredImage {
                height:     mainWindow.tbCellHeight * 0.65
dogmaphobic's avatar
dogmaphobic committed
261 262
                width:      height
                sourceSize.width: width
263 264
                source:     "/qmlimages/Battery.svg"
                fillMode:   Image.PreserveAspectFit
dogmaphobic's avatar
dogmaphobic committed
265
                color:      qgcPal.text
dogmaphobic's avatar
dogmaphobic committed
266 267
                anchors.verticalCenter: parent.verticalCenter
            }
268 269
            QGCLabel {
                text:           getBatteryPercentageText()
dogmaphobic's avatar
dogmaphobic committed
270
                font.pointSize: ScreenTools.mediumFontPointSize
271
                color:          getBatteryColor()
dogmaphobic's avatar
dogmaphobic committed
272
                anchors.verticalCenter: parent.verticalCenter
273 274 275 276 277
            }
        }
        MouseArea {
            anchors.fill:   parent
            onClicked: {
Don Gagne's avatar
Don Gagne committed
278 279 280 281
                if (activeVehicle) {
                    var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                    mainWindow.showPopUp(batteryInfo, centerX)
                }
dogmaphobic's avatar
dogmaphobic committed
282 283 284 285 286 287 288
            }
        }
    }

    //-------------------------------------------------------------------------
    //-- Vehicle Selector
    QGCButton {
Don Gagne's avatar
Don Gagne committed
289
        id:                     vehicleSelectorButton
290
        width:                  ScreenTools.defaultFontPixelHeight * 8
291
        text:                   "Vehicle " + (activeVehicle ? activeVehicle.id : "None")
Don Gagne's avatar
Don Gagne committed
292
        visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
dogmaphobic's avatar
dogmaphobic committed
293 294 295 296 297 298 299 300 301 302 303 304 305
        anchors.verticalCenter: parent.verticalCenter

        menu: vehicleMenu

        Menu {
            id: vehicleMenu
        }

        Component {
            id: vehicleMenuItemComponent

            MenuItem {
                checkable:      true
306
                onTriggered:    QGroundControl.multiVehicleManager.activeVehicle = vehicle
dogmaphobic's avatar
dogmaphobic committed
307 308

                property int vehicleId: Number(text.split(" ")[1])
309
                property var vehicle:   QGroundControl.multiVehicleManager.getVehicleById(vehicleId)
dogmaphobic's avatar
dogmaphobic committed
310 311 312 313 314 315 316 317 318 319 320 321 322
            }
        }

        property var vehicleMenuItems: []

        function updateVehicleMenu() {
            // Remove old menu items
            for (var i = 0; i < vehicleMenuItems.length; i++) {
                vehicleMenu.removeItem(vehicleMenuItems[i])
            }
            vehicleMenuItems.length = 0

            // Add new items
323 324
            for (var i=0; i<QGroundControl.multiVehicleManager.vehicles.count; i++) {
                var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i)
dogmaphobic's avatar
dogmaphobic committed
325 326 327 328 329 330 331 332 333
                var menuItem = vehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id })
                vehicleMenuItems.push(menuItem)
                vehicleMenu.insertItem(i, menuItem)
            }
        }

        Component.onCompleted: updateVehicleMenu()

        Connections {
334
            target:         QGroundControl.multiVehicleManager.vehicles
335
            onCountChanged: vehicleSelectorButton.updateVehicleMenu()
dogmaphobic's avatar
dogmaphobic committed
336 337 338 339 340 341 342
        }
    }

    //-------------------------------------------------------------------------
    //-- Mode Selector

    Item {
343
        id:     flightModeSelector
dogmaphobic's avatar
dogmaphobic committed
344
        width:  selectorRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
345
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
346
        anchors.verticalCenter: parent.verticalCenter
347

dogmaphobic's avatar
dogmaphobic committed
348 349 350 351 352
        Row {
            id:                 selectorRow
            spacing:            tbSpacing
            anchors.verticalCenter:   parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
353

dogmaphobic's avatar
dogmaphobic committed
354
            QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
355
                text:           activeVehicle ? activeVehicle.flightMode : qsTr("N/A", "No data to display")
dogmaphobic's avatar
dogmaphobic committed
356
                font.pointSize: ScreenTools.mediumFontPointSize
357
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
358 359 360 361 362 363 364 365 366 367 368 369
                anchors.verticalCenter: parent.verticalCenter
            }
        }

        Menu {
            id: flightModesMenu
        }

        Component {
            id: flightModeMenuItemComponent

            MenuItem {
370 371 372 373 374
                onTriggered: {
                    if(activeVehicle) {
                        activeVehicle.flightMode = text
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
            }
        }

        property var flightModesMenuItems: []

        function updateFlightModesMenu() {
            if (activeVehicle.flightModeSetAvailable) {
                // Remove old menu items
                for (var i = 0; i < flightModesMenuItems.length; i++) {
                    flightModesMenu.removeItem(flightModesMenuItems[i])
                }
                flightModesMenuItems.length = 0
                // Add new items
                for (var i = 0; i < activeVehicle.flightModes.length; i++) {
                    var menuItem = flightModeMenuItemComponent.createObject(null, { "text": activeVehicle.flightModes[i] })
                    flightModesMenuItems.push(menuItem)
                    flightModesMenu.insertItem(i, menuItem)
                }
            }
        }

        Component.onCompleted: updateFlightModesMenu()

        Connections {
399
            target:                 QGroundControl.multiVehicleManager
400
            onActiveVehicleChanged: flightModeSelector.updateFlightModesMenu
dogmaphobic's avatar
dogmaphobic committed
401 402 403
        }

        MouseArea {
404
            visible: activeVehicle ? activeVehicle.flightModeSetAvailable : false
dogmaphobic's avatar
dogmaphobic committed
405 406 407 408 409 410
            anchors.fill:   parent
            onClicked: {
                flightModesMenu.popup()
            }
        }
    }
dogmaphobic's avatar
dogmaphobic committed
411
}
dogmaphobic's avatar
dogmaphobic committed
412 413