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