Spectral/qml/component/MessageDelegate.qml

74 lines
2.3 KiB
QML
Raw Normal View History

2018-07-12 01:44:41 +00:00
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
2018-07-09 14:00:27 +00:00
Item {
2018-07-10 04:18:21 +00:00
id: messageDelegate
2018-07-20 04:14:02 +00:00
readonly property bool darkTheme: Material.theme == Material.Dark
readonly property color background: darkTheme ? "#242424" : "lightgrey"
2018-07-09 14:00:27 +00:00
readonly property bool sentByMe: author === currentRoom.localUser
readonly property bool isState: eventType === "state" || eventType === "emote"
readonly property bool isMessage: eventType === "message" || eventType === "notice"
readonly property bool isFile: eventType === "video" || eventType === "audio" || eventType === "file" || eventType === "image"
visible: eventType != "redaction"
2018-07-20 04:14:02 +00:00
z: -5
2018-07-10 04:18:21 +00:00
width: delegateLoader.width
height: delegateLoader.height
2018-07-09 14:00:27 +00:00
anchors.right: !isState && sentByMe ? parent.right : undefined
anchors.horizontalCenter: isState ? parent.horizontalCenter : undefined
2018-07-09 14:00:27 +00:00
MouseArea {
anchors.fill: parent
onPressAndHold: {
menuLoader.sourceComponent = menuComponent
menuLoader.item.popup()
}
Component {
id: menuComponent
Menu {
id: messageContextMenu
MenuItem {
text: "Copy"
onTriggered: matriqueController.copyToClipboard(plainText)
}
MenuItem {
visible: isFile
height: visible ? undefined : 0
text: "Open Externally"
onTriggered: delegateLoader.item.downloadAndOpen()
}
MenuItem {
visible: isFile
height: visible ? undefined : 0
text: "Save As"
onTriggered: delegateLoader.item.saveFileAs()
}
MenuItem {
visible: sentByMe
height: visible ? undefined : 0
text: "Redact"
onTriggered: currentRoom.redactEvent(eventId)
}
}
}
}
Loader {
id: menuLoader
}
2018-07-10 04:18:21 +00:00
Loader {
id: delegateLoader
source: eventType != "redaction" ? isMessage ? "MessageBubble.qml" : isState ? "StateBubble.qml" : isFile ? eventType === "image" ? "ImageBubble.qml" : "FileBubble.qml" : "" : ""
2018-07-09 14:00:27 +00:00
}
}