From a7af3bb96c60386074ed6220955ada05b27a84b3 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 10 Oct 2023 00:00:17 +0200 Subject: [PATCH] Restore reply context menu --- resources/qml/MessageView.qml | 16 +++++++++------- resources/qml/TimelineBubbleMessageStyle.qml | 19 ++++++++++++++----- resources/qml/TimelineDefaultMessageStyle.qml | 11 ++++++++--- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/resources/qml/MessageView.qml b/resources/qml/MessageView.qml index ab8a3ee8..98b9748a 100644 --- a/resources/qml/MessageView.qml +++ b/resources/qml/MessageView.qml @@ -26,7 +26,7 @@ Item { Connections { function onHideMenu() { messageContextMenuC.close(); - replyContextMenu.close(); + replyContextMenuC.close(); } target: MainWindow @@ -65,6 +65,7 @@ Item { TimelineDefaultMessageStyle { messageActions: messageActionsC messageContextMenu: messageContextMenuC + replyContextMenu: replyContextMenuC scrolledToThis: eventId === room.scrollTarget && (y + height > chat.y + chat.contentY && y < chat.y + chat.height + chat.contentY) } } @@ -74,6 +75,7 @@ Item { TimelineBubbleMessageStyle { messageActions: messageActionsC messageContextMenu: messageContextMenuC + replyContextMenu: replyContextMenuC scrolledToThis: eventId === room.scrollTarget && (y + height > chat.y + chat.contentY && y < chat.y + chat.height + chat.contentY) } } @@ -541,7 +543,7 @@ Item { } } Platform.Menu { - id: replyContextMenu + id: replyContextMenuC property string eventId property string link @@ -557,23 +559,23 @@ Item { Platform.MenuItem { enabled: visible text: qsTr("&Copy") - visible: replyContextMenu.text + visible: replyContextMenuC.text - onTriggered: Clipboard.text = replyContextMenu.text + onTriggered: Clipboard.text = replyContextMenuC.text } Platform.MenuItem { enabled: visible text: qsTr("Copy &link location") - visible: replyContextMenu.link + visible: replyContextMenuC.link - onTriggered: Clipboard.text = replyContextMenu.link + onTriggered: Clipboard.text = replyContextMenuC.link } Platform.MenuItem { enabled: visible text: qsTr("&Go to quoted message") visible: true - onTriggered: room.showEvent(replyContextMenu.eventId) + onTriggered: room.showEvent(replyContextMenuC.eventId) } } RoundButton { diff --git a/resources/qml/TimelineBubbleMessageStyle.qml b/resources/qml/TimelineBubbleMessageStyle.qml index ef6aba6e..2df3d917 100644 --- a/resources/qml/TimelineBubbleMessageStyle.qml +++ b/resources/qml/TimelineBubbleMessageStyle.qml @@ -44,6 +44,7 @@ TimelineEvent { required property bool isEditable required property QtObject messageContextMenu + required property QtObject replyContextMenu required property Item messageActions property int avatarMargin: (wrapper.isStateEvent || Settings.smallAvatars ? 0 : (Nheko.avatarSize + 8)) // align bubble with section header @@ -173,13 +174,14 @@ TimelineEvent { contentItem: Item { id: contentPlacementContainer - property int metadataWidth: 100 - property int metadataHeight: 20 - property bool fitsMetadata: ((wrapper.main?.width ?? 0) + wrapper.mainInset + metadata.width) < wrapper.maxWidth - implicitWidth: Math.max((wrapper.reply?.width ?? 0) + wrapper.replyInset, (wrapper.main?.width ?? 0) + wrapper.mainInset + (fitsMetadata ? metadata.width : 0)) - implicitHeight: contentColumn.implicitHeight + (fitsMetadata ? 0 : metadata.height) + // 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? + // 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 + property bool fitsMetadataInside: false + + implicitWidth: Math.max((wrapper.reply?.width ?? 0) + wrapper.replyInset, (wrapper.main?.width ?? 0) + wrapper.mainInset + ((fitsMetadata && !fitsMetadataInside) ? metadata.width : 0)) + implicitHeight: contentColumn.implicitHeight + ((fitsMetadata || fitsMetadataInside) ? 0 : metadata.height) TimelineMetadata { id: metadata @@ -275,6 +277,13 @@ TimelineEvent { wrapper.room.showEvent(wrapper.replyTo) } } + onPressAndHold: wrapper.replyContextMenu.show(wrapper.reply.copyText ?? "", wrapper.reply.linkAt ? wrapper.reply.linkAt(pressX-replyLine.width - Nheko.paddingSmall, pressY - replyUserButton.implicitHeight) : "", wrapper.replyTo) + TapHandler { + acceptedButtons: Qt.RightButton + 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) + gesturePolicy: TapHandler.ReleaseWithinBounds + acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad + } } data: [replyRow, wrapper.main] diff --git a/resources/qml/TimelineDefaultMessageStyle.qml b/resources/qml/TimelineDefaultMessageStyle.qml index 9685727d..e9a0712d 100644 --- a/resources/qml/TimelineDefaultMessageStyle.qml +++ b/resources/qml/TimelineDefaultMessageStyle.qml @@ -44,6 +44,7 @@ TimelineEvent { required property bool isEditable required property QtObject messageContextMenu + required property QtObject replyContextMenu required property Item messageActions property int avatarMargin: (wrapper.isStateEvent || Settings.smallAvatars ? 0 : (Nheko.avatarSize + 8)) // align bubble with section header @@ -261,6 +262,13 @@ TimelineEvent { wrapper.room.showEvent(wrapper.replyTo) } } + onPressAndHold: wrapper.replyContextMenu.show(wrapper.reply.copyText ?? "", wrapper.reply.linkAt ? wrapper.reply.linkAt(pressX-replyLine.width - Nheko.paddingSmall, pressY - replyUserButton.implicitHeight) : "", wrapper.replyTo) + TapHandler { + acceptedButtons: Qt.RightButton + 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) + gesturePolicy: TapHandler.ReleaseWithinBounds + acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad + } } data: [ @@ -292,14 +300,11 @@ TimelineEvent { id: reactionRow eventId: wrapper.eventId - layoutDirection: row.bubbleOnRight ? Qt.RightToLeft : Qt.LeftToRight reactions: wrapper.reactions width: wrapper.width - wrapper.avatarMargin x: wrapper.avatarMargin anchors { - //left: row.bubbleOnRight ? undefined : row.left - //right: row.bubbleOnRight ? row.right : undefined top: gridContainer.bottom topMargin: -4 }