QGCToolBarButton.qml 2.12 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


import QtQuick          2.4
12 13
import QtQuick.Controls 1.2

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

29 30
    readonly property real _topBottomMargins: ScreenTools.defaultFontPixelHeight / 2

Don Gagne's avatar
Don Gagne committed
31
    signal clicked()
32

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

39 40 41 42 43 44 45 46
    QGCPalette { id: qgcPal }

    Rectangle {
        anchors.fill:   parent
        visible:        logo
        color:          "#4A2C6D"
    }

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()
        }
    }
}