matrixion/qml/delegates/ImageMessage.qml

86 lines
3.2 KiB
QML
Raw Permalink Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
2021-12-08 03:46:40 +03:00
import QtQuick 2.15
import QtQuick.Window 2.15
2022-03-24 03:35:42 +03:00
import QtQuick.Controls 2.3
import im.nheko
2019-10-06 02:44:02 +03:00
2022-03-24 03:35:42 +03:00
AbstractButton {
required property string blurhash
required property string body
2022-04-16 03:13:01 +03:00
property double divisor: isReply ? 5 : 3
required property string eventId
required property string filename
2022-04-16 03:13:01 +03:00
property bool fitsMetadata: (parent.width - width) > metadataWidth + 4
required property bool isReply
2022-04-16 03:13:01 +03:00
property int metadataWidth
required property int originalWidth
required property double proportionalHeight
property int tempWidth: originalWidth < 1 ? 400 : originalWidth
required property int type
required property string url
2022-04-16 03:13:01 +03:00
height: width * proportionalHeight
2022-03-24 03:35:42 +03:00
hoverEnabled: true
2022-04-16 03:13:01 +03:00
implicitWidth: Math.round(tempWidth * Math.min((timelineView.height / divisor) / (tempWidth * proportionalHeight), 1))
width: Math.min(parent?.width ?? implicitWidth, implicitWidth)
2020-10-08 22:11:21 +03:00
2022-04-16 03:13:01 +03:00
onClicked: Settings.openImageExternal ? room.openMedia(eventId) : TimelineManager.openImageOverlay(room, url, eventId)
2022-02-14 23:07:03 +03:00
2020-10-08 22:11:21 +03:00
Image {
id: blurhash_
2020-10-08 22:11:21 +03:00
anchors.fill: parent
asynchronous: true
fillMode: Image.PreserveAspectFit
2022-04-16 03:13:01 +03:00
source: blurhash ? ("image://blurhash/" + blurhash) : ("image://colorimage/:/icons/icons/ui/image-failed.svg?" + timelineRoot.palette.placeholderText)
sourceSize.height: parent.height * Screen.devicePixelRatio
2022-04-16 03:13:01 +03:00
sourceSize.width: parent.width * Screen.devicePixelRatio
visible: img.status != Image.Ready
2020-10-08 22:11:21 +03:00
}
Image {
id: img
anchors.fill: parent
asynchronous: true
fillMode: Image.PreserveAspectFit
2020-08-21 22:46:42 +03:00
mipmap: true
2022-04-16 03:13:01 +03:00
smooth: true
source: url.replace("mxc://", "image://MxcImage/") + "?scale"
sourceSize.height: Math.min(Screen.desktopAvailableHeight, (originalWidth < 1 ? Screen.desktopAvailableHeight : originalWidth * proportionalHeight)) * Screen.devicePixelRatio
sourceSize.width: Math.min(Screen.desktopAvailableWidth, originalWidth < 1 ? Screen.desktopAvailableWidth : originalWidth) * Screen.devicePixelRatio
2022-04-16 03:13:01 +03:00
visible: !mxcimage.loaded
2021-08-29 06:20:23 +03:00
}
MxcAnimatedImage {
id: mxcimage
anchors.fill: parent
eventId: parent.eventId
2022-04-16 03:13:01 +03:00
play: !Settings.animateImagesOnHover || parent.hovered
roomm: room
visible: loaded
2021-08-29 06:20:23 +03:00
}
Item {
id: overlay
anchors.fill: parent
2022-03-24 03:35:42 +03:00
visible: parent.hovered
2020-10-18 23:30:42 +03:00
2021-08-29 06:20:23 +03:00
Rectangle {
id: container
anchors.bottom: overlay.bottom
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.window
2022-04-16 03:13:01 +03:00
implicitHeight: imgcaption.implicitHeight
2021-08-29 06:20:23 +03:00
opacity: 0.75
2022-04-16 03:13:01 +03:00
width: parent.width
2021-08-29 06:20:23 +03:00
}
Text {
id: imgcaption
anchors.fill: container
2022-04-16 03:13:01 +03:00
color: timelineRoot.palette.text
2021-08-29 06:20:23 +03:00
elide: Text.ElideMiddle
horizontalAlignment: Text.AlignHCenter
// See this MSC: https://github.com/matrix-org/matrix-doc/pull/2530
text: filename ? filename : body
2022-04-16 03:13:01 +03:00
verticalAlignment: Text.AlignVCenter
2020-10-13 23:24:42 +03:00
}
}
}