aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/modelviews/visualdatamodel/ComposerBubble.qml
blob: ed77d5d53ccdf4f7cb96289edac35bf363076350 (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
import QtQuick 2.0

Bubble {
    id: composerBubble

    property bool sending: false
    property int messageId
    property bool composing: true

    signal sent;

    outbound: true
    message: messageInput.text

    gradient: Gradient {
        GradientStop { position: 0.0; color: "#C1CDCD" }
        GradientStop {
            position: 1.0
            SequentialAnimation on position {
                running: sending
                alwaysRunToEnd: true
                loops: Animation.Infinite
                NumberAnimation { duration: 1000; from: 1.0; to: 0.1 }
                NumberAnimation { duration: 1000; from: 0.1; to: 1.0 }
            }
            color: "#F8F8FF"
        }
        GradientStop { position: 1.0; color: "#F8F8FF" }
    }

    Timer {
        interval: Math.random() * 20000
        running: composerBubble.sending
        onTriggered: {
            composerBubble.sending = false
            composerBubble.sent()
        }
    }

    TextInput {
        id: messageInput

        anchors.fill: parent

        focus: composing
        activeFocusOnPress: composing
        opacity: 0.0
        selectByMouse: false

        onAccepted: root.send()
    }

    onSent: messageModel.append({ "messageId": messageId, "outbound": outbound, "sender": sender, "message": message })
}