aboutsummaryrefslogtreecommitdiff
path: root/qml/ComposePane.qml
blob: dab07f1959693346b7debe222f945727c04a5e16 (plain) (blame)
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
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12

import DeltaChat 1.0

Pane {
    id: root

    required property DcContext context
    required property var chatId

    padding: 0

    RowLayout {
        width: parent.width

        TextArea {
            id: messageField

            Layout.fillWidth: true
            placeholderText: qsTr("Message")
            wrapMode: TextArea.Wrap
            selectByMouse: true

            Component.onCompleted: {
                let draft = root.context.getDraft(chatId)
                if (draft) {
                    messageField.text = draft.text
                }
            }

            Connections {
                function onEditingFinished() {
                    var msg = root.context.newMessage(10)
                    msg.setText(messageField.text)
                    root.context.setDraft(chatId, msg)
                }
            }
        }

        Button {
            id: sendButton

            Layout.alignment: Qt.AlignBottom

            icon.name: "document-send"
            text: qsTr("Send")
            enabled: messageField.length > 0
            onClicked: {
                let DC_MSG_TEXT = 10;

                let msg = root.context.newMessage(DC_MSG_TEXT);
                msg.setText(messageField.text)
                root.context.sendMessage(root.chatId, msg)

                messageField.text = ""
                root.context.setDraft(chatId, null)
            }
        }
    }
}