From 2546d79f268c7252ba98cf23501c6ae95fc9a4dd Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 25 Mar 2025 11:43:55 +0000 Subject: [PATCH] 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..."! --- src/timeline/LinkPreviewComponent.qml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/timeline/LinkPreviewComponent.qml b/src/timeline/LinkPreviewComponent.qml index c51f71fc0..013e0ebf3 100644 --- a/src/timeline/LinkPreviewComponent.qml +++ b/src/timeline/LinkPreviewComponent.qml @@ -31,7 +31,7 @@ QQC2.Control { * - description - the description of the URL preview. * - imageSource - a source URL for the preview image. */ - required property var linkPreviewer + required property LinkPreviewer linkPreviewer /** * @brief Standard height for the link preview. @@ -72,7 +72,9 @@ QQC2.Control { id: previewImage Layout.preferredWidth: 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 fillMode: Image.PreserveAspectFit } @@ -80,6 +82,7 @@ QQC2.Control { id: column implicitWidth: Math.max(linkPreviewTitle.implicitWidth, linkPreviewDescription.implicitWidth) spacing: Kirigami.Units.smallSpacing + visible: root.linkPreviewer.title.length > 0 || root.linkPreviewer.description.length > 0 Kirigami.Heading { id: linkPreviewTitle Layout.fillWidth: true @@ -98,12 +101,7 @@ QQC2.Control { text: root.linkPreviewer.title font: linkPreviewTitle.font elide: Text.ElideRight - elideWidth: (linkPreviewTitle.availableWidth()) * 3 - } - - function availableWidth() { - let previewImageWidth = (previewImage.visible ? previewImage.width + contentRow.spacing : 0); - return root.maxContentWidth - contentRow.spacing - separator.width - previewImageWidth; + elideWidth: linkPreviewTitle.width } } QQC2.Label {