MainToolBarIndicators.qml 13.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
    //-------------------------------------------------------------------------
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 142 143 144

        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 {
                visible:    activeVehicle && !isNaN(activeVehicle.gps.hdop.value)
                color:      qgcPal.buttonText
                text:       activeVehicle ? activeVehicle.gps.count.valueString : ""
dogmaphobic's avatar
dogmaphobic committed
145
            }
146 147 148 149 150

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

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

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

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

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

        menu: vehicleMenu

        Menu {
            id: vehicleMenu
        }

        Component {
            id: vehicleMenuItemComponent

            MenuItem {
                checkable:      true
282
                onTriggered:    QGroundControl.multiVehicleManager.activeVehicle = vehicle
dogmaphobic's avatar
dogmaphobic committed
283 284

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

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

        Component.onCompleted: updateVehicleMenu()

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

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

    Item {
319
        id:     flightModeSelector
dogmaphobic's avatar
dogmaphobic committed
320
        width:  selectorRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
321
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
322
        anchors.verticalCenter: parent.verticalCenter
323

dogmaphobic's avatar
dogmaphobic committed
324 325 326 327 328
        Row {
            id:                 selectorRow
            spacing:            tbSpacing
            anchors.verticalCenter:   parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
329

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

        Menu {
            id: flightModesMenu
        }

        Component {
            id: flightModeMenuItemComponent

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

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

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