SetupButton.qml 4.35 KB
Newer Older
1 2 3 4 5 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

Button {
    text: "Button"
    property bool setupComplete: false

    property var summaryModel: ListModel {
        ListElement { name: "Row 1"; state: "State 1" }
        ListElement { name: "Row 2"; state: "State 2" }
        ListElement { name: "Row 3"; state: "State 3" }
    }

    style: ButtonStyle {
        id: buttonStyle
        background: Rectangle {
            id: innerRect
            readonly property real titleHeight: 30

            //property alias summaryModel: summaryList.model

            border.color: "#888"
            radius: 10

            color: control.activeFocus ? "#47b" : "white"
            opacity: control.hovered || control.activeFocus ? 1 : 0.75
            Behavior on opacity {NumberAnimation{ duration: 100 }}

            Text {
                id: titleBar

                width: parent.width
                height: parent.titleHeight

                verticalAlignment: TextEdit.AlignVCenter
                horizontalAlignment: TextEdit.AlignHCenter

                text: control.text
                font.pixelSize: 12

                Rectangle {
                    id: setupIndicator

                    property bool setupComplete: true
                    readonly property real indicatorRadius: 6

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

                    radius: indicatorRadius
                    color: control.setupComplete ? "green" : "red"
                }
            }

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

                y: parent.titleHeight

                border.color: "#888"

                gradient: Gradient {
                    GradientStop { position: 0; color: "#ffffff" }
                    GradientStop { position: 1; color: "#000000" }
                }

                ListView {
                    id: summaryList
                    anchors.fill: parent
                    model: control.summaryModel
                    delegate: Row {
                        Text { text: modelData.name }
                        Text { text: modelData.state }
                    }
                }
            }
        }

    label: Item {}
    }
}

/*
Rectangle {
    readonly property real titleHeight: 30

    property alias title: titleBar.text
    property alias setupComplete: setupIndicator.setupComplete
    //property alias summaryModel: summaryList.model

    border.color: "#888"
    radius: 10

    gradient: Gradient {
        GradientStop { position: 0 ; color: "#cccccc" }
        GradientStop { position: 1 ; color: "#aaa" }
    }

    Text {
        id: titleBar

        width: parent.width
        height: parent.titleHeight

        verticalAlignment: TextEdit.AlignVCenter
        horizontalAlignment: TextEdit.AlignHCenter

        text: qsTr("TITLE")
        font.pixelSize: 12

        Rectangle {
            id: setupIndicator

            property bool setupComplete: true
            readonly property real indicatorRadius: 6

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

            radius: indicatorRadius
            color: setupComplete ? "green" : "red"
        }
    }

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

        y: parent.titleHeight

        border.color: "#888"

        gradient: Gradient {
            GradientStop {
                position: 0
                color: "#ffffff"
            }

            GradientStop {
                position: 1
                color: "#000000"
            }
        }

        ListView {
            id: summaryList
            anchors.fill: parent
            model: ListModel {
                        ListElement { name: "Row 1"; state: "State 1" }
                        ListElement { name: "Row 2"; state: "State 2" }
                        ListElement { name: "Row 3"; state: "State 3" }
            }
            delegate: Row { Text { text: modelData.name } Text { text: modelData.state } }
        }
    }
}
*/