LinkPreviewComponent: Fix a few bugs, restore the image preview

We realized that images don't display in link previews anymore, because
QML is terrible and this property is a QUrl, so when we call .length it
silently fails and never loads the image. This is easily fixed by
calling .toString().

There's also another bug where the title ie elided way too greedily, but
we can simplify the elision check and fix the bug at the same time.
No more "Hom..."!

(cherry picked from commit 2546d79f26)
This commit is contained in:
Joshua Goins
2025-03-25 11:43:55 +00:00
committed by Tobias Fella
parent 299d8e9c40
commit 3e683eac77

View File

@@ -31,7 +31,7 @@ QQC2.Control {
* - description - the description of the URL preview. * - description - the description of the URL preview.
* - imageSource - a source URL for the preview image. * - imageSource - a source URL for the preview image.
*/ */
required property var linkPreviewer required property LinkPreviewer linkPreviewer
/** /**
* @brief Standard height for the link preview. * @brief Standard height for the link preview.
@@ -77,7 +77,9 @@ QQC2.Control {
id: previewImage id: previewImage
Layout.preferredWidth: root.defaultHeight Layout.preferredWidth: root.defaultHeight
Layout.preferredHeight: root.defaultHeight Layout.preferredHeight: root.defaultHeight
visible: root.linkPreviewer.imageSource.length > 0 Layout.fillWidth: true
Layout.fillHeight: true
visible: root.linkPreviewer.imageSource.toString().length > 0
source: root.linkPreviewer.imageSource source: root.linkPreviewer.imageSource
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
@@ -85,6 +87,7 @@ QQC2.Control {
id: column id: column
implicitWidth: Math.max(linkPreviewTitle.implicitWidth, linkPreviewDescription.implicitWidth) implicitWidth: Math.max(linkPreviewTitle.implicitWidth, linkPreviewDescription.implicitWidth)
spacing: Kirigami.Units.smallSpacing spacing: Kirigami.Units.smallSpacing
visible: root.linkPreviewer.title.length > 0 || root.linkPreviewer.description.length > 0
Kirigami.Heading { Kirigami.Heading {
id: linkPreviewTitle id: linkPreviewTitle
Layout.fillWidth: true Layout.fillWidth: true
@@ -103,12 +106,7 @@ QQC2.Control {
text: root.linkPreviewer.title text: root.linkPreviewer.title
font: linkPreviewTitle.font font: linkPreviewTitle.font
elide: Text.ElideRight elide: Text.ElideRight
elideWidth: (linkPreviewTitle.availableWidth()) * 3 elideWidth: linkPreviewTitle.width
}
function availableWidth() {
let previewImageWidth = (previewImage.visible ? previewImage.width + contentRow.spacing : 0);
return root.maxContentWidth - contentRow.spacing - separator.width - previewImageWidth;
} }
} }
QQC2.Label { QQC2.Label {