diff options
Diffstat (limited to 'modules/sidebar')
| -rw-r--r-- | modules/sidebar/Notif.qml | 38 | ||||
| -rw-r--r-- | modules/sidebar/NotifDock.qml | 5 | ||||
| -rw-r--r-- | modules/sidebar/NotifGroup.qml | 37 | ||||
| -rw-r--r-- | modules/sidebar/NotifGroupList.qml | 136 |
4 files changed, 156 insertions, 60 deletions
diff --git a/modules/sidebar/Notif.qml b/modules/sidebar/Notif.qml index 8b96792..3aecc59 100644 --- a/modules/sidebar/Notif.qml +++ b/modules/sidebar/Notif.qml @@ -1,10 +1,8 @@ pragma ComponentBehavior: Bound import qs.components -import qs.components.controls import qs.services import qs.config -import Quickshell import QtQuick import QtQuick.Layouts @@ -15,8 +13,9 @@ StyledRect { required property Props props required property bool expanded - Layout.fillWidth: true - implicitHeight: expanded ? summary.implicitHeight + expandedContent.implicitHeight + expandedContent.anchors.topMargin + Appearance.padding.normal * 2 : summary.implicitHeight + readonly property real nonAnimHeight: expanded ? summary.implicitHeight + expandedContent.implicitHeight + expandedContent.anchors.topMargin + Appearance.padding.normal * 2 : summary.implicitHeight + + implicitHeight: nonAnimHeight radius: Appearance.rounding.small color: { @@ -44,34 +43,6 @@ StyledRect { } } - ParallelAnimation { - running: true - - Anim { - target: root - property: "opacity" - from: 0 - to: 1 - } - Anim { - target: root - property: "scale" - from: 0.7 - to: 1 - } - // Anim { - // target: root.Layout - // property: "preferredHeight" - // from: 0 - // to: root.implicitHeight - // } - } - - RetainableLock { - object: root.modelData.notification - locked: true - } - StyledText { id: summary @@ -139,7 +110,8 @@ StyledRect { StyledText { Layout.fillWidth: true - text: root.modelData.body || qsTr("No body here! :/") + textFormat: Text.MarkdownText + text: root.modelData.body.replace(/(.)\n(?!\n)/g, "$1\n\n") || qsTr("No body here! :/") color: root.modelData.urgency === "critical" ? Colours.palette.m3secondary : Colours.palette.m3outline wrapMode: Text.WordWrap } diff --git a/modules/sidebar/NotifDock.qml b/modules/sidebar/NotifDock.qml index 36b6665..490eeb8 100644 --- a/modules/sidebar/NotifDock.qml +++ b/modules/sidebar/NotifDock.qml @@ -160,8 +160,9 @@ Item { repeat: true interval: 50 onTriggered: { - Notifs.list[0]?.notification.dismiss(); - if (Notifs.list.length === 0) + if (Notifs.list.length > 0) + Notifs.list[0].close(); + else stop(); } } diff --git a/modules/sidebar/NotifGroup.qml b/modules/sidebar/NotifGroup.qml index 154b530..4476bf9 100644 --- a/modules/sidebar/NotifGroup.qml +++ b/modules/sidebar/NotifGroup.qml @@ -1,7 +1,6 @@ pragma ComponentBehavior: Bound import qs.components -import qs.components.controls import qs.components.effects import qs.services import qs.config @@ -119,13 +118,15 @@ StyledRect { } ColumnLayout { + id: column + Layout.topMargin: -Appearance.padding.small Layout.bottomMargin: -Appearance.padding.small / 2 Layout.fillWidth: true - spacing: Math.round(Appearance.spacing.small / 2) + spacing: 0 RowLayout { - Layout.bottomMargin: -parent.spacing + Layout.bottomMargin: root.expanded ? Math.round(Appearance.spacing.small / 2) : 0 Layout.fillWidth: true spacing: Appearance.spacing.smaller @@ -173,7 +174,7 @@ StyledRect { Layout.leftMargin: Appearance.padding.small / 2 animate: true - text: root.notifs.length + text: root.notifs.reduce((acc, n) => n.closed ? acc : acc + 1, 0) color: root.urgency === "critical" ? Colours.palette.m3onError : Colours.palette.m3onSurface font.pointSize: Appearance.font.size.small } @@ -186,31 +187,17 @@ StyledRect { } } } - } - - Repeater { - id: notifList - model: ScriptModel { - values: root.expanded ? root.notifs : root.notifs.slice(0, Config.notifs.groupPreviewNum) + Behavior on Layout.bottomMargin { + Anim {} } + } - Layout.fillWidth: true - - Notif { - id: notif - - props: root.props - expanded: root.expanded - } + NotifGroupList { + props: root.props + notifs: root.notifs + expanded: root.expanded } } } - - // Behavior on implicitHeight { - // Anim { - // duration: Appearance.anim.durations.expressiveDefaultSpatial - // easing.bezierCurve: Appearance.anim.curves.expressiveDefaultSpatial - // } - // } } diff --git a/modules/sidebar/NotifGroupList.qml b/modules/sidebar/NotifGroupList.qml new file mode 100644 index 0000000..7def80f --- /dev/null +++ b/modules/sidebar/NotifGroupList.qml @@ -0,0 +1,136 @@ +pragma ComponentBehavior: Bound + +import qs.components +import qs.services +import qs.config +import Quickshell +import QtQuick +import QtQuick.Layouts + +Item { + id: root + + required property Props props + required property list<var> notifs + required property bool expanded + + readonly property int spacing: Math.round(Appearance.spacing.small / 2) + property bool flag + + Layout.fillWidth: true + implicitHeight: { + const item = repeater.itemAt(repeater.count - 1); + return item ? item.y + item.implicitHeight : 0; + } + + Repeater { + id: repeater + + model: ScriptModel { + values: root.expanded ? root.notifs : root.notifs.slice(0, Config.notifs.groupPreviewNum) + onValuesChanged: root.flagChanged() + } + + MouseArea { + id: notif + + required property int index + required property Notifs.Notif modelData + + readonly property alias nonAnimHeight: notifInner.nonAnimHeight + property int startY + + y: { + root.flag; // Force update + let y = 0; + for (let i = 0; i < index; i++) { + const item = repeater.itemAt(i); + if (!item.modelData.closed) + y += item.nonAnimHeight + root.spacing; + } + return y; + } + + implicitWidth: root.width + implicitHeight: notifInner.implicitHeight + + hoverEnabled: true + cursorShape: pressed ? Qt.ClosedHandCursor : undefined + acceptedButtons: Qt.LeftButton | Qt.MiddleButton + + drag.target: this + drag.axis: Drag.XAxis + + onPressed: event => { + startY = event.y; + if (event.button === Qt.MiddleButton) + modelData.close(); + } + onReleased: event => { + if (Math.abs(x) < width * Config.notifs.clearThreshold) + x = 0; + else + modelData.close(); + } + + Component.onCompleted: modelData.lock(this) + Component.onDestruction: modelData.unlock(this) + + ParallelAnimation { + running: true + + Anim { + target: notif + property: "opacity" + from: 0 + to: 1 + } + Anim { + target: notif + property: "scale" + from: 0.7 + to: 1 + } + } + + ParallelAnimation { + running: notif.modelData.closed + onFinished: notif.modelData.unlock(notif) + + Anim { + target: notif + property: "opacity" + to: 0 + } + Anim { + target: notif + property: "x" + to: notif.x >= 0 ? notif.width : -notif.width + } + } + + Notif { + id: notifInner + + anchors.fill: parent + modelData: notif.modelData + props: root.props + expanded: root.expanded + } + + Behavior on x { + Anim { + duration: Appearance.anim.durations.expressiveDefaultSpatial + easing.bezierCurve: Appearance.anim.curves.expressiveDefaultSpatial + } + } + + Behavior on y { + Anim { + duration: Appearance.anim.durations.expressiveDefaultSpatial + easing.bezierCurve: Appearance.anim.curves.expressiveDefaultSpatial + } + } + } + } +} |