From 5a720c1a0084c1172512470d37886c11c01d5f39 Mon Sep 17 00:00:00 2001 From: John Gibbon Date: Tue, 19 Jan 2021 22:39:46 +0100 Subject: [PATCH] Use TDLibPhoto in MessagePhoto --- .../messageContent/MessagePhoto.qml | 64 ++++--------------- qml/pages/ChatPage.qml | 7 +- 2 files changed, 16 insertions(+), 55 deletions(-) diff --git a/qml/components/messageContent/MessagePhoto.qml b/qml/components/messageContent/MessagePhoto.qml index e4e9c95..8c30e6f 100644 --- a/qml/components/messageContent/MessagePhoto.qml +++ b/qml/components/messageContent/MessagePhoto.qml @@ -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 - } - } - if (photo) { - imageFile.fileInformation = photo - } - } + TDLibPhoto { + id: photo + anchors.fill: parent + photo: rawMessage.content.photo + highlighted: parent.highlighted } - - 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 } } diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index b297805..69735f7 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -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":