summaryrefslogtreecommitdiffstats
path: root/demos/declarative/calculator/CalcButton.qml
blob: c9253142f47e5146429c91cd2b3fb4a88925cc46 (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
<Item id="Button" width="50" height="30">

    <properties>
        <Property name="operation" type="string"/>
        <Property name="toggable" value="false"/>
        <Property name="toggled" value="false"/>
    </properties>

    <Script>
        function buttonClicked(operation) {
            if (Button.toggable == true) {
                if (Button.toggled == true) {
                    Button.toggled = false;
                    Button.state = 'Toggled';
                } else {
                    Button.toggled = true;
                    Button.state = '';
                }
            }
            else
                doOp(operation);
        }
    </Script>

    <Image id="Image" src="pics/button.sci" width="{Button.width}" height="{Button.height}"/>
    <Image id="ImagePressed" src="pics/button-pressed.sci" width="{Button.width}" height="{Button.height}" opacity="0"/>
    <Text anchors.centeredIn="{Image}" text="{Button.operation}" color="white" font.bold="true"/>
    <MouseRegion id="MouseRegion" anchors.fill="{Button}" onClicked="buttonClicked(Button.operation)"/>

    <states>
        <State name="Pressed" when="{MouseRegion.pressed == true}">
            <SetProperties target="{ImagePressed}" opacity="1"/>
        </State>
        <State name="Toggled" when="{Button.toggled == true}">
            <SetProperties target="{ImagePressed}" opacity="1"/>
        </State>
    </states>

</Item>