MainToolBarIndicators.qml 15.5 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

24 25 26 27 28
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
29 30 31 32

import QGroundControl               1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
33
import QGroundControl.Palette       1.0
dogmaphobic's avatar
dogmaphobic committed
34 35 36 37

Row {
    spacing:  tbSpacing * 2

38 39
    QGCPalette { id: qgcPal }

dogmaphobic's avatar
dogmaphobic committed
40
    //-------------------------------------------------------------------------
41
    function getSatStrength(hdop) {
42
        if (hdop <= 1.0)
43
            return 100
44
        if (hdop <= 1.4)
45
            return 75
46
        if (hdop <= 1.8)
47
            return 50
48
        if (hdop <= 3.0)
49 50
            return 25
        return 0
dogmaphobic's avatar
dogmaphobic committed
51 52
    }

dogmaphobic's avatar
dogmaphobic committed
53
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
54
    function getMessageColor() {
55 56 57 58 59 60 61 62 63
        if (activeVehicle) {
            if (activeVehicle.messageTypeNone)
                return colorGrey
            if (activeVehicle.messageTypeNormal)
                return colorBlue;
            if (activeVehicle.messageTypeWarning)
                return colorOrange;
            if (activeVehicle.messageTypeError)
                return colorRed;
64 65 66
            // Cannot be so make make it obnoxious to show error
            console.log("Invalid vehicle message type")
            return "purple";
67
        }
68 69
        //-- It can only get here when closing (vehicle gone while window active)
        return "white";
dogmaphobic's avatar
dogmaphobic committed
70 71
    }

dogmaphobic's avatar
dogmaphobic committed
72
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
73
    function getBatteryVoltageText() {
Don Gagne's avatar
Don Gagne committed
74 75
        if (activeVehicle.battery.voltage.value >= 0) {
            return activeVehicle.battery.voltage.valueString + activeVehicle.battery.voltage.units
dogmaphobic's avatar
dogmaphobic committed
76 77 78 79
        }
        return 'N/A';
    }

dogmaphobic's avatar
dogmaphobic committed
80
    //-------------------------------------------------------------------------
dogmaphobic's avatar
dogmaphobic committed
81
    function getBatteryPercentageText() {
82
        if(activeVehicle) {
Don Gagne's avatar
Don Gagne committed
83
            if(activeVehicle.battery.percentRemaining.value > 98.9) {
84 85
                return "100%"
            }
Don Gagne's avatar
Don Gagne committed
86 87
            if(activeVehicle.battery.percentRemaining.value > 0.1) {
                return activeVehicle.battery.percentRemaining.valueString + activeVehicle.battery.percentRemaining.units
88
            }
Don Gagne's avatar
Don Gagne committed
89 90
            if(activeVehicle.battery.voltage.value >= 0) {
                return activeVehicle.battery.voltage.valueString + activeVehicle.battery.voltage.units
91
            }
dogmaphobic's avatar
dogmaphobic committed
92 93 94 95 96 97 98 99
        }
        return "N/A"
    }

    //-------------------------------------------------------------------------
    //-- Message Indicator
    Item {
        id:         messages
dogmaphobic's avatar
dogmaphobic committed
100 101
        width:      mainWindow.tbCellHeight
        height:     mainWindow.tbCellHeight
102
        visible:    activeVehicle && activeVehicle.messageCount
dogmaphobic's avatar
dogmaphobic committed
103 104 105 106
        anchors.verticalCenter: parent.verticalCenter
        Item {
            id:                 criticalMessage
            anchors.fill:       parent
107
            visible:            activeVehicle && activeVehicle.messageCount > 0 && isMessageImportant
dogmaphobic's avatar
dogmaphobic committed
108
            Image {
dogmaphobic's avatar
dogmaphobic committed
109 110 111 112 113 114
                source:             "/qmlimages/Yield.svg"
                height:             mainWindow.tbCellHeight * 0.75
                sourceSize.height:  height
                fillMode:           Image.PreserveAspectFit
                cache:              false
                visible:            isMessageImportant
dogmaphobic's avatar
dogmaphobic committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
            SequentialAnimation {
                id:    loopAnimation
                loops: Animation.Infinite
                NumberAnimation { target: criticalMessage; property: "opacity"; duration: 1000; from: 0.25; to: 1 }
                NumberAnimation { target: criticalMessage; property: "opacity"; duration: 1000; from: 1; to: 0.25 }
            }
            onVisibleChanged: {
                if(messages.visible) {
                    loopAnimation.start()
                } else {
                    loopAnimation.stop()
                }
            }
        }
        Item {
            anchors.fill:       parent
            visible:            !criticalMessage.visible
135 136 137 138
            QGCColoredImage {
                id:         messageIcon
                source:     "/qmlimages/Megaphone.svg"
                height:     mainWindow.tbCellHeight * 0.5
139
                width:      height
dogmaphobic's avatar
dogmaphobic committed
140
                sourceSize.height: height
141 142
                fillMode:   Image.PreserveAspectFit
                color:      getMessageColor()
dogmaphobic's avatar
dogmaphobic committed
143 144 145 146 147 148 149
                anchors.verticalCenter:   parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        MouseArea {
            anchors.fill: parent
            onClicked: {
150
                mainWindow.showMessageArea()
dogmaphobic's avatar
dogmaphobic committed
151 152 153 154 155 156 157 158 159
            }
        }
    }

    //-------------------------------------------------------------------------
    //-- GPS Indicator
    Item {
        id:     satelitte
        width:  gpsRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
160
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
161
        Row {
dogmaphobic's avatar
dogmaphobic committed
162 163 164
            id:         gpsRow
            height:     parent.height
            spacing:    ScreenTools.defaultFontPixelWidth
165
            QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
166 167 168
                id:             gpsIcon
                source:         "/qmlimages/Gps.svg"
                fillMode:       Image.PreserveAspectFit
dogmaphobic's avatar
dogmaphobic committed
169 170
                width:          mainWindow.tbCellHeight * 0.65
                height:         mainWindow.tbCellHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
171
                sourceSize.height: height
Don Gagne's avatar
Don Gagne committed
172
                opacity:        (activeVehicle && activeVehicle.gps.count.value >= 0) ? 1 : 0.5
173
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
174 175 176
                anchors.verticalCenter: parent.verticalCenter
            }
            SignalStrength {
dogmaphobic's avatar
dogmaphobic committed
177
                size:           mainWindow.tbCellHeight * 0.5
Don Gagne's avatar
Don Gagne committed
178
                percent:        activeVehicle ? getSatStrength(activeVehicle.gps.hdop.value) : ""
dogmaphobic's avatar
dogmaphobic committed
179 180 181 182
                anchors.verticalCenter: parent.verticalCenter
            }
        }
        QGCLabel {
183
            anchors.top:        parent.top
dogmaphobic's avatar
dogmaphobic committed
184 185
            anchors.leftMargin: ScreenTools.defaultFontPixelWidth
            anchors.horizontalCenter: parent.horizontalCenter
186
            visible:            activeVehicle && !isNaN(activeVehicle.gps.hdop.value)
dogmaphobic's avatar
dogmaphobic committed
187
            font.pointSize:     ScreenTools.smallFontPointSize
188
            color:              qgcPal.buttonText
189
            text:               activeVehicle ? activeVehicle.gps.hdop.value.toFixed(0) : ""
dogmaphobic's avatar
dogmaphobic committed
190
        }
dogmaphobic's avatar
dogmaphobic committed
191 192 193 194 195 196 197
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                mainWindow.showPopUp(gpsInfo, centerX)
            }
        }
dogmaphobic's avatar
dogmaphobic committed
198 199 200 201 202 203 204
    }

    //-------------------------------------------------------------------------
    //-- RC RSSI
    Item {
        id:     rcRssi
        width:  rssiRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
205
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
206
        Row {
dogmaphobic's avatar
dogmaphobic committed
207 208 209
            id:         rssiRow
            height:     parent.height
            spacing:    ScreenTools.defaultFontPixelWidth
210
            QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
211
                width:          mainWindow.tbCellHeight * 0.65
dogmaphobic's avatar
dogmaphobic committed
212 213
                height:         width
                sourceSize.height: height
214 215
                source:         "/qmlimages/RC.svg"
                fillMode:       Image.PreserveAspectFit
216
                opacity:        activeVehicle ? (activeVehicle.rcRSSI < 1 ? 0.5 : 1) : 0.5
217
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
218 219 220
                anchors.verticalCenter: parent.verticalCenter
            }
            SignalStrength {
221 222
                size:       mainWindow.tbCellHeight * 0.5
                percent:    activeVehicle ? activeVehicle.rcRSSI : 0
dogmaphobic's avatar
dogmaphobic committed
223 224 225
                anchors.verticalCenter: parent.verticalCenter
            }
        }
226 227 228 229 230 231 232
        MouseArea {
            anchors.fill:   parent
            onClicked: {
                var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                mainWindow.showPopUp(rcRSSIInfo, centerX)
            }
        }
dogmaphobic's avatar
dogmaphobic committed
233 234
    }

