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
import QtQuick                  2.5
import QtQuick.Controls         1.2
dogmaphobic's avatar
dogmaphobic committed
13

Don Gagne's avatar
Don Gagne committed
14 15 16 17 18
import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Palette               1.0
dogmaphobic's avatar
dogmaphobic committed
19

Don Gagne's avatar
Don Gagne committed
20 21 22
Item {
    property var  _activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
    property bool _communicationLost:   _activeVehicle ? _activeVehicle.connectionLost : false
dogmaphobic's avatar
dogmaphobic committed
23 24

    function getMessageColor() {
Don Gagne's avatar
Don Gagne committed
25 26
        if (_activeVehicle) {
            if (_activeVehicle.messageTypeNone)
27
                return colorGrey
Don Gagne's avatar
Don Gagne committed
28
            if (_activeVehicle.messageTypeNormal)
29
                return colorBlue;
Don Gagne's avatar
Don Gagne committed
30
            if (_activeVehicle.messageTypeWarning)
31
                return colorOrange;
Don Gagne's avatar
Don Gagne committed
32
            if (_activeVehicle.messageTypeError)
33
                return colorRed;
34 35 36
            // Cannot be so make make it obnoxious to show error
            console.log("Invalid vehicle message type")
            return "purple";
37
        }
38 39
        //-- It can only get here when closing (vehicle gone while window active)
        return "white";
dogmaphobic's avatar
dogmaphobic committed
40 41 42
    }

    function getBatteryVoltageText() {
Don Gagne's avatar
Don Gagne committed
43 44
        if (_activeVehicle.battery.voltage.value >= 0) {
            return _activeVehicle.battery.voltage.valueString + _activeVehicle.battery.voltage.units
dogmaphobic's avatar
dogmaphobic committed
45 46 47 48 49
        }
        return 'N/A';
    }

    function getBatteryPercentageText() {
Don Gagne's avatar
Don Gagne committed
50 51
        if(_activeVehicle) {
            if(_activeVehicle.battery.percentRemaining.value > 98.9) {
52 53
                return "100%"
            }
Don Gagne's avatar
Don Gagne committed
54 55
            if(_activeVehicle.battery.percentRemaining.value > 0.1) {
                return _activeVehicle.battery.percentRemaining.valueString + _activeVehicle.battery.percentRemaining.units
56
            }
Don Gagne's avatar
Don Gagne committed
57 58
            if(_activeVehicle.battery.voltage.value >= 0) {
                return _activeVehicle.battery.voltage.valueString + _activeVehicle.battery.voltage.units
59
            }
dogmaphobic's avatar
dogmaphobic committed
60 61 62 63
        }
        return "N/A"
    }

Don Gagne's avatar
Don Gagne committed
64 65 66 67 68 69
    Row {
        id:                 indicatorRow
        anchors.top:        parent.top
        anchors.bottom:     parent.bottom
        spacing:            ScreenTools.defaultFontPixelWidth * 1.5
        visible:            !_communicationLost
dogmaphobic's avatar
dogmaphobic committed
70

Don Gagne's avatar
Don Gagne committed
71
        QGCPalette { id: qgcPal }
72

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

Don Gagne's avatar
Don Gagne committed
119 120 121 122 123 124 125
        //-------------------------------------------------------------------------
        //-- GPS Indicator
        Item {
            id:     satelitte
            width:  (gpsValuesColumn.x + gpsValuesColumn.width) * 1.1
            height: mainWindow.tbCellHeight

126
            QGCColoredImage {
Don Gagne's avatar
Don Gagne committed
127 128 129
                id:             gpsIcon
                source:         "/qmlimages/Gps.svg"
                fillMode:       Image.PreserveAspectFit
dogmaphobic's avatar
dogmaphobic committed
130
                width:          mainWindow.tbCellHeight * 0.65
Don Gagne's avatar
Don Gagne committed
131
                height:         mainWindow.tbCellHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
132
                sourceSize.height: height
Don Gagne's avatar
Don Gagne committed
133
                opacity:        (_activeVehicle && _activeVehicle.gps.count.value >= 0) ? 1 : 0.5
134
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
135 136
                anchors.verticalCenter: parent.verticalCenter
            }
Don Gagne's avatar
Don Gagne committed
137 138 139

            Column {
                id:                     gpsValuesColumn
dogmaphobic's avatar
dogmaphobic committed
140
                anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
                anchors.leftMargin:     ScreenTools.defaultFontPixelWidth / 2
                anchors.left:           gpsIcon.right

                QGCLabel {
                    anchors.horizontalCenter: hdopValue.horizontalCenter
                    visible:    _activeVehicle && !isNaN(_activeVehicle.gps.hdop.value)
                    color:      qgcPal.buttonText
                    text:       _activeVehicle ? _activeVehicle.gps.count.valueString : ""
                }

                QGCLabel {
                    id:         hdopValue
                    visible:    _activeVehicle && !isNaN(_activeVehicle.gps.hdop.value)
                    color:      qgcPal.buttonText
                    text:       _activeVehicle ? _activeVehicle.gps.hdop.value.toFixed(1) : ""
                }
            } // Column

            MouseArea {
                anchors.fill:   parent
                onClicked: {
                    var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                    mainWindow.showPopUp(gpsInfo, centerX)
                }
dogmaphobic's avatar
dogmaphobic committed
165 166 167
            }
        }

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

Don Gagne's avatar
Don Gagne committed
204 205 206 207 208 209 210
        //-------------------------------------------------------------------------
        //-- Telemetry RSSI
        Item {
            id:         telemRssi
            width:      telemIcon.width
            height:     mainWindow.tbCellHeight
            visible:    _controller.telemetryLRSSI < 0
211
            QGCColoredImage {
Don Gagne's avatar
Don Gagne committed
212 213 214 215 216
                id:         telemIcon
                height:     parent.height * 0.5
                sourceSize.height: height
                width:      height * 1.5
                source:     "/qmlimages/TelemRSSI.svg"
217
                fillMode:   Image.PreserveAspectFit
Don Gagne's avatar
Don Gagne committed
218
                color:      qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
219
                anchors.verticalCenter: parent.verticalCenter
220
            }
Don Gagne's avatar
Don Gagne committed
221 222 223
            MouseArea {
                anchors.fill:   parent
                onClicked: {
Don Gagne's avatar
Don Gagne committed
224
                    var centerX = mapToItem(toolBar, x, y).x + (width / 2)
Don Gagne's avatar
Don Gagne committed
225
                    mainWindow.showPopUp(telemRSSIInfo, centerX)
Don Gagne's avatar
Don Gagne committed
226
                }
dogmaphobic's avatar
dogmaphobic committed
227 228 229
            }
        }

Don Gagne's avatar
Don Gagne committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
        //-------------------------------------------------------------------------
        //-- Battery Indicator
        Item {
            id:         batteryStatus
            width:      battRow.width * 1.1
            height:     mainWindow.tbCellHeight
            opacity:    (_activeVehicle && _activeVehicle.battery.voltage.value >= 0) ? 1 : 0.5
            Row {
                id:     battRow
                height: mainWindow.tbCellHeight
                anchors.horizontalCenter: parent.horizontalCenter
                QGCColoredImage {
                    height:     mainWindow.tbCellHeight * 0.65
                    width:      height
                    sourceSize.width: width
                    source:     "/qmlimages/Battery.svg"
                    fillMode:   Image.PreserveAspectFit
                    color:      qgcPal.text
                    anchors.verticalCenter: parent.verticalCenter
                }
                QGCLabel {
                    text:           getBatteryPercentageText()
                    font.pointSize: ScreenTools.mediumFontPointSize
                    color:          getBatteryColor()
                    anchors.verticalCenter: parent.verticalCenter
                }
dogmaphobic's avatar
dogmaphobic committed
256 257
            }

Don Gagne's avatar
Don Gagne committed
258 259 260
            MouseArea {
                anchors.fill:   parent
                onClicked:      mainWindow.showPopUp(batteryInfo, mapToItem(toolBar, x, y).x + (width / 2))
dogmaphobic's avatar
dogmaphobic committed
261 262 263
            }
        }

Don Gagne's avatar
Don Gagne committed
264 265 266 267 268 269 270 271
        //-------------------------------------------------------------------------
        //-- Mode Selector
        QGCLabel {
            id:                     flightModeSelector
            text:                   _activeVehicle ? _activeVehicle.flightMode : qsTr("N/A", "No data to display")
            font.pointSize:         ScreenTools.mediumFontPointSize
            color:                  qgcPal.buttonText
            anchors.verticalCenter: parent.verticalCenter
272

Don Gagne's avatar
Don Gagne committed
273 274
            Menu {
                id: flightModesMenu
dogmaphobic's avatar
dogmaphobic committed
275 276
            }

Don Gagne's avatar
Don Gagne committed
277 278
            Component {
                id: flightModeMenuItemComponent
dogmaphobic's avatar
dogmaphobic committed
279

Don Gagne's avatar
Don Gagne committed
280 281
                MenuItem {
                    onTriggered: _activeVehicle.flightMode = text
282
                }
dogmaphobic's avatar
dogmaphobic committed
283 284
            }

Don Gagne's avatar
Don Gagne committed
285
            property var flightModesMenuItems: []
dogmaphobic's avatar
dogmaphobic committed
286

Don Gagne's avatar
Don Gagne committed
287 288 289 290 291 292 293 294 295 296 297 298 299
            function updateFlightModesMenu() {
                if (_activeVehicle && _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)
                    }
dogmaphobic's avatar
dogmaphobic committed
300 301 302
                }
            }

Don Gagne's avatar
Don Gagne committed
303
            Component.onCompleted: flightModeSelector.updateFlightModesMenu()
dogmaphobic's avatar
dogmaphobic committed
304

Don Gagne's avatar
Don Gagne committed
305 306 307 308
            Connections {
                target:                 QGroundControl.multiVehicleManager
                onActiveVehicleChanged: flightModeSelector.updateFlightModesMenu()
            }
dogmaphobic's avatar
dogmaphobic committed
309

Don Gagne's avatar
Don Gagne committed
310 311 312 313
            MouseArea {
                visible:        _activeVehicle && _activeVehicle.flightModeSetAvailable
                anchors.fill:   parent
                onClicked:      flightModesMenu.popup()
dogmaphobic's avatar
dogmaphobic committed
314
            }
Don Gagne's avatar
Don Gagne committed
315 316 317 318 319 320 321 322 323 324
        } // QGCLabel - Flight mode selector
    } // Row - Vehicle indicators

    Image {
        anchors.right:          parent.right
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
        visible:                x > indicatorRow.width && !_communicationLost
        fillMode:               Image.PreserveAspectFit
        source:                 _activeVehicle ? _activeVehicle.brandImage : ""
dogmaphobic's avatar
dogmaphobic committed
325
    }
dogmaphobic's avatar
dogmaphobic committed
326

Don Gagne's avatar
Don Gagne committed
327 328 329 330 331 332 333 334 335 336 337 338 339
    Row {
        anchors.fill:       parent
        layoutDirection:    Qt.RightToLeft
        spacing:            ScreenTools.defaultFontPixelWidth
        visible:            _communicationLost

        QGCButton {
            id:                     disconnectButton
            anchors.verticalCenter: parent.verticalCenter
            text:                   qsTr("Disconnect")
            primary:                true
            onClicked:              _activeVehicle.disconnectInactiveVehicle()
        }
dogmaphobic's avatar
dogmaphobic committed
340

Don Gagne's avatar
Don Gagne committed
341 342 343 344 345 346 347 348 349 350
        QGCLabel {
            id:                     connectionLost
            anchors.verticalCenter: parent.verticalCenter
            text:                   qsTr("COMMUNICATION LOST")
            font.pointSize:         ScreenTools.largeFontPointSize
            font.family:            ScreenTools.demiboldFontFamily
            color:                  colorRed
        }
    } // Row - Communication lost
} // Item