MainToolBar.qml 16.3 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 16


/**
 * @file
 *   @brief QGC Main Tool Bar
 *   @author Gus Grubba <mavlink@grubba.com>
 */

dogmaphobic's avatar
dogmaphobic committed
17
import QtQuick 2.5
18
import QtQuick.Layouts 1.2
dogmaphobic's avatar
dogmaphobic committed
19 20 21
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

Don Gagne's avatar
Don Gagne committed
22
import QGroundControl                       1.0
23 24 25 26
import QGroundControl.Controls              1.0
import QGroundControl.Palette               1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
27
import QGroundControl.Controllers           1.0
dogmaphobic's avatar
dogmaphobic committed
28

29
Rectangle {
30
    id:         toolBar
31
    color:      qgcPal.globalTheme === QGCPalette.Light ? Qt.rgba(1,1,1,0.8) : Qt.rgba(0,0,0,0.75)
dogmaphobic's avatar
dogmaphobic committed
32

Don Gagne's avatar
Don Gagne committed
33
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
34

35
    property var  activeVehicle:        QGroundControl.multiVehicleManager.activeVehicle
dogmaphobic's avatar
dogmaphobic committed
36
    property var  mainWindow:           null
dogmaphobic's avatar
dogmaphobic committed
37 38
    property bool isMessageImportant:   activeVehicle ? !activeVehicle.messageTypeNormal && !activeVehicle.messageTypeNone : false
    property bool isBackgroundDark:     true
dogmaphobic's avatar
dogmaphobic committed
39
    property bool opaqueBackground:     false
40

dogmaphobic's avatar
dogmaphobic committed
41 42 43 44 45 46
    readonly property var   colorGreen:     "#05f068"
    readonly property var   colorOrange:    "#f0ab06"
    readonly property var   colorRed:       "#fc4638"
    readonly property var   colorGrey:      "#7f7f7f"
    readonly property var   colorBlue:      "#636efe"
    readonly property var   colorWhite:     "#ffffff"
47

48
    signal showSettingsView()
Don Gagne's avatar
Don Gagne committed
49 50 51 52
    signal showSetupView()
    signal showPlanView()
    signal showFlyView()

53
    MainToolBarController { id: _controller }
dogmaphobic's avatar
dogmaphobic committed
54

55
    function checkSettingsButton() {
56 57 58
        preferencesButton.checked = true
    }

Don Gagne's avatar
Don Gagne committed
59 60 61 62 63 64 65 66 67 68 69 70
    function checkSetupButton() {
        setupButton.checked = true
    }

    function checkPlanButton() {
        planButton.checked = true
    }

    function checkFlyButton() {
        flyButton.checked = true
    }

71 72
    function getBatteryColor() {
        if(activeVehicle) {
Don Gagne's avatar
Don Gagne committed
73
            if(activeVehicle.battery.percentRemaining.value > 75) {
74
                return qgcPal.text
75
            }
Don Gagne's avatar
Don Gagne committed
76
            if(activeVehicle.battery.percentRemaining.value > 50) {
77 78
                return colorOrange
            }
Don Gagne's avatar
Don Gagne committed
79
            if(activeVehicle.battery.percentRemaining.value > 0.1) {
80 81 82 83 84 85
                return colorRed
            }
        }
        return colorGrey
    }

dogmaphobic's avatar
dogmaphobic committed
86 87 88 89 90 91 92 93 94 95
    function getRSSIColor(value) {
        if(value >= 0)
            return colorGrey;
        if(value > -60)
            return colorGreen;
        if(value > -90)
            return colorOrange;
        return colorRed;
    }

dogmaphobic's avatar
dogmaphobic committed
96 97 98 99
    Component.onCompleted: {
        //-- TODO: Get this from the actual state
        flyButton.checked = true
    }
100

dogmaphobic's avatar
dogmaphobic committed
101 102 103 104
    //---------------------------------------------
    // GPS Info
    Component {
        id: gpsInfo
105

dogmaphobic's avatar
dogmaphobic committed
106
        Rectangle {
107 108 109 110 111
            width:  gpsCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: gpsCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

dogmaphobic's avatar
dogmaphobic committed
112 113 114 115 116 117
            Column {
                id:                 gpsCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(gpsGrid.width, gpsLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
118

dogmaphobic's avatar
dogmaphobic committed
119
                QGCLabel {
120 121 122
                    id:             gpsLabel
                    text:           (activeVehicle && activeVehicle.gps.count.value >= 0) ? qsTr("GPS Status") : qsTr("GPS Data Unavailable")
                    font.family:    ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
123 124
                    anchors.horizontalCenter: parent.horizontalCenter
                }
125

dogmaphobic's avatar
dogmaphobic committed
126 127
                GridLayout {
                    id:                 gpsGrid
Don Gagne's avatar
Don Gagne committed
128
                    visible:            (activeVehicle && activeVehicle.gps.count.value >= 0)
dogmaphobic's avatar
dogmaphobic committed
129 130 131 132
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
                    anchors.horizontalCenter: parent.horizontalCenter
                    columns: 2
133

Tomaz Canabrava's avatar
Tomaz Canabrava committed
134 135 136 137 138 139 140 141 142 143
                    QGCLabel { text: qsTr("GPS Count:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.count.valueString : qsTr("N/A", "No data to display") }
                    QGCLabel { text: qsTr("GPS Lock:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.lock.enumStringValue : qsTr("N/A", "No data to display") }
                    QGCLabel { text: qsTr("HDOP:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.hdop.valueString : qsTr("--.--", "No data to display") }
                    QGCLabel { text: qsTr("VDOP:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.vdop.valueString : qsTr("--.--", "No data to display") }
                    QGCLabel { text: qsTr("Course Over Ground:") }
                    QGCLabel { text: activeVehicle ? activeVehicle.gps.courseOverGround.valueString : qsTr("--.--", "No data to display") }
dogmaphobic's avatar
dogmaphobic committed
144 145
                }
            }
146

dogmaphobic's avatar
dogmaphobic committed
147 148 149 150 151 152 153 154
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

155 156 157 158
    //---------------------------------------------
    // Battery Info
    Component {
        id: batteryInfo
Don Gagne's avatar
Don Gagne committed
159

160
        Rectangle {
161 162 163 164
            width:  battCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: battCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window
Don Gagne's avatar
Don Gagne committed
165

166 167 168 169 170 171
            Column {
                id:                 battCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(battGrid.width, battLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
Don Gagne's avatar
Don Gagne committed
172

173
                QGCLabel {
174 175 176
                    id:             battLabel
                    text:           qsTr("Battery Status")
                    font.family:    ScreenTools.demiboldFontFamily
177 178
                    anchors.horizontalCenter: parent.horizontalCenter
                }
179

180 181 182 183
                GridLayout {
                    id:                 battGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
184
                    columns:            2
185
                    anchors.horizontalCenter: parent.horizontalCenter
186

Tomaz Canabrava's avatar
Tomaz Canabrava committed
187
                    QGCLabel { text: qsTr("Voltage:") }
188
                    QGCLabel { text: (activeVehicle && activeVehicle.battery.voltage.value != -1) ? (activeVehicle.battery.voltage.valueString + " " + activeVehicle.battery.voltage.units) : "N/A" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
189
                    QGCLabel { text: qsTr("Accumulated Consumption:") }
190
                    QGCLabel { text: (activeVehicle && activeVehicle.battery.mahConsumed.value != -1) ? (activeVehicle.battery.mahConsumed.valueString + " " + activeVehicle.battery.mahConsumed.units) : "N/A" }
191 192
                }
            }
Don Gagne's avatar
Don Gagne committed
193

194 195 196 197 198 199 200 201 202 203 204 205
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

    //---------------------------------------------
    // RC RSSI Info
    Component {
        id: rcRSSIInfo
206

207
        Rectangle {
208 209 210 211 212
            width:  rcrssiCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: rcrssiCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

213
            Column {
dogmaphobic's avatar
dogmaphobic committed
214
                id:                 rcrssiCol
215
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
dogmaphobic's avatar
dogmaphobic committed
216
                width:              Math.max(rcrssiGrid.width, rssiLabel.width)
217 218
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
219

220
                QGCLabel {
221
                    id:             rssiLabel
Ricardo de Almeida Gonzaga's avatar
Ricardo de Almeida Gonzaga committed
222
                    text:           activeVehicle ? (activeVehicle.rcRSSI != 255 ? qsTr("RC RSSI Status") : qsTr("RC RSSI Data Unavailable")) : qsTr("N/A", "No data available")
223
                    font.family:    ScreenTools.demiboldFontFamily
224 225
                    anchors.horizontalCenter: parent.horizontalCenter
                }
226

227
                GridLayout {
dogmaphobic's avatar
dogmaphobic committed
228
                    id:                 rcrssiGrid
229
                    visible:            activeVehicle && activeVehicle.rcRSSI != 255
230 231
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
232
                    columns:            2
233
                    anchors.horizontalCenter: parent.horizontalCenter
234

Tomaz Canabrava's avatar
Tomaz Canabrava committed
235
                    QGCLabel { text: qsTr("RSSI:") }
236
                    QGCLabel { text: activeVehicle ? (activeVehicle.rcRSSI + "%") : 0 }
237 238
                }
            }
239

240 241 242 243 244 245 246 247
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

dogmaphobic's avatar
dogmaphobic committed
248 249 250 251
    //---------------------------------------------
    // Telemetry RSSI Info
    Component {
        id: telemRSSIInfo
252

dogmaphobic's avatar
dogmaphobic committed
253
        Rectangle {
254 255 256 257 258
            width:  telemCol.width   + ScreenTools.defaultFontPixelWidth  * 3
            height: telemCol.height  + ScreenTools.defaultFontPixelHeight * 2
            radius: ScreenTools.defaultFontPixelHeight * 0.5
            color:  qgcPal.window

dogmaphobic's avatar
dogmaphobic committed
259 260 261 262 263 264
            Column {
                id:                 telemCol
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                width:              Math.max(telemGrid.width, telemLabel.width)
                anchors.margins:    ScreenTools.defaultFontPixelHeight
                anchors.centerIn:   parent
265

dogmaphobic's avatar
dogmaphobic committed
266
                QGCLabel {
267
                    id:             telemLabel
Tomaz Canabrava's avatar
Tomaz Canabrava committed
268
                    text:           qsTr("Telemetry RSSI Status")
269
                    font.family:    ScreenTools.demiboldFontFamily
dogmaphobic's avatar
dogmaphobic committed
270 271
                    anchors.horizontalCenter: parent.horizontalCenter
                }
272

dogmaphobic's avatar
dogmaphobic committed
273 274 275 276
                GridLayout {
                    id:                 telemGrid
                    anchors.margins:    ScreenTools.defaultFontPixelHeight
                    columnSpacing:      ScreenTools.defaultFontPixelWidth
277
                    columns:            2
dogmaphobic's avatar
dogmaphobic committed
278
                    anchors.horizontalCenter: parent.horizontalCenter
279

Tomaz Canabrava's avatar
Tomaz Canabrava committed
280
                    QGCLabel { text: qsTr("Local RSSI:") }
281
                    QGCLabel { text: _controller.telemetryLRSSI + " dBm" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
282
                    QGCLabel { text: qsTr("Remote RSSI:") }
283
                    QGCLabel { text: _controller.telemetryRRSSI + " dBm" }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
284
                    QGCLabel { text: qsTr("RX Errors:") }
285
                    QGCLabel { text: _controller.telemetryRXErrors }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
286
                    QGCLabel { text: qsTr("Errors Fixed:") }
287
                    QGCLabel { text: _controller.telemetryFixed }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
288
                    QGCLabel { text: qsTr("TX Buffer:") }
289
                    QGCLabel { text: _controller.telemetryTXBuffer }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
290
                    QGCLabel { text: qsTr("Local Noise:") }
291
                    QGCLabel { text: _controller.telemetryLNoise }
Tomaz Canabrava's avatar
Tomaz Canabrava committed
292
                    QGCLabel { text: qsTr("Remote Noise:") }
293
                    QGCLabel { text: _controller.telemetryRNoise }
dogmaphobic's avatar
dogmaphobic committed
294 295
                }
            }
296

dogmaphobic's avatar
dogmaphobic committed
297 298 299 300 301 302 303 304
            Component.onCompleted: {
                var pos = mapFromItem(toolBar, centerX - (width / 2), toolBar.height)
                x = pos.x
                y = pos.y + ScreenTools.defaultFontPixelHeight
            }
        }
    }

305 306 307 308 309 310
    Rectangle {
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
        height:         1
        color:          "black"
dogmaphobic's avatar
dogmaphobic committed
311 312 313
        visible:        qgcPal.globalTheme == QGCPalette.Light
    }

314 315
    //---------------------------------------------
    // Toolbar Row
dogmaphobic's avatar
dogmaphobic committed
316
    Row {
317 318 319
        id:                     viewRow
        height:                 mainWindow.tbCellHeight
        spacing:                mainWindow.tbSpacing
320
        anchors.left:           parent.left
321 322 323
        anchors.bottomMargin:   1
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
dogmaphobic's avatar
dogmaphobic committed
324 325 326

        ExclusiveGroup { id: mainActionGroup }

327 328 329 330 331 332 333 334
        QGCToolBarButton {
            id:                 preferencesButton
            width:              mainWindow.tbButtonWidth
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            exclusiveGroup:     mainActionGroup
            source:             "/res/QGCLogoWhite"
            logo:               true
335
            onClicked:          toolBar.showSettingsView()
336 337
        }

dogmaphobic's avatar
dogmaphobic committed
338 339
        QGCToolBarButton {
            id:                 setupButton
dogmaphobic's avatar
dogmaphobic committed
340
            width:              mainWindow.tbButtonWidth
341 342
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
343
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
344
            source:             "/qmlimages/Gears.svg"
Don Gagne's avatar
Don Gagne committed
345
            onClicked:          toolBar.showSetupView()
dogmaphobic's avatar
dogmaphobic committed
346
        }
347

dogmaphobic's avatar
dogmaphobic committed
348 349
        QGCToolBarButton {
            id:                 planButton
dogmaphobic's avatar
dogmaphobic committed
350
            width:              mainWindow.tbButtonWidth
351 352
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
353
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
354
            source:             "/qmlimages/Plan.svg"
Don Gagne's avatar
Don Gagne committed
355
            onClicked:          toolBar.showPlanView()
dogmaphobic's avatar
dogmaphobic committed
356
        }
Don Gagne's avatar
Don Gagne committed
357

dogmaphobic's avatar
dogmaphobic committed
358 359
        QGCToolBarButton {
            id:                 flyButton
dogmaphobic's avatar
dogmaphobic committed
360
            width:              mainWindow.tbButtonWidth
361 362
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
363
            exclusiveGroup:     mainActionGroup
dogmaphobic's avatar
dogmaphobic committed
364
            source:             "/qmlimages/PaperPlane.svg"
Don Gagne's avatar
Don Gagne committed
365
            onClicked:          toolBar.showFlyView()
Don Gagne's avatar
Don Gagne committed
366
        }
dogmaphobic's avatar
dogmaphobic committed
367
    }
368

dogmaphobic's avatar
dogmaphobic committed
369
    Item {
dogmaphobic's avatar
dogmaphobic committed
370
        id:                     vehicleIndicators
dogmaphobic's avatar
dogmaphobic committed
371 372
        height:                 mainWindow.tbCellHeight
        anchors.leftMargin:     mainWindow.tbSpacing * 2
Don Gagne's avatar
Don Gagne committed
373 374
        anchors.left:           viewRow.right
        anchors.right:          parent.right
dogmaphobic's avatar
dogmaphobic committed
375
        anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
376

377
        property bool vehicleConnectionLost: activeVehicle ? activeVehicle.connectionLost : false
Don Gagne's avatar
Don Gagne committed
378

dogmaphobic's avatar
dogmaphobic committed
379
        Loader {
380
            source:                 activeVehicle && !parent.vehicleConnectionLost ? "MainToolBarIndicators.qml" : ""
Don Gagne's avatar
Don Gagne committed
381 382
            anchors.left:           parent.left
            anchors.verticalCenter: parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
383
        }
dogmaphobic's avatar
dogmaphobic committed
384

Don Gagne's avatar
Don Gagne committed
385 386
        QGCLabel {
            id:                     connectionLost
Tomaz Canabrava's avatar
Tomaz Canabrava committed
387
            text:                   qsTr("COMMUNICATION LOST")
dogmaphobic's avatar
dogmaphobic committed
388
            font.pointSize:         ScreenTools.largeFontPointSize
389
            font.family:            ScreenTools.demiboldFontFamily
Don Gagne's avatar
Don Gagne committed
390
            color:                  colorRed
391 392
            anchors.rightMargin:    ScreenTools.defaultFontPixelWidth
            anchors.right:          disconnectButton.left
Don Gagne's avatar
Don Gagne committed
393
            anchors.verticalCenter: parent.verticalCenter
394
            visible:                parent.vehicleConnectionLost
Don Gagne's avatar
Don Gagne committed
395 396 397 398

        }

        QGCButton {
399
            id:                     disconnectButton
Don Gagne's avatar
Don Gagne committed
400 401 402
            anchors.rightMargin:     mainWindow.tbSpacing * 2
            anchors.right:          parent.right
            anchors.verticalCenter: parent.verticalCenter
Tomaz Canabrava's avatar
Tomaz Canabrava committed
403
            text:                   qsTr("Disconnect")
404
            visible:                parent.vehicleConnectionLost
405
            primary:                true
Don Gagne's avatar
Don Gagne committed
406 407
            onClicked:              activeVehicle.disconnectInactiveVehicle()
        }
dogmaphobic's avatar
dogmaphobic committed
408
    }
dogmaphobic's avatar
dogmaphobic committed
409

410 411
    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
412
        id:             progressBar
dogmaphobic's avatar
dogmaphobic committed
413 414
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
415
        width:          parent.width * _controller.progressBarValue
dogmaphobic's avatar
dogmaphobic committed
416
        color:          colorGreen
417
    }
dogmaphobic's avatar
dogmaphobic committed
418

419
}