QGCToolBarButton.qml 1.86 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 19 20 21 22 23 24
Item {
    id: _root

    property alias          source:  icon.source
    property bool           checked: false
    property ExclusiveGroup exclusiveGroup:  null

25 26
    readonly property real _topBottomMargins: ScreenTools.defaultFontPixelHeight / 2

dogmaphobic's avatar
dogmaphobic committed
27 28
    signal   clicked()

29 30
    QGCPalette { id: qgcPal }

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

37 38 39 40 41 42 43 44
    QGCColoredImage {
        id:                     icon
        anchors.left:           parent.left
        anchors.right:          parent.right
        anchors.topMargin:      _topBottomMargins
        anchors.bottomMargin:   _topBottomMargins
        anchors.top:            parent.top
        anchors.bottom:         parent.bottom
dogmaphobic's avatar
dogmaphobic committed
45
        sourceSize.height:      parent.height
46 47 48 49
        fillMode:               Image.PreserveAspectFit
        color:                  checked ? qgcPal.buttonHighlight : qgcPal.buttonText
    }

50
    Rectangle {
51 52 53
        anchors.left:   parent.left
        anchors.right:  parent.right
        anchors.bottom: parent.bottom
dogmaphobic's avatar
dogmaphobic committed
54
        height:         _topBottomMargins * 0.25
55 56
        color:          qgcPal.buttonHighlight
        visible:        checked
dogmaphobic's avatar
dogmaphobic committed
57 58 59 60 61 62 63 64 65 66
    }

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