2019-12-19 22:46:16 +11:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-12-28 00:06:42 +11:00
|
|
|
import Clipboard 0.1
|
2019-12-03 07:29:29 +11:00
|
|
|
import "../../.."
|
2019-12-18 19:53:08 +11:00
|
|
|
import "../../../Base"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-12-17 18:45:00 +11:00
|
|
|
HColumnLayout {
|
2019-07-20 13:07:26 +10:00
|
|
|
id: eventDelegate
|
2019-09-03 17:04:57 +10:00
|
|
|
width: eventList.width
|
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
ListView.onRemove: eventList.delegatesUnchecked(model.id)
|
|
|
|
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
enum Media { Page, File, Image, Video, Audio }
|
|
|
|
|
|
|
|
property var hoveredMediaTypeUrl: []
|
|
|
|
|
2019-07-20 13:07:26 +10:00
|
|
|
// Remember timeline goes from newest message at index 0 to oldest
|
2019-12-17 18:45:00 +11:00
|
|
|
readonly property var previousModel: eventList.model.get(model.index + 1)
|
|
|
|
readonly property var nextModel: eventList.model.get(model.index - 1)
|
|
|
|
readonly property QtObject currentModel: model
|
2019-07-03 13:32:39 +10:00
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
property bool checked: model.id in eventList.checkedDelegates
|
2020-03-23 04:30:03 +11:00
|
|
|
property bool compact: window.settings.compactMode
|
2019-12-09 20:25:31 +11:00
|
|
|
property bool isOwn: chat.userId === model.sender_id
|
2019-07-20 13:07:26 +10:00
|
|
|
property bool onRight: eventList.ownEventsOnRight && isOwn
|
2019-12-17 18:45:00 +11:00
|
|
|
property bool combine: eventList.canCombine(previousModel, model)
|
|
|
|
property bool talkBreak: eventList.canTalkBreak(previousModel, model)
|
|
|
|
property bool dayBreak: eventList.canDayBreak(previousModel, model)
|
2019-07-20 10:55:52 +10:00
|
|
|
|
2020-03-24 07:10:13 +11:00
|
|
|
readonly property bool smallAvatar: compact
|
2019-07-20 13:07:26 +10:00
|
|
|
readonly property bool collapseAvatar: combine
|
|
|
|
readonly property bool hideAvatar: onRight
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-20 13:07:26 +10:00
|
|
|
readonly property bool hideNameLine:
|
2019-11-05 05:37:25 +11:00
|
|
|
model.event_type === "RoomMessageEmote" ||
|
2019-11-05 05:45:20 +11:00
|
|
|
! (
|
|
|
|
model.event_type.startsWith("RoomMessage") ||
|
|
|
|
model.event_type.startsWith("RoomEncrypted")
|
|
|
|
) ||
|
2019-07-20 13:07:26 +10:00
|
|
|
onRight ||
|
|
|
|
combine
|
2019-04-20 17:29:24 +10:00
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
readonly property int cursorShape:
|
|
|
|
eventContent.hoveredLink || hoveredMediaTypeUrl.length > 0 ?
|
|
|
|
Qt.PointingHandCursor :
|
|
|
|
|
|
|
|
eventContent.hoveredSelectable ? Qt.IBeamCursor :
|
|
|
|
|
|
|
|
Qt.ArrowCursor
|
|
|
|
|
2019-12-17 18:45:00 +11:00
|
|
|
readonly property int separationSpacing:
|
|
|
|
dayBreak ? theme.spacing * 4 :
|
|
|
|
talkBreak ? theme.spacing * 6 :
|
2020-03-23 04:20:16 +11:00
|
|
|
combine ? theme.spacing / (compact ? 4 : 2) :
|
|
|
|
theme.spacing * (compact ? 1 : 2)
|
2019-12-17 18:45:00 +11:00
|
|
|
|
2020-03-27 11:31:19 +11:00
|
|
|
readonly property alias leftTapHandler: leftTapHandler
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
// Needed because of eventList's MouseArea which steals the
|
|
|
|
// HSelectableLabel's MouseArea hover events
|
|
|
|
onCursorShapeChanged: eventList.cursorShape = cursorShape
|
|
|
|
|
2019-09-01 19:16:47 +10:00
|
|
|
|
2019-09-06 06:24:49 +10:00
|
|
|
function json() {
|
2020-02-13 04:04:46 +11:00
|
|
|
let event = ModelStore.get(chat.userId, chat.roomId, "events")
|
2020-03-20 09:49:33 +11:00
|
|
|
.get(model.index)
|
2020-02-13 04:04:46 +11:00
|
|
|
event = JSON.parse(JSON.stringify(event))
|
|
|
|
event.source = JSON.parse(event.source)
|
|
|
|
return JSON.stringify(event, null, 4)
|
2019-09-06 06:24:49 +10:00
|
|
|
}
|
|
|
|
|
2019-09-15 08:52:43 +10:00
|
|
|
function openContextMenu() {
|
|
|
|
contextMenu.media = eventDelegate.hoveredMediaTypeUrl
|
|
|
|
contextMenu.link = eventContent.hoveredLink
|
|
|
|
contextMenu.popup()
|
|
|
|
}
|
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
function toggleChecked() {
|
|
|
|
eventDelegate.checked ?
|
|
|
|
eventList.delegatesUnchecked(model.index) :
|
|
|
|
eventList.delegatesChecked(model.index)
|
|
|
|
}
|
|
|
|
|
2019-09-06 06:24:49 +10:00
|
|
|
|
2019-12-17 18:45:00 +11:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight:
|
|
|
|
model.event_type === "RoomCreateEvent" ? 0 : separationSpacing
|
|
|
|
}
|
|
|
|
|
2019-07-20 16:21:12 +10:00
|
|
|
Daybreak {
|
|
|
|
visible: dayBreak
|
2019-12-17 18:45:00 +11:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumWidth: parent.width
|
2019-04-29 04:48:59 +10:00
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-20 16:27:17 +10:00
|
|
|
Item {
|
|
|
|
visible: dayBreak
|
2019-12-17 18:45:00 +11:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.preferredHeight: separationSpacing
|
2019-07-20 16:27:17 +10:00
|
|
|
}
|
|
|
|
|
2019-07-03 12:29:09 +10:00
|
|
|
EventContent {
|
2019-09-02 09:03:32 +10:00
|
|
|
id: eventContent
|
2019-12-17 18:45:00 +11:00
|
|
|
|
|
|
|
Layout.fillWidth: true
|
2019-09-02 09:03:32 +10:00
|
|
|
|
2019-12-16 19:42:41 +11:00
|
|
|
Behavior on x { HNumberAnimation {} }
|
2019-04-29 04:48:59 +10:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
TapHandler {
|
2020-03-27 11:31:19 +11:00
|
|
|
id: leftTapHandler
|
2020-03-26 14:06:51 +11:00
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
onTapped: toggleChecked()
|
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
|
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.RightButton
|
2020-03-25 04:52:48 +11:00
|
|
|
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Pen
|
2019-09-15 08:52:43 +10:00
|
|
|
onTapped: openContextMenu()
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
|
|
|
|
2020-03-25 01:42:41 +11:00
|
|
|
TapHandler {
|
|
|
|
acceptedPointerTypes: PointerDevice.Finger | PointerDevice.Pen
|
|
|
|
onLongPressed: openContextMenu()
|
|
|
|
}
|
|
|
|
|
2019-09-02 09:03:32 +10:00
|
|
|
HMenu {
|
|
|
|
id: contextMenu
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
property var media: []
|
2019-09-02 09:03:32 +10:00
|
|
|
property string link: ""
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
onClosed: { media = []; link = "" }
|
2019-09-03 17:04:57 +10:00
|
|
|
|
2020-03-26 14:06:51 +11:00
|
|
|
HMenuItem {
|
|
|
|
icon.name: "toggle-select-message"
|
|
|
|
text: eventDelegate.checked ? qsTr("Unselect") : qsTr("Select")
|
|
|
|
onTriggered: eventDelegate.toggleChecked()
|
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
visible: eventList.selectedCount >= 2
|
|
|
|
icon.name: "unselect-all-messages"
|
|
|
|
text: qsTr("Unselect all")
|
|
|
|
onTriggered: eventList.checkedDelegates = {}
|
|
|
|
}
|
|
|
|
|
2019-09-03 17:04:57 +10:00
|
|
|
HMenuItem {
|
2019-09-15 08:33:32 +10:00
|
|
|
id: copyMedia
|
2019-09-03 17:04:57 +10:00
|
|
|
icon.name: "copy-link"
|
2019-09-15 08:33:32 +10:00
|
|
|
text:
|
|
|
|
contextMenu.media.length < 1 ? "" :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.Page ?
|
|
|
|
qsTr("Copy page address") :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.File ?
|
|
|
|
qsTr("Copy file address") :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.Image ?
|
|
|
|
qsTr("Copy image address") :
|
|
|
|
|
2019-09-18 13:23:47 +10:00
|
|
|
contextMenu.media[0] === EventDelegate.Media.Video ?
|
|
|
|
qsTr("Copy video address") :
|
|
|
|
|
|
|
|
contextMenu.media[0] === EventDelegate.Media.Audio ?
|
|
|
|
qsTr("Copy audio address") :
|
|
|
|
|
2019-09-15 08:33:32 +10:00
|
|
|
qsTr("Copy media address")
|
|
|
|
|
|
|
|
visible: Boolean(text)
|
2019-10-25 23:42:04 +11:00
|
|
|
onTriggered: Clipboard.text = contextMenu.media[1]
|
2019-09-03 17:04:57 +10:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
id: copyLink
|
|
|
|
icon.name: "copy-link"
|
|
|
|
text: qsTr("Copy link address")
|
|
|
|
visible: Boolean(contextMenu.link)
|
2019-10-25 23:42:04 +11:00
|
|
|
onTriggered: Clipboard.text = contextMenu.link
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy-text"
|
|
|
|
text: qsTr("Copy text")
|
2020-03-26 14:06:51 +11:00
|
|
|
visible: ! copyLink.visible && ! copyMedia.visible
|
|
|
|
onTriggered: {
|
|
|
|
if (! eventList.selectedCount) {
|
|
|
|
Clipboard.text = JSON.parse(model.source).body
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-27 12:23:43 +11:00
|
|
|
eventList.copySelectedDelegates()
|
2020-03-26 14:06:51 +11:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
2019-09-06 06:09:04 +10:00
|
|
|
|
2019-12-21 01:39:10 +11:00
|
|
|
HMenuItem {
|
|
|
|
icon.name: "debug"
|
|
|
|
text: qsTr("Debug this event")
|
|
|
|
onTriggered: eventContent.debugConsoleLoader.toggle()
|
|
|
|
}
|
|
|
|
|
2019-12-21 01:29:45 +11:00
|
|
|
HMenuItemPopupSpawner {
|
2019-09-09 01:40:39 +10:00
|
|
|
icon.name: "clear-messages"
|
|
|
|
text: qsTr("Clear messages")
|
2019-12-21 01:29:45 +11:00
|
|
|
|
|
|
|
popup: "Popups/ClearMessagesPopup.qml"
|
|
|
|
popupParent: chat
|
|
|
|
properties: ({userId: chat.userId, roomId: chat.roomId})
|
2019-09-09 01:40:39 +10:00
|
|
|
}
|
2019-09-02 09:03:32 +10:00
|
|
|
}
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|