Skip to content
SetupButton.qml 2.56 KiB
Newer Older
Don Gagne's avatar
Don Gagne committed
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
import QtGraphicalEffects 1.0

import QGroundControl.Palette 1.0
Don Gagne's avatar
Don Gagne committed

Button {
    checkable: true
Don Gagne's avatar
Don Gagne committed

    text: "Button"
    property bool setupComplete: true
    property bool setupIndicator: true
    property string imageResource: "setupButtonImage.png"
Don Gagne's avatar
Don Gagne committed

    style: ButtonStyle {
        id: buttonStyle

        property var __qgcPal: QGCPalette {
Don Gagne's avatar
Don Gagne committed
            colorGroup: control.enabled ? QGCPalette.Active : QGCPalette.Disabled
        }

        background: Rectangle {
            id: innerRect
            readonly property real titleHeight: 20
            color: control.pressed ? __qgcPal.buttonHighlight : (control.checked ? __qgcPal.buttonHighlight : __qgcPal.button)
Don Gagne's avatar
Don Gagne committed

            Text {
                id: titleBar

                width: parent.width
                height: parent.titleHeight

                verticalAlignment: TextEdit.AlignVCenter
                horizontalAlignment: TextEdit.AlignHCenter

                text: control.text
                font.pixelSize: 12
                color: __qgcPal.buttonText
Don Gagne's avatar
Don Gagne committed

                Rectangle {
                    id: setupIndicator

                    readonly property real indicatorRadius: 4
Don Gagne's avatar
Don Gagne committed

                    x: parent.width - (indicatorRadius * 2) - 5
                    y: (parent.height - (indicatorRadius * 2)) / 2
                    width: indicatorRadius * 2
                    height: indicatorRadius * 2

                    radius: indicatorRadius
                    color: control.setupIndicator ? (control.setupComplete ? "#00d932" : "red") : innerRect.color
Don Gagne's avatar
Don Gagne committed
                }
            }

            Rectangle {
                width: parent.width
                height: parent.height - parent.titleHeight

                y: parent.titleHeight

                color: __qgcPal.windowShade
Don Gagne's avatar
Don Gagne committed

                Image {
                    id: buttonImage
                    source: control.imageResource
Don Gagne's avatar
Don Gagne committed
                    sourceSize: Qt.size(parent.width - 20, parent.height - 20)
                    anchors.horizontalCenter: parent.horizontalCenter
                    anchors.verticalCenter: parent.verticalCenter
                    smooth: true
                    visible: false
                }

                ColorOverlay {
                    anchors.fill: buttonImage
                    source: buttonImage
                    color: control.pressed ? __qgcPal.buttonHighlight : (control.checked ? __qgcPal.buttonHighlight : __qgcPal.button)
Don Gagne's avatar
Don Gagne committed
                }
            }
        }

    label: Item {}
    }
}