diff --git a/qml/components/TDLibMinithumbnail.qml b/qml/components/TDLibMinithumbnail.qml
new file mode 100644
index 0000000..50f169a
--- /dev/null
+++ b/qml/components/TDLibMinithumbnail.qml
@@ -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 .
+*/
+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
+ }
+ }
+ }
+}
diff --git a/qml/components/TDLibPhoto.qml b/qml/components/TDLibPhoto.qml
new file mode 100644
index 0000000..567f129
--- /dev/null
+++ b/qml/components/TDLibPhoto.qml
@@ -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 .
+*/
+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()
+}
diff --git a/qml/components/TDLibThumbnail.qml b/qml/components/TDLibThumbnail.qml
index 8454dd7..291f507 100644
--- a/qml/components/TDLibThumbnail.qml
+++ b/qml/components/TDLibThumbnail.qml
@@ -50,7 +50,7 @@ Item {
- video
- videoNote
*/
- property var minithumbnail
+ property alias minithumbnail: minithumbnailLoader.minithumbnail
property bool useBackgroundImage: true
property bool highlighted
@@ -65,29 +65,12 @@ Item {
effect: PressEffect { source: tdlibThumbnail }
}
- Loader {
- id: backgroundLoader
- anchors.fill: parent
- 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 {} }
- }
- }
+ TDLibMinithumbnail {
+ id: minithumbnailLoader
+ active: !!minithumbnail && thumbnailImage.opacity < 1.0
+ }
+ BackgroundImage {
+ visible: tdlibThumbnail.useBackgroundImage && thumbnailImage.opacity < 1.0
}
// image thumbnail