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-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
|
2022-04-15 03:58:44 +03:00
|
|
|
import im.nheko
|
2019-10-06 02:44:02 +03:00
|
|
|
|
2022-03-24 03:35:42 +03:00
|
|
|
AbstractButton {
|
2021-07-12 01:24:33 +03:00
|
|
|
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
|
2021-07-12 01:24:33 +03:00
|
|
|
required property string filename
|
2022-04-16 03:13:01 +03:00
|
|
|
property bool fitsMetadata: (parent.width - width) > metadataWidth + 4
|
2021-07-12 01:24:33 +03:00
|
|
|
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-02-17 02:42:57 +03:00
|
|
|
|
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 {
|
2021-07-12 01:24:33 +03:00
|
|
|
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)
|
2021-12-13 21:09:03 +03:00
|
|
|
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
|
2022-01-04 07:19:48 +03:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2019-09-08 13:44:46 +03:00
|
|
|
}
|