MainToolBar.qml 14.8 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 24 25 26 27 28 29
/*=====================================================================

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/>.

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

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

dogmaphobic's avatar
dogmaphobic committed
30
import QtQuick 2.5
dogmaphobic's avatar
dogmaphobic committed
31 32 33
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

34 35 36 37 38
import QGroundControl.Controls              1.0
import QGroundControl.FactControls          1.0
import QGroundControl.Palette               1.0
import QGroundControl.MultiVehicleManager   1.0
import QGroundControl.ScreenTools           1.0
39
import QGroundControl.Controllers           1.0
dogmaphobic's avatar
dogmaphobic committed
40

41
Rectangle {
dogmaphobic's avatar
dogmaphobic committed
42 43
    id:     toolBar
    color:  isBackgroundDark ? Qt.rgba(0,0,0,0.75) : Qt.rgba(0,0,0,0.5)
dogmaphobic's avatar
dogmaphobic committed
44

Don Gagne's avatar
Don Gagne committed
45
    QGCPalette { id: qgcPal; colorGroupEnabled: true }
46

dogmaphobic's avatar
dogmaphobic committed
47 48 49
    property var  activeVehicle:        multiVehicleManager.activeVehicle
    property bool isMessageImportant:   activeVehicle ? !activeVehicle.messageTypeNormal && !activeVehicle.messageTypeNone : false
    property bool isBackgroundDark:     true
50

dogmaphobic's avatar
dogmaphobic committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
    /*
        Dev System (Mac OS)

        qml: Main Window Width:   1008
        qml: Toolbar height:      51.2
        qml: Default font:        12.8
        qml: Font (.75):          9.600000000000001
        qml: Font (.85):          10.88
        qml: Font 1.5):           19.200000000000003
        qml: Default Font Width:  8.328125
        qml: Default Font Height: 12.8
        qml: --
        qml: Real Font Height:    16
        qml: fontHRatio:          1
        qml: --
        qml: cellHeight:          38
        qml: tbFontSmall:         10
        qml: tbFontNormal:        12
        qml: tbFontLarge:         18
        qml: tbSpacing:           9.54

        Nexus 9

        qml: Main Window Width:   2048
        qml: Toolbar height:      90.9312
        qml: Default font:        38
        qml: Font (.75):          28.5
        qml: Font (.85):          32.3
        qml: Font 1.5):           57
        qml: Default Font Width:  20.0625
        qml: Default Font Height: 38
        qml: --
        qml: Real Font Height:    38
        qml: fontHRatio:          2.375
        qml: --
        qml: cellHeight:          68
        qml: tbFontSmall:         23.75
        qml: tbFontNormal:        28.5
        qml: tbFontLarge:         42.75
        qml: tbSpacing:           16.87552

        Nexus 7

        qml: Main Window Width:   1920
        qml: Toolbar height:      85.248
        qml: Default font:        38
        qml: Font (.75):          28.5
        qml: Font (.85):          32.3
        qml: Font 1.5):           57
        qml: Default Font Width:  20.140625
        qml: Default Font Height: 38
        qml: --
        qml: Real Font Height:    38
        qml: fontHRatio:          2.375
        qml: --
        qml: cellHeight:          63
        qml: tbFontSmall:         23.75
        qml: tbFontNormal:        28.5
        qml: tbFontLarge:         42.75
        qml: tbSpacing:           15.820800000000002

        Nexus 4

        qml: Main Window Width:   1196
        qml: Toolbar height:      79.65360000000001
        qml: Default font:        38
        qml: Font (.75):          28.5
        qml: Font (.85):          32.3
        qml: Font 1.5):           57
        qml: Default Font Width:  20.140625
        qml: Default Font Height: 38
        qml: --
        qml: Real Font Height:    38
        qml: fontHRatio:          2.375
        qml: --
        qml: cellHeight:          59
        qml: tbFontSmall:         23.75
        qml: tbFontNormal:        28.5
        qml: tbFontLarge:         42.75
        qml: tbSpacing:           9.85504

    */

    readonly property int   cellHeight:     height * 0.75
Don Gagne's avatar
Don Gagne committed
135

dogmaphobic's avatar
dogmaphobic committed
136 137 138
    readonly property real  tbFontSmall:    10 * ScreenTools.fontHRatio
    readonly property real  tbFontNormal:   12 * ScreenTools.fontHRatio
    readonly property real  tbFontLarge:    18 * ScreenTools.fontHRatio
dogmaphobic's avatar
dogmaphobic committed
139

