summaryrefslogtreecommitdiffstats
path: root/demos/declarative/contacts/Button.qml
blob: 971923160b6b3e13502607f2790aa5cee4b8448d (plain)
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
import Qt 4.6

Item {
    id: button
    width: 30
    height: 30
    property var icon: ""
    signal clicked
    Rectangle {
        id: buttonRect
        anchors.fill: parent
        color: "lightgreen"
        radius: 5
        Image {
            id: iconImage
            source: button.icon
            anchors.horizontalCenter: buttonRect.horizontalCenter
            anchors.verticalCenter: buttonRect.verticalCenter
        }
        MouseRegion {
            id: buttonMouseRegion
            anchors.fill: buttonRect
            onClicked: { button.clicked() }
        }
        states: [
            State {
                name: "pressed"
                when: buttonMouseRegion.pressed == true
                PropertyChanges {
                    target: buttonRect
                    color: "green"
                }
            }
        ]
        transitions: [
            Transition {
                from: "*"
                to: "pressed"
                ColorAnimation {
                    property: "color"
                    duration: 200
                }
            },
            Transition {
                from: "pressed"
                to: "*"
                ColorAnimation {
                    property: "color"
                    duration: 1000
                }
            }
        ]
    }
    opacity: Behavior {
        NumberAnimation {
            property: "opacity"
            duration: 250
        }
    }
}