From 2e4a7904d5ca2442c001078a8803ad5040186ead Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 30 Oct 2019 06:47:59 -0400 Subject: [PATCH] Play m.image events GIFs, rename some properties --- src/qml/Base/HImage.qml | 2 +- src/qml/Chat/Timeline/EventContent.qml | 6 +++--- src/qml/Chat/Timeline/EventImage.qml | 13 ++++++++----- src/qml/Chat/Timeline/EventMediaLoader.qml | 17 +++++++++++------ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/qml/Base/HImage.qml b/src/qml/Base/HImage.qml index 2ac6f8d5..e4ecb8f9 100644 --- a/src/qml/Base/HImage.qml +++ b/src/qml/Base/HImage.qml @@ -13,7 +13,7 @@ Image { property bool animate: true - readonly property bool animated: Utils.urlExtension(image.source) == "gif" + property bool animated: Utils.urlExtension(image.source) === "gif" readonly property alias loadingLabel: loadingLabel diff --git a/src/qml/Chat/Timeline/EventContent.qml b/src/qml/Chat/Timeline/EventContent.qml index 91bebad1..9ce01528 100644 --- a/src/qml/Chat/Timeline/EventContent.qml +++ b/src/qml/Chat/Timeline/EventContent.qml @@ -140,7 +140,7 @@ HRowLayout { model: eventDelegate.currentItem.links EventMediaLoader { - info: eventDelegate.currentItem + singleMediaInfo: eventDelegate.currentItem mediaUrl: modelData transform: Translate { x: xOffset } @@ -151,12 +151,12 @@ HRowLayout { Layout.minimumWidth: type === EventDelegate.Media.Image ? - (info.media_width || + (singleMediaInfo.media_width || (item ? item.loadingLabel.implicitWidth : -1)) : -1 Layout.minimumHeight: type === EventDelegate.Media.Image ? - (info.media_height || + (singleMediaInfo.media_height || (item ? item.loadingLabel.implicitHeight : -1)) : -1 // Layout.minimumWidth: diff --git a/src/qml/Chat/Timeline/EventImage.qml b/src/qml/Chat/Timeline/EventImage.qml index 42b0ae6b..62f1d798 100644 --- a/src/qml/Chat/Timeline/EventImage.qml +++ b/src/qml/Chat/Timeline/EventImage.qml @@ -6,21 +6,24 @@ HImage { id: image horizontalAlignment: Image.AlignLeft sourceSize.width: theme.chat.message.thumbnailWidth // FIXME + source: animated ? openUrl : thumbnailUrl - // source = thumbnail, fullSource = full original image - property url fullSource: source + property url thumbnailUrl + property url fullImageUrl + + readonly property url openUrl: fullImageUrl || thumbnailUrl TapHandler { - onTapped: if (! image.animated) Qt.openUrlExternally(fullSource) - onDoubleTapped: Qt.openUrlExternally(fullSource) + onTapped: if (! image.animated) Qt.openUrlExternally(openUrl) + onDoubleTapped: Qt.openUrlExternally(openUrl) } HoverHandler { id: hover onHoveredChanged: eventDelegate.hoveredMediaTypeUrl = - hovered ? [EventDelegate.Media.Image, fullSource] : [] + hovered ? [EventDelegate.Media.Image, openUrl] : [] } } diff --git a/src/qml/Chat/Timeline/EventMediaLoader.qml b/src/qml/Chat/Timeline/EventMediaLoader.qml index 1f25f48d..ece855dd 100644 --- a/src/qml/Chat/Timeline/EventMediaLoader.qml +++ b/src/qml/Chat/Timeline/EventMediaLoader.qml @@ -7,7 +7,7 @@ HLoader { x: eventContent.spacing - property QtObject info + property QtObject singleMediaInfo property url mediaUrl readonly property var imageExtensions: [ @@ -26,15 +26,16 @@ HLoader { ] readonly property int type: { - let main_type = info.media_mime.split("/")[0].toLowerCase() + let main_type = singleMediaInfo.media_mime.split("/")[0].toLowerCase() if (main_type === "image") return EventDelegate.Media.Image if (main_type === "video") return EventDelegate.Media.Video if (main_type === "audio") return EventDelegate.Media.Audio - if (info.event_type === "RoomMessageFile") + if (singleMediaInfo.event_type === "RoomMessageFile") return EventDelegate.Media.File + // If this is a preview for a link in a normal message let ext = Utils.urlExtension(mediaUrl) if (imageExtensions.includes(ext)) return EventDelegate.Media.Image @@ -47,15 +48,19 @@ HLoader { readonly property url previewUrl: ( type === EventDelegate.Media.File || type === EventDelegate.Media.Image ? - info.thumbnail_url : "" + singleMediaInfo.thumbnail_url : "" ) || mediaUrl onPreviewUrlChanged: { - print( mediaUrl) if (type === EventDelegate.Media.Image) { var file = "EventImage.qml" - var props = { source: previewUrl, fullSource: mediaUrl } + var props = { + thumbnailUrl: previewUrl, + fullImageUrl: mediaUrl, + animated: singleMediaInfo.media_mime === "image/gif" || + Utils.urlExtension(mediaUrl) === "gif", + } // } else if (type === EventDelegate.Media.File) { // var file = "EventFile.qml"