MainToolBarIndicators.qml 14.4 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
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        Item {
            anchors.fill:       parent
            visible:            !criticalMessage.visible
109 110 111 112
            QGCColoredImage {
                id:         messageIcon
                source:     "/qmlimages/Megaphone.svg"
                height:     mainWindow.tbCellHeight * 0.5
113
                width:      height
dogmaphobic's avatar
dogmaphobic committed
114
                sourceSize.height: height
115 116
                fillMode:   Image.PreserveAspectFit
                color:      getMessageColor()
dogmaphobic's avatar
dogmaphobic committed
117 118 119 120 121 122 123
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
124
                mainWindow.showMessageArea()
dogmaphobic's avatar
dogmaphobic committed
125 126 127 128 129 130 131 132 133
            }
        }
    }

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

    //-------------------------------------------------------------------------
    //-- RC RSSI
    Item {
        id:     rcRssi
        width:  rssiRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
179
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
180
        Row {
dogmaphobic's avatar
dogmaphobic committed
181 182 183
            id:         rssiRow
            height:     parent.height
            spacing:    ScreenTools.defaultFontPixelWidth
184
            QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
185
                width:          mainWindow.tbCellHeight * 0.65
dogmaphobic's avatar
dogmaphobic committed
186 187
                height:         width
                sourceSize.height: height
188 189
                source:         "/qmlimages/RC.svg"
                fillMode:       Image.PreserveAspectFit
190
                opacity:        activeVehicle ? (((activeVehicle.rcRSSI < 0) || (activeVehicle.rcRSSI > 100)) ? 0.5 : 1) : 0.5
191
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
192 193 194
                anchors.verticalCenter: parent.verticalCenter
            }
            SignalStrength {
195
                size:       mainWindow.tbCellHeight * 0.5
196
                percent:    activeVehicle ? ((activeVehicle.rcRSSI > 100) ? 0 : activeVehicle.rcRSSI) : 0
dogmaphobic's avatar
dogmaphobic committed
197 198 199
                anchors.verticalCenter: parent.verticalCenter
            }
        }
200 201 202 203 204 205 206
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                mainWindow.showPopUp(rcRSSIInfo, centerX)
            }
        }
dogmaphobic's avatar
dogmaphobic committed
207 208
    }