dogmaphobic's avatar
dogmaphobic committed
235 236 237 238 239 240 241
    //-------------------------------------------------------------------------
    //-- Telemetry RSSI
    Item {
        id:         telemRssi
        width:      telemIcon.width
        height:     mainWindow.tbCellHeight
        visible:    _controller.telemetryLRSSI < 0
242 243 244
        QGCColoredImage {
            id:         telemIcon
            height:     parent.height * 0.5
dogmaphobic's avatar
dogmaphobic committed
245
            sourceSize.height: height
246 247 248 249
            width:      height * 1.5
            source:     "/qmlimages/TelemRSSI.svg"
            fillMode:   Image.PreserveAspectFit
            color:      qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
250 251 252 253 254 255 256 257 258 259 260
            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
261 262 263
    //-------------------------------------------------------------------------
    //-- Battery Indicator
    Item {
264 265 266 267
        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
268
        Row {
269 270
            id:     battRow
            height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
271
            anchors.horizontalCenter: parent.horizontalCenter
272 273
            QGCColoredImage {
                height:     mainWindow.tbCellHeight * 0.65
dogmaphobic's avatar
dogmaphobic committed
274 275
                width:      height
                sourceSize.width: width
276 277
                source:     "/qmlimages/Battery.svg"
                fillMode:   Image.PreserveAspectFit
dogmaphobic's avatar
dogmaphobic committed
278
                color:      qgcPal.text
dogmaphobic's avatar
dogmaphobic committed
279 280
                anchors.verticalCenter: parent.verticalCenter
            }
281 282
            QGCLabel {
                text:           getBatteryPercentageText()
dogmaphobic's avatar
dogmaphobic committed
283
                font.pointSize: ScreenTools.mediumFontPointSize
284
                color:          getBatteryColor()
dogmaphobic's avatar
dogmaphobic committed
285
                anchors.verticalCenter: parent.verticalCenter
286 287 288 289 290
            }
        }
        MouseArea {
            anchors.fill:   parent
            onClicked: {
Don Gagne's avatar
Don Gagne committed
291 292 293 294
                if (activeVehicle) {
                    var centerX = mapToItem(toolBar, x, y).x + (width / 2)
                    mainWindow.showPopUp(batteryInfo, centerX)
                }
dogmaphobic's avatar
dogmaphobic committed
295 296 297 298 299 300 301
            }
        }
    }

    //-------------------------------------------------------------------------
    //-- Vehicle Selector
    QGCButton {
Don Gagne's avatar
Don Gagne committed
302
        id:                     vehicleSelectorButton
303
        width:                  ScreenTools.defaultFontPixelHeight * 8
304
        text:                   "Vehicle " + (activeVehicle ? activeVehicle.id : "None")
Don Gagne's avatar
Don Gagne committed
305
        visible:                QGroundControl.multiVehicleManager.vehicles.count > 1
dogmaphobic's avatar
dogmaphobic committed
306 307 308 309 310 311 312 313 314 315 316 317 318
        anchors.verticalCenter: parent.verticalCenter

        menu: vehicleMenu

        Menu {
            id: vehicleMenu
        }

        Component {
            id: vehicleMenuItemComponent

            MenuItem {
                checkable:      true
319
                onTriggered:    QGroundControl.multiVehicleManager.activeVehicle = vehicle
dogmaphobic's avatar
dogmaphobic committed
320 321

                property int vehicleId: Number(text.split(" ")[1])
322
                property var vehicle:   QGroundControl.multiVehicleManager.getVehicleById(vehicleId)
dogmaphobic's avatar
dogmaphobic committed
323 324 325 326 327 328 329 330 331 332 333 334 335
            }
        }

        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
336 337
            for (var i=0; i<QGroundControl.multiVehicleManager.vehicles.count; i++) {
                var vehicle = QGroundControl.multiVehicleManager.vehicles.get(i)
dogmaphobic's avatar
dogmaphobic committed
338 339 340 341 342 343 344 345 346
                var menuItem = vehicleMenuItemComponent.createObject(null, { "text": "Vehicle " + vehicle.id })
                vehicleMenuItems.push(menuItem)
                vehicleMenu.insertItem(i, menuItem)
            }
        }

        Component.onCompleted: updateVehicleMenu()

        Connections {
347
            target:         QGroundControl.multiVehicleManager.vehicles
348
            onCountChanged: vehicleSelectorButton.updateVehicleMenu()
dogmaphobic's avatar
dogmaphobic committed
349 350 351 352 353 354 355
        }
    }

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

    Item {
356
        id:     flightModeSelector
dogmaphobic's avatar
dogmaphobic committed
357
        width:  selectorRow.width * 1.1
dogmaphobic's avatar
dogmaphobic committed
358
        height: mainWindow.tbCellHeight
dogmaphobic's avatar
dogmaphobic committed
359
        anchors.verticalCenter: parent.verticalCenter
360

dogmaphobic's avatar
dogmaphobic committed
361 362 363 364 365
        Row {
            id:                 selectorRow
            spacing:            tbSpacing
            anchors.verticalCenter:   parent.verticalCenter
            anchors.horizontalCenter: parent.horizontalCenter
366

dogmaphobic's avatar
dogmaphobic committed
367
            QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
368
                text:           activeVehicle ? activeVehicle.flightMode : qsTr("N/A", "No data to display")
dogmaphobic's avatar
dogmaphobic committed
369
                font.pointSize: ScreenTools.mediumFontPointSize
370
                color:          qgcPal.buttonText
dogmaphobic's avatar
dogmaphobic committed
371 372 373 374 375 376 377 378 379 380 381 382
                anchors.verticalCenter: parent.verticalCenter
            }
        }

        Menu {
            id: flightModesMenu
        }

        Component {
            id: flightModeMenuItemComponent

            MenuItem {
383 384 385 386 387
                onTriggered: {
                    if(activeVehicle) {
                        activeVehicle.flightMode = text
                    }
                }
dogmaphobic's avatar
dogmaphobic committed
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
            }
        }

        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 {
412
            target:                 QGroundControl.multiVehicleManager
413
            onActiveVehicleChanged: flightModeSelector.updateFlightModesMenu
dogmaphobic's avatar
dogmaphobic committed
414 415 416
        }

        MouseArea {
417
            visible: activeVehicle ? activeVehicle.flightModeSetAvailable : false
dogmaphobic's avatar
dogmaphobic committed
418 419 420 421 422 423
            anchors.fill:   parent
            onClicked: {
                flightModesMenu.popup()
            }
        }
    }
dogmaphobic's avatar
dogmaphobic committed
424
}
dogmaphobic's avatar
dogmaphobic committed
425 426