summaryrefslogtreecommitdiffstats
path: root/demos/declarative/flickr/common/MediaLineEdit.qml
blob: 4b21f662b77ba2bef7ab7caf7072f1c83ef08a50 (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
import Qt 4.6

Item {
    id: container

    property string label
    property string text

    width: Math.max(94,label.width + editor.width + 20)
    height: buttonImage.height

    states: [
        State {
            name: "Edit"
            PropertyChanges {
                target: label
                text: container.label + ": "
            }
            PropertyChanges {
                target: label
                x: 10
            }
            PropertyChanges {
                target: editor
                cursorVisible: true
                width: 100
            }
            PropertyChanges {
                target: container
                focus: true
            }
            StateChangeScript {
                script:"editor.selectAll()"
            }
        },
        State {
            // When returning to default state, typed text is propagated
            StateChangeScript {
                script: "container.text = editor.text"
            }
        }
    ]
    transitions: [
        Transition {
            NumberAnimation { properties: "x,width"; duration: 500; easing: "easeInOutQuad" }
        }
    ]


    BorderImage {
        id: buttonImage
        source: "pics/button.sci"
        anchors.left: container.left
        anchors.right: container.right
    }

    BorderImage {
        id: pressed
        source: "pics/button-pressed.sci"
        opacity: 0
        anchors.left: container.left
        anchors.right: container.right
    }

    MouseRegion {
        id: mouseRegion
        anchors.fill: buttonImage
        onClicked: { container.state = container.state=="Edit" ? "" : "Edit" }
        states: [
            State {
                when: mouseRegion.pressed == true
                PropertyChanges {
                    target: pressed
                    opacity: 1
                }
            }
        ]
    }

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

    TextInput {
        id: editor
        font.bold: true
        color: "white"
        selectionColor: "green"
        width: 0
        clip: true
        anchors.left: label.right
        anchors.verticalCenter: container.verticalCenter
    }
    Keys.forwardTo: [(returnKey), (editor)]
    Item {
        id: returnKey
        Keys.onReturnPressed: "container.state = ''"
    }
}