dogmaphobic's avatar
dogmaphobic committed
140
    readonly property real  tbSpacing:      ScreenTools.isMobile ? toolBar.width * 0.00824 : 9.54
dogmaphobic's avatar
dogmaphobic committed
141

dogmaphobic's avatar
dogmaphobic committed
142 143 144 145 146 147
    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"
148

149
    MainToolBarController { id: _controller }
dogmaphobic's avatar
dogmaphobic committed
150

151 152 153
    function showToolbarMessage(message) {
        toolBarMessage.text = message
        toolBarMessageArea.visible = true
Don Gagne's avatar
Don Gagne committed
154 155
    }

dogmaphobic's avatar
dogmaphobic committed
156
    function showMavStatus() {
157
         return (multiVehicleManager.activeVehicleAvailable && activeVehicle.heartbeatTimeout === 0 && _controller.connectionCount > 0);
dogmaphobic's avatar
dogmaphobic committed
158 159
    }

dogmaphobic's avatar
dogmaphobic committed
160 161 162 163
    Component.onCompleted: {
        //-- TODO: Get this from the actual state
        flyButton.checked = true
    }
164

dogmaphobic's avatar
dogmaphobic committed
165 166 167 168 169 170
    Connections {
        target:         controller
        onShowFlyView:  { flyButton.checked   = true }
        onShowPlanView: { planButton.checked  = true }
        onShowSetupView:{ setupButton.checked = true }
    }
171

dogmaphobic's avatar
dogmaphobic committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
    Row {
        id:             viewRow
        height:         cellHeight
        spacing:        tbSpacing
        anchors.left:   parent.left
        anchors.leftMargin:     tbSpacing
        anchors.verticalCenter: parent.verticalCenter

        ExclusiveGroup { id: mainActionGroup }

        QGCToolBarButton {
            id:                 setupButton
            width:              cellHeight * 1.3
            height:             cellHeight
            exclusiveGroup:     mainActionGroup
            source:             "qrc:/res/Gears"
            onClicked: {
189
                _controller.onSetupView();
dogmaphobic's avatar
dogmaphobic committed
190 191
            }
        }
192

dogmaphobic's avatar
dogmaphobic committed
193 194 195 196 197
        Rectangle {
            height: cellHeight
            width:  1
            color: Qt.rgba(1,1,1,0.45)
        }
198

dogmaphobic's avatar
dogmaphobic committed
199 200 201 202 203 204 205
        QGCToolBarButton {
            id:                 planButton
            width:              cellHeight * 1.3
            height:             cellHeight
            exclusiveGroup:     mainActionGroup
            source:             "qrc:/res/Plan"
            onClicked: {
206
                _controller.onPlanView();
dogmaphobic's avatar
dogmaphobic committed
207 208
            }
        }
Don Gagne's avatar
Don Gagne committed
209

dogmaphobic's avatar
dogmaphobic committed
210 211 212 213
        Rectangle {
            height: cellHeight
            width:  1
            color: Qt.rgba(1,1,1,0.45)
Don Gagne's avatar
Don Gagne committed
214
        }
dogmaphobic's avatar
dogmaphobic committed
215

dogmaphobic's avatar
dogmaphobic committed
216 217 218 219 220 221 222 223
        QGCToolBarButton {
            id:                 flyButton
            width:              cellHeight * 1.3
            height:             cellHeight
            exclusiveGroup:     mainActionGroup
            source:             "qrc:/res/PaperPlane"
            onClicked: {
                _controller.onFlyView();
224
            }
Don Gagne's avatar
Don Gagne committed
225
        }
226

Don Gagne's avatar
Don Gagne committed
227
        Rectangle {
dogmaphobic's avatar
dogmaphobic committed
228 229 230
            height: cellHeight
            width:  1
            color: Qt.rgba(1,1,1,0.45)
Don Gagne's avatar
Don Gagne committed
231
        }
232

dogmaphobic's avatar
dogmaphobic committed
233
    }
234

dogmaphobic's avatar
dogmaphobic committed
235 236 237 238 239 240 241 242 243 244 245
    Item {
        visible:                showMavStatus() && !connectionStatus.visible
        height:                 cellHeight
        width:                  (toolBar.width - viewRow.width - connectRow.width)
        anchors.left:           viewRow.right
        anchors.leftMargin:     tbSpacing * 2
        anchors.verticalCenter: parent.verticalCenter
        Loader {
            source:             multiVehicleManager.activeVehicleAvailable ? "MainToolBarIndicators.qml" : ""
            anchors.left:       parent.left
            anchors.verticalCenter:   parent.verticalCenter
Don Gagne's avatar
Don Gagne committed
246
        }
dogmaphobic's avatar
dogmaphobic committed
247
    }
