Extract minithumbnail into own Loader
This commit is contained in:
parent
390f6eaca6
commit
290114f3f2
3 changed files with 141 additions and 24 deletions
56
qml/components/TDLibMinithumbnail.qml
Normal file
56
qml/components/TDLibMinithumbnail.qml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
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 Sailfish.Silica 1.0
|
||||||
|
import QtGraphicalEffects 1.0
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
id: loader
|
||||||
|
property var minithumbnail
|
||||||
|
property bool highlighted
|
||||||
|
anchors.fill: parent
|
||||||
|
active: !!minithumbnail
|
||||||
|
visible: active
|
||||||
|
sourceComponent: Component {
|
||||||
|
Item {
|
||||||
|
Image {
|
||||||
|
id: minithumbnailImage
|
||||||
|
anchors.fill: parent
|
||||||
|
source: "data:image/jpg;base64,"+minithumbnail.data
|
||||||
|
asynchronous: true
|
||||||
|
fillMode: tdLibImage.fillMode
|
||||||
|
opacity: status === Image.Ready ? 1.0 : 0.0
|
||||||
|
cache: false
|
||||||
|
visible: opacity > 0
|
||||||
|
Behavior on opacity { FadeAnimation {} }
|
||||||
|
|
||||||
|
layer {
|
||||||
|
enabled: loader.highlighted
|
||||||
|
effect: PressEffect { source: minithumbnailImage }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FastBlur {
|
||||||
|
anchors.fill: parent
|
||||||
|
source: minithumbnailImage
|
||||||
|
radius: Theme.paddingLarge
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
78
qml/components/TDLibPhoto.qml
Normal file
78
qml/components/TDLibPhoto.qml
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
/*
|
||||||
|
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
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Loader {
|
||||||
|
anchors.fill: parent
|
||||||
|
active: !!tdLibPhoto.photo.minithumbnail
|
||||||
|
asynchronous: true
|
||||||
|
sourceComponent: Component {
|
||||||
|
Image {
|
||||||
|
id: minithumbnail
|
||||||
|
source: "data:image/jpg;base64,"+tdLibPhoto.photo.minithumbnail.data
|
||||||
|
asynchronous: true
|
||||||
|
fillMode: tdLibImage.fillMode
|
||||||
|
smooth: false
|
||||||
|
cache: false
|
||||||
|
|
||||||
|
layer {
|
||||||
|
enabled: tdLibPhoto.highlighted
|
||||||
|
effect: PressEffect { source: minithumbnail }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
|
@ -50,7 +50,7 @@ Item {
|
||||||
- video
|
- video
|
||||||
- videoNote
|
- videoNote
|
||||||
*/
|
*/
|
||||||
property var minithumbnail
|
property alias minithumbnail: minithumbnailLoader.minithumbnail
|
||||||
property bool useBackgroundImage: true
|
property bool useBackgroundImage: true
|
||||||
property bool highlighted
|
property bool highlighted
|
||||||
|
|
||||||
|
@ -65,29 +65,12 @@ Item {
|
||||||
effect: PressEffect { source: tdlibThumbnail }
|
effect: PressEffect { source: tdlibThumbnail }
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader {
|
TDLibMinithumbnail {
|
||||||
id: backgroundLoader
|
id: minithumbnailLoader
|
||||||
anchors.fill: parent
|
active: !!minithumbnail && thumbnailImage.opacity < 1.0
|
||||||
active: !parent.hasVisibleThumbnail
|
|
||||||
asynchronous: true
|
|
||||||
sourceComponent: !!parent.minithumbnail ? miniThumbnailComponent : parent.useBackgroundImage ? backgroundImageComponent : ""
|
|
||||||
Component {
|
|
||||||
id: backgroundImageComponent
|
|
||||||
BackgroundImage {}
|
|
||||||
}
|
|
||||||
Component {
|
|
||||||
id: miniThumbnailComponent
|
|
||||||
Image {
|
|
||||||
clip: true
|
|
||||||
asynchronous: true
|
|
||||||
fillMode: Image.PreserveAspectCrop
|
|
||||||
opacity: status === Image.Ready ? 1.0 : 0.0
|
|
||||||
smooth: false
|
|
||||||
source: "data:image/jpg;base64," + tdlibThumbnail.miniThumbnail.data
|
|
||||||
visible: opacity > 0
|
|
||||||
Behavior on opacity { FadeAnimation {} }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
BackgroundImage {
|
||||||
|
visible: tdlibThumbnail.useBackgroundImage && thumbnailImage.opacity < 1.0
|
||||||
}
|
}
|
||||||
|
|
||||||
// image thumbnail
|
// image thumbnail
|
||||||
|
|
Loading…
Reference in a new issue