summaryrefslogtreecommitdiff
path: root/components/images/CachingImage.qml
blob: 2aa055864310471425727e31d0b01dc0ef81a568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import qs.utils
import Caelestia
import Quickshell
import QtQuick

Image {
    id: root

    property alias path: manager.path

    property int sourceWidth
    property int sourceHeight

    asynchronous: true
    fillMode: Image.PreserveAspectCrop
    sourceSize.width: sourceWidth
    sourceSize.height: sourceHeight

    onStatusChanged: {
        if (!manager.usingCache && status === Image.Ready)
            CUtils.saveItem(this, manager.cachePath);
    }

    Connections {
        target: QsWindow.window

        function onDevicePixelRatioChanged(): void {
            manager.updateSource();
        }
    }

    CachingImageManager {
        id: manager

        item: root
        cacheDir: Paths.imagecache
    }
}