QGCToolBarButton.qml 2.38 KB
Newer Older
1 2 3 4 5
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls.Private 1.0

6
import QGroundControl.Controls 1.0
7 8
import QGroundControl.Palette 1.0

9
QGCButton {
10 11 12
    id: button
    property bool repaintChevron: false
    property var  __qgcPal: QGCPalette { colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
13
    property bool showHighlight: __showHighlight
14 15 16 17 18 19 20 21 22 23 24 25
    style: ButtonStyle {
        background: Item {
            anchors.margins: 3
            Canvas {
                id: chevron
                anchors.fill: parent
                antialiasing: true
                Connections {
                    target: button
                    onHoveredChanged: chevron.requestPaint()
                    onPressedChanged: chevron.requestPaint()
                    onCheckedChanged: chevron.requestPaint()
26
                    onShowHighlightChanged: chevron.requestPaint()
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
                    onRepaintChevronChanged: {
                        if(repaintChevron) {
                            chevron.requestPaint()
                            repaintChevron = false;
                        }
                    }
                }
                onPaint: {
                    var vMiddle = height / 2;
                    var context = getContext("2d");
                    context.reset();
                    context.beginPath();
                    context.lineWidth = 6;
                    context.beginPath();
                    context.moveTo(0, 0);
                    context.lineTo(width - 12 - 3, 0);
                    context.lineTo(width - 3, vMiddle);
                    context.lineTo(width - 12 - 3, height);
                    context.lineTo(0, height);
                    context.closePath();
                    context.strokeStyle = __qgcPal.windowShade
48
                    context.fillStyle = showHighlight ? __qgcPal.buttonHighlight : (button.checked ? __qgcPal.buttonHighlight : __qgcPal.button);
49 50 51 52 53 54 55
                    context.stroke();
                    context.fill();
                }
            }
        }
        label: Label {
            text: button.text
56
            font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize
57 58
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
59
            color: showHighlight ? __qgcPal.buttonHighlightText : (button.checked ? __qgcPal.primaryButtonText : __qgcPal.buttonText)
60 61 62
        }
    }
}