Spectral/imports/Spectral/Component/Timeline/MessageDelegate.qml

250 lines
7.8 KiB
QML
Raw Normal View History

2018-12-07 01:18:42 +00:00
import QtQuick 2.12
2018-12-22 14:25:03 +00:00
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls.Material 2.12
2018-10-01 08:07:48 +00:00
import Spectral 0.1
2018-10-01 08:07:48 +00:00
import Spectral.Setting 0.1
import Spectral.Component 2.0
import Spectral.Dialog 2.0
2019-04-30 03:05:35 +00:00
import Spectral.Menu.Timeline 2.0
import Spectral.Effect 2.0
2019-05-10 11:26:17 +00:00
ColumnLayout {
2019-05-09 13:18:04 +00:00
readonly property bool avatarVisible: !sentByMe && showAuthor
readonly property bool sentByMe: author === currentRoom.localUser
readonly property bool darkBackground: !sentByMe
readonly property bool replyVisible: replyEventId || false
2018-09-04 06:58:41 +00:00
signal saveFileAs()
signal openExternally()
id: root
2018-09-04 13:13:14 +00:00
z: -5
2018-09-04 06:58:41 +00:00
2019-05-10 11:26:17 +00:00
spacing: 0
2018-09-04 06:58:41 +00:00
2019-05-10 11:26:17 +00:00
RowLayout {
Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft
2019-05-10 11:26:17 +00:00
id: messageRow
2018-07-09 14:00:27 +00:00
2019-05-10 11:26:17 +00:00
spacing: 4
2019-05-10 11:26:17 +00:00
Avatar {
2019-05-11 13:03:44 +00:00
Layout.preferredWidth: 36
Layout.preferredHeight: 36
Layout.alignment: Qt.AlignBottom
2019-05-10 11:26:17 +00:00
visible: avatarVisible
hint: author.displayName
source: author.avatarMediaId
2019-05-10 11:26:17 +00:00
Component {
id: userDetailDialog
2019-05-10 11:26:17 +00:00
UserDetailDialog {}
}
2019-05-10 11:26:17 +00:00
RippleEffect {
anchors.fill: parent
2019-05-10 11:26:17 +00:00
circular: true
2019-05-10 11:26:17 +00:00
onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": author}).open()
}
}
2019-05-10 11:26:17 +00:00
Item {
2019-05-11 13:03:44 +00:00
Layout.preferredWidth: 36
Layout.preferredHeight: 36
2019-05-10 11:26:17 +00:00
visible: !(sentByMe || avatarVisible)
}
2019-05-10 11:26:17 +00:00
Control {
2019-05-11 13:03:44 +00:00
Layout.maximumWidth: messageListView.width - (!sentByMe ? 36 + messageRow.spacing : 0) - 48
2019-05-17 07:01:01 +00:00
padding: 0
2019-05-09 13:18:04 +00:00
2019-05-17 07:01:01 +00:00
background: AutoRectangle {
readonly property int minorRadius: 2
2019-05-09 13:18:04 +00:00
2019-05-17 07:01:01 +00:00
id: bubbleBackground
2019-05-09 13:18:04 +00:00
2019-05-17 07:01:01 +00:00
color: sentByMe ? MPalette.background : eventType === "notice" ? MPalette.primary : MPalette.accent
radius: 18
2019-05-09 13:18:04 +00:00
2019-05-19 18:03:37 +00:00
topLeftVisible: true
topRightVisible: true
bottomLeftVisible: true
bottomRightVisible: true
2019-05-17 07:01:01 +00:00
topLeftRadius: minorRadius
topRightRadius: minorRadius
bottomLeftRadius: minorRadius
bottomRightRadius: minorRadius
2018-11-22 00:01:07 +00:00
2019-05-10 11:26:17 +00:00
AutoMouseArea {
anchors.fill: parent
2018-11-22 00:01:07 +00:00
2019-05-10 11:26:17 +00:00
id: messageMouseArea
onSecondaryClicked: {
var contextMenu = messageDelegateContextMenu.createObject(ApplicationWindow.overlay)
contextMenu.viewSource.connect(function() {
messageSourceDialog.createObject(ApplicationWindow.overlay, {"sourceText": toolTip}).open()
})
contextMenu.reply.connect(function() {
roomPanelInput.replyUser = author
roomPanelInput.replyEventID = eventId
roomPanelInput.replyContent = contentLabel.selectedText || message
roomPanelInput.isReply = true
roomPanelInput.focus()
})
contextMenu.redact.connect(function() {
currentRoom.redactEvent(eventId)
})
contextMenu.popup()
}
2018-09-04 06:58:41 +00:00
2019-05-10 11:26:17 +00:00
Component {
id: messageDelegateContextMenu
MessageDelegateContextMenu {}
}
Component {
id: messageSourceDialog
2018-11-16 12:30:42 +00:00
2019-05-10 11:26:17 +00:00
MessageSourceDialog {}
}
}
}
2018-11-16 12:30:42 +00:00
2019-05-10 11:26:17 +00:00
contentItem: ColumnLayout {
2019-05-17 07:01:01 +00:00
spacing: 0
2019-05-17 07:01:01 +00:00
Control {
2019-05-10 11:26:17 +00:00
Layout.fillWidth: true
2018-12-15 14:29:51 +00:00
2019-05-19 18:24:36 +00:00
Layout.topMargin: 4
Layout.leftMargin: 4
Layout.rightMargin: 4
2018-12-15 14:29:51 +00:00
2019-05-19 18:24:36 +00:00
padding: 8
2019-05-17 11:29:41 +00:00
rightPadding: 12
2018-12-15 14:29:51 +00:00
2019-05-10 11:26:17 +00:00
visible: replyVisible
2018-12-15 14:29:51 +00:00
2019-05-17 07:01:01 +00:00
contentItem: RowLayout {
Avatar {
Layout.preferredWidth: 28
Layout.preferredHeight: 28
Layout.alignment: Qt.AlignTop
2018-09-04 06:58:41 +00:00
2019-05-17 07:01:01 +00:00
source: replyVisible ? replyAuthor.avatarMediaId : ""
hint: replyVisible ? replyAuthor.displayName : "H"
2018-11-27 00:09:45 +00:00
2019-05-17 07:01:01 +00:00
RippleEffect {
anchors.fill: parent
2019-05-17 07:01:01 +00:00
circular: true
2018-11-27 10:14:48 +00:00
2019-05-17 07:01:01 +00:00
onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": replyAuthor}).open()
}
2019-05-10 11:26:17 +00:00
}
2018-11-27 00:09:45 +00:00
2019-05-17 07:01:01 +00:00
Label {
Layout.fillWidth: true
2019-05-17 07:01:01 +00:00
color: !sentByMe ? MPalette.foreground : "white"
2019-05-18 08:32:36 +00:00
text: "<style>a{color: " + color + ";} .user-pill{}</style>" + (replyDisplay || "")
2018-11-27 00:09:45 +00:00
2019-05-10 11:26:17 +00:00
wrapMode: Label.Wrap
textFormat: Label.RichText
}
}
2018-09-04 06:58:41 +00:00
2019-05-17 11:29:41 +00:00
background: Rectangle {
2019-05-17 07:01:01 +00:00
color: sentByMe ? MPalette.accent : MPalette.background
2019-05-19 18:24:36 +00:00
radius: 0
2019-05-17 07:01:01 +00:00
AutoMouseArea {
anchors.fill: parent
onClicked: goToEvent(replyEventId)
}
}
2019-05-10 11:26:17 +00:00
}
TextEdit {
Layout.fillWidth: true
2018-11-27 00:09:45 +00:00
2019-05-17 07:01:01 +00:00
Layout.leftMargin: 16
Layout.rightMargin: 16
Layout.topMargin: 8
Layout.bottomMargin: 8
2019-05-10 11:26:17 +00:00
id: contentLabel
2019-05-18 08:32:36 +00:00
text: "<style>a{color: " + color + ";} .user-pill{}</style>" + display
2019-05-10 11:26:17 +00:00
color: darkBackground ? "white" : MPalette.foreground
font.family: window.font.family
font.pixelSize: 14
selectByMouse: true
readOnly: true
wrapMode: Label.Wrap
selectedTextColor: darkBackground ? MPalette.accent : "white"
selectionColor: darkBackground ? "white" : MPalette.accent
textFormat: Text.RichText
onLinkActivated: {
if (link.startsWith("https://matrix.to/")) {
var result = link.replace(/\?.*/, "").match("https://matrix.to/#/(!.*:.*)/(\\$.*:.*)")
if (!result || result.length < 3) return
if (result[1] != currentRoom.id) return
if (!result[2]) return
goToEvent(result[2])
} else {
Qt.openUrlExternally(link)
}
2018-11-27 00:09:45 +00:00
}
2019-05-10 11:26:17 +00:00
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
2018-09-04 06:58:41 +00:00
}
}
}
2018-07-09 14:00:27 +00:00
}
2019-05-10 11:26:17 +00:00
RowLayout {
Layout.alignment: sentByMe ? Qt.AlignRight : Qt.AlignLeft
2019-05-11 13:03:44 +00:00
Layout.leftMargin: sentByMe ? undefined : 36 + messageRow.spacing + 12
2019-05-10 11:26:17 +00:00
Layout.rightMargin: sentByMe ? 12 : undefined
Layout.bottomMargin: 4
visible: showAuthor
2019-05-10 11:26:17 +00:00
Label {
visible: !sentByMe
2019-05-10 11:26:17 +00:00
text: author.displayName
2019-05-10 11:26:17 +00:00
color: MPalette.lighter
}
Label {
text: Qt.formatTime(time, "hh:mm AP")
2019-05-10 11:26:17 +00:00
color: MPalette.lighter
}
}
2018-07-09 14:00:27 +00:00
}