nheko/resources/qml/delegates/ImageMessage.qml

112 lines
3.3 KiB
QML
Raw Normal View History

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