Merge pull request #316 from monich/image
Handle message data change in ImagePreview
This commit is contained in:
commit
3abdbe6a58
2 changed files with 23 additions and 30 deletions
|
@ -26,7 +26,6 @@ Item {
|
||||||
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
|
|
||||||
readonly property int defaultHeight: Math.round(width * 2 / 3)
|
readonly property int defaultHeight: Math.round(width * 2 / 3)
|
||||||
property bool highlighted
|
property bool highlighted
|
||||||
|
|
||||||
|
@ -35,15 +34,19 @@ Item {
|
||||||
|
|
||||||
function clicked() {
|
function clicked() {
|
||||||
pageStack.push(Qt.resolvedUrl("../pages/ImagePage.qml"), {
|
pageStack.push(Qt.resolvedUrl("../pages/ImagePage.qml"), {
|
||||||
"photoData" : imagePreviewItem.photoData,
|
"photoData" : imagePreviewItem.rawMessage.content.photo
|
||||||
"pictureFileInformation" : imageFile.fileInformation
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: updateImage()
|
||||||
if (photoData) {
|
|
||||||
|
onRawMessageChanged: updateImage()
|
||||||
|
|
||||||
|
function updateImage() {
|
||||||
|
if (rawMessage.content.photo) {
|
||||||
// Check first which size fits best...
|
// Check first which size fits best...
|
||||||
var photo
|
var photo
|
||||||
|
var photoData = rawMessage.content.photo
|
||||||
for (var i = 0; i < photoData.sizes.length; i++) {
|
for (var i = 0; i < photoData.sizes.length; i++) {
|
||||||
photo = photoData.sizes[i].photo
|
photo = photoData.sizes[i].photo
|
||||||
if (photoData.sizes[i].width >= imagePreviewItem.width) {
|
if (photoData.sizes[i].width >= imagePreviewItem.width) {
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
import QtQuick 2.6
|
import QtQuick 2.6
|
||||||
import Sailfish.Silica 1.0
|
import Sailfish.Silica 1.0
|
||||||
|
import WerkWolf.Fernschreiber 1.0
|
||||||
import "../components"
|
import "../components"
|
||||||
import "../js/functions.js" as Functions
|
import "../js/functions.js" as Functions
|
||||||
import "../js/debug.js" as Debug
|
import "../js/debug.js" as Debug
|
||||||
|
@ -28,9 +29,7 @@ Page {
|
||||||
backNavigation: !imageOnly
|
backNavigation: !imageOnly
|
||||||
|
|
||||||
property var photoData;
|
property var photoData;
|
||||||
property var pictureFileInformation;
|
|
||||||
|
|
||||||
property string imageUrl;
|
|
||||||
property int imageWidth;
|
property int imageWidth;
|
||||||
property int imageHeight;
|
property int imageHeight;
|
||||||
|
|
||||||
|
@ -47,40 +46,31 @@ Page {
|
||||||
property bool imageOnly
|
property bool imageOnly
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
updatePicture();
|
if (photoData) {
|
||||||
}
|
|
||||||
|
|
||||||
function updatePicture() {
|
|
||||||
if (typeof photoData === "object") {
|
|
||||||
// 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++) {
|
||||||
imagePage.imageWidth = photoData.sizes[i].width;
|
imagePage.imageWidth = photoData.sizes[i].width;
|
||||||
imagePage.imageHeight = photoData.sizes[i].height;
|
imagePage.imageHeight = photoData.sizes[i].height;
|
||||||
imagePage.pictureFileInformation = photoData.sizes[i].photo;
|
photo = photoData.sizes[i].photo
|
||||||
if (photoData.sizes[i].width >= imagePage.width) {
|
if (photoData.sizes[i].width >= imagePage.width) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (photo) {
|
||||||
if (imagePage.pictureFileInformation.local.is_downloading_completed) {
|
imageFile.fileInformation = photo
|
||||||
imagePage.imageUrl = imagePage.pictureFileInformation.local.path;
|
|
||||||
} else {
|
|
||||||
tdLibWrapper.downloadFile(imagePage.pictureFileInformation.id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TDLibFile {
|
||||||
|
id: imageFile
|
||||||
|
tdlib: tdLibWrapper
|
||||||
|
autoLoad: true
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: tdLibWrapper
|
target: tdLibWrapper
|
||||||
onFileUpdated: {
|
|
||||||
if (fileId === imagePage.pictureFileInformation.id) {
|
|
||||||
Debug.log("File updated, completed? ", fileInformation.local.is_downloading_completed);
|
|
||||||
if (fileInformation.local.is_downloading_completed) {
|
|
||||||
imagePage.pictureFileInformation = fileInformation;
|
|
||||||
imagePage.imageUrl = fileInformation.local.path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
onCopyToDownloadsSuccessful: {
|
onCopyToDownloadsSuccessful: {
|
||||||
appNotification.show(qsTr("Download of %1 successful.").arg(fileName), filePath);
|
appNotification.show(qsTr("Download of %1 successful.").arg(fileName), filePath);
|
||||||
}
|
}
|
||||||
|
@ -96,11 +86,11 @@ Page {
|
||||||
interactive: !imageOnly
|
interactive: !imageOnly
|
||||||
|
|
||||||
PullDownMenu {
|
PullDownMenu {
|
||||||
visible: !imageOnly && imageUrl
|
visible: !imageOnly && imageFile.isDownloadingCompleted && imageFile.path
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Download Picture")
|
text: qsTr("Download Picture")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
tdLibWrapper.copyFileToDownloads(imagePage.imageUrl);
|
tdLibWrapper.copyFileToDownloads(imageFile.path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +124,7 @@ Page {
|
||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: singleImage
|
id: singleImage
|
||||||
source: imageUrl
|
source: imageFile.isDownloadingCompleted ? imageFile.path : ""
|
||||||
width: imagePage.imageWidth * imagePage.sizingFactor
|
width: imagePage.imageWidth * imagePage.sizingFactor
|
||||||
height: imagePage.imageHeight * imagePage.sizingFactor
|
height: imagePage.imageHeight * imagePage.sizingFactor
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
Loading…
Reference in a new issue