moment/src/gui/Pages/Chat/Timeline/EventImage.qml

127 lines
3.6 KiB
QML
Raw Normal View History

2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
2019-12-18 19:53:08 +11:00
import "../../../Base"
HMxcImage {
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-10 03:06:58 +11:00
title: thumbnail ? loader.thumbnailTitle : loader.title
animated: loader.singleMediaInfo.media_mime === "image/gif" ||
utils.urlExtension(loader.mediaUrl).toLowerCase() === "gif"
thumbnail: ! animated && loader.thumbnailMxc
2019-11-05 01:46:06 +11:00
mxc: thumbnail ?
(loader.thumbnailMxc || loader.mediaUrl) :
(loader.mediaUrl || loader.thumbnailMxc)
cryptDict: JSON.parse(
thumbnail && loader.thumbnailMxc ?
loader.singleMediaInfo.thumbnail_crypt_dict :
loader.singleMediaInfo.media_crypt_dict
)
property EventMediaLoader loader
readonly property bool isEncrypted: ! utils.isEmptyObject(cryptDict)
readonly property real maxHeight:
eventList.height * theme.chat.message.thumbnailMaxHeightRatio
readonly property size fitSize: utils.fitSize(
2019-11-06 00:19:48 +11:00
// Minimum display size
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(
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
),
Math.max(maxHeight, theme.chat.message.thumbnailMinSize.height),
2019-11-06 00:19:48 +11:00
)
function getOpenUrl(callback) {
if (image.isEncrypted && loader.mediaUrl) {
loader.download(callback)
return
}
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://")
isMxc ?
2019-12-09 20:25:31 +11:00
py.callClientCoro(chat.userId, "mxc_to_http", [toOpen], callback) :
callback(toOpen)
}
TapHandler {
onTapped: if (! image.animated) getOpenUrl(Qt.openUrlExternally)
onDoubleTapped: getOpenUrl(Qt.openUrlExternally)
}
HoverHandler {
id: hover
onHoveredChanged: {
if (! hovered) {
eventDelegate.hoveredMediaTypeUrl = []
return
}
2019-12-17 09:05:09 +11:00
eventDelegate.hoveredMediaTypeUrl = [
EventDelegate.Media.Image,
loader.downloadedPath.replace(/^file:\/\//, "") ||
loader.mediaUrl
2019-12-17 09:05:09 +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 {} }
}
EventImageTextBubble {
anchors.right: parent.right
anchors.bottom: parent.bottom
text: [loader.showDate, loader.showLocalEcho].join(" ").trim()
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 {} }
}
}