dogmaphobic's avatar
dogmaphobic committed
248

dogmaphobic's avatar
dogmaphobic committed
249 250 251 252 253 254 255 256 257 258 259
    QGCLabel {
        id:             connectionStatus
        visible:        (_controller.connectionCount > 0 && multiVehicleManager.activeVehicleAvailable && activeVehicle.heartbeatTimeout != 0)
        text:           "CONNECTION LOST"
        font.pixelSize: tbFontLarge
        font.weight:    Font.DemiBold
        color:          colorRed
        anchors.left:           viewRow.right
        anchors.leftMargin:     tbSpacing * 2
        anchors.verticalCenter: parent.verticalCenter
    }
dogmaphobic's avatar
dogmaphobic committed
260 261

    Row {
Don Gagne's avatar
Don Gagne committed
262
        id:                     connectRow
dogmaphobic's avatar
dogmaphobic committed
263 264 265
        height:                 cellHeight
        spacing:                tbSpacing
        anchors.rightMargin:    tbSpacing
Don Gagne's avatar
Don Gagne committed
266
        anchors.right:          parent.right
dogmaphobic's avatar
dogmaphobic committed
267
        anchors.verticalCenter: parent.verticalCenter
dogmaphobic's avatar
dogmaphobic committed
268

dogmaphobic's avatar
dogmaphobic committed
269 270
        Menu {
            id: connectMenu
dogmaphobic's avatar
dogmaphobic committed
271
            Component.onCompleted: {
272
                _controller.configListChanged.connect(connectMenu.updateConnectionList);
dogmaphobic's avatar
dogmaphobic committed
273
                connectMenu.updateConnectionList();
dogmaphobic's avatar
dogmaphobic committed
274
            }
dogmaphobic's avatar
dogmaphobic committed
275 276 277 278 279
            function addMenuEntry(name) {
                var label = "Add Connection"
                if(name !== "")
                    label = name;
                var mItem = connectMenu.addItem(label);
280
                var menuSlot = function() {_controller.onConnect(name)};
dogmaphobic's avatar
dogmaphobic committed
281 282 283 284
                mItem.triggered.connect(menuSlot);
            }
            function updateConnectionList() {
                connectMenu.clear();
285 286
                for(var i = 0; i < _controller.configList.length; i++) {
                    connectMenu.addMenuEntry(_controller.configList[i]);
dogmaphobic's avatar
dogmaphobic committed
287
                }
288
                if(_controller.configList.length > 0) {
dogmaphobic's avatar
dogmaphobic committed
289 290 291 292
                    connectMenu.addSeparator();
                }
                // Add "Add Connection" to the list
                connectMenu.addMenuEntry("");
dogmaphobic's avatar
dogmaphobic committed
293 294 295
            }
        }

dogmaphobic's avatar
dogmaphobic committed
296 297 298 299
        Rectangle {
            height: cellHeight
            width:  1
            color: Qt.rgba(1,1,1,0.45)
dogmaphobic's avatar
dogmaphobic committed
300 301
        }

dogmaphobic's avatar
dogmaphobic committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
        QGCToolBarButton {
            id:             connectButton
            width:          cellHeight * 1.3
            height:         cellHeight
            visible:        _controller.connectionCount === 0
            source:         "/qmlimages/Connect.svg"
            checked:        false
            onClicked: {
                checked = false
                connectMenu.popup()
                /*
                console.log("Main Window Width:   " + mainWindow.width)
                console.log("Toolbar height:      " + toolBar.height)
                console.log("Default font:        " + ScreenTools.defaultFontPixelSize)
                console.log("Font (.75):          " + ScreenTools.defaultFontPixelSize * 0.75)
                console.log("Font (.85):          " + ScreenTools.defaultFontPixelSize * 0.85)
                console.log("Font 1.5):           " + ScreenTools.defaultFontPixelSize * 1.5)
                console.log("Default Font Width:  " + ScreenTools.defaultFontPixelWidth)
                console.log("Default Font Height: " + ScreenTools.defaultFontPixelHeight)
                console.log("--")
                console.log("Real Font Height:    " + ScreenTools.realFontHeight)
                console.log("fontHRatio:          " + ScreenTools.fontHRatio)
                console.log("--")
                console.log("cellHeight:          " + cellHeight)
                console.log("tbFontSmall:         " + tbFontSmall);
                console.log("tbFontNormal:        " + tbFontNormal);
                console.log("tbFontLarge:         " + tbFontLarge);
                console.log("tbSpacing:           " + tbSpacing);
                */
            }
        }

        QGCToolBarButton {
            id:             disconnectButton
            width:          cellHeight * 1.3
            height:         cellHeight
            visible:        _controller.connectionCount === 1
            source:         "/qmlimages/Disconnect.svg"
            checked:        false
dogmaphobic's avatar
dogmaphobic committed
341
            onClicked: {
dogmaphobic's avatar
dogmaphobic committed
342
                checked = false
343
                _controller.onDisconnect("");
dogmaphobic's avatar
dogmaphobic committed
344 345 346 347 348 349
            }
        }

        Menu {
            id: disconnectMenu
            Component.onCompleted: {
350
                _controller.connectedListChanged.connect(disconnectMenu.onConnectedListChanged)
dogmaphobic's avatar
dogmaphobic committed
351
            }
dogmaphobic's avatar
dogmaphobic committed
352 353
            function addMenuEntry(name) {
                var mItem = disconnectMenu.addItem(name);
354
                var menuSlot = function() {_controller.onDisconnect(name)};
dogmaphobic's avatar
dogmaphobic committed
355 356
                mItem.triggered.connect(menuSlot);
            }
dogmaphobic's avatar
dogmaphobic committed
357 358 359
            function onConnectedListChanged(conList) {
                disconnectMenu.clear();
                for(var i = 0; i < conList.length; i++) {
dogmaphobic's avatar
dogmaphobic committed
360
                    disconnectMenu.addMenuEntry(conList[i]);
dogmaphobic's avatar
dogmaphobic committed
361 362 363 364
                }
            }
        }

dogmaphobic's avatar
dogmaphobic committed
365 366 367 368 369 370 371 372 373 374 375
        QGCToolBarButton {
            id:             multidisconnectButton
            width:          cellHeight * 1.3
            height:         cellHeight
            visible:        _controller.connectionCount > 1
            source:         "/qmlimages/Disconnect.svg"
            checked:        false
            onClicked: {
                checked = false
                disconnectMenu.popup()
            }
dogmaphobic's avatar
dogmaphobic committed
376
        }
dogmaphobic's avatar
dogmaphobic committed
377 378

    }
