Use TDLibPhoto in MessagePhoto

This commit is contained in:
John Gibbon 2021-01-19 22:39:46 +01:00
parent b61bf2a46b
commit 5a720c1a00
2 changed files with 16 additions and 55 deletions

View file

@ -18,68 +18,26 @@
*/
import QtQuick 2.6
import Sailfish.Silica 1.0
import WerkWolf.Fernschreiber 1.0
import "../"
MessageContentBase {
id: imagePreviewItem
readonly property int defaultHeight: Math.round(width * 2 / 3)
height: singleImage.visible ? Math.min(defaultHeight, singleImage.bestHeight + Theme.paddingSmall) : defaultHeight
height: Math.max(Theme.itemSizeExtraSmall, Math.min(defaultHeight, width / (biggest.width/biggest.height)))
readonly property int defaultHeight: Math.round(width * 0.66666666)
readonly property var biggest: rawMessage.content.photo.sizes[rawMessage.content.photo.sizes.length - 1];
onClicked: {
pageStack.push(Qt.resolvedUrl("../../pages/ImagePage.qml"), {
"photoData" : imagePreviewItem.rawMessage.content.photo
"photoData" : photo.photo,
// "pictureFileInformation" : photo.fileInformation
})
}
Component.onCompleted: updateImage()
onRawMessageChanged: updateImage()
function updateImage() {
if (rawMessage.content.photo) {
// Check first which size fits best...
var photo
var photoData = rawMessage.content.photo
for (var i = 0; i < photoData.sizes.length; i++) {
photo = photoData.sizes[i].photo
if (photoData.sizes[i].width >= imagePreviewItem.width) {
break
TDLibPhoto {
id: photo
anchors.fill: parent
photo: rawMessage.content.photo
highlighted: parent.highlighted
}
}
if (photo) {
imageFile.fileInformation = photo
}
}
}
TDLibFile {
id: imageFile
tdlib: tdLibWrapper
autoLoad: true
}
Image {
id: singleImage
width: parent.width - Theme.paddingSmall
height: parent.height - Theme.paddingSmall
readonly property int bestHeight: (status === Image.Ready) ? Math.round(implicitHeight * width / implicitWidth) : 0
anchors.centerIn: parent
fillMode: Image.PreserveAspectCrop
autoTransform: true
asynchronous: true
source: imageFile.isDownloadingCompleted ? imageFile.path : ""
visible: status === Image.Ready
opacity: visible ? 1 : 0
Behavior on opacity { FadeAnimation {} }
layer.enabled: imagePreviewItem.highlighted
layer.effect: PressEffect { source: singleImage }
}
BackgroundImage {
visible: singleImage.status !== Image.Ready
visible: !rawMessage.content.photo.minithumbnail && photo.image.status !== Image.Ready
}
}

View file

@ -1059,7 +1059,7 @@ Page {
function getContentComponentHeight(contentType, content, parentWidth) {
switch(contentType) {
case "messageAnimation":
return Functions.getVideoHeight(parentWidth, content.video);
return Functions.getVideoHeight(parentWidth, content.animation);
case "messageAudio":
case "messageVoiceNote":
case "messageDocument":
@ -1067,9 +1067,12 @@ Page {
case "messageGame":
return parentWidth * 0.66666666 + Theme.itemSizeLarge; // 2 / 3;
case "messageLocation":
case "messagePhoto":
case "messageVenue":
return parentWidth * 0.66666666; // 2 / 3;
case "messagePhoto":
var biggest = content.photo.sizes[content.photo.sizes.length - 1];
var aspectRatio = biggest.width/biggest.height;
return Math.max(Theme.itemSizeExtraSmall, Math.min(parentWidth * 0.66666666, parentWidth / aspectRatio));
case "messagePoll":
return Theme.itemSizeSmall * (4 + content.poll.options);
case "messageSticker":