2019-12-19 07:46:16 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-09-03 03:04:57 -04:00
|
|
|
import QtQuick 2.12
|
2019-12-18 04:53:08 -04:00
|
|
|
import "../../../Base"
|
2019-09-03 03:04:57 -04:00
|
|
|
|
2019-11-04 07:00:28 -04:00
|
|
|
HMxcImage {
|
2019-09-03 03:04:57 -04:00
|
|
|
id: image
|
2019-11-05 09:19:48 -04:00
|
|
|
width: fitSize.width
|
|
|
|
height: fitSize.height
|
2019-10-27 13:26:00 -04:00
|
|
|
horizontalAlignment: Image.AlignLeft
|
2019-12-16 17:36:14 -04:00
|
|
|
|
2020-03-09 12:06:58 -04:00
|
|
|
title: thumbnail ? loader.thumbnailTitle : loader.title
|
2019-10-30 09:21:58 -04:00
|
|
|
animated: loader.singleMediaInfo.media_mime === "image/gif" ||
|
2020-03-09 11:00:48 -04:00
|
|
|
utils.urlExtension(loader.mediaUrl).toLowerCase() === "gif"
|
2019-11-06 06:34:52 -04:00
|
|
|
thumbnail: ! animated && loader.thumbnailMxc
|
2019-11-04 10:46:06 -04:00
|
|
|
mxc: thumbnail ?
|
|
|
|
(loader.thumbnailMxc || loader.mediaUrl) :
|
|
|
|
(loader.mediaUrl || loader.thumbnailMxc)
|
2020-02-12 13:04:46 -04:00
|
|
|
cryptDict: JSON.parse(
|
|
|
|
thumbnail && loader.thumbnailMxc ?
|
|
|
|
loader.singleMediaInfo.thumbnail_crypt_dict :
|
|
|
|
loader.singleMediaInfo.media_crypt_dict
|
|
|
|
)
|
2019-09-03 03:04:57 -04:00
|
|
|
|
2019-09-14 01:03:56 -04:00
|
|
|
|
2019-10-30 09:21:58 -04:00
|
|
|
property EventMediaLoader loader
|
2019-12-16 17:36:14 -04:00
|
|
|
|
2019-12-17 17:59:53 -04:00
|
|
|
readonly property bool isEncrypted: ! utils.isEmptyObject(cryptDict)
|
2019-09-14 01:03:56 -04:00
|
|
|
|
2019-11-11 05:43:17 -04:00
|
|
|
readonly property real maxHeight:
|
2019-12-20 08:32:57 -04:00
|
|
|
eventList.height * theme.chat.message.thumbnailMaxHeightRatio
|
2019-11-11 05:43:17 -04:00
|
|
|
|
2019-12-17 17:59:53 -04:00
|
|
|
readonly property size fitSize: utils.fitSize(
|
2019-11-05 09:19:48 -04:00
|
|
|
// Minimum display size
|
2019-11-11 05:43:17 -04:00
|
|
|
theme.chat.message.thumbnailMinSize.width,
|
|
|
|
theme.chat.message.thumbnailMinSize.height,
|
2019-11-05 09:19:48 -04:00
|
|
|
|
|
|
|
// Real size
|
2019-12-05 10:51:57 -04:00
|
|
|
(
|
|
|
|
loader.singleMediaInfo.thumbnail_width ||
|
|
|
|
loader.singleMediaInfo.media_width ||
|
|
|
|
implicitWidth ||
|
|
|
|
800
|
|
|
|
) * theme.uiScale,
|
2019-11-05 09:19:48 -04:00
|
|
|
|
2019-12-05 10:51:57 -04:00
|
|
|
(
|
|
|
|
loader.singleMediaInfo.thumbnail_height ||
|
|
|
|
loader.singleMediaInfo.media_height ||
|
|
|
|
implicitHeight ||
|
|
|
|
600
|
|
|
|
) * theme.uiScale,
|
2019-11-05 09:19:48 -04:00
|
|
|
|
|
|
|
// Maximum display size
|
2019-12-05 10:51:57 -04:00
|
|
|
Math.min(
|
2019-12-20 08:32:57 -04:00
|
|
|
Math.max(maxHeight, theme.chat.message.thumbnailMinSize.width),
|
|
|
|
pureMedia ? Infinity : eventContent.maxMessageWidth,
|
|
|
|
eventDelegate.width - eventContent.spacing - avatarWrapper.width -
|
|
|
|
eventContent.spacing * 2, // padding
|
2019-12-05 10:51:57 -04:00
|
|
|
),
|
2019-12-20 08:32:57 -04:00
|
|
|
Math.max(maxHeight, theme.chat.message.thumbnailMinSize.height),
|
2019-11-05 09:19:48 -04:00
|
|
|
)
|
|
|
|
|
2019-09-14 01:03:56 -04:00
|
|
|
|
2019-11-16 08:06:56 -04:00
|
|
|
function getOpenUrl(callback) {
|
2019-12-16 17:36:14 -04:00
|
|
|
if (image.isEncrypted && loader.mediaUrl) {
|
2019-12-16 17:48:07 -04:00
|
|
|
loader.download(callback)
|
2019-12-16 17:36:14 -04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-16 08:06:56 -04:00
|
|
|
if (image.isEncrypted) {
|
|
|
|
callback(image.cachedPath)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-08 04:46:20 -04:00
|
|
|
const toOpen = loader.mediaUrl || loader.thumbnailMxc
|
|
|
|
const isMxc = toOpen.startsWith("mxc://")
|
2019-11-16 08:06:56 -04:00
|
|
|
|
|
|
|
isMxc ?
|
2019-12-09 05:25:31 -04:00
|
|
|
py.callClientCoro(chat.userId, "mxc_to_http", [toOpen], callback) :
|
2019-12-02 06:42:48 -04:00
|
|
|
callback(toOpen)
|
2019-11-16 08:06:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-03 03:04:57 -04:00
|
|
|
TapHandler {
|
2019-11-16 08:06:56 -04:00
|
|
|
onTapped: if (! image.animated) getOpenUrl(Qt.openUrlExternally)
|
|
|
|
onDoubleTapped: getOpenUrl(Qt.openUrlExternally)
|
2019-09-03 03:04:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HoverHandler {
|
|
|
|
id: hover
|
2019-11-16 08:06:56 -04:00
|
|
|
onHoveredChanged: {
|
2019-12-16 17:36:14 -04:00
|
|
|
if (! hovered) {
|
2019-11-16 08:06:56 -04:00
|
|
|
eventDelegate.hoveredMediaTypeUrl = []
|
2019-12-16 17:36:14 -04:00
|
|
|
return
|
2019-11-16 08:06:56 -04:00
|
|
|
}
|
2019-12-16 17:36:14 -04:00
|
|
|
|
2019-12-16 18:05:09 -04:00
|
|
|
eventDelegate.hoveredMediaTypeUrl = [
|
|
|
|
EventDelegate.Media.Image,
|
2019-12-16 18:22:25 -04:00
|
|
|
loader.downloadedPath.replace(/^file:\/\//, "") ||
|
|
|
|
loader.mediaUrl
|
2019-12-16 18:05:09 -04:00
|
|
|
]
|
2019-11-16 08:06:56 -04:00
|
|
|
}
|
2019-09-03 03:04:57 -04:00
|
|
|
}
|
2019-10-30 09:21:58 -04:00
|
|
|
|
|
|
|
EventImageTextBubble {
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.top: parent.top
|
|
|
|
text: loader.showSender
|
|
|
|
textFormat: Text.StyledText
|
2019-11-30 11:15:54 -04:00
|
|
|
opacity: hover.hovered ? 0 : 1
|
|
|
|
visible: opacity > 0
|
|
|
|
|
2019-12-16 04:42:41 -04:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-10-30 09:21:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
EventImageTextBubble {
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.bottom: parent.bottom
|
2019-11-06 16:11:12 -04:00
|
|
|
text: [loader.showDate, loader.showLocalEcho].join(" ").trim()
|
2019-11-06 09:48:27 -04:00
|
|
|
textFormat: Text.StyledText
|
2019-11-30 11:15:54 -04:00
|
|
|
opacity: hover.hovered ? 0 : 1
|
|
|
|
visible: opacity > 0
|
|
|
|
|
2019-12-16 04:42:41 -04:00
|
|
|
Behavior on opacity { HNumberAnimation {} }
|
2019-10-30 09:21:58 -04:00
|
|
|
}
|
2019-09-03 03:04:57 -04:00
|
|
|
}
|