379 380 381

    // Progress bar
    Rectangle {
Don Gagne's avatar
Don Gagne committed
382
        id:             progressBar
dogmaphobic's avatar
dogmaphobic committed
383 384
        anchors.bottom: parent.bottom
        height:         toolBar.height * 0.05
385
        width:          parent.width * _controller.progressBarValue
dogmaphobic's avatar
dogmaphobic committed
386
        color:          colorGreen
387
    }
dogmaphobic's avatar
dogmaphobic committed
388

Don Gagne's avatar
Don Gagne committed
389 390
    // Toolbar message area
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
391 392 393 394 395 396 397
        id:             toolBarMessageArea
        x:              toolBar.parent.width * 0.225
        y:              toolBar.parent.height - (ScreenTools.defaultFontPixelHeight * ScreenTools.fontHRatio * 6)
        width:          toolBar.parent.width * 0.55
        height:         ScreenTools.defaultFontPixelHeight * ScreenTools.fontHRatio * 6
        color:          Qt.rgba(0,0,0,0.65)
        visible:        false
Don Gagne's avatar
Don Gagne committed
398
        QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
399 400 401 402 403 404 405 406 407 408
            id:                 toolBarMessage
            width:              toolBarMessageArea.width - toolBarMessageCloseButton.width
            wrapMode:           Text.WordWrap
            color:              qgcPal.warningText
            lineHeightMode:     Text.ProportionalHeight
            lineHeight:         1.25
            anchors.left:       parent.left
            anchors.top:        parent.top
            anchors.bottom:     parent.bottom
            anchors.margins:    tbSpacing
Don Gagne's avatar
Don Gagne committed
409 410
        }
        QGCButton {
dogmaphobic's avatar
dogmaphobic committed
411 412 413 414 415 416
            id:                 toolBarMessageCloseButton
            primary:            true
            text:               "Close Message"
            anchors.right:      parent.right
            anchors.bottom:     parent.bottom
            anchors.margins:    tbSpacing
Don Gagne's avatar
Don Gagne committed
417
            onClicked: {
dogmaphobic's avatar
dogmaphobic committed
418
                toolBarMessageArea.visible = false
419
                _controller.onToolBarMessageClosed()
Don Gagne's avatar
Don Gagne committed
420 421 422
            }
        }
    }
Don Gagne's avatar
Don Gagne committed
423

Don Gagne's avatar
Don Gagne committed
424
} // Rectangle