summaryrefslogtreecommitdiffstats
path: root/demos/declarative/flickr/content/MediaLineEdit.qml
blob: 691bb5b70b94122f9daa435c67ed3f5b2258f2d5 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Item {
    id: Container

    property string label
    property string text

    width: Math.max(94,Label.width + Editor.width + 20)
    height: Image.height

    states: [
        State {
            name: "Edit"
            SetProperties {
                target: Label
                text: Container.label + ": "
            }
            SetProperty {
                target: Label
                property: "x"
                binding: 10
            }
            SetProperties {
                target: Editor
                cursorVisible: true
                width: 100
            }
            SetProperties {
                target: Proxy
                focus: true
            }
            RunScript {
                script:"Editor.selectAll()"
            }
        },
        State {
            // When returning to default state, typed text is propagated
            RunScript {
                script: "Container.text = Editor.text"
            }
        }
    ]
    transitions: [
        Transition {
            NumericAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" }
        }
    ]


    Image {
        id: Image
        source: "pics/button.sci"
        anchors.left: Container.left
        anchors.right: Container.right
    }

    Image {
        id: Pressed
        source: "pics/button-pressed.sci"
        opacity: 0
        anchors.left: Container.left
        anchors.right: Container.right
    }

    MouseRegion {
        id: MouseRegion
        anchors.fill: Image
        onClicked: { Container.state = Container.state=="Edit" ? "" : "Edit" }
        states: [
            State {
                when: MouseRegion.pressed == true
                SetProperties {
                    target: Pressed
                    opacity: 1
                }
            }
        ]
    }

    Text {
        id: Label
        font.bold: true
        color: "white"
        anchors.verticalCenter: Container.verticalCenter
        x: (Container.width - width)/2
        text: Container.label + "..."
    }

    TextEdit {
        id: Editor
        font.bold: true
        color: "white"
        highlightColor: "green"
        width: 0
        clip: true
        anchors.left: Label.right
        anchors.verticalCenter: Container.verticalCenter
    }
    KeyProxy {
        id: Proxy
        anchors.left: Container.left
        anchors.fill: Container
        focusable: true
        targets: [(ReturnKey), (Editor)]
    }
    KeyActions {
        id: ReturnKey
        return: "Container.state = ''"
    }
}