summaryrefslogtreecommitdiffstats
path: root/demos/declarative/photoviewer/PhotoViewerCore/EditableButton.qml
blob: ccfda02526eee668ca490bac94494a051ead9ab6 (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
import Qt 4.7

Item {
    id: container

    property string label
    property color tint: "#FFFFFFFF"
    signal clicked
    signal labelChanged(string label)

    width: labelText.width + 70 ; height: labelText.height + 18

    BorderImage {
        anchors { fill: container; leftMargin: -6; topMargin: -6; rightMargin: -8; bottomMargin: -8 }
        source: 'images/box-shadow.png'; smooth: true
        border.left: 10; border.top: 10; border.right: 10; border.bottom: 10
    }

    Image { anchors.fill: parent; source: "images/cardboard.png"; smooth: true }

    Rectangle {
        anchors.fill: container; color: container.tint; visible: container.tint != ""
        opacity: 0.1; smooth: true
    }

    Text { id: labelText; text: label; font.pixelSize: 15; anchors.centerIn: parent; smooth: true }

    TextInput {
        id: textInput; text: label; font.pixelSize: 15; anchors.centerIn: parent; smooth: true; visible: false
        Keys.onReturnPressed: container.labelChanged(textInput.text)
        Keys.onEscapePressed: {
            textInput.text = labelText.text
            container.state = ''
        }
    }

    MouseArea {
        anchors { fill: parent; leftMargin: -20; topMargin: -20; rightMargin: -20; bottomMargin: -20 }
        onClicked: container.state = "editMode"
    }

    states: State {
        name: "editMode"
        PropertyChanges { target: container; width: textInput.width + 70; height: textInput.height + 17 }
        PropertyChanges { target: textInput; visible: true; focus: true }
        PropertyChanges { target: labelText; visible: false }
    }

    onLabelChanged: {
        labelText.text = label
        container.state = ''
    }
}