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
|
2020-07-20 10:10:31 +10:00
|
|
|
import "../../.."
|
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-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-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-11-16 23:06:56 +11:00
|
|
|
|
2020-07-12 14:25:57 +10:00
|
|
|
width: fitSize.width
|
|
|
|
height: fitSize.height
|
|
|
|
horizontalAlignment: Image.AlignLeft
|
|
|
|
|
|
|
|
title: thumbnail ? loader.thumbnailTitle : loader.title
|
2020-07-20 10:10:31 +10:00
|
|
|
animated: eventList.isAnimated(loader.singleMediaInfo)
|
2020-07-12 14:25:57 +10:00
|
|
|
thumbnail: ! animated && loader.thumbnailMxc
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2020-07-20 10:10:31 +10:00
|
|
|
onCachedPathChanged:
|
|
|
|
eventList.thumbnailCachedPaths[loader.singleMediaInfo.id] = cachedPath
|
|
|
|
|
2019-09-03 17:04:57 +10:00
|
|
|
TapHandler {
|
2020-07-19 17:02:14 +10:00
|
|
|
acceptedButtons: Qt.LeftButton
|
2020-03-27 14:24:37 +11:00
|
|
|
acceptedModifiers: Qt.NoModifier
|
2020-07-20 10:10:31 +10:00
|
|
|
gesturePolicy: TapHandler.ReleaseWithinBounds
|
2020-07-20 10:33:40 +10:00
|
|
|
|
2020-07-20 15:07:00 +10:00
|
|
|
onTapped: {
|
|
|
|
if (eventList.selectedCount) {
|
|
|
|
eventDelegate.toggleChecked()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const wasPaused = image.pause
|
|
|
|
image.pause = true
|
|
|
|
|
|
|
|
eventList.openImageViewer(singleMediaInfo, "", popup => {
|
|
|
|
popup.closed.connect(() => image.pause = wasPaused)
|
|
|
|
})
|
|
|
|
}
|
2019-09-03 17:04:57 +10:00
|
|
|
}
|
|
|
|
|
2020-07-19 17:02:14 +10:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.MiddleButton
|
|
|
|
acceptedModifiers: Qt.NoModifier
|
|
|
|
gesturePolicy: TapHandler.ReleaseWithinBounds
|
2020-07-20 10:10:31 +10:00
|
|
|
onTapped: {
|
|
|
|
loader.isMedia ?
|
|
|
|
eventList.openMediaExternally(singleMediaInfo) :
|
|
|
|
Qt.openUrlExternally(loader.mediaUrl)
|
|
|
|
}
|
2020-07-19 17:02:14 +10:00
|
|
|
}
|
|
|
|
|
2020-03-27 14:24:37 +11:00
|
|
|
TapHandler {
|
|
|
|
acceptedModifiers: Qt.ShiftModifier
|
2020-07-20 10:10:31 +10:00
|
|
|
gesturePolicy: TapHandler.ReleaseWithinBounds
|
2020-03-27 14:24:37 +11:00
|
|
|
onTapped:
|
2020-03-27 20:05:25 +11:00
|
|
|
eventList.checkFromLastToHere(singleMediaInfo.index)
|
2020-03-27 14:24:37 +11:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-07-20 14:22:12 +10:00
|
|
|
eventDelegate.hoveredMediaTypeUrl =
|
|
|
|
[Utils.Media.Image, loader.mediaUrl, loader.title]
|
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
|
|
|
}
|