Debian Codegraph @

resources/qml/delegates/ImageMessage.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import QtQuick
6 import QtQuick.Window
7 import QtQuick.Controls
8 import im.nheko
9
10 AbstractButton {
11 required property int type
12 required property int originalWidth
13 required property int originalHeight
14 required property double proportionalHeight
15 required property string url
16 required property string blurhash
17 required property string body
18 required property string filename
19 required property string eventId
20 required property int containerHeight
21 property double divisor: EventDelegateChooser.isReply ? 10 : 4
22
23 property bool showImage: room.showImage()
24
25 EventDelegateChooser.keepAspectRatio: true
26 EventDelegateChooser.maxWidth: originalWidth
27 EventDelegateChooser.maxHeight: containerHeight / divisor
28 EventDelegateChooser.aspectRatio: proportionalHeight
29
30 hoverEnabled: true
31 enabled: !EventDelegateChooser.isReply
32
33 state: (img.status != Image.Ready || timeline.privacyScreen.active) ? "BlurhashVisible" : "ImageVisible"
34 states: [
35 State {
36 name: "BlurhashVisible"
37
38 PropertyChanges {
39 blurhash_ {
40 opacity: (img.status != Image.Ready) || (timeline.privacyScreen.active && blurhash) ? 1 : 0
41 visible: (img.status != Image.Ready) || (timeline.privacyScreen.active && blurhash)
42 }
43 }
44
45 PropertyChanges {
46 img.opacity: 0
47 }
48
49 PropertyChanges {
50 mxcimage.opacity: 0
51 }
52 },
53 State {
54 name: "ImageVisible"
55
56 PropertyChanges {
57 blurhash_ {
58 opacity: 0
59 visible: false
60 }
61 }
62
63 PropertyChanges {
64 img.opacity: 1
65 }
66
67 PropertyChanges {
68 mxcimage.opacity: 1
69 }
70 }
71 ]
72 transitions: [
73 Transition {
74 from: "ImageVisible"
75 to: "BlurhashVisible"
76 reversible: true
77
78 SequentialAnimation {
79 PropertyAction {
80 target: blurhash_
81 property: "visible"
82 }
83
84 ParallelAnimation {
85 NumberAnimation {
86 target: blurhash_
87 property: "opacity"
88 duration: 300
89 easing.type: Easing.Linear
90 }
91
92 NumberAnimation {
93 target: img
94 property: "opacity"
95 duration: 300
96 easing.type: Easing.Linear
97 }
98
99 NumberAnimation {
100 target: mxcimage
101 property: "opacity"
102 duration: 300
103 easing.type: Easing.Linear
104 }
105 }
106 }
107 }
108 ]
109
110 property int metadataWidth
111 property bool fitsMetadata: parent != null ? (parent.width - width) > metadataWidth+4 : false
112
113 Image {
114 id: img
115
116 visible: !mxcimage.loaded
117 anchors.fill: parent
118 source: (url != "" && showImage) ? (url.replace("mxc://", "image://MxcImage/") + "?scale") : ""
119 asynchronous: true
120 fillMode: Image.PreserveAspectFit
121 horizontalAlignment: Image.AlignLeft
122 smooth: true
123 mipmap: true
124
125 sourceSize.width: Math.min(Screen.desktopAvailableWidth, originalWidth < 1 ? Screen.desktopAvailableWidth : originalWidth) * Screen.devicePixelRatio
126 sourceSize.height: Math.min(Screen.desktopAvailableHeight, (originalWidth < 1 ? Screen.desktopAvailableHeight : originalWidth*proportionalHeight)) * Screen.devicePixelRatio
127 }
128
129 MxcAnimatedImage {
130 id: mxcimage
131
132 visible: loaded
133 roomm: room
134 play: !Settings.animateImagesOnHover || parent.hovered
135 eventId: showImage ? parent.eventId : ""
136
137 anchors.fill: parent
138 }
139
140 Image {
141 id: blurhash_
142
143 source: blurhash ? ("image://blurhash/" + blurhash) : ("image://colorimage/:/icons/icons/ui/image-failed.svg?" + palette.buttonText)
144 asynchronous: true
145 fillMode: Image.PreserveAspectFit
146 sourceSize.width: blurhash ? parent.width * Screen.devicePixelRatio : Math.min(parent.width, parent.height)
147 sourceSize.height: blurhash ? parent.height * Screen.devicePixelRatio : Math.min(parent.width, parent.height)
148
149 anchors.fill: parent
150 }
151
152 onClicked: {
153 Settings.openImageExternal ? room.openMedia(eventId) : TimelineManager.openImageOverlay(room, url, eventId, originalWidth, proportionalHeight);
154 }
155
156 Item {
157 id: overlay
158
159 anchors.fill: parent
160
161 visible: parent.hovered
162
163 Rectangle {
164 id: container
165
166 width: parent.width
167 implicitHeight: imgcaption.implicitHeight
168 anchors.bottom: overlay.bottom
169 color: palette.window
170 opacity: 0.75
171 }
172
173 Text {
174 id: imgcaption
175
176 anchors.fill: container
177 elide: Text.ElideMiddle
178 horizontalAlignment: Text.AlignHCenter
179 verticalAlignment: Text.AlignVCenter
180 // See this MSC: https://github.com/matrix-org/matrix-doc/pull/2530
181 text: filename ? filename : body
182 color: palette.text
183 }
184
185 }
186
187 Button {
188 anchors.centerIn: parent
189 visible: !showImage && !parent.EventDelegateChooser.isReply
190 enabled: visible
191 text: qsTr("Show")
192 onClicked: {
193 showImage = true;
194 }
195 }
196 }