repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
quickshell/nuguland/NotificationGroup.qml
Rawpragma ComponentBehavior: Bound
import QtQuick
import "Util.js" as Util
Column {
id: root
required property Theme theme
required property Notifications notificationService
property var panelState: notificationService ? Util.parseJson(notificationService.stateJson(), {
"groups": [],
"dnd": false,
"activeCount": 0
}) : ({
"groups": [],
"dnd": false,
"activeCount": 0
})
readonly property var groups: panelState.groups || []
// mutators trigger side-effects only; never assign to `state` — that
// would destroy the binding above and freeze the open popup, so
// externally-arriving notifications would stop appearing until reopen.
// stateJson() reads reactive props (notifications/dnd/expandedGroups/…)
// so the binding re-evaluates on its own after every mutation.
function runAction(id, actionId) {
if (notificationService)
notificationService.runAction(id, actionId);
}
function sendReply(id, text) {
if (notificationService)
notificationService.sendReply(id, text);
}
function toggleGroup(appName) {
if (notificationService)
notificationService.toggleGroup(appName);
}
function toggleDnd() {
if (notificationService)
notificationService.toggleDnd();
}
function clearAll() {
if (notificationService)
notificationService.discardAllNotifications();
}
spacing: 8
width: parent ? parent.width : 0
Item {
width: parent.width
height: 28
NuguText {
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
theme: root.theme
variant: "title"
text: `Notifications${root.panelState.activeCount ? " · " + root.panelState.activeCount : ""}`
}
Row {
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
spacing: 8
Rectangle {
width: dndLabel.implicitWidth + 18
height: 24
radius: 8
color: root.theme ? root.theme.withAlpha(root.panelState.dnd ? root.theme.ui.accent : root.theme.ui.minor, root.panelState.dnd ? 0.3 : 0.12) : "transparent"
NuguText {
id: dndLabel
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: root.panelState.dnd ? "DND on" : "DND"
}
MouseArea {
anchors.fill: parent
onClicked: root.toggleDnd()
}
}
Rectangle {
width: clearLabel.implicitWidth + 18
height: 24
radius: 8
visible: (root.panelState.activeCount || 0) > 0
color: clearArea.containsMouse && root.theme ? root.theme.withAlpha(root.theme.error, 0.24) : (root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.12) : "transparent")
NuguText {
id: clearLabel
anchors.centerIn: parent
theme: root.theme
variant: "meta"
text: "Clear all"
}
MouseArea {
id: clearArea
anchors.fill: parent
hoverEnabled: true
onClicked: root.clearAll()
}
}
}
}
// History can outgrow the popup; the header stays fixed and everything
// below scrolls. The Loader hosting this Column forces a concrete
// root.height, so the viewport can bound on it.
Item {
id: scrollArea
width: parent.width
height: Math.max(0, root.height - 28 - root.spacing)
Flickable {
id: scroll
anchors.fill: parent
contentHeight: scrollColumn.height
clip: true
interactive: contentHeight > height
boundsBehavior: Flickable.StopAtBounds
flickableDirection: Flickable.VerticalFlick
Column {
id: scrollColumn
width: scroll.width
spacing: 8
Item {
width: parent.width
height: 220
visible: root.groups.length === 0
Column {
anchors.centerIn: parent
spacing: 8
NuguText {
anchors.horizontalCenter: parent.horizontalCenter
theme: root.theme
variant: "title"
text: "No notifications"
}
NuguText {
anchors.horizontalCenter: parent.horizontalCenter
theme: root.theme
variant: "meta"
text: "You're all caught up"
}
}
}
Repeater {
model: root.groups
delegate: Column {
id: groupDelegate
required property var modelData
width: root.width
spacing: 6
// collapsible group header: an obvious interactive pill with a
// hover background and an explicit "Show N more" / "Show less"
// label so the collapse affordance reads as a button, not decor.
Rectangle {
id: groupHeader
width: parent.width
height: (groupDelegate.modelData.count || 0) > 1 ? 26 : 0
visible: (groupDelegate.modelData.count || 0) > 1
radius: 8
color: grpArea.containsMouse && root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.16) : "transparent"
Behavior on color {
ColorAnimation {
duration: root.theme && root.theme.lowPowerMode ? 0 : 120
}
}
Row {
anchors.left: parent.left
anchors.leftMargin: 8
anchors.verticalCenter: parent.verticalCenter
spacing: 6
NuguText {
theme: root.theme
variant: "meta"
text: groupDelegate.modelData.appName || ""
}
NuguText {
theme: root.theme
variant: "meta"
text: `· ${groupDelegate.modelData.count}`
}
}
Row {
anchors.right: parent.right
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
spacing: 4
NuguText {
theme: root.theme
variant: "meta"
opacity: grpArea.containsMouse ? 1 : 0.7
text: groupDelegate.modelData.expanded ? "Show less" : `Show ${Math.max(1, (groupDelegate.modelData.count || 1) - (groupDelegate.modelData.previewCount || 1))} more`
}
NuguText {
theme: root.theme
variant: "mono"
opacity: grpArea.containsMouse ? 1 : 0.7
text: groupDelegate.modelData.expanded ? "⌃" : "⌄"
}
}
MouseArea {
id: grpArea
anchors.fill: parent
hoverEnabled: true
onClicked: root.toggleGroup(groupDelegate.modelData.appName || "")
}
}
Repeater {
model: groupDelegate.modelData.visibleNotifications || []
delegate: Item {
id: cardWrap
required property var modelData
width: root.width
implicitHeight: cardInner.implicitHeight
height: implicitHeight
NotificationCard {
id: cardInner
width: parent.width
theme: root.theme
modelData: cardWrap.modelData
onDismiss: id => root.runAction(id, "close")
onInvokeAction: (id, actionId) => root.runAction(id, actionId)
onSendReply: (id, text) => root.sendReply(id, text)
}
}
}
}
}
}
}
// slim scroll indicator, overlaid (outside the Flickable so it
// doesn't scroll with content); shown only when content overflows.
Rectangle {
anchors.right: parent.right
width: 3
radius: 2
visible: scroll.contentHeight > scroll.height + 1
color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.5) : "transparent"
height: Math.max(24, scrollArea.height * scrollArea.height / Math.max(1, scroll.contentHeight))
y: scroll.contentY * scrollArea.height / Math.max(1, scroll.contentHeight)
}
}
}