MainToolBarIndicators.qml 14.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
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
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
28
    function getMessageColor() {
29 30 31 32 33 34 35 36 37
        if (activeVehicle) {
            if (activeVehicle.messageTypeNone)
                return colorGrey
            if (activeVehicle.messageTypeNormal)
                return colorBlue;
            if (activeVehicle.messageTypeWarning)
                return colorOrange;
            if (activeVehicle.messageTypeError)
                return colorRed;
38 39 40
            // Cannot be so make make it obnoxious to show error
            console.log("Invalid vehicle message type")
            return "purple";
41
        }
42 43
        //-- It can only get here when closing (vehicle gone while window active)
        return "white";
dogmaphobic's avatar
dogmaphobic committed
44 45
    }

dogmaphobic's avatar
dogmaphobic committed
46
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
47
    function getBatteryVoltageText() {
Don Gagne's avatar
Don Gagne committed
48 49
        if (activeVehicle.battery.voltage.value >= 0) {
            return activeVehicle.battery.voltage.valueString + activeVehicle.battery.voltage.units
dogmaphobic's avatar
dogmaphobic committed
50 51 52 53
        }
        return 'N/A';
    }

dogmaphobic's avatar
dogmaphobic committed
54
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
55
    function getBatteryPercentageText() {
56
        if(activeVehicle) {
Don Gagne's avatar
Don Gagne committed
57
            if(activeVehicle.battery.percentRemaining.value > 98.9) {
58 59
                return "100%"
            }
Don Gagne's avatar
Don Gagne committed
60 61
            if(activeVehicle.battery.percentRemaining.value > 0.1) {
                return activeVehicle.battery.percentRemaining.valueString + activeVehicle.battery.percentRemaining.units
62
            }
Don Gagne's avatar
Don Gagne committed
63 64
            if(activeVehicle.battery.voltage.value >= 0) {
                return activeVehicle.battery.voltage.valueString + activeVehicle.battery.voltage.units
65
            }
dogmaphobic's avatar
dogmaphobic committed
66 67 68 69 70 71 72 73
        }
        return "N/A"
    }

    //-------------------------------------------------------------------------
    //-- Message Indicator
    Item {
        id:         messages
dogmaphobic's avatar
dogmaphobic committed
74 75
        width:      mainWindow.tbCellHeight
        height:     mainWindow.tbCellHeight
76
        visible:    activeVehicle && activeVehicle.messageCount
dogmaphobic's avatar
dogmaphobic committed
77 78 79 80
        anchors.verticalCenter: parent.verticalCenter
        Item {
            id:                 criticalMessage
            anchors.fill:       parent
81
            visible:            activeVehicle && activeVehicle.messageCount > 0 && isMessageImportant
dogmaphobic's avatar
dogmaphobic committed
82
            Image {
dogmaphobic's avatar
dogmaphobic committed
83 84 85 86 87 88
                source:             "/qmlimages/Yield.svg"
                height:             mainWindow.tbCellHeight * 0.75
                sourceSize.height:  height
                fillMode:           Image.PreserveAspectFit
                cache:              false
                visible:            isMessageImportant
dogmaphobic's avatar
dogmaphobic committed
89 90 91 92 93 94 95
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        Item {
            anchors.fill:       parent
            visible:            !criticalMessage.visible
96 97 98 99
            QGCColoredImage {
                id:         messageIcon
                source:     "/qmlimages/Megaphone.svg"
                height:     mainWindow.tbCellHeight * 0.5
100
                width:      height
dogmaphobic's avatar
dogmaphobic committed
101
                sourceSize.height: height
102 103
                fillMode:   Image.PreserveAspectFit
                color:      getMessageColor()
dogmaphobic's avatar
dogmaphobic committed
104 105 106 107 108 109 110
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
111
                mainWindow.showMessageArea()
dogmaphobic's avatar
dogmaphobic committed
112 113 114 115 116 117 118 119
            }
        }
    }

    //-------------------------------------------------------------------------
    //-- GPS Indicator
    Item {
        id:     satelitte
120
        width:  (gpsValuesColumn.x + gpsValuesColumn.width) * 1.1
dogmaphobic's avatar
dogmaphobic committed
121
        height: mainWindow.tbCellHeight
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141

        QGCColoredImage {
            id:             gpsIcon
            source:         "/qmlimages/Gps.svg"
            fillMode:       Image.PreserveAspectFit
            width:          mainWindow.tbCellHeight * 0.65
            height:         mainWindow.tbCellHeight * 0.5
            sourceSize.height: height
            opacity:        (activeVehicle && activeVehicle.gps.count.value >= 0) ? 1 : 0.5
            color:          qgcPal.buttonText
            anchors.verticalCenter: parent.verticalCenter
        }

        Column {
            id:                     gpsValuesColumn
            anchors.verticalCenter: parent.verticalCenter
            anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
            anchors.left:           gpsIcon.right

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
142
                anchors.horizontalCenter: hdopValue.horizontalCenter
143 144 145
                visible:    activeVehicle && !isNaN(activeVehicle.gps.hdop.value)
                color:      qgcPal.buttonText
                text:       activeVehicle ? activeVehicle.gps.count.valueString : ""
dogmaphobic's avatar
dogmaphobic committed
146
            }
147 148

            QGCLabel {
Don Gagne's avatar
Don Gagne committed
149
                id:         hdopValue
150 151 152
                visible:    activeVehicle && !isNaN(activeVehicle.gps.hdop.value)
                color:      qgcPal.buttonText
                text:       activeVehicle ? activeVehicle.gps.hdop.value.toFixed(1) : ""
dogmaphobic's avatar
dogmaphobic committed
153
            }
154 155
        } // Column

dogmaphobic's avatar
dogmaphobic committed
156 157 158 159 160 161 162
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                mainWindow.showPopUp(gpsInfo, centerX)
            }
        }
