From 099e996f2f6a0b633908a1f2c57c11dde6ad1605 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 27 Oct 2025 16:34:13 -0400 Subject: [PATCH] Improve standalone images in link preview and more We would incorrectly show a "truncate" button for standalone images which isn't applicable since there's no text. That check has been fixed, and it doesn't seem to regress normal link previews. Another is that if there's only an image, our layout would center the image which looks awkward since almost everything else is left-aligned in chat. This is also fixed, which notably matches up to Element Web's behavior. I added support for the hover link indicator as well. Someone could maliciously hide it via Markdown but have a legitimate-looking link preview, for example. You can check that by hovering over the link in the message itself, but now the link preview is another way to confirm that! --- src/messagecontent/LinkPreviewComponent.qml | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/messagecontent/LinkPreviewComponent.qml b/src/messagecontent/LinkPreviewComponent.qml index 99c0798b8..8d6c8219f 100644 --- a/src/messagecontent/LinkPreviewComponent.qml +++ b/src/messagecontent/LinkPreviewComponent.qml @@ -41,7 +41,12 @@ QQC2.Control { */ property var defaultHeight: Kirigami.Units.gridUnit * 3 + Kirigami.Units.largeSpacing * 2 - property bool truncated: linkPreviewDescription.truncated || !linkPreviewDescription.visible + /** + * @brief Whether the link preview description is truncated. + * + * This is only applicable if there *is* a text description, and is never true for images. + */ + property bool truncated: linkPreviewDescription.truncated && linkPreviewDescription.visible /** * @brief Request for this delegate to be removed. @@ -72,7 +77,7 @@ QQC2.Control { id: previewImage Layout.preferredWidth: root.defaultHeight Layout.preferredHeight: root.defaultHeight - Layout.fillWidth: true + Layout.maximumWidth: root.defaultHeight Layout.fillHeight: true visible: root.linkPreviewer.imageSource.toString().length > 0 source: root.linkPreviewer.imageSource @@ -82,9 +87,9 @@ QQC2.Control { } ColumnLayout { id: column - implicitWidth: Math.max(linkPreviewTitle.implicitWidth, linkPreviewDescription.implicitWidth) + Layout.preferredWidth: Math.max(linkPreviewTitle.implicitWidth, linkPreviewDescription.implicitWidth) + Layout.fillWidth: true spacing: Kirigami.Units.smallSpacing - visible: root.linkPreviewer.title.length > 0 || root.linkPreviewer.description.length > 0 Kirigami.Heading { id: linkPreviewTitle Layout.fillWidth: true @@ -121,10 +126,11 @@ QQC2.Control { acceptedButtons: Qt.LeftButton onTapped: RoomManager.resolveResource(root.linkPreviewer.url, "join") } - } - HoverHandler { - cursorShape: Qt.PointingHandCursor + HoverHandler { + cursorShape: Qt.PointingHandCursor + onHoveredChanged: (root.QQC2.ApplicationWindow.window as Main).hoverLinkIndicator.text = hovered ? root.linkPreviewer.url : "" + } } QQC2.Button {