dogmaphobic's avatar
dogmaphobic committed
209 210 211 212 213 214 215
    //-------------------------------------------------------------------------
    //-- Telemetry RSSI
    Item {
        id:         telemRssi
        width:      telemIcon.width
        height:     mainWindow.tbCellHeight
        visible:    _controller.telemetryLRSSI < 0
216 217 218
        QGCColoredImage {
            id:         telemIcon
            height:     parent.height * 0.5
dogmaphobic's avatar
dogmaphobic committed
219
            sourceSize.height: height
220 221 222 223
            width:      height * 1.5
            source:     "/qmlimages/TelemRSSI.svg"
            fillMode:   Image.PreserveAspectFit
            color:      qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
224 225 226 227 228 229 230 231 232 233 234
            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
235 236 237
    //-------------------------------------------------------------------------
    //-- Battery Indicator
    Item {
238 239 240 241
        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
242
        Row {
243 244
            id:     battRow
            height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
245
            anchors.horizontalCenter: parent.horizontalCenter
246 247
            QGCColoredImage {
                height:     mainWindow.tbCellHeight * 0.65
dogmaphobic's avatar
dogmaphobic committed
248 249
                width:      height
                sourceSize.width: width
250 251
                source:     "/qmlimages/Battery.svg"
                fillMode:   Image.PreserveAspectFit
dogmaphobic's avatar
dogmaphobic committed
252
                color:      qgcPal.text
dogmaphobic's avatar
dogmaphobic committed
253 254
                anchors.verticalCenter: parent.verticalCenter
            }
255 256
            QGCLabel {
                text:           getBatteryPercentageText()
dogmaphobic's avatar
dogmaphobic committed
257
                font.pointSize: ScreenTools.mediumFontPointSize
258
                color:          getBatteryColor()
dogmaphobic's avatar
dogmaphobic committed
259
                anchors.verticalCenter: parent.verticalCenter
260 261 262 263 264
            }
        }
        MouseArea {
            anchors.fill:   parent
            onClicked: {
Don Gagne's avatar
Don Gagne committed
265 266 267 268
                if (activeVehicle) {
                    var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                    mainWindow.showPopUp(batteryInfo, centerX)
                }
dogmaphobic's avatar
dogmaphobic committed
269 270 271 272 273 274 275
            }
        }
    }

    //-------------------------------------------------------------------------
    //-- Vehicle Selector
    QGCButton {
Don Gagne's avatar
Don Gagne committed
276
        id:                     vehicleSelectorButton
277
        width:                  ScreenTools.defaultFontPixelHeight * 8
278
        text:                   "Vehicle " + (activeVehicle ? activeVehicle.id : "None")
Don Gagne's avatar
Don Gagne committed
279
        visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
dogmaphobic's avatar
dogmaphobic committed
280 281 282 283 284 285 286 287 288 289 290 291 292
        anchors.verticalCenter: parent.verticalCenter

        menu: vehicleMenu

        Menu {
            id: vehicleMenu
        }

        Component {
            id: vehicleMenuItemComponent

            MenuItem {
                checkable:      true
293
                onTriggered:    QGroundControl.multiVehicleManager.activeVehicle = vehicle
dogmaphobic's avatar
dogmaphobic committed
294 295

                property int vehicleId: Number(text.split(" ")[1])
296
                property var vehicle:   QGroundControl.multiVehicleManager.getVehicleById(vehicleId)
dogmaphobic's avatar
dogmaphobic committed
297 298 299 300 301 302 303 304 305 306 307 308 309
            }
        }

        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
310 311
            for (var i=0; i<QGroundControl.multiVehicleManager.vehicles.count; i++) {
                var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i)
dogmaphobic's avatar
dogmaphobic committed
312 313 314 315 316 317 318 319 320
                var menuItem = vehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id })
                vehicleMenuItems.push(menuItem)
                vehicleMenu.insertItem(i, menuItem)
            }
        }

        Component.onCompleted: updateVehicleMenu()

        Connections {
321
            target:         QGroundControl.multiVehicleManager.vehicles
322
            onCountChanged: vehicleSelectorButton.updateVehicleMenu()
dogmaphobic's avatar
dogmaphobic committed
323 324 325 326 327 328 329
        }
    }

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

    Item {
330
        id:     flightModeSelector
dogmaphobic's avatar
dogmaphobic committed
331
        width:  selectorRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
332
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
333
        anchors.verticalCenter: parent.verticalCenter
334

dogmaphobic's avatar
dogmaphobic committed
335 336 337 338 339
        Row {
            id:                 selectorRow
            spacing:            tbSpacing
            anchors.verticalCenter:   parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
340

dogmaphobic's avatar
dogmaphobic committed
341
            QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
342
                text:           activeVehicle ? activeVehicle.flightMode : qsTr("N/A", "No data to display")
dogmaphobic's avatar
dogmaphobic committed
343
                font.pointSize: ScreenTools.mediumFontPointSize
344
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
345 346 347 348 349 350 351 352 353 354 355 356
                anchors.verticalCenter: parent.verticalCenter
            }
        }

        Menu {
            id: flightModesMenu
        }

        Component {
            id: flightModeMenuItemComponent

            MenuItem {
357 358 359 360 361
                onTriggered: {
                    if(activeVehicle) {
                        activeVehicle.flightMode = text
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
            }
        }

        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 {
386
            target:                 QGroundControl.multiVehicleManager
387
            onActiveVehicleChanged: flightModeSelector.updateFlightModesMenu
dogmaphobic's avatar
dogmaphobic committed
388 389 390
        }

        MouseArea {
391
            visible: activeVehicle ? activeVehicle.flightModeSetAvailable : false
dogmaphobic's avatar
dogmaphobic committed
392 393 394 395 396 397
            anchors.fill:   parent
            onClicked: {
                flightModesMenu.popup()
            }
        }
    }
dogmaphobic's avatar
dogmaphobic committed
398
}
dogmaphobic's avatar
dogmaphobic committed
399 400