summaryrefslogtreecommitdiff
path: root/modules/notifications/AppIconBadge.qml
blob: 8bbae89c448e391566c8a860cde975ce6b26d13c (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import qs.components
import qs.components.effects
import qs.services
import qs.config
import qs.utils
import Quickshell
import Quickshell.Services.Notifications
import QtQuick

StyledRect {
    id: root

    required property Notifs.Notif modelData
    required property bool hasImage
    required property bool hasAppIcon
    required property bool isCritical
    required property bool isLow

    radius: Appearance.rounding.full
    color: {
        if (root.isCritical) return Colours.palette.m3error;
        if (root.isLow) return Colours.layer(Colours.palette.m3surfaceContainerHighest, 2);
        return Colours.palette.m3secondaryContainer;
    }
    implicitWidth: root.hasImage ? Config.notifs.sizes.badge : Config.notifs.sizes.image
    implicitHeight: root.hasImage ? Config.notifs.sizes.badge : Config.notifs.sizes.image

    Loader {
        id: icon

        active: root.hasAppIcon
        asynchronous: false
        visible: active

        anchors.centerIn: parent

        width: Math.round(parent.width * 0.6)
        height: Math.round(parent.width * 0.6)

        sourceComponent: ColouredIcon {
            anchors.fill: parent
            source: Quickshell.iconPath(root.modelData.appIcon)
            colour: {
                if (root.isCritical) return Colours.palette.m3onError;
                if (root.isLow) return Colours.palette.m3onSurface;
                return Colours.palette.m3onSecondaryContainer;
            }
            layer.enabled: root.modelData.appIcon.endsWith("symbolic")
        }
    }

    Loader {
        active: !root.hasAppIcon
        asynchronous: false
        visible: active
        anchors.centerIn: parent
        anchors.horizontalCenterOffset: -Appearance.font.size.large * 0.02
        anchors.verticalCenterOffset: Appearance.font.size.large * 0.02

        sourceComponent: MaterialIcon {
            text: Icons.getNotifIcon(root.modelData.summary, root.modelData.urgency)

            color: {
                if (root.isCritical) return Colours.palette.m3onError;
                if (root.isLow) return Colours.palette.m3onSurface;
                return Colours.palette.m3onSecondaryContainer;
            }
            font.pointSize: Appearance.font.size.large
        }
    }
}