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

201 lines
6.3 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
RowLayout {
2018-09-14 04:16:25 +00:00
readonly property bool avatarVisible: !sentByMe && (aboveAuthor !== author || aboveSection !== section || aboveEventType === "state" || aboveEventType === "emote" || aboveEventType === "other")
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
spacing: 4
2018-09-04 06:58:41 +00:00
Avatar {
Layout.preferredWidth: 32
Layout.preferredHeight: 32
Layout.alignment: Qt.AlignTop
2018-07-09 14:00:27 +00:00
2018-09-04 06:58:41 +00:00
visible: avatarVisible
hint: author.displayName
source: author.avatarMediaId
Component {
id: userDetailDialog
UserDetailDialog {}
}
RippleEffect {
anchors.fill: parent
circular: true
onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": author}).open()
}
}
Item {
Layout.preferredWidth: 32
Layout.preferredHeight: 32
visible: !(sentByMe || avatarVisible)
}
Control {
Layout.maximumWidth: messageListView.width - (!sentByMe ? 32 + root.spacing : 0) - 48
verticalPadding: 8
horizontalPadding: 16
background: Rectangle {
color: sentByMe ? MPalette.background : eventType === "notice" ? MPalette.primary : MPalette.accent
radius: 18
antialiasing: true
AutoMouseArea {
anchors.fill: parent
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-11-22 00:01:07 +00:00
Component {
id: messageDelegateContextMenu
2018-09-04 06:58:41 +00:00
MessageDelegateContextMenu {}
}
2018-09-04 06:58:41 +00:00
Component {
id: messageSourceDialog
2018-11-16 12:30:42 +00:00
MessageSourceDialog {}
}
}
}
2018-11-16 12:30:42 +00:00
contentItem: ColumnLayout {
RowLayout {
Layout.fillWidth: true
visible: replyVisible
Avatar {
Layout.preferredWidth: 28
Layout.preferredHeight: 28
Layout.alignment: Qt.AlignTop
2018-12-15 14:29:51 +00:00
source: replyVisible ? replyAuthor.avatarMediaId : ""
hint: replyVisible ? replyAuthor.displayName : "H"
2018-12-15 14:29:51 +00:00
RippleEffect {
anchors.fill: parent
2018-12-15 14:29:51 +00:00
circular: true
2018-12-15 14:29:51 +00:00
onClicked: userDetailDialog.createObject(ApplicationWindow.overlay, {"room": currentRoom, "user": replyAuthor}).open()
}
2018-11-16 12:30:42 +00:00
}
2018-09-04 06:58:41 +00:00
Control {
2018-11-27 00:09:45 +00:00
Layout.fillWidth: true
padding: 0
2018-11-27 10:14:48 +00:00
background: RippleEffect {
onClicked: goToEvent(replyEventId)
2018-11-27 00:09:45 +00:00
}
contentItem: Label {
2019-05-06 01:31:57 +00:00
Layout.fillWidth: true
2018-11-27 00:09:45 +00:00
visible: replyVisible
color: darkBackground ? "white" : MPalette.lighter
text: "<style>a{color: " + (darkBackground ? "white" : MPalette.foreground) + ";} .user-pill{}</style>" + (replyDisplay || "")
2018-11-27 00:09:45 +00:00
wrapMode: Label.Wrap
textFormat: Label.RichText
}
}
}
2018-09-04 06:58:41 +00:00
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: 1
visible: replyVisible
color: darkBackground ? "white" : MPalette.lighter
}
2018-11-27 00:09:45 +00:00
TextEdit {
Layout.fillWidth: true
id: contentLabel
text: "<style>a{color: " + (darkBackground ? "white" : MPalette.foreground) + ";} .user-pill{}</style>" + display
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
}
}
2018-11-27 00:09:45 +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
}
}