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

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

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

        menu: vehicleMenu

        Menu {
            id: vehicleMenu
        }

        Component {
            id: vehicleMenuItemComponent

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

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

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

        Component.onCompleted: updateVehicleMenu()

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

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

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

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

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

        Menu {
            id: flightModesMenu
        }

        Component {
            id: flightModeMenuItemComponent

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

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

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