From 01f724800f27a7de63c33b72717456940daa4905 Mon Sep 17 00:00:00 2001 From: Soramane <61896496+soramanew@users.noreply.github.com> Date: Wed, 16 Jul 2025 17:32:27 +1000 Subject: notifs: add close button Closes #220 --- modules/notifications/Notification.qml | 83 ++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 35 deletions(-) (limited to 'modules') diff --git a/modules/notifications/Notification.qml b/modules/notifications/Notification.qml index 1a520c8..6022e9d 100644 --- a/modules/notifications/Notification.qml +++ b/modules/notifications/Notification.qml @@ -413,53 +413,66 @@ StyledRect { Anim {} } + Action { + modelData: QtObject { + readonly property string text: qsTr("Close") + function invoke(): void { + root.modelData.notification.dismiss(); + } + } + } + Repeater { model: root.modelData.actions - delegate: StyledRect { - id: action + delegate: Component { + Action {} + } + } + } + } - required property NotificationAction modelData + component Action: StyledRect { + id: action - radius: Appearance.rounding.full - color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3secondary : Colours.palette.m3surfaceContainerHigh + required property var modelData - Layout.preferredWidth: actionText.width + Appearance.padding.normal * 2 - Layout.preferredHeight: actionText.height + Appearance.padding.small * 2 - implicitWidth: actionText.width + Appearance.padding.normal * 2 - implicitHeight: actionText.height + Appearance.padding.small * 2 + radius: Appearance.rounding.full + color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3secondary : Colours.palette.m3surfaceContainerHigh - StateLayer { - radius: Appearance.rounding.full - color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurface + Layout.preferredWidth: actionText.width + Appearance.padding.normal * 2 + Layout.preferredHeight: actionText.height + Appearance.padding.small * 2 + implicitWidth: actionText.width + Appearance.padding.normal * 2 + implicitHeight: actionText.height + Appearance.padding.small * 2 - function onClicked(): void { - action.modelData.invoke(); - } - } + StateLayer { + radius: Appearance.rounding.full + color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurface + + function onClicked(): void { + action.modelData.invoke(); + } + } - StyledText { - id: actionText + StyledText { + id: actionText - anchors.centerIn: parent - text: actionTextMetrics.elidedText - color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurfaceVariant - font.pointSize: Appearance.font.size.small - } + anchors.centerIn: parent + text: actionTextMetrics.elidedText + color: root.modelData.urgency === NotificationUrgency.Critical ? Colours.palette.m3onSecondary : Colours.palette.m3onSurfaceVariant + font.pointSize: Appearance.font.size.small + } - TextMetrics { - id: actionTextMetrics + TextMetrics { + id: actionTextMetrics - text: modelData.text - font.family: actionText.font.family - font.pointSize: actionText.font.pointSize - elide: Text.ElideRight - elideWidth: { - const numActions = root.modelData.actions.length; - return (inner.width - actions.spacing * (numActions - 1)) / numActions - Appearance.padding.normal * 2; - } - } - } + text: action.modelData.text + font.family: actionText.font.family + font.pointSize: actionText.font.pointSize + elide: Text.ElideRight + elideWidth: { + const numActions = root.modelData.actions.length + 1; + return (inner.width - actions.spacing * (numActions - 1)) / numActions - Appearance.padding.normal * 2; } } } -- cgit v1.2.3-freya