aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/modelviews/visualdatamodel/Bubble.qml
blob: de2c80763f51f5e8424af0683b9b9d119df8c609 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import QtQuick 2.0

Rectangle {
    id: content

    property int contentHeight: height - senderText.implicitHeight - 2

    x: 1;
    width: 477
    height: Math.max(messageText.implicitHeight, 48) + senderText.implicitHeight + 6

    border.width: 1
    border.color:  "#404040"
    color: outbound ? "#202020" : "#313131"

    state: delegateState

    Item {
        id: avatarItem

        width: 48; height: 48

        anchors {
            left: outbound ? undefined : parent.left; right: outbound ? parent.right: undefined
            top: parent.top
            leftMargin: 3; topMargin: 3; rightMargin: 2
        }

        Image {
            id: avatarImage
            height: 48
            anchors.centerIn: parent
            sourceSize.width: 48

            source: avatar != "" ? avatar : "images/face-smile.png"
        }

        Component {
            id: sendComponent

            Rectangle {
                id: sendButton
                anchors { fill: parent; rightMargin: 1; bottomMargin: 1 }

                color:  "#202020"

                opacity: sendArea.pressed ? 0.5 : 1.0

                Behavior on opacity { NumberAnimation { duration: 150 } }

                Rectangle {
                    anchors.fill: parent
                    radius: 4
                    color: "#080808"
                }

                Text {
                    id: sendText
                    anchors.fill: parent
                    text: "Send"

                    color: "#FFFFFF"
                    font.pixelSize: 16
                    horizontalAlignment: Text.AlignHCenter
                    verticalAlignment: Text.AlignVCenter
                }

                MouseArea {
                    id: sendArea

                    anchors.fill: parent

                    onClicked:  root.send(editorLoader.item.text)
                }
            }
        }

        Loader {
            id: sendLoader
            anchors.fill: parent
        }
    }

    Text {
        id: messageText

        anchors {
            left: outbound ? parent.left : avatarItem.right; top: parent.top
            right: outbound ? avatarItem.left : parent.right; margins: 2
        }
        color: "#FFFFFF"
        font.pixelSize: 18
        wrapMode: Text.WordWrap
        text: message
    }

    Component {
        id: editorComponent

        TextEdit {
            color: "#FFFFFF"
            font.pixelSize: 18
            wrapMode: Text.WordWrap
            focus: true

            Keys.onReturnPressed: root.send(text)
            Keys.onEnterPressed: root.send(text)
        }
    }

    Loader {
        id: editorLoader
        anchors.fill: messageText
    }

    Text {
        id: senderText
        anchors { left: parent.left; bottom: parent.bottom; margins: 2 }
        color: "#DDDDDD"
        font.pixelSize: 12
        text: sender
    }

    Text {
        id: timeText
        anchors { right: parent.right; bottom: parent.bottom; margins: 2 }
        color: "#DDDDDD"
        font.pixelSize:  12
        text: time
    }

    states: State {
        name: "composing"

        PropertyChanges { target: editorLoader; sourceComponent: editorComponent }
        PropertyChanges { target: sendLoader; sourceComponent: sendComponent }
    }

    transitions: Transition {
        from: "composing"
        NumberAnimation { target: sendLoader.item; property: "opacity"; to: 0.0; duration: 3000 }
    }
}