Skip to content

Commit

Permalink
refactor: use Enum for panel icon types
Browse files Browse the repository at this point in the history
  • Loading branch information
ccatterina committed Aug 13, 2024
1 parent cdf3f06 commit 8165d0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
23 changes: 8 additions & 15 deletions src/contents/ui/PanelIcon.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import org.kde.plasma.components as PlasmaComponents3
import org.kde.kirigami as Kirigami

Item {
enum Type {
Icon,
Image
}

id: root
property string type: "icon"
property int type: PanelIcon.Type.Icon
property var imageUrl: null
property var imageRadius: null
property var icon: null
Expand All @@ -15,20 +20,8 @@ Item {
Layout.preferredHeight: size
Layout.preferredWidth: size

onTypeChanged: () => {
if ([ "icon", "image" ].includes(type)) {
console.error("Panel icon type not supported")
}
if (type === "icon" && !icon) {
console.error("Panel icon type is icon but no icon is set")
}
if (type === "image" && !imageUrl) {
console.error("Panel icon type is image but no image url is set")
}
}

Kirigami.Icon {
visible: type === "icon"
visible: type === PanelIcon.Type.Icon
id: iconComponent
source: root.icon
implicitHeight: root.size
Expand All @@ -37,7 +30,7 @@ Item {
}

Image {
visible: type === "image"
visible: type === PanelIcon.Type.Image
width: root.size
height: root.size
id: imageComponent
Expand Down
2 changes: 1 addition & 1 deletion src/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ PlasmoidItem {
icon: plasmoid.configuration.panelIcon
imageUrl: player.artUrl
imageRadius: plasmoid.configuration.albumCoverRadius
type: plasmoid.configuration.useAlbumCoverAsPanelIcon ? "image": "icon"
type: plasmoid.configuration.useAlbumCoverAsPanelIcon ? PanelIcon.Type.Image: PanelIcon.Type.Icon
Layout.rightMargin: Kirigami.Units.smallSpacing * 2
}

Expand Down

0 comments on commit 8165d0f

Please sign in to comment.