2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
2022-01-01 06:57:53 +03:00
|
|
|
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
2021-03-07 07:57:56 +03:00
|
|
|
//
|
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
|
2019-11-30 03:43:39 +03:00
|
|
|
import im.nheko 1.0
|
2019-10-06 02:44:02 +03:00
|
|
|
|
2019-09-08 13:44:46 +03:00
|
|
|
Item {
|
2021-07-12 01:24:33 +03:00
|
|
|
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 06:20:23 +03:00
|
|
|
required property string eventId
|
2021-07-12 01:24:33 +03:00
|
|
|
property double divisor: isReply ? 5 : 3
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2022-02-17 02:42:57 +03:00
|
|
|
property int tempWidth: originalWidth < 1? 400: originalWidth
|
|
|
|
|
2022-03-22 22:33:14 +03:00
|
|
|
implicitWidth: Math.round(tempWidth*Math.min((timelineView.fullHeight/divisor)/(tempWidth*proportionalHeight), 1))
|
2022-02-14 23:07:03 +03:00
|
|
|
width: Math.min(parent.width,implicitWidth)
|
2022-02-12 00:02:30 +03:00
|
|
|
height: width*proportionalHeight
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2022-02-14 23:07:03 +03:00
|
|
|
property int metadataWidth
|
|
|
|
property bool fitsMetadata: (parent.width - width) > metadataWidth+4
|
|
|
|
|
2020-10-08 22:11:21 +03:00
|
|
|
Image {
|
2021-07-12 01:24:33 +03:00
|
|
|
id: blurhash_
|
2020-10-08 22:11:21 +03:00
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
visible: img.status != Image.Ready
|
2021-11-14 04:23:10 +03:00
|
|
|
source: blurhash ? ("image://blurhash/" + blurhash) : ("image://colorimage/:/icons/icons/ui/image-failed.svg?" + Nheko.colors.buttonText)
|
2020-10-08 22:11:21 +03:00
|
|
|
asynchronous: true
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2021-12-13 21:09:03 +03:00
|
|
|
sourceSize.width: parent.width * Screen.devicePixelRatio
|
|
|
|
sourceSize.height: parent.height * Screen.devicePixelRatio
|
2020-10-08 22:11:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Image {
|
|
|
|
id: img
|
|
|
|
|
2021-08-29 06:20:23 +03:00
|
|
|
visible: !mxcimage.loaded
|
2020-10-08 22:11:21 +03:00
|
|
|
anchors.fill: parent
|
2022-03-09 22:15:37 +03:00
|
|
|
source: url.replace("mxc://", "image://MxcImage/") + "?scale"
|
2020-10-08 22:11:21 +03:00
|
|
|
asynchronous: true
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2020-08-21 22:46:42 +03:00
|
|
|
smooth: true
|
|
|
|
mipmap: true
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2022-01-04 07:19:48 +03: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 06:20:23 +03:00
|
|
|
}
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2021-08-29 06:20:23 +03:00
|
|
|
MxcAnimatedImage {
|
|
|
|
id: mxcimage
|
2020-10-18 23:30:42 +03:00
|
|
|
|
2021-08-29 06:20:23 +03:00
|
|
|
visible: loaded
|
|
|
|
anchors.fill: parent
|
|
|
|
roomm: room
|
2021-08-29 16:33:39 +03:00
|
|
|
play: !Settings.animateImagesOnHover || mouseArea.hovered
|
2021-08-29 06:20:23 +03:00
|
|
|
eventId: parent.eventId
|
|
|
|
}
|
2020-10-15 18:52:49 +03:00
|
|
|
|
2021-11-15 00:18:25 +03:00
|
|
|
TapHandler {
|
2022-01-02 23:46:29 +03:00
|
|
|
//enabled: type == MtxEvent.ImageMessage && (img.status == Image.Ready || mxcimage.loaded)
|
2021-11-15 00:18:25 +03:00
|
|
|
onSingleTapped: {
|
2022-03-19 07:54:02 +03:00
|
|
|
Settings.openImageExternal ? room.openMedia(eventId) : TimelineManager.openImageOverlay(room, url, eventId);
|
2021-11-15 00:18:25 +03:00
|
|
|
eventPoint.accepted = true;
|
|
|
|
}
|
|
|
|
gesturePolicy: TapHandler.ReleaseWithinBounds
|
|
|
|
}
|
|
|
|
|
2021-08-29 06:20:23 +03:00
|
|
|
HoverHandler {
|
|
|
|
id: mouseArea
|
|
|
|
}
|
2020-10-18 23:30:42 +03:00
|
|
|
|
2021-08-29 06:20:23 +03:00
|
|
|
Item {
|
|
|
|
id: overlay
|
2020-10-13 23:24:42 +03:00
|
|
|
|
2021-08-29 06:20:23 +03:00
|
|
|
anchors.fill: parent
|
|
|
|
visible: mouseArea.hovered
|
2020-10-18 23:30:42 +03:00
|
|
|
|
2021-08-29 06:20:23 +03: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 23:30:42 +03:00
|
|
|
|
2021-08-29 06:20:23 +03: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 23:24:42 +03:00
|
|
|
}
|
2020-10-18 23:30:42 +03:00
|
|
|
|
2020-10-13 23:24:42 +03:00
|
|
|
}
|
2020-10-18 23:30:42 +03:00
|
|
|
|
2019-09-08 13:44:46 +03:00
|
|
|
}
|