Debian Codegraph @

resources/qml/TimelineBubbleMessageStyle.qml

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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.reply
214
215 height: replyLine.height
216 anchors.left: parent.left
217 anchors.right: parent.right
218
219 property color userColor: TimelineManager.userColor(wrapper.reply?.userId ?? '', palette.base)
220
221 clip: true
222
223 NhekoCursorShape {
224 anchors.fill: parent
225 cursorShape: Qt.PointingHandCursor
226 }
227
228 contentItem: Row {
229 id: replyRowLay
230
231 spacing: Nheko.paddingSmall
232
233 Rectangle {
234 id: replyLine
235 height: Math.min( wrapper.reply?.height, timelineView.height / 10) + Nheko.paddingSmall + replyUserButton.height
236 color: replyRow.userColor
237 width: 4
238 }
239
240 Column {
241 spacing: 0
242
243 id: replyCol
244
245 AbstractButton {
246 id: replyUserButton
247
248 contentItem: Label {
249 id: userName_
250 text: wrapper.reply?.userName ?? ''
251 color: replyRow.userColor
252 textFormat: Text.RichText
253 width: wrapper.maxWidth
254 //elideWidth: wrapper.maxWidth
255 }
256 onClicked: wrapper.room.openUserProfile(wrapper.reply?.userId)
257 }
258 data: [
259 replyUserButton,
260 wrapper.reply,
261 ]
262 }
263 }
264
265 background: Rectangle {
266 //width: replyRow.implicitContentWidth
267 color: Qt.tint(palette.base, Qt.hsla(replyRow.userColor.hslHue, 0.5, replyRow.userColor.hslLightness, 0.1))
268 }
269
270 onClicked: {
271 let link = wrapper.reply.hoveredLink
272 if (link) {
273 Nheko.openLink(link)
274 } else {
275 console.log("Scrolling to "+wrapper.replyTo);
276 wrapper.room.showEvent(wrapper.replyTo)
277 }
278 }
279 onPressAndHold: wrapper.replyContextMenu.show(wrapper.reply.copyText ?? "", wrapper.reply.linkAt ? wrapper.reply.linkAt(pressX-replyLine.width - Nheko.paddingSmall, pressY - replyUserButton.implicitHeight) : "", wrapper.replyTo)
280 TapHandler {
281 acceptedButtons: Qt.RightButton
282 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)
283 gesturePolicy: TapHandler.ReleaseWithinBounds
284 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
285 }
286 }
287
288 data: [replyRow, wrapper.main]
289 }
290
291
292 }
293
294 padding: wrapper.isStateEvent ? 0 : 4
295 background: Rectangle {
296 color: !wrapper.isStateEvent ? Qt.tint(palette.base, Qt.hsla(messageBubble.userColor.hslHue, wrapper.hovered ? 0.8 : 0.5, messageBubble.userColor.hslLightness, 0.2)) : "transparent"
297 radius: 4
298 border.color: Nheko.theme.red
299 border.width: wrapper.notificationlevel == MtxEvent.Highlight ? 1 : 0
300 }
301 }
302
303 DragHandler {
304 id: replyDragHandler
305 yAxis.enabled: false
306 xAxis.enabled: true
307 xAxis.minimum: wrapper.avatarMargin - 100
308 xAxis.maximum: wrapper.avatarMargin
309 onActiveChanged: {
310 if (!replyDragHandler.active) {
311 if (replyDragHandler.xAxis.minimum <= replyDragHandler.xAxis.activeValue + 1) {
312 wrapper.room.reply = wrapper.eventId
313 }
314 gridContainer.x = wrapper.avatarMargin;
315 }
316 }
317 }
318
319 TapHandler {
320 onDoubleTapped: wrapper.room.reply = wrapper.eventId
321 }
322
323 },
324 Item {
325 // 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...
326 // https://invent.kde.org/frameworks/qqc2-desktop-style/-/blob/9d71fe874186009f76d392e203d9fa25a49f8be7/org.kde.desktop/TextArea.qml#L55
327
328 anchors.fill: gridContainer
329 anchors.topMargin: replyRow.height
330 TapHandler {
331
332 acceptedButtons: Qt.RightButton
333 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
334 gesturePolicy: TapHandler.ReleaseWithinBounds
335
336 onSingleTapped: (event) => {
337 messageContextMenu.show(wrapper.eventId, wrapper.threadId, wrapper.type, wrapper.isSender, wrapper.isEncrypted, wrapper.isEditable, wrapper.main.hoveredLink, wrapper.main.copyText);
338 }
339 }
340 },
341 Reactions {
342 id: reactionRow
343
344 eventId: wrapper.eventId
345 layoutDirection: (!wrapper.isStateEvent && wrapper.isSender) ? Qt.RightToLeft : Qt.LeftToRight
346 reactions: wrapper.reactions
347 width: wrapper.width - wrapper.avatarMargin
348 x: wrapper.avatarMargin
349
350 anchors {
351 //left: row.bubbleOnRight ? undefined : row.left
352 //right: row.bubbleOnRight ? row.right : undefined
353 top: gridContainer.bottom
354 topMargin: -4
355 }
356 },
357 Rectangle {
358 id: unreadRow
359
360 color: palette.highlight
361 height: visible ? 3 : 0
362 visible: (wrapper.index > 0 && (wrapper.room.fullyReadEventId == wrapper.eventId))
363
364 anchors {
365 left: parent.left
366 right: parent.right
367 top: reactionRow.bottom
368 topMargin: 5
369 }
370 }
371 ]
372 }
373