2018-07-12 01:44:41 +00:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.2
|
2018-09-04 06:58:41 +00:00
|
|
|
import QtQuick.Layouts 1.3
|
2018-07-12 01:44:41 +00:00
|
|
|
import QtQuick.Controls.Material 2.2
|
2018-09-17 13:01:02 +00:00
|
|
|
import Spectral 0.1
|
|
|
|
import Spectral.Settings 0.1
|
2018-09-10 01:51:02 +00:00
|
|
|
import "qrc:/js/util.js" as Util
|
2018-07-09 14:00:27 +00:00
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
RowLayout {
|
2018-09-14 04:16:25 +00:00
|
|
|
readonly property bool avatarVisible: !sentByMe && (aboveAuthor !== author || aboveSection !== section || aboveEventType === "state" || aboveEventType === "emote" || aboveEventType === "other")
|
2018-09-06 13:00:58 +00:00
|
|
|
readonly property bool highlighted: !(sentByMe || eventType === "notice" )
|
2018-08-01 12:26:29 +00:00
|
|
|
readonly property bool sentByMe: author === currentRoom.localUser
|
2018-09-04 06:58:41 +00:00
|
|
|
readonly property bool isText: eventType === "notice" || eventType === "message"
|
2018-08-01 12:26:29 +00:00
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
signal saveFileAs()
|
|
|
|
signal openExternally()
|
|
|
|
|
2018-07-20 04:14:02 +00:00
|
|
|
z: -5
|
2018-07-09 14:00:27 +00:00
|
|
|
|
2018-09-04 13:13:14 +00:00
|
|
|
id: messageRow
|
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft
|
|
|
|
|
|
|
|
spacing: 6
|
|
|
|
|
2018-09-10 01:51:02 +00:00
|
|
|
ImageItem {
|
2018-09-04 06:58:41 +00:00
|
|
|
Layout.preferredWidth: 40
|
|
|
|
Layout.preferredHeight: 40
|
|
|
|
Layout.alignment: Qt.AlignTop
|
2018-07-09 14:00:27 +00:00
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
round: false
|
|
|
|
visible: avatarVisible
|
2018-09-10 01:51:02 +00:00
|
|
|
hint: author.displayName
|
|
|
|
image: author.avatar
|
2018-09-04 06:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
Layout.preferredWidth: 40
|
|
|
|
Layout.preferredHeight: 40
|
|
|
|
Layout.alignment: Qt.AlignTop
|
2018-08-24 05:25:41 +00:00
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
color: "transparent"
|
|
|
|
visible: !(sentByMe || avatarVisible)
|
2018-08-04 12:40:23 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
GenericBubble {
|
|
|
|
Layout.maximumWidth: messageListView.width - (!sentByMe ? 40 + messageRow.spacing : 0)
|
|
|
|
|
|
|
|
id: genericBubble
|
|
|
|
|
2018-09-06 13:00:58 +00:00
|
|
|
highlighted: messageRow.highlighted
|
2018-09-06 04:34:15 +00:00
|
|
|
colored: highlighted && (eventType === "notice" || highlight)
|
2018-09-04 06:58:41 +00:00
|
|
|
|
|
|
|
contentItem: ColumnLayout {
|
|
|
|
id: messageColumn
|
|
|
|
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
AutoLabel {
|
|
|
|
visible: messageRow.avatarVisible
|
|
|
|
text: author.displayName
|
|
|
|
Material.foreground: Material.accent
|
|
|
|
coloredBackground: highlighted
|
|
|
|
font.bold: true
|
2018-09-10 01:51:02 +00:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
onClicked: inputField.insert(inputField.cursorPosition, author.displayName)
|
|
|
|
}
|
2018-09-04 06:58:41 +00:00
|
|
|
}
|
|
|
|
|
2018-09-17 00:13:45 +00:00
|
|
|
TextEdit {
|
2018-09-04 06:58:41 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
2018-09-24 12:52:24 +00:00
|
|
|
text: (highlighted ? "<style>a{color: white;} .user-pill{color: white}</style>" : "<style>a{color: " + Material.accent + ";} .user-pill{color: " + Material.accent + "}</style>") + display
|
2018-09-17 00:13:45 +00:00
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
visible: isText
|
2018-09-17 00:13:45 +00:00
|
|
|
color: highlighted ? "white": Material.foreground
|
|
|
|
|
|
|
|
font.family: "Noto Sans"
|
|
|
|
font.pointSize: 10
|
|
|
|
selectByMouse: true
|
|
|
|
readOnly: true
|
|
|
|
wrapMode: Label.Wrap
|
2018-09-17 03:58:02 +00:00
|
|
|
selectedTextColor: highlighted ? Material.accent : "white"
|
|
|
|
selectionColor: highlighted ? "white" : Material.accent
|
2018-09-17 00:13:45 +00:00
|
|
|
textFormat: Text.RichText
|
|
|
|
|
|
|
|
onLinkActivated: Qt.openUrlExternally(link)
|
2018-09-04 06:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Loader {
|
|
|
|
sourceComponent: {
|
|
|
|
switch (eventType) {
|
|
|
|
case "image":
|
|
|
|
return imageComponent
|
|
|
|
case "file":
|
|
|
|
return fileComponent
|
|
|
|
case "audio":
|
|
|
|
return audioComponent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
active: eventType === "image" || eventType === "file" || eventType === "audio"
|
|
|
|
}
|
|
|
|
|
2018-09-13 05:05:51 +00:00
|
|
|
Row {
|
2018-09-04 06:58:41 +00:00
|
|
|
Layout.alignment: Qt.AlignRight
|
2018-09-13 05:05:51 +00:00
|
|
|
|
2018-09-16 12:56:47 +00:00
|
|
|
spacing: 4
|
2018-09-13 05:05:51 +00:00
|
|
|
|
2018-09-19 23:01:55 +00:00
|
|
|
AutoLabel {
|
|
|
|
visible: userMarker.length > 5
|
|
|
|
text: userMarker.length - 5 + "+"
|
|
|
|
coloredBackground: highlighted
|
|
|
|
Material.foreground: "grey"
|
|
|
|
font.pointSize: 8
|
|
|
|
}
|
|
|
|
|
2018-09-15 13:09:53 +00:00
|
|
|
Repeater {
|
2018-09-17 12:47:09 +00:00
|
|
|
model: userMarker.length > 5 ? userMarker.slice(0, 5) : userMarker
|
2018-09-15 13:09:53 +00:00
|
|
|
|
|
|
|
ImageItem {
|
|
|
|
width: parent.height
|
|
|
|
height: parent.height
|
|
|
|
|
|
|
|
hint: modelData.displayName
|
|
|
|
image: modelData.avatar
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 05:05:51 +00:00
|
|
|
AutoLabel {
|
|
|
|
id: timeLabel
|
|
|
|
|
|
|
|
visible: Math.abs(time - aboveTime) > 600000 || index == 0
|
|
|
|
text: Qt.formatTime(time, "hh:mm")
|
|
|
|
coloredBackground: highlighted
|
|
|
|
Material.foreground: "grey"
|
|
|
|
font.pointSize: 8
|
|
|
|
}
|
2018-09-04 06:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: imageComponent
|
|
|
|
|
|
|
|
DownloadableContent {
|
|
|
|
width: messageImage.width
|
|
|
|
height: messageImage.height
|
|
|
|
|
2018-09-04 13:13:14 +00:00
|
|
|
id: downloadable
|
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
AutoImage {
|
|
|
|
z: -4
|
2018-09-04 13:13:14 +00:00
|
|
|
|
|
|
|
id: messageImage
|
|
|
|
|
2018-09-04 06:58:41 +00:00
|
|
|
sourceSize: 128
|
|
|
|
source: "image://mxc/" + (content.thumbnail_url ? content.thumbnail_url : content.url)
|
|
|
|
|
|
|
|
onClicked: downloadAndOpen()
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
messageRow.saveFileAs.connect(saveFileAs)
|
|
|
|
messageRow.openExternally.connect(downloadAndOpen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: fileComponent
|
|
|
|
|
|
|
|
AutoLabel {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
id: downloadDelegate
|
|
|
|
|
|
|
|
text: "<b>File: </b>" + content.body
|
|
|
|
coloredBackground: highlighted
|
|
|
|
|
|
|
|
background: DownloadableContent {
|
|
|
|
id: downloadable
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
messageRow.saveFileAs.connect(saveFileAs)
|
|
|
|
messageRow.openExternally.connect(downloadAndOpen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: audioComponent
|
|
|
|
|
|
|
|
AutoLabel {
|
|
|
|
id: downloadDelegate
|
|
|
|
|
|
|
|
text: content.info.duration / 1000 + '"'
|
|
|
|
coloredBackground: highlighted
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
propagateComposedEvents: true
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
if (downloadable.downloaded)
|
2018-09-17 13:01:02 +00:00
|
|
|
spectralController.playAudio(progressInfo.localPath)
|
2018-09-04 06:58:41 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
playOnFinished = true
|
|
|
|
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_") + ".tmp")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
background: DownloadableContent {
|
|
|
|
id: downloadable
|
|
|
|
|
2018-09-17 13:01:02 +00:00
|
|
|
onDownloadedChanged: downloaded && playOnFinished ? spectralController.playAudio(progressInfo.localPath) : {}
|
2018-09-04 06:58:41 +00:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
messageRow.saveFileAs.connect(saveFileAs)
|
|
|
|
messageRow.openExternally.connect(downloadAndOpen)
|
|
|
|
}
|
|
|
|
}
|
2018-08-13 14:44:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-09 14:00:27 +00:00
|
|
|
}
|
|
|
|
}
|