Debian Codegraph @

resources/qml/TimelineDefaultMessageStyle.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)
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.replyTo
196
•197 leftPadding: Nheko.paddingSmall + 4
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: Column {
209 spacing: 0
210
211 id: replyCol
212
213 AbstractButton {
214 id: replyUserButton
215
216 contentItem: Label {
217 id: userName_
•218 text: wrapper.reply?.userName ?? 'missing name'
219 color: replyRow.userColor
220 textFormat: Text.RichText
221 width: wrapper.maxWidth
222 //elideWidth: wrapper.maxWidth
223 }
224 onClicked: wrapper.room.openUserProfile(wrapper.reply?.userId)
225 }
226 data: [
227 replyUserButton,
228 wrapper.reply,
229 ]
230 }
231
232 background: Rectangle {
233 color: Qt.tint(palette.base, Qt.hsla(replyRow.userColor.hslHue, 0.5, replyRow.userColor.hslLightness, 0.1))
•234
235 Rectangle {
236 anchors.top: parent.top
237 anchors.bottom: parent.bottom
238 anchors.left: parent.left
239
240 id: replyLine
241 color: replyRow.userColor
242 width: 4
243 }
244 }
245
246 onClicked: {
247 let link = wrapper.reply.hoveredLink
248 if (link) {
249 Nheko.openLink(link)
250 } else {
251 console.log("Scrolling to "+wrapper.replyTo);
252 wrapper.room.showEvent(wrapper.replyTo)
253 }
254 }
255 onPressAndHold: wrapper.replyContextMenu.show(wrapper.reply.copyText ?? "", wrapper.reply.linkAt ? wrapper.reply.linkAt(pressX-replyLine.width - Nheko.paddingSmall, pressY - replyUserButton.implicitHeight) : "", wrapper.replyTo)
256 TapHandler {
257 acceptedButtons: Qt.RightButton
258 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)
259 gesturePolicy: TapHandler.ReleaseWithinBounds
260 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
261 }
262 }
263
264 data: [
265 replyRow, wrapper.main,
266 ]
267 }
268
269 DragHandler {
270 id: replyDragHandler
271 enabled: !Settings.disableSwipe
272 yAxis.enabled: false
273 xAxis.enabled: true
274 xAxis.minimum: wrapper.avatarMargin - 100
275 xAxis.maximum: wrapper.avatarMargin
276 onActiveChanged: {
277 if (!replyDragHandler.active) {
278 if (replyDragHandler.xAxis.minimum <= replyDragHandler.xAxis.activeValue + 1) {
279 wrapper.room.reply = wrapper.eventId
280 }
281 gridContainer.x = wrapper.avatarMargin;
282 }
283 }
284 }
285
286 TapHandler {
287 onDoubleTapped: wrapper.room.reply = wrapper.eventId
288 }
289 },
290 Rectangle {
291 anchors.top: gridContainer.top
292 anchors.left: gridContainer.left
293 anchors.topMargin: -2
294 anchors.leftMargin: -2 + (stateEventSpacing.visible ? (stateEventSpacing.width + gridContainer.spacing) : 0)
295 color: "transparent"
296 border.color: Nheko.theme.red
297 border.width: wrapper.notificationlevel == MtxEvent.Highlight ? 1 : 0
298 radius: 4
299 height: contentColumn.implicitHeight + 4
300 width: contentColumn.implicitWidth + 4 + (wrapper.threadId ? (4 + gridContainer.spacing) : 0)
301 },
302 TimelineMetadata {
303 id: metadata
304
305 scaling: 1
306
307 anchors.right: parent.right
308 y: section.visible && section.active ? section.y + section.height : 0
309
310 visible: !wrapper.isStateEvent
311
312 eventId: wrapper.eventId
313 status: wrapper.status
314 trustlevel: wrapper.trustlevel
315 isEdited: wrapper.isEdited
316 isEncrypted: wrapper.isEncrypted
317 threadId: wrapper.threadId
318 timestamp: wrapper.timestamp
319 room: wrapper.room
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 reactions: wrapper.reactions
343 width: wrapper.width - wrapper.avatarMargin
344 x: wrapper.avatarMargin
345
346 anchors {
347 top: gridContainer.bottom
348 topMargin: -4
349 }
350 },
351 Rectangle {
352 id: unreadRow
353
354 color: palette.highlight
355 height: visible ? 3 : 0
356 visible: (wrapper.index > 0 && (wrapper.room.fullyReadEventId == wrapper.eventId))
357
358 anchors {
359 left: parent.left
360 right: parent.right
361 top: reactionRow.bottom
362 topMargin: 5
363 }
364 }
365 ]
366 }