2023-02-22 01:48:49 +03:00
|
|
|
// SPDX-FileCopyrightText: 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
|
|
|
|
|
2023-07-08 20:22:50 +03:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Window
|
|
|
|
import QtQuick.Controls
|
|
|
|
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 int type
|
|
|
|
required property int originalWidth
|
2023-09-18 00:11:24 +03:00
|
|
|
required property int originalHeight
|
2021-07-12 01:24:33 +03:00
|
|
|
required property double proportionalHeight
|
|
|
|
required property string url
|
|
|
|
required property string blurhash
|
|
|
|
required property string body
|
|
|
|
required property string filename
|
2021-08-29 06:20:23 +03:00
|
|
|
required property string eventId
|
2023-07-08 20:22:50 +03:00
|
|
|
required property int containerHeight
|
2023-10-09 22:41:00 +03:00
|
|
|
property double divisor: EventDelegateChooser.isReply ? 10 : 4
|
2023-10-09 00:52:23 +03:00
|
|
|
|
2024-08-21 01:14:34 +03:00
|
|
|
property bool showImage: room.showImage()
|
|
|
|
|
2023-10-09 00:52:23 +03:00
|
|
|
EventDelegateChooser.keepAspectRatio: true
|
|
|
|
EventDelegateChooser.maxWidth: originalWidth
|
|
|
|
EventDelegateChooser.maxHeight: containerHeight / divisor
|
|
|
|
EventDelegateChooser.aspectRatio: proportionalHeight
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2022-03-24 03:35:42 +03:00
|
|
|
hoverEnabled: true
|
2023-10-09 00:52:23 +03:00
|
|
|
enabled: !EventDelegateChooser.isReply
|
2020-10-08 22:11:21 +03:00
|
|
|
|
2023-02-23 04:16:55 +03:00
|
|
|
state: (img.status != Image.Ready || timeline.privacyScreen.active) ? "BlurhashVisible" : "ImageVisible"
|
2023-02-21 03:59:06 +03:00
|
|
|
states: [
|
|
|
|
State {
|
2023-02-23 04:16:55 +03:00
|
|
|
name: "BlurhashVisible"
|
2023-02-21 03:59:06 +03:00
|
|
|
|
|
|
|
PropertyChanges {
|
2023-10-26 02:51:45 +03:00
|
|
|
blurhash_ {
|
|
|
|
opacity: (img.status != Image.Ready) || (timeline.privacyScreen.active && blurhash) ? 1 : 0
|
|
|
|
visible: (img.status != Image.Ready) || (timeline.privacyScreen.active && blurhash)
|
|
|
|
}
|
2023-02-21 03:59:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
2023-10-26 02:51:45 +03:00
|
|
|
img.opacity: 0
|
2023-02-21 03:59:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
2023-10-26 02:51:45 +03:00
|
|
|
mxcimage.opacity: 0
|
2023-02-21 03:59:06 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
2023-02-23 04:16:55 +03:00
|
|
|
name: "ImageVisible"
|
2023-02-21 03:59:06 +03:00
|
|
|
|
|
|
|
PropertyChanges {
|
2023-10-26 02:51:45 +03:00
|
|
|
blurhash_ {
|
|
|
|
opacity: 0
|
|
|
|
visible: false
|
|
|
|
}
|
2023-02-21 03:59:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
2023-10-26 02:51:45 +03:00
|
|
|
img.opacity: 1
|
2023-02-21 03:59:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PropertyChanges {
|
2023-10-26 02:51:45 +03:00
|
|
|
mxcimage.opacity: 1
|
2023-02-21 03:59:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
transitions: [
|
|
|
|
Transition {
|
2023-02-23 04:16:55 +03:00
|
|
|
from: "ImageVisible"
|
|
|
|
to: "BlurhashVisible"
|
2023-02-21 03:59:06 +03:00
|
|
|
reversible: true
|
2024-06-24 04:24:39 +03:00
|
|
|
enabled: !Settings.reducedMotion
|
2023-02-21 03:59:06 +03:00
|
|
|
|
|
|
|
SequentialAnimation {
|
|
|
|
PropertyAction {
|
|
|
|
target: blurhash_
|
|
|
|
property: "visible"
|
|
|
|
}
|
|
|
|
|
|
|
|
ParallelAnimation {
|
|
|
|
NumberAnimation {
|
|
|
|
target: blurhash_
|
|
|
|
property: "opacity"
|
|
|
|
duration: 300
|
|
|
|
easing.type: Easing.Linear
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberAnimation {
|
|
|
|
target: img
|
|
|
|
property: "opacity"
|
|
|
|
duration: 300
|
|
|
|
easing.type: Easing.Linear
|
|
|
|
}
|
|
|
|
|
|
|
|
NumberAnimation {
|
|
|
|
target: mxcimage
|
|
|
|
property: "opacity"
|
|
|
|
duration: 300
|
|
|
|
easing.type: Easing.Linear
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2022-02-14 23:07:03 +03:00
|
|
|
property int metadataWidth
|
2023-06-02 02:29:05 +03:00
|
|
|
property bool fitsMetadata: parent != null ? (parent.width - width) > metadataWidth+4 : false
|
2022-02-14 23:07:03 +03:00
|
|
|
|
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
|
2024-08-21 01:14:34 +03:00
|
|
|
source: (url != "" && showImage) ? (url.replace("mxc://", "image://MxcImage/") + "?scale") : ""
|
2020-10-08 22:11:21 +03:00
|
|
|
asynchronous: true
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2023-08-27 13:38:48 +03:00
|
|
|
horizontalAlignment: Image.AlignLeft
|
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
|
|
|
|
roomm: room
|
2022-03-24 03:35:42 +03:00
|
|
|
play: !Settings.animateImagesOnHover || parent.hovered
|
2024-08-21 01:14:34 +03:00
|
|
|
eventId: showImage ? parent.eventId : ""
|
2023-10-09 00:52:23 +03:00
|
|
|
|
|
|
|
anchors.fill: parent
|
2021-08-29 06:20:23 +03:00
|
|
|
}
|
2020-10-15 18:52:49 +03:00
|
|
|
|
2023-02-14 04:44:42 +03:00
|
|
|
Image {
|
|
|
|
id: blurhash_
|
|
|
|
|
2023-06-02 02:29:05 +03:00
|
|
|
source: blurhash ? ("image://blurhash/" + blurhash) : ("image://colorimage/:/icons/icons/ui/image-failed.svg?" + palette.buttonText)
|
2023-02-14 04:44:42 +03:00
|
|
|
asynchronous: true
|
|
|
|
fillMode: Image.PreserveAspectFit
|
2024-02-15 17:57:07 +03:00
|
|
|
sourceSize.width: blurhash ? parent.width * Screen.devicePixelRatio : Math.min(parent.width, parent.height)
|
|
|
|
sourceSize.height: blurhash ? parent.height * Screen.devicePixelRatio : Math.min(parent.width, parent.height)
|
2023-10-09 00:52:23 +03:00
|
|
|
|
|
|
|
anchors.fill: parent
|
2023-02-14 04:44:42 +03:00
|
|
|
}
|
|
|
|
|
2024-08-21 01:14:34 +03:00
|
|
|
onClicked: {
|
|
|
|
Settings.openImageExternal ? room.openMedia(eventId) : TimelineManager.openImageOverlay(room, url, eventId, originalWidth, proportionalHeight);
|
|
|
|
}
|
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
|
|
|
|
2023-10-09 00:52:23 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
width: parent.width
|
|
|
|
implicitHeight: imgcaption.implicitHeight
|
|
|
|
anchors.bottom: overlay.bottom
|
2023-06-02 02:29:05 +03:00
|
|
|
color: palette.window
|
2021-08-29 06:20:23 +03:00
|
|
|
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
|
2023-06-02 02:29:05 +03:00
|
|
|
color: palette.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
|
|
|
|
2024-08-21 01:14:34 +03:00
|
|
|
Button {
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: !showImage && !parent.EventDelegateChooser.isReply
|
|
|
|
enabled: visible
|
|
|
|
text: qsTr("Show")
|
|
|
|
onClicked: {
|
|
|
|
showImage = true;
|
|
|
|
}
|
|
|
|
}
|
2019-09-08 13:44:46 +03:00
|
|
|
}
|