nheko/resources/qml/TimelineRow.qml

251 lines
10 KiB
QML
Raw Normal View History

2021-03-05 00:35:15 +01:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
//
2021-03-05 00:35:15 +01:00
// SPDX-License-Identifier: GPL-3.0-or-later
2020-10-08 21:11:21 +02:00
import "./delegates"
import "./emoji"
2021-02-14 01:28:28 +01:00
import QtQuick 2.12
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.2
import QtQuick.Window 2.13
import im.nheko 1.0
2020-07-26 02:06:38 +02:00
Item {
id: r
required property double proportionalHeight
required property int type
required property string typeString
required property int originalWidth
required property string blurhash
required property string body
required property string formattedBody
required property string eventId
required property string filename
required property string filesize
required property string url
required property string thumbnailUrl
required property bool isOnlyEmoji
required property bool isSender
required property bool isEncrypted
required property bool isEditable
required property bool isEdited
required property bool isStateEvent
required property string replyTo
required property string userId
required property string userName
2021-07-12 01:28:09 +02:00
required property string roomTopic
required property string roomName
required property string callType
required property var reactions
required property int trustlevel
required property int encryptionError
required property var timestamp
required property int status
required property int relatedEventCacheBuster
width: parent.width
height: childrenRect.height
2020-10-08 21:11:21 +02:00
Rectangle {
2021-05-13 08:23:56 +02:00
color: (Settings.messageHoverHighlight && hoverHandler.hovered) ? Nheko.colors.alternateBase : "transparent"
anchors.fill: row
}
2021-02-14 01:28:28 +01:00
HoverHandler {
id: hoverHandler
2021-01-19 03:25:56 +01:00
2021-02-14 01:28:28 +01:00
acceptedDevices: PointerDevice.GenericPointer
}
TapHandler {
acceptedButtons: Qt.RightButton
onSingleTapped: messageContextMenu.show(eventId, type, isSender, isEncrypted, isEditable, contentItem.child.hoveredLink, contentItem.child.copyText)
2021-04-11 22:24:39 +02:00
gesturePolicy: TapHandler.ReleaseWithinBounds
2021-02-14 01:28:28 +01:00
}
TapHandler {
onLongPressed: messageContextMenu.show(eventId, type, isSender, isEncrypted, isEditable, contentItem.child.hoveredLink, contentItem.child.copyText)
onDoubleTapped: chat.model.reply = eventId
2021-04-11 22:24:39 +02:00
gesturePolicy: TapHandler.ReleaseWithinBounds
2020-10-08 21:11:21 +02:00
}
2022-02-05 21:53:21 +01:00
Control {
2020-10-08 21:11:21 +02:00
id: row
property bool bubbleOnRight : isSender && Settings.bubbles
anchors.rightMargin: isSender || !Settings.bubbles? 0 : parent.width/8
anchors.leftMargin: (Settings.bubbles? 0 : Nheko.avatarSize) + (bubbleOnRight? parent.width/8 : 8) // align bubble with section header
anchors.left: bubbleOnRight? undefined : parent.left
anchors.right: bubbleOnRight? parent.right : undefined
property int maxWidth: parent.width-anchors.leftMargin-anchors.rightMargin
width: Settings.bubbles? Math.min(maxWidth,implicitWidth+metadata.width) : maxWidth
padding: isStateEvent? 0 : 2
2022-02-05 21:53:21 +01:00
background: Rectangle {
2022-02-04 23:12:30 +01:00
property color userColor: TimelineManager.userColor(userId, Nheko.colors.base)
property color bgColor: Nheko.colors.base
color: Qt.tint(bgColor, Qt.rgba(userColor.r, userColor.g, userColor.b, 0.2))
radius: parent.padding*2
visible: Settings.bubbles && !isStateEvent
2022-02-04 23:12:30 +01:00
}
contentItem: GridLayout {
id: msg
2022-02-09 21:36:04 +01:00
property bool narrowLayout: Settings.bubbles //&& (timelineView.width < 500) // timelineView causes fewew binding loops than r. But maybe it shouldn't depend on width anyway
rowSpacing: 0
2022-02-05 21:53:21 +01:00
columnSpacing: 2
columns: narrowLayout? 1 : 2
rows: narrowLayout? 3 : 2
2020-10-08 21:11:21 +02:00
// fancy reply, if this is a reply
Reply {
Layout.row: 0
Layout.column: 0
Layout.fillWidth: true
2022-02-05 21:53:21 +01:00
Layout.bottomMargin: visible? 2 : 0
Layout.preferredHeight: height
Layout.maximumWidth: implicitWidth
id: reply
2021-07-12 22:28:01 +02:00
function fromModel(role) {
return replyTo != "" ? room.dataById(replyTo, role, r.eventId) : null;
2021-07-12 22:28:01 +02:00
}
visible: replyTo
userColor: r.relatedEventCacheBuster, TimelineManager.userColor(userId, Nheko.colors.base)
blurhash: r.relatedEventCacheBuster, fromModel(Room.Blurhash) ?? ""
body: r.relatedEventCacheBuster, fromModel(Room.Body) ?? ""
formattedBody: r.relatedEventCacheBuster, fromModel(Room.FormattedBody) ?? ""
2021-07-12 22:28:01 +02:00
eventId: fromModel(Room.EventId) ?? ""
filename: r.relatedEventCacheBuster, fromModel(Room.Filename) ?? ""
filesize: r.relatedEventCacheBuster, fromModel(Room.Filesize) ?? ""
proportionalHeight: r.relatedEventCacheBuster, fromModel(Room.ProportionalHeight) ?? 1
type: r.relatedEventCacheBuster, fromModel(Room.Type) ?? MtxEvent.UnknownMessage
typeString: r.relatedEventCacheBuster, fromModel(Room.TypeString) ?? ""
url: r.relatedEventCacheBuster, fromModel(Room.Url) ?? ""
originalWidth: r.relatedEventCacheBuster, fromModel(Room.OriginalWidth) ?? 0
isOnlyEmoji: r.relatedEventCacheBuster, fromModel(Room.IsOnlyEmoji) ?? false
isStateEvent: r.relatedEventCacheBuster, fromModel(Room.IsStateEvent) ?? false
userId: r.relatedEventCacheBuster, fromModel(Room.UserId) ?? ""
userName: r.relatedEventCacheBuster, fromModel(Room.UserName) ?? ""
thumbnailUrl: r.relatedEventCacheBuster, fromModel(Room.ThumbnailUrl) ?? ""
roomTopic: r.relatedEventCacheBuster, fromModel(Room.RoomTopic) ?? ""
roomName: r.relatedEventCacheBuster, fromModel(Room.RoomName) ?? ""
callType: r.relatedEventCacheBuster, fromModel(Room.CallType) ?? ""
encryptionError: r.relatedEventCacheBuster, fromModel(Room.EncryptionError) ?? ""
relatedEventCacheBuster: r.relatedEventCacheBuster, fromModel(Room.RelatedEventCacheBuster) ?? 0
2020-10-08 21:11:21 +02:00
}
// actual message content
MessageDelegate {
Layout.row: 1
Layout.column: 0
Layout.fillWidth: true
Layout.preferredHeight: height
Layout.maximumWidth: implicitWidth
2020-10-08 21:11:21 +02:00
id: contentItem
blurhash: r.blurhash
body: r.body
formattedBody: r.formattedBody
eventId: r.eventId
filename: r.filename
filesize: r.filesize
proportionalHeight: r.proportionalHeight
type: r.type
typeString: r.typeString ?? ""
url: r.url
thumbnailUrl: r.thumbnailUrl
originalWidth: r.originalWidth
isOnlyEmoji: r.isOnlyEmoji
isStateEvent: r.isStateEvent
userId: r.userId
userName: r.userName
2021-07-12 01:28:09 +02:00
roomTopic: r.roomTopic
roomName: r.roomName
callType: r.callType
encryptionError: r.encryptionError
relatedEventCacheBuster: r.relatedEventCacheBuster
isReply: false
2020-10-08 21:11:21 +02:00
}
RowLayout {
id: metadata
Layout.column: msg.narrowLayout? 0 : 1
Layout.row: msg.narrowLayout? 2 : 0
Layout.rowSpan: msg.narrowLayout? 1 : 2
Layout.bottomMargin: -4
Layout.alignment: Qt.AlignTop | Qt.AlignRight
Layout.preferredWidth: implicitWidth
visible: !isStateEvent
2022-02-05 21:53:21 +01:00
property double scaling: msg.narrowLayout? 0.75 : 1
StatusIndicator {
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Layout.preferredHeight: 16*parent.scaling
Layout.preferredWidth: 16*parent.scaling
status: r.status
eventId: r.eventId
}
2020-10-08 21:11:21 +02:00
Image {
visible: isEdited || eventId == chat.model.edit
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Layout.preferredHeight: 16*parent.scaling
Layout.preferredWidth: 16*parent.scaling
sourceSize.width: 16 * Screen.devicePixelRatio*parent.scaling
sourceSize.height: 16 * Screen.devicePixelRatio*parent.scaling
source: "image://colorimage/:/icons/icons/ui/edit.svg?" + ((eventId == chat.model.edit) ? Nheko.colors.highlight : Nheko.colors.buttonText)
ToolTip.visible: editHovered.hovered
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: qsTr("Edited")
HoverHandler {
id: editHovered
}
2020-10-08 21:11:21 +02:00
}
2020-10-08 21:11:21 +02:00
EncryptionIndicator {
visible: room.isEncrypted
encrypted: isEncrypted
trust: trustlevel
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Layout.preferredHeight: 16*parent.scaling
Layout.preferredWidth: 16*parent.scaling
sourceSize.width: 16 * Screen.devicePixelRatio*parent.scaling
sourceSize.height: 16 * Screen.devicePixelRatio*parent.scaling
}
2020-10-08 21:11:21 +02:00
Label {
Layout.alignment: Qt.AlignRight | Qt.AlignTop
Layout.preferredWidth: implicitWidth
text: timestamp.toLocaleTimeString(Locale.ShortFormat)
color: Nheko.inactiveColors.text
ToolTip.visible: ma.hovered
ToolTip.delay: Nheko.tooltipDelay
ToolTip.text: Qt.formatDateTime(timestamp, Qt.DefaultLocaleLongDate)
font.pointSize: 10*parent.scaling
HoverHandler {
id: ma
}
2020-10-08 21:11:21 +02:00
}
}
2021-11-11 04:43:37 +01:00
}
2022-02-05 21:53:21 +01:00
}
Reactions {
anchors {
top: row.bottom
topMargin: -2
2022-02-05 21:53:21 +01:00
left: parent.left
leftMargin: Nheko.avatarSize + 16
}
2021-11-11 04:43:37 +01:00
2022-02-05 21:53:21 +01:00
id: reactionRow
2020-10-08 21:11:21 +02:00
2022-02-05 21:53:21 +01:00
reactions: r.reactions
eventId: r.eventId
2020-10-08 21:11:21 +02:00
}
}