harbour-fernschreiber/qml/components/TDLibPhoto.qml

70 lines
2.2 KiB
QML
Raw Normal View History

2021-01-20 00:38:34 +03:00
/*
Copyright (C) 2020 Sebastian J. Wolf and other contributors
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.6
import WerkWolf.Fernschreiber 1.0
import Sailfish.Silica 1.0
2021-01-20 00:38:53 +03:00
import QtGraphicalEffects 1.0
2021-01-20 00:38:34 +03:00
Item {
id: tdLibPhoto
property var photo
property bool highlighted
readonly property alias fileInformation: tdLibImage.fileInformation
readonly property alias image: tdLibImage
onWidthChanged: setImageFile()
onPhotoChanged: setImageFile()
function setImageFile() {
if (photo) {
var photoSize;
for (var i = 0; i < photo.sizes.length; i++) {
photoSize = photo.sizes[i].photo;
if (photo.sizes[i].width >= width) {
break;
}
}
if (photoSize && photoSize.id !== tdLibImage.fileInformation.id) {
tdLibImage.fileInformation = photoSize;
}
}
}
2021-01-20 00:38:53 +03:00
TDLibMinithumbnail {
id: minithumbnailLoader
active: !!minithumbnail && tdLibImage.opacity < 1.0
minithumbnail: tdLibPhoto.photo.minithumbnail
highlighted: parent.highlighted
}
2021-01-20 00:38:34 +03:00
2021-01-20 00:38:53 +03:00
BackgroundImage {
visible: !tdLibImage.visible && !(minithumbnailLoader.item && minithumbnailLoader.item.visible)
2021-01-20 00:38:34 +03:00
}
TDLibImage {
id: tdLibImage
width: parent.width //don't use anchors here for easier custom scaling
height: parent.height
cache: false
highlighted: parent.highlighted
}
Component.onCompleted: setImageFile()
}