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!
This commit is contained in:
Joshua Goins
2025-10-27 16:34:13 -04:00
parent 6d9974b2b1
commit 099e996f2f

View File

@@ -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 {