summaryrefslogtreecommitdiffstats
path: root/examples/declarative/tutorials/contacts/t8/FieldText.qml
blob: d3a158a9fa6a904d7b85354363d97cc59f8bc7c8 (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
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
<Item height="30" id="fieldText">
    <properties>
        <Property name="open" value="false"/>
        <Property name="text" value="" onValueChanged="setText(fieldText.text)"/>
        <Property name="label" value=""/>
    </properties>
    <signals>
        <Signal name="textEdited"/>
    </signals>
    <resources>
        <Script>
            function start() {
                if (Page.mouseGrabbed != 'true') {
                    fieldText.state='editing';
                    open='true';
                    Page.mouseGrabbed='true';
                }
            }
            function confirm() {
                fieldText.text = textEdit.text;
                fieldText.state='';
                open='false';
                Page.mouseGrabbed='false';
                fieldText.textEdited.emit();
            }
            function cancel() {
                textEdit.text = fieldText.text;
                fieldText.state='';
                open='false';
                Page.mouseGrabbed='false';
            }
            function setText(value) {
                if (textEdit.text != value) {
                    fieldText.state='';
                    open='false';
                    textEdit.text = value;
                }
            }
        </Script>
    </resources>
    <Rect id="border" radius="5" anchors.fill="{parent}" color="{field.editable == 1 ? '#202020' : '#000000'}">
        <TextEdit id="textEdit" vAlign="AlignVCenter" text=""
            readOnly="true" font.bold="true" wrap="false" color="white"
            x="5" width="{parent.width-10}"
            anchors.verticalCenter="{parent.verticalCenter}"
            />
        <Text id="textLabel" vAlign="AlignVCenter" hAlign="AlignHCenter"
            color="#505050" font.italic="true"
            anchors.fill="{border}" text="{fieldText.label}"
            opacity="{textEdit.text == '' ? 1 : 0}">
            <opacity>
                <Behaviour>
                    <NumericAnimation target="{textLabel}" property="opacity" duration="250"/>
                </Behaviour>
            </opacity>
        </Text>
        <Image id="cancelIcon" src="../shared/pics/cancel.png"
            width="22" height="22" opacity="0"
            anchors.right="{parent.right}" anchors.rightMargin="4"
            anchors.verticalCenter="{parent.verticalCenter}"/>
        <Image id="confirmIcon" src="../shared/pics/ok.png"
            width="22" height="22" opacity="0"
            anchors.left="{parent.left}" anchors.leftMargin="4"
            anchors.verticalCenter="{parent.verticalCenter}"/>
        <MouseRegion anchors.fill="{cancelIcon}" onClicked="cancel()"/>
        <MouseRegion anchors.fill="{confirmIcon}" onClicked="confirm()"/>
        <MouseRegion id="editRegion" anchors.fill="{textEdit}" onClicked="start()"/>
    </Rect>
    <states>
        <State name="editing">
            <SetProperty target="{confirmIcon}" property="opacity" value="1"/>
            <SetProperty target="{cancelIcon}" property="opacity" value="1"/>
            <SetProperty target="{border}" property="color" value="white"/>
            <SetProperty target="{textEdit}" property="color" value="black"/>
            <SetProperty target="{textEdit}" property="readOnly" value="false"/>
            <SetProperty target="{textEdit}" property="focus" value="true"/>
            <SetProperty target="{textEdit}" property="x" value="35"/>
            <SetProperty target="{editRegion}" property="opacity" value="0"/>
        </State>
    </states>
    <transitions>
        <Transition fromState='' toState="*" reversible="true">
            <NumericAnimation target="{textEdit}" properties="x" duration="200"/>
            <NumericAnimation target="{confirmIcon}" properties="opacity" duration="200"/>
            <NumericAnimation target="{cancelIcon}" properties="opacity" duration="200"/>
            <ColorAnimation duration="150"/>
        </Transition>
    </transitions>
</Item>