1import QtQuick 2.7
2
3import Clipboard 1.0
4import Common 1.0
5import Linphone.Styles 1.0
6import TextToSpeech 1.0
7import Utils 1.0
8
9import 'Message.js' as Logic
10
11// =============================================================================
12
13Item {
14  id: container
15
16  // ---------------------------------------------------------------------------
17
18  property alias backgroundColor: rectangle.color
19  property alias color: message.color
20  property alias pointSize: message.font.pointSize
21
22  default property alias _content: content.data
23
24  // ---------------------------------------------------------------------------
25
26  implicitHeight: message.contentHeight + message.padding * 2
27
28  Rectangle {
29    id: rectangle
30
31    height: parent.height
32    radius: ChatStyle.entry.message.radius
33    width: (
34      message.contentWidth < parent.width
35        ? message.contentWidth
36        : parent.width
37    ) + message.padding * 2
38  }
39
40  // ---------------------------------------------------------------------------
41  // Message.
42  // ---------------------------------------------------------------------------
43
44  TextEdit {
45    id: message
46
47    anchors {
48      left: container.left
49      right: container.right
50    }
51
52    clip: true
53    padding: ChatStyle.entry.message.padding
54    readOnly: true
55    selectByMouse: true
56    text: Utils.encodeTextToQmlRichFormat($chatEntry.content, {
57      imagesHeight: ChatStyle.entry.message.images.height,
58      imagesWidth: ChatStyle.entry.message.images.width
59    })
60
61    // See http://doc.qt.io/qt-5/qml-qtquick-text.html#textFormat-prop
62    // and http://doc.qt.io/qt-5/richtext-html-subset.html
63    textFormat: Text.RichText // To supports links and imgs.
64    wrapMode: TextEdit.Wrap
65
66    onCursorRectangleChanged: Logic.ensureVisible(cursorRectangle)
67    onLinkActivated: Qt.openUrlExternally(link)
68
69    onActiveFocusChanged: deselect()
70
71    Menu {
72      id: messageMenu
73
74      MenuItem {
75        text: qsTr('menuCopy')
76        onTriggered: Clipboard.text = $chatEntry.content
77      }
78
79      MenuItem {
80        enabled: TextToSpeech.available
81        text: qsTr('menuPlayMe')
82
83        onTriggered: TextToSpeech.say($chatEntry.content)
84      }
85    }
86
87    // Handle hovered link.
88    MouseArea {
89      height: parent.height
90      width: rectangle.width
91
92      acceptedButtons: Qt.RightButton
93      cursorShape: parent.hoveredLink
94        ? Qt.PointingHandCursor
95        : Qt.IBeamCursor
96
97      onClicked: mouse.button === Qt.RightButton && messageMenu.open()
98    }
99  }
100
101  // ---------------------------------------------------------------------------
102  // Extra content.
103  // ---------------------------------------------------------------------------
104
105  Item {
106    id: content
107
108    anchors {
109      left: rectangle.right
110      leftMargin: ChatStyle.entry.message.extraContent.leftMargin
111    }
112  }
113}
114