Debian Codegraph @

resources/qml/TimelineBubbleMessageStyle.qml

raw ◀ ▶
1 Debian patch touch this file
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import QtQuick
6 import QtQuick.Controls
7 import QtQuick.Window
8 import im.nheko
9
10 TimelineEvent {
11 id: wrapper
12 ListView.delayRemove: true
13 width: chat.delegateMaxWidth
14 // We return a larger size for any item but the most bottom one, if it isn't initialized yet, since otherwise Qt will create way too many items.
15 // If we did that also for the first item, it would mess with the scroll location a bit, so we don't do it for that item.
16 height: Math.max((section.item?.height ?? 0) + ((gridContainer.implicitHeight < 1 && index != 0) ? 100 : gridContainer.implicitHeight) + reactionRow.implicitHeight + unreadRow.height, 10)
17 anchors.horizontalCenter: ListView.view.contentItem.horizontalCenter
18 //room: chatRoot.roommodel
19
20 required property var day
21 required property bool isSender
22 required property int index
23 property var previousMessageDay: (index + 1) >= chat.count ? 0 : chat.model.dataByIndex(index + 1, Room.Day)
24 property var previousMessageTimestamp: (index + 1) >= chat.count ? 0 : chat.model.dataByIndex(index + 1, Room.Timestamp)
25 property bool previousMessageIsStateEvent: (index + 1) >= chat.count ? true : chat.model.dataByIndex(index + 1, Room.IsStateEvent)
26 property string previousMessageUserId: (index + 1) >= chat.count ? "" : chat.model.dataByIndex(index + 1, Room.UserId)
27
28 required property date timestamp
29 required property string userId
30 required property string userName
31 required property string threadId
32 required property int userPowerlevel
33 required property bool isEdited
34 required property bool isEncrypted
35 required property var reactions
36 required property int status
37 required property int trustlevel
38 required property int notificationlevel
39 required property int type
40 required property bool isEditable
41
42 required property QtObject messageContextMenu
43 required property QtObject replyContextMenu
44 required property Item messageActions
45
46 property int avatarMargin: (wrapper.isStateEvent || Settings.smallAvatars ? 0 : (Nheko.avatarSize + 8)) // align bubble with section header
47
48 property alias hovered: messageHover.hovered
49
50 property int oneHour: 60 * 60 * 1000
51 property bool showSection: wrapper.previousMessageDay !== wrapper.day || wrapper.timestamp - wrapper.previousMessageTimestamp > oneHour
52
53 mainInset: (threadId ? (4 + Nheko.paddingSmall) : 0) + 4
54 replyInset: mainInset + 4 + Nheko.paddingSmall
55
56 property int bubbleMargin: 40
57
58 maxWidth: chat.delegateMaxWidth - avatarMargin - bubbleMargin
59
60 data: [
61 Loader {
62 id: section
63
64 active: wrapper.previousMessageUserId !== wrapper.userId || wrapper.showSection || wrapper.previousMessageIsStateEvent !== wrapper.isStateEvent
65 //asynchronous: true
66 sourceComponent: TimelineSectionHeader {
67 day: wrapper.day
68 isSender: wrapper.isSender
69 isStateEvent: wrapper.isStateEvent
70 parentWidth: wrapper.width
71 previousMessageDay: wrapper.previousMessageDay
72 previousMessageTimestamp: wrapper.previousMessageTimestamp
73 previousMessageIsStateEvent: wrapper.previousMessageIsStateEvent
74 previousMessageUserId: wrapper.previousMessageUserId
75 timestamp: wrapper.timestamp
76 userId: wrapper.userId
77 userName: wrapper.userName
78 userPowerlevel: wrapper.userPowerlevel
79 }
80 visible: status == Loader.Ready
81 z: 4
82 },
83 Rectangle {
84 anchors.fill: gridContainer
85 property color threadColor: TimelineManager.userColor(wrapper.threadId, palette.base)
86 property color threadBackgroundColor: wrapper.threadId ? Qt.tint(palette.base, Qt.hsla(threadColor.hslHue, 0.7, threadColor.hslLightness, 0.1)) : "transparent"
87 color: (Settings.messageHoverHighlight && messageHover.hovered) ? palette.alternateBase : threadBackgroundColor
88
89 // this looks better without margins
90 TapHandler {
91 acceptedButtons: Qt.RightButton
92 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
93 gesturePolicy: TapHandler.ReleaseWithinBounds
94
95 onSingleTapped: messageContextMenu.show(wrapper.eventId, wrapper.threadId, wrapper.type, wrapper.isSender, wrapper.isEncrypted, wrapper.isEditable, wrapper.main.hoveredLink, wrapper.main.copyText)
96 }
97 },
98 Rectangle {
99 id: scrollHighlight
100 anchors.fill: gridContainer
101
102 color: palette.highlight
103 enabled: false
104 opacity: 0
105 visible: true
106 z: 1
107
108 states: State {
109 name: "revealed"
110 when: wrapper.scrolledToThis
111 }
112 transitions: Transition {
113 from: ""
114 to: "revealed"
115
116 SequentialAnimation {
117 PropertyAnimation {
118 duration: 500
119 easing.type: Easing.InOutQuad
120 from: 0
121 properties: "opacity"
122 target: scrollHighlight
123 to: 1
124 }
125 PropertyAnimation {
126 duration: 500
127 easing.type: Easing.InOutQuad
128 from: 1
129 properties: "opacity"
130 target: scrollHighlight
131 to: 0
132 }
133 ScriptAction {
134 script: wrapper.room.eventShown()
135 }
136 }
137 }
138 },
139 Item {
140 id: gridContainer
141
142 width: wrapper.width - wrapper.avatarMargin
143 implicitHeight: messageBubble.implicitHeight
144 x: wrapper.avatarMargin
145 y: section.visible && section.active ? section.y + section.height : 0
146
147 HoverHandler {
148 id: messageHover
149 blocking: false
150 onHoveredChanged: () => {
151 if (!Settings.mobileMode && hovered) {
152 if (!messageActions.hovered) {
153 messageActions.model = wrapper;
154 messageActions.attached = wrapper;
155 messageActions.anchors.bottomMargin = -gridContainer.y
156 //messageActions.anchors.rightMargin = metadata.width
157 }
158 }
159 }
160
161 }
162
163
164 AbstractButton {
165 id: messageBubble
166
167 anchors.left: (wrapper.isStateEvent || wrapper.isSender) ? undefined : parent.left // qmllint disable Quick.anchor-combinations
168 anchors.right: (wrapper.isStateEvent || !wrapper.isSender) ? undefined : parent.right
169 anchors.horizontalCenter: wrapper.isStateEvent ? parent.horizontalCenter : undefined
170
171 property color userColor: TimelineManager.userColor(wrapper.main?.userId ?? '', palette.base)
172
173 contentItem: Item {
174 id: contentPlacementContainer
175
176 property bool fitsMetadata: ((wrapper.main?.width ?? 0) + wrapper.mainInset + metadata.width) < wrapper.maxWidth
177
178 // This doesnt work because of tables. They might have content in the top of the cell, while the background reaches to the bottom. Maybe using the textDocument we could do more?
179 // property bool fitsMetadataInside: wrapper.main?.positionAt ? (wrapper.main.positionAt(wrapper.main.width, wrapper.main.height - 4) == wrapper.main.positionAt(wrapper.main.width - metadata.width, wrapper.main.height - 4)) : false
180 property bool fitsMetadataInside: false
181
182 implicitWidth: Math.max((wrapper.reply?.width ?? 0) + wrapper.replyInset, (wrapper.main?.width ?? 0) + wrapper.mainInset + ((fitsMetadata && !fitsMetadataInside) ? metadata.width : 0))
183 implicitHeight: contentColumn.implicitHeight + ((fitsMetadata || fitsMetadataInside) ? 0 : metadata.height)
184
185 TimelineMetadata {
186 id: metadata
187
188 scaling: 0.75
189
190 anchors.right: parent.right
191 anchors.bottom: parent.bottom
192
193 visible: !wrapper.isStateEvent
194
195 eventId: wrapper.eventId
196 status: wrapper.status
197 trustlevel: wrapper.trustlevel
198 isEdited: wrapper.isEdited
199 isEncrypted: wrapper.isEncrypted
200 threadId: wrapper.threadId
201 timestamp: wrapper.timestamp
202 room: wrapper.room
203 }
204
205 Column {
206 id: contentColumn
207
208 anchors.left: parent.left
209 anchors.right: parent.right
210
211 AbstractButton {
212 id: replyRow
•213 visible: wrapper.replyTo
214
215 leftPadding: Nheko.paddingSmall + 4
216
217 anchors.left: parent.left
218 anchors.right: parent.right
219
220 property color userColor: TimelineManager.userColor(wrapper.reply?.userId ?? '', palette.base)
221
222 clip: true
223
224 NhekoCursorShape {
225 anchors.fill: parent
226 cursorShape: Qt.PointingHandCursor
227 }
228
•229 contentItem: Column {
230 spacing: 0
231
232 id: replyCol
233
234 AbstractButton {
235 id: replyUserButton
236
237 contentItem: Label {
238 id: userName_
•239 text: wrapper.reply?.userName ?? 'missing name'
240 color: replyRow.userColor
241 textFormat: Text.RichText
242 width: wrapper.maxWidth
243 //elideWidth: wrapper.maxWidth
244 }
245 onClicked: wrapper.room.openUserProfile(wrapper.reply?.userId)
246 }
247 data: [
248 replyUserButton,
249 wrapper.reply,
250 ]
251 }
252
253 background: Rectangle {
254 //width: replyRow.implicitContentWidth
255 color: Qt.tint(palette.base, Qt.hsla(replyRow.userColor.hslHue, 0.5, replyRow.userColor.hslLightness, 0.1))
•256 Rectangle {
257 anchors.top: parent.top
258 anchors.bottom: parent.bottom
259 anchors.left: parent.left
260
261 id: replyLine
262 color: replyRow.userColor
263 width: 4
264 }
265 }
266
267 onClicked: {
268 let link = wrapper.reply.hoveredLink
269 if (link) {
270 Nheko.openLink(link)
271 } else {
272 console.log("Scrolling to "+wrapper.replyTo);
273 wrapper.room.showEvent(wrapper.replyTo)
274 }
275 }
276 onPressAndHold: wrapper.replyContextMenu.show(wrapper.reply.copyText ?? "", wrapper.reply.linkAt ? wrapper.reply.linkAt(pressX-replyLine.width - Nheko.paddingSmall, pressY - replyUserButton.implicitHeight) : "", wrapper.replyTo)
277 TapHandler {
278 acceptedButtons: Qt.RightButton
279 onSingleTapped: (eventPoint) => wrapper.replyContextMenu.show(wrapper.reply.copyText ?? "", wrapper.reply.linkAt ? wrapper.reply.linkAt(eventPoint.position.x-replyLine.width - Nheko.paddingSmall, eventPoint.position.y - replyUserButton.implicitHeight) : "", wrapper.replyTo)
280 gesturePolicy: TapHandler.ReleaseWithinBounds
281 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
282 }
283 }
284
285 data: [replyRow, wrapper.main]
286 }
287
288
289 }
290
291 padding: wrapper.isStateEvent ? 0 : 4
292 background: Rectangle {
293 color: !wrapper.isStateEvent ? Qt.tint(palette.base, Qt.hsla(messageBubble.userColor.hslHue, wrapper.hovered ? 0.8 : 0.5, messageBubble.userColor.hslLightness, 0.2)) : "transparent"
294 radius: 4
295 border.color: Nheko.theme.red
296 border.width: wrapper.notificationlevel == MtxEvent.Highlight ? 1 : 0
297 }
298 }
299
300 DragHandler {
301 id: replyDragHandler
302 yAxis.enabled: false
303 xAxis.enabled: true
304 xAxis.minimum: wrapper.avatarMargin - 100
305 xAxis.maximum: wrapper.avatarMargin
306 onActiveChanged: {
307 if (!replyDragHandler.active) {
308 if (replyDragHandler.xAxis.minimum <= replyDragHandler.xAxis.activeValue + 1) {
309 wrapper.room.reply = wrapper.eventId
310 }
311 gridContainer.x = wrapper.avatarMargin;
312 }
313 }
314 }
315
316 TapHandler {
317 onDoubleTapped: wrapper.room.reply = wrapper.eventId
318 }
319
320 },
321 Item {
322 // We need this item to grab events, that otherwise would go to the TextArea in the main item. If we don't have this, it would trigger a right click menu on KDE...
323 // https://invent.kde.org/frameworks/qqc2-desktop-style/-/blob/9d71fe874186009f76d392e203d9fa25a49f8be7/org.kde.desktop/TextArea.qml#L55
324
325 anchors.fill: gridContainer
326 anchors.topMargin: replyRow.height
327 TapHandler {
328
329 acceptedButtons: Qt.RightButton
330 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
331 gesturePolicy: TapHandler.ReleaseWithinBounds
332
333 onSingleTapped: (event) => {
334 messageContextMenu.show(wrapper.eventId, wrapper.threadId, wrapper.type, wrapper.isSender, wrapper.isEncrypted, wrapper.isEditable, wrapper.main.hoveredLink, wrapper.main.copyText);
335 }
336 }
337 },
338 Reactions {
339 id: reactionRow
340
341 eventId: wrapper.eventId
342 layoutDirection: (!wrapper.isStateEvent && wrapper.isSender) ? Qt.RightToLeft : Qt.LeftToRight
343 reactions: wrapper.reactions
344 width: wrapper.width - wrapper.avatarMargin
345 x: wrapper.avatarMargin
346
347 anchors {
348 //left: row.bubbleOnRight ? undefined : row.left
349 //right: row.bubbleOnRight ? row.right : undefined
350 top: gridContainer.bottom
351 topMargin: -4
352 }
353 },
354 Rectangle {
355 id: unreadRow
356
357 color: palette.highlight
358 height: visible ? 3 : 0
359 visible: (wrapper.index > 0 && (wrapper.room.fullyReadEventId == wrapper.eventId))
360
361 anchors {
362 left: parent.left
363 right: parent.right
364 top: reactionRow.bottom
365 topMargin: 5
366 }
367 }
368 ]
369 }
370