summaryrefslogtreecommitdiffstats
path: root/demos/declarative/calculator/CalcButton.qml
blob: 6210e460888a0979ba3d57b50371465936a12d18 (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
import Qt 4.6

Rectangle {
    property alias operation: label.text
    property bool toggable: false
    property bool toggled: false
    signal clicked

    id: button; width: 50; height: 30
    border.color: palette.mid; radius: 6
    gradient: Gradient {
        GradientStop { id: gradientStop1; position: 0.0; color: Qt.lighter(palette.button) }
        GradientStop { id: gradientStop2; position: 1.0; color: palette.button }
    }

    Text { id: label; anchors.centerIn: parent; color: palette.buttonText }

    MouseArea {
        id: clickRegion
        anchors.fill: parent
        onClicked: {
            doOp(operation);
            button.clicked();
            if (!button.toggable) return;
            button.toggled ? button.toggled = false : button.toggled = true
        }
    }

    states: [
        State {
            name: "Pressed"; when: clickRegion.pressed == true
            PropertyChanges { target: gradientStop1; color: palette.dark }
            PropertyChanges { target: gradientStop2; color: palette.button }
        },
        State {
            name: "Toggled"; when: button.toggled == true
            PropertyChanges { target: gradientStop1; color: palette.dark }
            PropertyChanges { target: gradientStop2; color: palette.button }
        }
    ]
}