Page MenuHomePhorge

Image.qml
No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None

Image.qml

/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2020-2023 tusooa <tusooa@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Controls 2.15
import moe.kazv.mxc.kazv 0.0 as MK
import org.kde.kirigami 2.13 as Kirigami
import '.' as Types
import '..' as Kazv
Simple {
id: upper
property var gender: 'neutral'
property var body: event.content.body
property var thumbnailFile: imageInfo.thumbnail_file || {}
property var thumbnailInfo: imageInfo.thumbnail_info || {}
property var thumbnailMxcUri: thumbnailFile.url || imageInfo.thumbnail_url || ""
property var thumbnailSha256: thumbnailFile.hashes ? thumbnailFile.hashes.sha256 : ""
property var thumbnailKey: thumbnailFile.key ? thumbnailFile.key.k : ""
property var thumbnailIv: thumbnailFile.iv || ""
property var thumbnailUri: thumbnailMxcUri ? kazvIOManager.cacheFile(matrixSdk.mxcUriToHttp(thumbnailMxcUri), thumbnailMxcUri.split('/')[3], thumbnailSha256, thumbnailKey, thumbnailIv) : ""
property var thumbnailWidth: thumbnailInfo.w
property var thumbnailHeight: thumbnailInfo.h
property var imageInfo: event.content.info || {}
property var imageFile: event.content.file || {}
property var imageMxcUri: imageFile.url || event.content.url
property var imageSha256: imageFile.hashes ? imageFile.hashes.sha256 : ""
property var imageKey: imageFile.key ? imageFile.key.k : ""
property var imageIv: imageFile.iv || ""
property var imageUri: thumbnailMxcUri ? matrixSdk.mxcUriToHttp(imageMxcUri) : kazvIOManager.cacheFile(matrixSdk.mxcUriToHttp(imageMxcUri), imageMxcUri.split('/')[3], imageSha256, imageKey, imageIv) // If there are no thumbnail, cache the image
property var imageWidth: imageInfo.w
property var imageHeight: imageInfo.h
property var previewUri: thumbnailMxcUri ? thumbnailUri : imageUri // Uri for source of Image QML type
property var mediaId: previewUri.toString().split('/').slice(-1)[0]
property var innerContentWidth: upper.contentMaxWidth - bubble.bubbleSpacing
property var kazvIOJob
Types.MediaBubble {
id: bubble
eventId: event.eventId
serverUrl: upper.imageUri
fileName: body
hash: imageSha256
key: upper.imageKey
iv: upper.imageIv
property var label: Kazv.SelectableText {
Layout.fillWidth: true
wrapMode: Text.Wrap
text: l10n.get('event-message-image-sent', { gender, body })
}
property var image: Image {
id: image
source: kazvIOJob ? "" : previewUri
Layout.preferredWidth: calcImageWidth()
Layout.maximumWidth: innerContentWidth
Layout.preferredHeight: calcImageHeight()
fillMode: Image.PreserveAspectFit
}
ColumnLayout {
id: layout
Layout.fillWidth: true
data: [
bubble.mediaFileMenu,
bubble.label,
bubble.image,
bubble.progressBar
]
}
}
function calcImageWidth() {
const eventSpecWidth = thumbnailMxcUri ? thumbnailWidth : imageWidth
return eventSpecWidth || image.implicitWidth || 1
}
function calcImageHeight() {
const eventSpecHeight = thumbnailMxcUri ? thumbnailHeight : imageHeight
const height = eventSpecHeight || image.implicitHeight || 1
const width = calcImageWidth()
if (width > innerContentWidth) {
return height * (innerContentWidth / width)
}
return height
}
Component.onCompleted: {
upper.kazvIOJob = kazvIOManager.getDownloadJob(mediaId)
}
}

File Metadata

Mime Type
text/plain
Expires
Tue, Jun 24, 3:39 PM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
234913
Default Alt Text
Image.qml (3 KB)

Event Timeline