dogmaphobic's avatar
dogmaphobic committed
163 164 165 166 167 168 169
    }

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

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

    //-------------------------------------------------------------------------
    //-- Vehicle Selector
    QGCButton {
Don Gagne's avatar
Don Gagne committed
268
        id:                     vehicleSelectorButton
269
        width:                  ScreenTools.defaultFontPixelHeight * 8
270
        text:                   "Vehicle " + (activeVehicle ? activeVehicle.id : "None")
Don Gagne's avatar
Don Gagne committed
271
        visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
dogmaphobic's avatar
dogmaphobic committed
272 273 274 275 276 277 278 279 280 281 282 283 284
        anchors.verticalCenter: parent.verticalCenter

        menu: vehicleMenu

        Menu {
            id: vehicleMenu
        }

        Component {
            id: vehicleMenuItemComponent

            MenuItem {
                checkable:      true
285
                onTriggered:    QGroundControl.multiVehicleManager.activeVehicle = vehicle
dogmaphobic's avatar
dogmaphobic committed
286 287

                property int vehicleId: Number(text.split(" ")[1])
288
                property var vehicle:   QGroundControl.multiVehicleManager.getVehicleById(vehicleId)
dogmaphobic's avatar
dogmaphobic committed
289 290 291 292 293 294 295 296 297 298 299 300 301
            }
        }

        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
302 303
            for (var i=0; i<QGroundControl.multiVehicleManager.vehicles.count; i++) {
                var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i)
dogmaphobic's avatar
dogmaphobic committed
304 305 306 307 308 309 310 311 312
                var menuItem = vehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id })
                vehicleMenuItems.push(menuItem)
                vehicleMenu.insertItem(i, menuItem)
            }
        }

        Component.onCompleted: updateVehicleMenu()

        Connections {
313
            target:         QGroundControl.multiVehicleManager.vehicles
314
            onCountChanged: vehicleSelectorButton.updateVehicleMenu()
dogmaphobic's avatar
dogmaphobic committed
315 316 317 318 319 320 321
        }
    }

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

    Item {
322
        id:     flightModeSelector
dogmaphobic's avatar
dogmaphobic committed
323
        width:  selectorRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
324
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
325
        anchors.verticalCenter: parent.verticalCenter
326

dogmaphobic's avatar
dogmaphobic committed
327 328 329 330 331
        Row {
            id:                 selectorRow
            spacing:            tbSpacing
            anchors.verticalCenter:   parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
332

dogmaphobic's avatar
dogmaphobic committed
333
            QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
334
                text:           activeVehicle ? activeVehicle.flightMode : qsTr("N/A", "No data to display")
dogmaphobic's avatar
dogmaphobic committed
335
                font.pointSize: ScreenTools.mediumFontPointSize
336
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
337 338 339 340 341 342 343 344 345 346 347 348
                anchors.verticalCenter: parent.verticalCenter
            }
        }

        Menu {
            id: flightModesMenu
        }

        Component {
            id: flightModeMenuItemComponent

            MenuItem {
349 350 351 352 353
                onTriggered: {
                    if(activeVehicle) {
                        activeVehicle.flightMode = text
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
            }
        }

        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 {
378
            target:                 QGroundControl.multiVehicleManager
379
            onActiveVehicleChanged: flightModeSelector.updateFlightModesMenu
dogmaphobic's avatar
dogmaphobic committed
380 381 382
        }

        MouseArea {
383
            visible: activeVehicle ? activeVehicle.flightModeSetAvailable : false
dogmaphobic's avatar
dogmaphobic committed
384 385 386 387 388 389
            anchors.fill:   parent
            onClicked: {
                flightModesMenu.popup()
            }
        }
    }
dogmaphobic's avatar
dogmaphobic committed
390
}
dogmaphobic's avatar
dogmaphobic committed
391 392