QGCToolBarButton.qml 2.57 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
    style: ButtonStyle {
        background: Item {
16
            anchors.margins: height * 0.1 // 3
17 18 19 20 21 22 23 24 25
            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
                    onRepaintChevronChanged: {
                        if(repaintChevron) {
                            chevron.requestPaint()
                            repaintChevron = false;
                        }
                    }
                }
                onPaint: {
                    var vMiddle = height / 2;
                    var context = getContext("2d");
37 38 39
                    var w12 = button.height * 0.4 // 12
                    var w3  = button.height * 0.1 // 3
                    var w15 = w12 + w3
40 41
                    context.reset();
                    context.beginPath();
42
                    context.lineWidth = button.height * 0.2; // 6
43 44
                    context.beginPath();
                    context.moveTo(0, 0);
45 46 47
                    context.lineTo(width - w15, 0);
                    context.lineTo(width - w3,  vMiddle);
                    context.lineTo(width - w15, height);
48 49 50
                    context.lineTo(0, height);
                    context.closePath();
                    context.strokeStyle = __qgcPal.windowShade
51
                    context.fillStyle = showHighlight ? __qgcPal.buttonHighlight : (button.checked ? __qgcPal.buttonHighlight : __qgcPal.button);
52 53 54 55 56 57 58
                    context.stroke();
                    context.fill();
                }
            }
        }
        label: Label {
            text: button.text
59
            font.pointSize: __qgcPal.dpiAdjustedDefaultFontPointSize
60 61
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
62
            color: showHighlight ? __qgcPal.buttonHighlightText : (button.checked ? __qgcPal.primaryButtonText : __qgcPal.buttonText)
63 64 65
        }
    }
}