diff --git a/src/contents/ui/PanelIcon.qml b/src/contents/ui/PanelIcon.qml index b6fb338..59c7680 100644 --- a/src/contents/ui/PanelIcon.qml +++ b/src/contents/ui/PanelIcon.qml @@ -16,12 +16,15 @@ Item { property var imageRadius: null property var icon: null property real size: Kirigami.Units.iconSizes.medium + property bool imageReady: false + property bool fallbackToIconWhenImageNotAvailable: false + visible: type === PanelIcon.Type.Icon || imageReady || (fallbackToIconWhenImageNotAvailable && !imageReady) Layout.preferredHeight: size Layout.preferredWidth: size Kirigami.Icon { - visible: type === PanelIcon.Type.Icon + visible: type === PanelIcon.Type.Icon || (fallbackToIconWhenImageNotAvailable && !imageReady) id: iconComponent source: root.icon implicitHeight: root.size @@ -29,6 +32,14 @@ Item { color: Kirigami.Theme.textColor } + Timer { + id: imageStatusTimer + interval: 500 + onTriggered: { + imageReady = imageComponent.status === Image.Ready + } + } + Image { visible: type === PanelIcon.Type.Image width: root.size @@ -37,6 +48,9 @@ Item { anchors.fill: parent source: root.imageUrl fillMode: Image.PreserveAspectFit + onStatusChanged: { + imageStatusTimer.restart() + } // enables round corners while the radius is set // ref: https://stackoverflow.com/questions/6090740/image-rounded-corners-in-qml diff --git a/src/contents/ui/main.qml b/src/contents/ui/main.qml index f992330..b6c7218 100644 --- a/src/contents/ui/main.qml +++ b/src/contents/ui/main.qml @@ -112,13 +112,11 @@ PlasmoidItem { icon: plasmoid.configuration.panelIcon imageUrl: player.artUrl imageRadius: plasmoid.configuration.albumCoverRadius + fallbackToIconWhenImageNotAvailable: plasmoid.configuration.fallbackToIconWhenArtNotAvailable type: { if (!plasmoid.configuration.useAlbumCoverAsPanelIcon) { return PanelIcon.Type.Icon; } - if (plasmoid.configuration.fallbackToIconWhenArtNotAvailable && !player.artUrl) { - return PanelIcon.Type.Icon; - } return PanelIcon.Type.Image; } Layout.alignment : Qt.AlignVCenter | Qt.AlignHCenter