Debian Codegraph @

resources/qml/TimelineDefaultMessageStyle.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)
54 replyInset: mainInset + 4 + Nheko.paddingSmall
55
56 maxWidth: chat.delegateMaxWidth - avatarMargin - metadata.width
57
58 data: [
59 Loader {
60 id: section
61
62 active: wrapper.previousMessageUserId !== wrapper.userId || wrapper.showSection || wrapper.previousMessageIsStateEvent !== wrapper.isStateEvent
63 //asynchronous: true
64 sourceComponent: TimelineSectionHeader {
65 day: wrapper.day
66 isSender: wrapper.isSender
67 isStateEvent: wrapper.isStateEvent
68 parentWidth: wrapper.width
69 previousMessageDay: wrapper.previousMessageDay
70 previousMessageTimestamp: wrapper.previousMessageTimestamp
71 previousMessageIsStateEvent: wrapper.previousMessageIsStateEvent
72 previousMessageUserId: wrapper.previousMessageUserId
73 timestamp: wrapper.timestamp
74 userId: wrapper.userId
75 userName: wrapper.userName
76 userPowerlevel: wrapper.userPowerlevel
77 }
78 visible: status == Loader.Ready
79 z: 4
80 },
81 Rectangle {
82 // this looks better without margins
83 anchors.fill: gridContainer
84 color: (Settings.messageHoverHighlight && messageHover.hovered) ? palette.alternateBase : "transparent"
85
86 // This is partially duplicated by a later handler, however we need this to handle the remaining events around the reply.
87 TapHandler {
88 acceptedButtons: Qt.RightButton
89 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
90 gesturePolicy: TapHandler.ReleaseWithinBounds
91
92 onSingleTapped: (event) => {
93 messageContextMenu.show(wrapper.eventId, wrapper.threadId, wrapper.type, wrapper.isSender, wrapper.isEncrypted, wrapper.isEditable, wrapper.main.hoveredLink, wrapper.main.copyText);
94 event.accepted = true;
95 }
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: {
135 wrapper.room.eventShown();
136 }
137 }
138 }
139 }
140 },
141 Row {
142 id: gridContainer
143
144 width: wrapper.width - wrapper.avatarMargin
145 x: wrapper.avatarMargin
146 y: section.visible && section.active ? section.y + section.height : 0
147 spacing: Nheko.paddingSmall
148
149 HoverHandler {
150 id: messageHover
151 blocking: false
152 onHoveredChanged: () => {
153 if (!Settings.mobileMode && hovered) {
154 if (!messageActions.hovered) {
155 messageActions.model = wrapper;
156 messageActions.attached = wrapper;
157 messageActions.anchors.bottomMargin = -gridContainer.y
158 messageActions.anchors.rightMargin = metadata.width
159 }
160 }
161 }
162
163 }
164
165 AbstractButton {
166 ToolTip.delay: Nheko.tooltipDelay
167 ToolTip.text: qsTr("Part of a thread")
168 ToolTip.visible: hovered
169 height: contentColumn.height
170 visible: wrapper.threadId
171 width: 4
172
173 onClicked: wrapper.room.thread = wrapper.threadId
174
175 Rectangle {
176 id: threadLine
177
178 anchors.fill: parent
179 color: TimelineManager.userColor(wrapper.threadId, palette.base)
180 }
181 }
182
183 Item {
184 id: stateEventSpacing
185 visible: wrapper.isStateEvent
186 width: (wrapper.maxWidth - (wrapper.main?.width ?? 0)) / 2
187 height: 1
188 }
189
190 Column {
191 id: contentColumn
192
193 AbstractButton {
194 id: replyRow
195 visible: wrapper.reply
196
197 height: replyLine.height
198
199 property color userColor: TimelineManager.userColor(wrapper.reply?.userId ?? '', palette.base)
200
201 clip: true
202
203 NhekoCursorShape {
204 anchors.fill: parent
205 cursorShape: Qt.PointingHandCursor
206 }
207
208 contentItem: Row {
209 id: replyRowLay
210
211 spacing: Nheko.paddingSmall
212
213 Rectangle {
214 id: replyLine
215 height: Math.min( wrapper.reply?.height, timelineView.height / 10) + Nheko.paddingSmall + replyUserButton.height
216 color: replyRow.userColor
217 width: 4
218 }
219
220 Column {
221 spacing: 0
222
223 id: replyCol
224
225 AbstractButton {
226 id: replyUserButton
227
228 contentItem: Label {
229 id: userName_
230 text: wrapper.reply?.userName ?? ''
231 color: replyRow.userColor
232 textFormat: Text.RichText
233 width: wrapper.maxWidth
234 //elideWidth: wrapper.maxWidth
235 }
236 onClicked: wrapper.room.openUserProfile(wrapper.reply?.userId)
237 }
238 data: [
239 replyUserButton,
240 wrapper.reply,
241 ]
242 }
243 }
244
245 background: Rectangle {
246 //width: replyRow.implicitContentWidth
247 color: Qt.tint(palette.base, Qt.hsla(replyRow.userColor.hslHue, 0.5, replyRow.userColor.hslLightness, 0.1))
248 }
249
250 onClicked: {
251 let link = wrapper.reply.hoveredLink
252 if (link) {
253 Nheko.openLink(link)
254 } else {
255 console.log("Scrolling to "+wrapper.replyTo);
256 wrapper.room.showEvent(wrapper.replyTo)
257 }
258 }
259 onPressAndHold: wrapper.replyContextMenu.show(wrapper.reply.copyText ?? "", wrapper.reply.linkAt ? wrapper.reply.linkAt(pressX-replyLine.width - Nheko.paddingSmall, pressY - replyUserButton.implicitHeight) : "", wrapper.replyTo)
260 TapHandler {
261 acceptedButtons: Qt.RightButton
262 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)
263 gesturePolicy: TapHandler.ReleaseWithinBounds
264 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
265 }
266 }
267
268 data: [
269 replyRow, wrapper.main,
270 ]
271 }
272
273 DragHandler {
274 id: replyDragHandler
275 enabled: !Settings.disableSwipe
276 yAxis.enabled: false
277 xAxis.enabled: true
278 xAxis.minimum: wrapper.avatarMargin - 100
279 xAxis.maximum: wrapper.avatarMargin
280 onActiveChanged: {
281 if (!replyDragHandler.active) {
282 if (replyDragHandler.xAxis.minimum <= replyDragHandler.xAxis.activeValue + 1) {
283 wrapper.room.reply = wrapper.eventId
284 }
285 gridContainer.x = wrapper.avatarMargin;
286 }
287 }
288 }
289
290 TapHandler {
291 onDoubleTapped: wrapper.room.reply = wrapper.eventId
292 }
293 },
294 Rectangle {
295 anchors.top: gridContainer.top
296 anchors.left: gridContainer.left
297 anchors.topMargin: -2
298 anchors.leftMargin: -2 + (stateEventSpacing.visible ? (stateEventSpacing.width + gridContainer.spacing) : 0)
299 color: "transparent"
300 border.color: Nheko.theme.red
301 border.width: wrapper.notificationlevel == MtxEvent.Highlight ? 1 : 0
302 radius: 4
303 height: contentColumn.implicitHeight + 4
304 width: contentColumn.implicitWidth + 4 + (wrapper.threadId ? (4 + gridContainer.spacing) : 0)
305 },
306 TimelineMetadata {
307 id: metadata
308
309 scaling: 1
310
311 anchors.right: parent.right
312 y: section.visible && section.active ? section.y + section.height : 0
313
314 visible: !wrapper.isStateEvent
315
316 eventId: wrapper.eventId
317 status: wrapper.status
318 trustlevel: wrapper.trustlevel
319 isEdited: wrapper.isEdited
320 isEncrypted: wrapper.isEncrypted
321 threadId: wrapper.threadId
322 timestamp: wrapper.timestamp
323 room: wrapper.room
324 },
325 Item {
326 // 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...
327 // https://invent.kde.org/frameworks/qqc2-desktop-style/-/blob/9d71fe874186009f76d392e203d9fa25a49f8be7/org.kde.desktop/TextArea.qml#L55
328
329 anchors.fill: gridContainer
330 anchors.topMargin: replyRow.height
331 TapHandler {
332
333 acceptedButtons: Qt.RightButton
334 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
335 gesturePolicy: TapHandler.ReleaseWithinBounds
336
337 onSingleTapped: (event) => {
338 messageContextMenu.show(wrapper.eventId, wrapper.threadId, wrapper.type, wrapper.isSender, wrapper.isEncrypted, wrapper.isEditable, wrapper.main.hoveredLink, wrapper.main.copyText);
339 }
340 }
341 },
342 Reactions {
343 id: reactionRow
344
345 eventId: wrapper.eventId
346 reactions: wrapper.reactions
347 width: wrapper.width - wrapper.avatarMargin
348 x: wrapper.avatarMargin
349
350 anchors {
351 top: gridContainer.bottom
352 topMargin: -4
353 }
354 },
355 Rectangle {
356 id: unreadRow
357
358 color: palette.highlight
359 height: visible ? 3 : 0
360 visible: (wrapper.index > 0 && (wrapper.room.fullyReadEventId == wrapper.eventId))
361
362 anchors {
363 left: parent.left
364 right: parent.right
365 top: reactionRow.bottom
366 topMargin: 5
367 }
368 }
369 ]
370 }