summaryrefslogtreecommitdiff
path: root/components/images/CachingIconImage.qml
blob: 1acc6a1817d1ec84f00eac278b4e14477c48fbf3 (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
39
40
41
42
pragma ComponentBehavior: Bound

import qs.utils
import Quickshell.Widgets
import QtQuick

Item {
    id: root

    readonly property int status: loader.item?.status ?? Image.Null
    readonly property real actualSize: Math.min(width, height)
    property real implicitSize
    property url source

    implicitWidth: implicitSize
    implicitHeight: implicitSize

    Loader {
        id: loader

        anchors.fill: parent
        sourceComponent: root.source ? root.source.toString().startsWith("image://icon/") ? iconImage : cachingImage : null
    }

    Component {
        id: cachingImage

        CachingImage {
            path: Paths.toLocalFile(root.source)
            fillMode: Image.PreserveAspectFit
        }
    }

    Component {
        id: iconImage

        IconImage {
            source: root.source
            asynchronous: true
        }
    }
}