Let context menu to appear when sticker is long-pressed

And don't load placeholder image too quickly.
This commit is contained in:
Slava Monich 2020-10-18 19:10:26 +03:00
parent 1dfc31d1db
commit f86e60b4a2

View file

@ -17,37 +17,29 @@
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>. along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/ */
import QtQuick 2.5 import QtQuick 2.5
import QtGraphicalEffects 1.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
Item { Item {
id: stickerPreviewItem
property variant stickerData; property variant stickerData;
property int usedFileId; property int usedFileId;
width: stickerData.width + Theme.paddingSmall width: stickerData.width
height: stickerData.height + Theme.paddingSmall height: stickerData.height
Component.onCompleted: { Component.onCompleted: {
updateSticker();
}
function updateSticker() {
if (stickerData) { if (stickerData) {
if (stickerData.is_animated) { if (stickerData.is_animated) {
// Use thumbnail until we can decode TGS files // Use thumbnail until we can decode TGS files
usedFileId = stickerData.thumbnail.photo.id; usedFileId = stickerData.thumbnail.photo.id;
if (stickerData.thumbnail.photo.local.is_downloading_completed) { if (stickerData.thumbnail.photo.local.is_downloading_completed) {
singleImage.source = stickerData.thumbnail.photo.local.path; stickerImage.source = stickerData.thumbnail.photo.local.path;
} else { } else {
tdLibWrapper.downloadFile(usedFileId); tdLibWrapper.downloadFile(usedFileId);
} }
} else { } else {
usedFileId = stickerData.sticker.id; usedFileId = stickerData.sticker.id;
if (stickerData.sticker.local.is_downloading_completed) { if (stickerData.sticker.local.is_downloading_completed) {
singleImage.source = stickerData.sticker.local.path; stickerImage.source = stickerData.sticker.local.path;
} else { } else {
tdLibWrapper.downloadFile(usedFileId); tdLibWrapper.downloadFile(usedFileId);
} }
@ -65,45 +57,43 @@ Item {
} else { } else {
stickerData.sticker = fileInformation; stickerData.sticker = fileInformation;
} }
singleImage.source = fileInformation.local.path; stickerImage.source = fileInformation.local.path;
} }
} }
} }
} }
Image { Image {
id: singleImage id: stickerImage
width: ( ( parent.width - Theme.paddingSmall ) >= stickerData.width ) ? stickerData.width : ( parent.width - Theme.paddingSmall ) anchors.fill: parent
height: ( ( parent.height - Theme.paddingSmall ) >= stickerData.height ) ? stickerData.height : ( parent.height - Theme.paddingSmall )
anchors.centerIn: parent
fillMode: Image.PreserveAspectCrop
autoTransform: true
asynchronous: true
visible: status === Image.Ready
opacity: status === Image.Ready ? 1 : 0
Behavior on opacity { NumberAnimation {} }
MouseArea {
anchors.fill: parent
onClicked: {
//pageStack.push(Qt.resolvedUrl("../pages/ImagePage.qml"), { "photoData" : imagePreviewItem.photoData, "pictureFileInformation" : imagePreviewItem.pictureFileInformation });
}
}
}
Image {
id: imageLoadingBackgroundImage
source: "../../images/background-" + ( Theme.colorScheme ? "black" : "white" ) + "-small.png"
anchors {
centerIn: parent
}
width: ( ( parent.width - Theme.paddingSmall ) >= stickerData.width ) ? stickerData.width : ( parent.width - Theme.paddingSmall )
height: ( ( parent.height - Theme.paddingSmall ) >= stickerData.height ) ? stickerData.height : ( parent.height - Theme.paddingSmall )
visible: singleImage.status !== Image.Ready
asynchronous: true
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
opacity: 0.15 autoTransform: true
asynchronous: true
visible: opacity > 0
opacity: status === Image.Ready ? 1 : 0
Behavior on opacity { FadeAnimation {} }
} }
Loader {
anchors.fill: parent
sourceComponent: Component {
Image {
source: "../../images/background-" + ( Theme.colorScheme ? "black" : "white" ) + "-small.png"
asynchronous: true
fillMode: Image.PreserveAspectFit
}
}
active: opacity > 0
opacity: !stickerImage.visible && !placeHolderDelayTimer.running ? 0.15 : 0
Behavior on opacity { FadeAnimation {} }
}
Timer {
id: placeHolderDelayTimer
interval: 1000
running: true
}
} }