| 1 | import QtQuick |
| 2 | import QtQuick.Layouts |
| 3 | import Quickshell |
| 4 | import Quickshell.Services.Notifications |
| 5 | |
| 6 | Rectangle { |
| 7 | id: card |
| 8 | required property var n // Notification |
| 9 | property bool popup: false |
| 10 | |
| 11 | Layout.fillWidth: true |
| 12 | implicitHeight: body.implicitHeight + 20 |
| 13 | color: popup ? Theme.bg : Theme.surface |
| 14 | border.width: popup ? 2 : 1 |
| 15 | border.color: n.urgency === NotificationUrgency.Critical ? Theme.err : (popup ? Theme.accent : Theme.line) |
| 16 | |
| 17 | readonly property string imgSource: { |
| 18 | if (n.image && n.image !== "") return n.image |
| 19 | if (n.appIcon && n.appIcon !== "") return Quickshell.iconPath(n.appIcon, true) |
| 20 | return "" |
| 21 | } |
| 22 | |
| 23 | function close() { |
| 24 | if (popup) Notifs.dropPopup(n) |
| 25 | else n.dismiss() |
| 26 | } |
| 27 | |
| 28 | MouseArea { |
| 29 | anchors.fill: parent |
| 30 | onClicked: if (card.popup) Notifs.dropPopup(card.n) |
| 31 | } |
| 32 | |
| 33 | RowLayout { |
| 34 | id: body |
| 35 | anchors.fill: parent |
| 36 | anchors.margins: 10 |
| 37 | spacing: 10 |
| 38 | |
| 39 | Image { |
| 40 | visible: card.imgSource !== "" |
| 41 | source: card.imgSource |
| 42 | Layout.preferredWidth: 36 |
| 43 | Layout.preferredHeight: 36 |
| 44 | Layout.alignment: Qt.AlignTop |
| 45 | sourceSize: Qt.size(72, 72) |
| 46 | fillMode: Image.PreserveAspectFit |
| 47 | asynchronous: true |
| 48 | } |
| 49 | |
| 50 | ColumnLayout { |
| 51 | Layout.fillWidth: true |
| 52 | spacing: 2 |
| 53 | |
| 54 | RowLayout { |
| 55 | Layout.fillWidth: true |
| 56 | Text { |
| 57 | Layout.fillWidth: true |
| 58 | elide: Text.ElideRight |
| 59 | text: card.n.appName |
| 60 | color: Theme.accent |
| 61 | font.family: Theme.font |
| 62 | font.pixelSize: Theme.fontSize - 3 |
| 63 | font.letterSpacing: 1 |
| 64 | } |
| 65 | IconBtn { |
| 66 | icon: Theme.iClose |
| 67 | iconSize: 12 |
| 68 | implicitWidth: 22 |
| 69 | implicitHeight: 22 |
| 70 | onClicked: card.close() |
| 71 | } |
| 72 | } |
| 73 | Text { |
| 74 | Layout.fillWidth: true |
| 75 | text: card.n.summary |
| 76 | wrapMode: Text.Wrap |
| 77 | maximumLineCount: 2 |
| 78 | elide: Text.ElideRight |
| 79 | color: Theme.fg |
| 80 | font.family: Theme.font |
| 81 | font.pixelSize: Theme.fontSize |
| 82 | font.bold: true |
| 83 | } |
| 84 | Text { |
| 85 | visible: card.n.body !== "" |
| 86 | Layout.fillWidth: true |
| 87 | text: card.n.body |
| 88 | textFormat: Text.StyledText |
| 89 | wrapMode: Text.Wrap |
| 90 | maximumLineCount: card.popup ? 4 : 6 |
| 91 | elide: Text.ElideRight |
| 92 | color: Theme.dim |
| 93 | font.family: Theme.font |
| 94 | font.pixelSize: Theme.fontSize - 1 |
| 95 | } |
| 96 | Flow { |
| 97 | visible: card.n.actions.length > 0 |
| 98 | Layout.fillWidth: true |
| 99 | spacing: 6 |
| 100 | Repeater { |
| 101 | model: card.n.actions |
| 102 | delegate: IconBtn { |
| 103 | required property var modelData |
| 104 | label: modelData.text |
| 105 | implicitHeight: 24 |
| 106 | onClicked: { modelData.invoke(); if (card.popup) Notifs.dropPopup(card.n) } |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | } |