qml: use CachedTexture for placeholder in MediaCover

This commit is contained in:
Fatih Uzunoglu 2024-05-07 02:14:56 +03:00
parent 5de1180720
commit 7d6d743dc5
1 changed files with 48 additions and 8 deletions

View File

@ -47,6 +47,11 @@ Rectangle {
property bool isImageReady: image.status == RoundImage.Ready
onIsImageReadyChanged: {
if (!isImageReady) {
placeholderTimer.restart()
}
}
property string fallbackImageSource
@ -79,20 +84,55 @@ Rectangle {
cache: false
}
RoundImage {
id: fallbackImage
Loader {
id: placeholderLoader
anchors.fill: parent
radius: root.radius
active: !root.isImageReady
visible: !root.isImageReady
Component {
id: roundImageComponent
// we only keep this image till there is no main image
// try to release the resources otherwise
source: !root.isImageReady ? root.fallbackImageSource : ""
RoundImage {
anchors.fill: parent
cache: true
radius: root.radius
source: root.fallbackImageSource
cache: true
}
}
Component {
id: textureComponent
CachedTexture {
implicitWidth: root.width
implicitHeight: root.height
radius: root.radius
source: root.fallbackImageSource
}
}
sourceComponent: root.fallbackImageSource.startsWith("image") ? roundImageComponent
: textureComponent
Timer {
id: placeholderTimer
interval: VLCStyle.duration_humanMoment
onTriggered: {
if (!root.isImageReady)
placeholderLoader.sourceComponent = roundImageComponent
}
Component.onCompleted: start()
}
}
Loader {