QGCToolBarButton.qml 2.13 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.
 *
 ****************************************************************************/
9 10


11 12
import QtQuick          2.3
import QtQuick.Controls 1.2
13

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

dogmaphobic's avatar
dogmaphobic committed
18
Item {
19
    id:     _root
Don Gagne's avatar
Don Gagne committed
20
    width:  height
21 22
    state:  "HelpShown"
    clip:   true
dogmaphobic's avatar
dogmaphobic committed
23

24 25 26
    property alias          source:         icon.source
    property bool           checked:        false
    property bool           logo:           false
dogmaphobic's avatar
dogmaphobic committed
27 28
    property ExclusiveGroup exclusiveGroup:  null

Don Gagne's avatar
Don Gagne committed
29
    signal clicked()
30

31 32
    readonly property real _topBottomMargins: ScreenTools.defaultFontPixelHeight / 2

dogmaphobic's avatar
dogmaphobic committed
33 34 35 36 37 38
    onExclusiveGroupChanged: {
        if (exclusiveGroup) {
            exclusiveGroup.bindCheckable(_root)
        }
    }

39 40 41 42 43
    QGCPalette { id: qgcPal }

    Rectangle {
        anchors.fill:   parent
        visible:        logo
44
        color:          qgcPal.brandingPurple
45 46
    }

47 48 49 50 51 52
    QGCColoredImage {
        id:                     icon
        anchors.left:           parent.left
        anchors.right:          parent.right
        anchors.topMargin:      _topBottomMargins
        anchors.top:            parent.top
Don Gagne's avatar
Don Gagne committed
53 54
        anchors.bottomMargin:   _topBottomMargins
        anchors.bottom:         parent.bottom
dogmaphobic's avatar
dogmaphobic committed
55
        sourceSize.height:      parent.height
56
        fillMode:               Image.PreserveAspectFit
57
        color:                  logo ? "white" : (checked ? qgcPal.buttonHighlight : qgcPal.buttonText)
58 59
    }

60
    Rectangle {
61 62 63
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
dogmaphobic's avatar
dogmaphobic committed
64
        height:         _topBottomMargins * 0.25
65 66
        color:          qgcPal.buttonHighlight
        visible:        checked
dogmaphobic's avatar
dogmaphobic committed
67 68 69 70 71 72 73 74 75 76
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            checked = true
            _root.clicked()
        }
    }
}