summaryrefslogtreecommitdiffstats
path: root/demos/declarative/calculator/CalcButton.qml
blob: ebb19672dd6cb864cefbf5e918e308fd5e59787e (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

Rect {
    property string operation
    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: G1; position: 0.0; color: Palette.lighter(Palette.button) }
        GradientStop { id: G2; position: 1.0; color: Palette.button }
    }

    Text { anchors.centerIn: parent; text: operation; color: Palette.buttonText }

    MouseRegion {
        id: MouseRegion
        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: MouseRegion.pressed == true
            SetProperties { target: G1; color: Palette.dark }
            SetProperties { target: G2; color: Palette.button }
        },
        State {
            name: "Toggled"; when: Button.toggled == true
            SetProperties { target: G1; color: Palette.dark }
            SetProperties { target: G2; color: Palette.button }
        }
    ]
}