Merge pull request #222 from monich/wideImages

Improve preview of wide images
This commit is contained in:
Sebastian Wolf 2020-12-03 21:53:22 +01:00 committed by GitHub
commit fce3f1edff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,70 +18,63 @@
*/ */
import QtQuick 2.6 import QtQuick 2.6
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import WerkWolf.Fernschreiber 1.0
Item { Item {
id: imagePreviewItem id: imagePreviewItem
property ListItem messageListItem property ListItem messageListItem
property MessageOverlayFlickable overlayFlickable property MessageOverlayFlickable overlayFlickable
property var rawMessage: messageListItem ? messageListItem.myMessage : overlayFlickable.overlayMessage property var rawMessage: messageListItem ? messageListItem.myMessage : overlayFlickable.overlayMessage
property var photoData: rawMessage.content.photo; property var photoData: rawMessage.content.photo
property var pictureFileInformation; readonly property int defaultHeight: Math.round(width * 2 / 3)
width: parent.width width: parent.width
height: width * 2 / 3 height: singleImage.visible ? Math.min(defaultHeight, singleImage.bestHeight + Theme.paddingSmall) : defaultHeight
Component.onCompleted: { Component.onCompleted: {
updatePicture();
}
function updatePicture() {
if (photoData) { if (photoData) {
// Check first which size fits best... // Check first which size fits best...
var photo
for (var i = 0; i < photoData.sizes.length; i++) { for (var i = 0; i < photoData.sizes.length; i++) {
imagePreviewItem.pictureFileInformation = photoData.sizes[i].photo; photo = photoData.sizes[i].photo
if (photoData.sizes[i].width >= imagePreviewItem.width) { if (photoData.sizes[i].width >= imagePreviewItem.width) {
break; break
} }
} }
if (photo) {
if (imagePreviewItem.pictureFileInformation.local.is_downloading_completed) { imageFile.fileInformation = photo
singleImage.source = imagePreviewItem.pictureFileInformation.local.path;
} else {
tdLibWrapper.downloadFile(imagePreviewItem.pictureFileInformation.id);
} }
} }
} }
Connections { TDLibFile {
target: tdLibWrapper id: imageFile
onFileUpdated: { tdlib: tdLibWrapper
if (imagePreviewItem.pictureFileInformation) { autoLoad: true
if (fileId === imagePreviewItem.pictureFileInformation.id && fileInformation.local.is_downloading_completed) {
imagePreviewItem.pictureFileInformation = fileInformation;
singleImage.source = fileInformation.local.path;
}
}
}
} }
Image { Image {
id: singleImage id: singleImage
width: parent.width - Theme.paddingSmall width: parent.width - Theme.paddingSmall
height: parent.height - Theme.paddingSmall height: parent.height - Theme.paddingSmall
readonly property int bestHeight: (status === Image.Ready) ? Math.round(implicitHeight * width / implicitWidth) : 0
anchors.centerIn: parent anchors.centerIn: parent
fillMode: Image.PreserveAspectCrop fillMode: Image.PreserveAspectCrop
autoTransform: true autoTransform: true
asynchronous: true asynchronous: true
source: imageFile.isDownloadingCompleted ? imageFile.path : ""
visible: status === Image.Ready visible: status === Image.Ready
opacity: status === Image.Ready ? 1 : 0 opacity: visible ? 1 : 0
Behavior on opacity { NumberAnimation {} } Behavior on opacity { FadeAnimation {} }
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onClicked: { onClicked: {
pageStack.push(Qt.resolvedUrl("../pages/ImagePage.qml"), { "photoData" : imagePreviewItem.photoData, "pictureFileInformation" : imagePreviewItem.pictureFileInformation }); pageStack.push(Qt.resolvedUrl("../pages/ImagePage.qml"), {
"photoData" : imagePreviewItem.photoData,
"pictureFileInformation" : imageFile.fileInformation
})
} }
} }
} }