aboutsummaryrefslogtreecommitdiff
path: root/qml/Message.qml
blob: a217bc8103389c127e6a85f9e1ff21cc1f8b6ae9 (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
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
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQml.Models 2.1
import QtQuick.Dialogs 1.1
import org.kde.kirigami 2.12 as Kirigami

import DeltaChat 1.0

RowLayout {
    id: messageObject

    property DcMessage message
    readonly property DcContact from: context.getContact(message.fromId)

    width: ListView.view.width
    layoutDirection: message.fromId == 1 ? Qt.RightToLeft : Qt.LeftToRight

    readonly property string overrideName: message.getOverrideSenderName()
    readonly property string displayName: overrideName != "" ? ("~" + overrideName)
                                                             : messageObject.message.fromId > 0 ? messageObject.from.displayName
                                                                                                : ""

    Rectangle {
        Layout.preferredWidth: messageContents.width
        Layout.preferredHeight: messageContents.height

        Component {
            id: imageMessageView

            ColumnLayout {
                Image {
                    source: "file:" + messageObject.message.file
                    sourceSize.width: messageObject.message.width
                    sourceSize.height: messageObject.message.height
                    fillMode: Image.PreserveAspectFit
                    Layout.maximumWidth: messageObject.width
                }
                Label {
                    font.bold: true
                    color: messageObject.message.fromId > 0 ? messageObject.from.color : "black"
                    text: messageObject.displayName
                    textFormat: Text.PlainText
                }
            }
        }

        Component {
            id: textMessageView

            Label {
                font.bold: true
                color: messageObject.message.fromId > 0 ? messageObject.from.color : "black"
                text: messageObject.displayName
                textFormat: Text.PlainText
            }
        }

        color: Kirigami.Theme.backgroundColor
        radius: 5

        MouseArea {
            anchors.fill: parent

            acceptedButtons: Qt.LeftButton | Qt.RightButton
            onClicked: {
                if (mouse.button === Qt.RightButton)
                    contextMenu.popup()
            }
            onPressAndHold: {
                if (mouse.source === Qt.MouseEventNotSynthesized)
                    contextMenu.popup()
            }

            MessageDialog {
                id: messageDialog
                title: "Message info"
                text: context.getMessageInfo(messageObject.message.id)
                onAccepted: { }
            }

            Menu {
                id: contextMenu
                Action {
                    text: "Info"
                    onTriggered: messageDialog.open()
                }
                Action {
                    text: "Start chat"
                    onTriggered: context.decideOnContactRequest(message.id, 0)
                }
            }
        }

        ColumnLayout {
            id: messageContents

            anchors.centerIn: parent


            Loader {
                sourceComponent: messageObject.message.viewtype == 20 ? imageMessageView : textMessageView
            }

            TextEdit {
                Layout.maximumWidth: messageObject.width > 30 ? messageObject.width - 30 : messageObject.width
                text: messageObject.message.quotedText ? messageObject.message.quotedText : ""
                textFormat: Text.PlainText
                selectByMouse: true
                readOnly: true
                color: "grey"
                wrapMode: Text.Wrap
                font.pixelSize: 12
            }

            TextEdit {
                Layout.maximumWidth: messageObject.width > 30 ? messageObject.width - 30 : messageObject.width
                text: messageObject.message.text
                textFormat: Text.PlainText
                selectByMouse: true
                readOnly: true
                color: "black"
                wrapMode: Text.Wrap
                font.pixelSize: 14
            }
            Label {
                Layout.fillWidth: true
                text: messageObject.message.state == 26 ? "✓"
                    : messageObject.message.state == 28 ? "✓✓"
                    : messageObject.message.state == 24 ? "✗"
                    : "";
            }
        }
    }
}