summaryrefslogtreecommitdiffstats
path: root/demos/declarative/flickr/common/MediaLineEdit.qml
blob: 7599ce6a05d663426ea9ab7a07a05b58dfeb0af7 (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: MyMouseRegion
        anchors.fill: ButtonImage
        onClicked: { Container.state = Container.state=="Edit" ? "" : "Edit" }
        states: [
            State {
                when: MyMouseRegion.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 = ''"
    }
}