QGCToolBarButton.qml 2.18 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10
import QtQuick          2.3
11
import QtQuick.Controls 2.4
12

13 14 15
import QGroundControl.Controls      1.0
import QGroundControl.Palette       1.0
import QGroundControl.ScreenTools   1.0
16

17 18
// Important Note: Toolbar buttons must manage their checked state manually in order to support
// view switch prevention. This means they can't be checkable or autoExclusive.
19

20 21 22 23 24 25
Button {
    id:                 button
    height:             ScreenTools.defaultFontPixelHeight * 3
    leftPadding:        _horizontalMargin
    rightPadding:       _horizontalMargin
    checkable:          false
26

27
    property bool logo: false
dogmaphobic's avatar
dogmaphobic committed
28

29
    property real _horizontalMargin: ScreenTools.defaultFontPixelWidth
30

31
    onCheckedChanged: checkable = false
32

33 34 35
    background: Rectangle {
        anchors.fill: parent
        color:  button.checked ? qgcPal.buttonHighlight : Qt.rgba(0,0,0,0)
dogmaphobic's avatar
dogmaphobic committed
36 37
    }

38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    contentItem: Row {
        spacing:                ScreenTools.defaultFontPixelWidth
        anchors.verticalCenter: button.verticalCenter
        QGCColoredImage {
            id:                     _icon
            height:                 ScreenTools.defaultFontPixelHeight * 2
            width:                  height
            sourceSize.height:      parent.height
            fillMode:               Image.PreserveAspectFit
            color:                  logo ? "transparent" : (button.checked ? qgcPal.buttonHighlightText : qgcPal.buttonText)
            source:                 button.icon.source
            anchors.verticalCenter: parent.verticalCenter
        }
        Label {
            id:                     _label
            visible:                text !== ""
            text:                   button.text
            color:                  button.checked ? qgcPal.buttonHighlightText : qgcPal.buttonText
            anchors.verticalCenter: parent.verticalCenter
dogmaphobic's avatar
dogmaphobic committed
57 58 59
        }
    }
}