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

153 lines
4.2 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
import "../../.."
2019-12-18 19:53:08 +11:00
import "../../../Base"
HMxcImage {
id: image
property EventMediaLoader loader
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
)
width: fitSize.width
height: fitSize.height
horizontalAlignment: Image.AlignLeft
title: thumbnail ? loader.thumbnailTitle : loader.title
animated: eventList.isAnimated(loader.singleMediaInfo)
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
)
onCachedPathChanged:
eventList.thumbnailCachedPaths[loader.singleMediaInfo.id] = cachedPath
Binding on pause {
value: true
when: Object.keys(window.visiblePopups).length > 0
}
TapHandler {
acceptedButtons: Qt.LeftButton
acceptedModifiers: Qt.NoModifier
gesturePolicy: TapHandler.ReleaseWithinBounds
onTapped: {
if (eventList.selectedCount) {
eventDelegate.toggleChecked()
return
}
eventList.openImageViewer(
singleMediaInfo,
loader.mediaUrl.startsWith("mxc://") ? "" : loader.mediaUrl,
)
}
}
TapHandler {
acceptedButtons: Qt.MiddleButton
acceptedModifiers: Qt.NoModifier
gesturePolicy: TapHandler.ReleaseWithinBounds
onTapped: {
loader.isMedia ?
eventList.openMediaExternally(singleMediaInfo) :
Qt.openUrlExternally(loader.mediaUrl)
}
}
TapHandler {
acceptedModifiers: Qt.ShiftModifier
gesturePolicy: TapHandler.ReleaseWithinBounds
onTapped:
eventList.checkFromLastToHere(singleMediaInfo.index)
}
HoverHandler {
id: hover
onHoveredChanged: {
if (! hovered) {
eventDelegate.hoveredMediaTypeUrl = []
return
}
eventDelegate.hoveredMediaTypeUrl =
[Utils.Media.Image, loader.mediaUrl, loader.title]
}
}
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 {} }
}
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 {} }
}
}