QGCToolBarButton.qml 3.37 KB
Newer Older
dogmaphobic's avatar
dogmaphobic committed
1
import QtQuick 2.4
2
import QtQuick.Controls 1.2
dogmaphobic's avatar
dogmaphobic committed
3
import QtGraphicalEffects 1.0
4 5


dogmaphobic's avatar
dogmaphobic committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Item {
    id: _root

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

    signal   clicked()

    onExclusiveGroupChanged: {
        if (exclusiveGroup) {
            exclusiveGroup.bindCheckable(_root)
        }
    }

    Image {
        id:             icon
        width:          parent.height * 0.9
        height:         parent.height * 0.9
        mipmap:         true
        fillMode:       Image.PreserveAspectFit
        visible:        false
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
    }

    ColorOverlay {
        id:             iconOverlay
        anchors.fill:   icon
        source:         icon
dogmaphobic's avatar
dogmaphobic committed
36
        color:          (checked ? "#e4e428" : "#ffffff")
dogmaphobic's avatar
dogmaphobic committed
37 38 39 40 41 42 43 44 45 46 47 48
    }

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

/*
49
QGCButton {
50 51 52
    id: button
    property bool repaintChevron: false
    property var  __qgcPal: QGCPalette { colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
53
    property bool showHighlight: __showHighlight
54 55
    style: ButtonStyle {
        background: Item {
56
            anchors.margins: height * 0.1 // 3
57 58 59 60 61 62 63 64 65
            Canvas {
                id: chevron
                anchors.fill: parent
                antialiasing: true
                Connections {
                    target: button
                    onHoveredChanged: chevron.requestPaint()
                    onPressedChanged: chevron.requestPaint()
                    onCheckedChanged: chevron.requestPaint()
66
                    onShowHighlightChanged: chevron.requestPaint()
67 68 69 70 71 72 73 74 75 76
                    onRepaintChevronChanged: {
                        if(repaintChevron) {
                            chevron.requestPaint()
                            repaintChevron = false;
                        }
                    }
                }
                onPaint: {
                    var vMiddle = height / 2;
                    var context = getContext("2d");
77 78 79
                    var w12 = button.height * 0.4 // 12
                    var w3  = button.height * 0.1 // 3
                    var w15 = w12 + w3
80 81
                    context.reset();
                    context.beginPath();
82
                    context.lineWidth = button.height * 0.2; // 6
83 84
                    context.beginPath();
                    context.moveTo(0, 0);
85 86 87
                    context.lineTo(width - w15, 0);
                    context.lineTo(width - w3,  vMiddle);
                    context.lineTo(width - w15, height);
88 89 90
                    context.lineTo(0, height);
                    context.closePath();
                    context.strokeStyle = __qgcPal.windowShade
91
                    context.fillStyle = showHighlight ? __qgcPal.buttonHighlight : (button.checked ? __qgcPal.buttonHighlight : __qgcPal.button);
92 93 94 95 96
                    context.stroke();
                    context.fill();
                }
            }
        }
97
        label: QGCLabel {
98 99
            text: button.text
            horizontalAlignment: Text.AlignHCenter
100
            verticalAlignment:   Text.AlignVCenter
101
            color: showHighlight ? __qgcPal.buttonHighlightText : (button.checked ? __qgcPal.primaryButtonText : __qgcPal.buttonText)
102 103 104
        }
    }
}
dogmaphobic's avatar
dogmaphobic committed
105
*/