Play m.image events GIFs, rename some properties

This commit is contained in:
miruka 2019-10-30 06:47:59 -04:00
parent b11c9d5675
commit 2e4a7904d5
4 changed files with 23 additions and 15 deletions

View File

@ -13,7 +13,7 @@ Image {
property bool animate: true 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 readonly property alias loadingLabel: loadingLabel

View File

@ -140,7 +140,7 @@ HRowLayout {
model: eventDelegate.currentItem.links model: eventDelegate.currentItem.links
EventMediaLoader { EventMediaLoader {
info: eventDelegate.currentItem singleMediaInfo: eventDelegate.currentItem
mediaUrl: modelData mediaUrl: modelData
transform: Translate { x: xOffset } transform: Translate { x: xOffset }
@ -151,12 +151,12 @@ HRowLayout {
Layout.minimumWidth: Layout.minimumWidth:
type === EventDelegate.Media.Image ? type === EventDelegate.Media.Image ?
(info.media_width || (singleMediaInfo.media_width ||
(item ? item.loadingLabel.implicitWidth : -1)) : -1 (item ? item.loadingLabel.implicitWidth : -1)) : -1
Layout.minimumHeight: Layout.minimumHeight:
type === EventDelegate.Media.Image ? type === EventDelegate.Media.Image ?
(info.media_height || (singleMediaInfo.media_height ||
(item ? item.loadingLabel.implicitHeight : -1)) : -1 (item ? item.loadingLabel.implicitHeight : -1)) : -1
// Layout.minimumWidth: // Layout.minimumWidth:

View File

@ -6,21 +6,24 @@ HImage {
id: image id: image
horizontalAlignment: Image.AlignLeft horizontalAlignment: Image.AlignLeft
sourceSize.width: theme.chat.message.thumbnailWidth // FIXME sourceSize.width: theme.chat.message.thumbnailWidth // FIXME
source: animated ? openUrl : thumbnailUrl
// source = thumbnail, fullSource = full original image property url thumbnailUrl
property url fullSource: source property url fullImageUrl
readonly property url openUrl: fullImageUrl || thumbnailUrl
TapHandler { TapHandler {
onTapped: if (! image.animated) Qt.openUrlExternally(fullSource) onTapped: if (! image.animated) Qt.openUrlExternally(openUrl)
onDoubleTapped: Qt.openUrlExternally(fullSource) onDoubleTapped: Qt.openUrlExternally(openUrl)
} }
HoverHandler { HoverHandler {
id: hover id: hover
onHoveredChanged: onHoveredChanged:
eventDelegate.hoveredMediaTypeUrl = eventDelegate.hoveredMediaTypeUrl =
hovered ? [EventDelegate.Media.Image, fullSource] : [] hovered ? [EventDelegate.Media.Image, openUrl] : []
} }
} }

View File

@ -7,7 +7,7 @@ HLoader {
x: eventContent.spacing x: eventContent.spacing
property QtObject info property QtObject singleMediaInfo
property url mediaUrl property url mediaUrl
readonly property var imageExtensions: [ readonly property var imageExtensions: [
@ -26,15 +26,16 @@ HLoader {
] ]
readonly property int type: { 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 === "image") return EventDelegate.Media.Image
if (main_type === "video") return EventDelegate.Media.Video if (main_type === "video") return EventDelegate.Media.Video
if (main_type === "audio") return EventDelegate.Media.Audio if (main_type === "audio") return EventDelegate.Media.Audio
if (info.event_type === "RoomMessageFile") if (singleMediaInfo.event_type === "RoomMessageFile")
return EventDelegate.Media.File return EventDelegate.Media.File
// If this is a preview for a link in a normal message
let ext = Utils.urlExtension(mediaUrl) let ext = Utils.urlExtension(mediaUrl)
if (imageExtensions.includes(ext)) return EventDelegate.Media.Image if (imageExtensions.includes(ext)) return EventDelegate.Media.Image
@ -47,15 +48,19 @@ HLoader {
readonly property url previewUrl: ( readonly property url previewUrl: (
type === EventDelegate.Media.File || type === EventDelegate.Media.File ||
type === EventDelegate.Media.Image ? type === EventDelegate.Media.Image ?
info.thumbnail_url : "" singleMediaInfo.thumbnail_url : ""
) || mediaUrl ) || mediaUrl
onPreviewUrlChanged: { onPreviewUrlChanged: {
print( mediaUrl)
if (type === EventDelegate.Media.Image) { if (type === EventDelegate.Media.Image) {
var file = "EventImage.qml" 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) { // } else if (type === EventDelegate.Media.File) {
// var file = "EventFile.qml" // var file = "EventFile.qml"