matrixion/resources/qml/delegates/ImageMessage.qml

183 lines
5.3 KiB
QML
Raw Normal View History

// SPDX-FileCopyrightText: Nheko Contributors
//
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 QtQuick.Layouts
import im.nheko
2019-10-06 02:44:02 +03:00
2022-03-24 03:35:42 +03:00
AbstractButton {
required property int type
required property int originalWidth
required property int originalHeight
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
2023-07-08 20:22:50 +03:00
required property int containerHeight
property double divisor: isReply ? 5 : 3
2020-10-08 22:11:21 +03:00
//Layout.maximumWidth: originalWidth
Layout.maximumHeight: Math.min(originalHeight, containerHeight / divisor)
implicitWidth: height/proportionalHeight
implicitHeight: Math.min(Layout.maximumHeight, width*proportionalHeight)
2022-03-24 03:35:42 +03:00
hoverEnabled: true
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"
states: [
State {
2023-02-23 04:16:55 +03:00
name: "BlurhashVisible"
PropertyChanges {
target: blurhash_
2023-02-23 04:16:55 +03:00
opacity: (img.status != Image.Ready) || (timeline.privacyScreen.active && blurhash) ? 1 : 0
visible: (img.status != Image.Ready) || (timeline.privacyScreen.active && blurhash)
}
PropertyChanges {
target: img
opacity: 0
}
PropertyChanges {
target: mxcimage
opacity: 0
}
},
State {
2023-02-23 04:16:55 +03:00
name: "ImageVisible"
PropertyChanges {
target: blurhash_
opacity: 0
visible: false
}
PropertyChanges {
target: img
opacity: 1
}
PropertyChanges {
target: mxcimage
opacity: 1
}
}
]
transitions: [
Transition {
2023-02-23 04:16:55 +03:00
from: "ImageVisible"
to: "BlurhashVisible"
reversible: true
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
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
source: url != "" ? (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
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
2022-03-24 03:35:42 +03:00
play: !Settings.animateImagesOnHover || parent.hovered
2021-08-29 06:20:23 +03:00
eventId: parent.eventId
}
Image {
id: blurhash_
anchors.fill: parent
source: blurhash ? ("image://blurhash/" + blurhash) : ("image://colorimage/:/icons/icons/ui/image-failed.svg?" + palette.buttonText)
asynchronous: true
fillMode: Image.PreserveAspectFit
sourceSize.width: parent.width * Screen.devicePixelRatio
sourceSize.height: parent.height * Screen.devicePixelRatio
}
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
2021-08-29 06:20: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
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
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
}