perf: replace notifcenter repeater with listview for virtualization

This commit is contained in:
Damocles 2026-04-13 20:14:11 +02:00
parent e1241b33d2
commit c5067c4e7f

View file

@ -64,24 +64,32 @@ M.PopupPanel {
} }
} }
property var _delegates: []
property var _pendingDismissIds: [] property var _pendingDismissIds: []
function _cascadeDismiss() { function _cascadeDismiss() {
const dels = _delegates.filter(d => d && d.modelData && !d.modelData.closed); const list = M.NotifService.list;
if (dels.length === 0) if (list.length === 0)
return; return;
_pendingDismissIds = dels.map(d => d.modelData.id); _pendingDismissIds = list.map(n => n.id);
for (let i = 0; i < dels.length; i++) { const visibles = [];
const d = dels[i]; for (let i = 0; i < list.length; i++) {
const isLast = (i === dels.length - 1); const d = notifList.itemAtIndex(i);
if (d && d.modelData?.state !== "dismissing")
visibles.push(d);
}
if (visibles.length === 0) {
_finishCascade();
return;
}
for (let i = 0; i < visibles.length; i++) {
_cascadeTimer.createObject(menuWindow, { _cascadeTimer.createObject(menuWindow, {
_target: d, _target: visibles[i],
_delay: i * 60, _delay: i * 60,
_isLast: isLast _isLast: i === visibles.length - 1
}); });
} }
} }
@ -114,7 +122,7 @@ M.PopupPanel {
property Component _bulkTimer: Component { property Component _bulkTimer: Component {
Timer { Timer {
interval: 400 // swipe (200) + collapse (150) + margin interval: 400 // swipe (200) + collapse (150) + margin
running: true running: true
onTriggered: { onTriggered: {
menuWindow._finishCascade(); menuWindow._finishCascade();
@ -132,297 +140,273 @@ M.PopupPanel {
} }
// Notification list (scrollable) // Notification list (scrollable)
Item { ListView {
id: notifList
width: menuWindow.panelWidth width: menuWindow.panelWidth
height: Math.min(notifFlick.contentHeight, _maxHeight) height: Math.min(contentHeight, 60 * (M.Modules.notifications.maxVisible || 10))
readonly property real _itemHeight: 60 clip: true
readonly property real _maxHeight: _itemHeight * (M.Modules.notifications.maxVisible || 10) boundsBehavior: Flickable.StopAtBounds
model: M.NotifService.list
Flickable { delegate: Item {
id: notifFlick id: notifItem
anchors.fill: parent required property var modelData
contentWidth: width required property int index
contentHeight: notifCol.implicitHeight
width: menuWindow.panelWidth
height: _targetHeight * _heightScale
opacity: 0
clip: true clip: true
boundsBehavior: Flickable.StopAtBounds
Column { readonly property real _targetHeight: notifContent.height + 12
id: notifCol property real _heightScale: 1
width: parent.width property bool _skipDismiss: false
Repeater { function dismiss() {
model: M.NotifService.list if (notifItem.modelData.state === "dismissing")
return;
notifItem.modelData.beginDismiss();
_dismissAnim.start();
}
delegate: Item { function dismissVisualOnly() {
id: notifItem if (notifItem.modelData.state === "dismissing")
required property var modelData return;
required property int index notifItem.modelData.beginDismiss();
_skipDismiss = true;
_dismissAnim.start();
}
width: menuWindow.panelWidth Component.onCompleted: fadeIn.start()
height: _targetHeight * _heightScale
opacity: 0
clip: true
readonly property real _targetHeight: notifContent.height + 12 NumberAnimation {
property real _heightScale: 1 id: fadeIn
property bool _skipDismiss: false target: notifItem
property: "opacity"
to: 1
duration: 150
easing.type: Easing.OutCubic
}
function dismiss() { Rectangle {
if (notifItem.modelData.state === "dismissing") anchors.fill: parent
return; anchors.leftMargin: 4
notifItem.modelData.beginDismiss(); anchors.rightMargin: 4
_dismissAnim.start(); color: notifArea.containsMouse ? M.Theme.base02 : "transparent"
} radius: M.Theme.radius
function dismissVisualOnly() { Rectangle {
if (notifItem.modelData.state === "dismissing") visible: (notifItem.modelData.hints?.value ?? -1) >= 0
return; anchors.top: parent.top
notifItem.modelData.beginDismiss(); anchors.bottom: parent.bottom
_skipDismiss = true; anchors.left: parent.left
_dismissAnim.start(); width: parent.width * Math.min(1, Math.max(0, (notifItem.modelData.hints?.value ?? 0) / 100))
} color: M.Theme.base02
radius: parent.radius
Component.onCompleted: {
menuWindow._delegates.push(notifItem);
fadeIn.start();
}
Component.onDestruction: {
const idx = menuWindow._delegates.indexOf(notifItem);
if (idx >= 0)
menuWindow._delegates.splice(idx, 1);
}
Behavior on width {
NumberAnimation { NumberAnimation {
id: fadeIn duration: 200
target: notifItem
property: "opacity"
to: 1
duration: 150
easing.type: Easing.OutCubic
}
Rectangle {
anchors.fill: parent
anchors.leftMargin: 4
anchors.rightMargin: 4
color: notifArea.containsMouse ? M.Theme.base02 : "transparent"
radius: M.Theme.radius
Rectangle {
visible: (notifItem.modelData.hints?.value ?? -1) >= 0
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
width: parent.width * Math.min(1, Math.max(0, (notifItem.modelData.hints?.value ?? 0) / 100))
color: M.Theme.base02
radius: parent.radius
Behavior on width {
NumberAnimation {
duration: 200
}
}
}
}
// Urgency accent
Rectangle {
anchors.left: parent.left
anchors.leftMargin: 4
anchors.top: parent.top
anchors.topMargin: 4
anchors.bottom: parent.bottom
anchors.bottomMargin: 4
width: 2
radius: 1
color: {
const u = notifItem.modelData.urgency;
return u === NotificationUrgency.Critical ? M.Theme.base08 : u === NotificationUrgency.Low ? M.Theme.base04 : M.Theme.base0D;
}
}
Image {
id: ncIcon
anchors.left: parent.left
anchors.leftMargin: 14
anchors.top: parent.top
anchors.topMargin: 6
width: 24
height: 24
source: notifItem.modelData.image || notifItem.modelData.appIcon || ""
visible: status === Image.Ready
fillMode: Image.PreserveAspectFit
sourceSize: Qt.size(24, 24)
asynchronous: true
}
Column {
id: notifContent
anchors.left: ncIcon.visible ? ncIcon.right : parent.left
anchors.right: dismissBtn.left
anchors.top: parent.top
anchors.leftMargin: ncIcon.visible ? 6 : 14
anchors.topMargin: 6
spacing: 1
// App + time
Row {
width: parent.width
Text {
text: notifItem.modelData.appName || "Notification"
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
elide: Text.ElideRight
width: parent.width - ageText.width - 4
}
Text {
id: ageText
text: {
const diff = Math.floor((Date.now() - notifItem.modelData.time) / 60000);
if (diff < 1)
return "now";
if (diff < 60)
return diff + "m";
if (diff < 1440)
return Math.floor(diff / 60) + "h";
return Math.floor(diff / 1440) + "d";
}
color: M.Theme.base03
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
}
}
Text {
width: parent.width
text: notifItem.modelData.summary || ""
color: M.Theme.base05
font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily
font.bold: true
elide: Text.ElideRight
}
Text {
width: parent.width
text: notifItem.modelData.body || ""
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize - 1
font.family: M.Theme.fontFamily
wrapMode: Text.WordWrap
maximumLineCount: 2
elide: Text.ElideRight
visible: text !== ""
}
// Actions
Row {
spacing: 4
visible: notifItem.modelData.actions && notifItem.modelData.actions.length > 0
Repeater {
model: notifItem.modelData.actions || []
delegate: Rectangle {
required property var modelData
width: actText.implicitWidth + 10
height: actText.implicitHeight + 4
radius: M.Theme.radius
color: actArea.containsMouse ? M.Theme.base02 : "transparent"
border.color: M.Theme.base03
border.width: 1
Text {
id: actText
anchors.centerIn: parent
text: parent.modelData.text
color: M.Theme.base0D
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
}
MouseArea {
id: actArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
parent.modelData.invoke();
M.NotifService.dismiss(notifItem.modelData.id);
}
}
}
}
}
}
// Dismiss button
Text {
id: dismissBtn
anchors.right: parent.right
anchors.rightMargin: 10
anchors.top: parent.top
anchors.topMargin: 8
text: "\uF00D"
color: dismissArea.containsMouse ? M.Theme.base08 : M.Theme.base03
font.pixelSize: M.Theme.fontSize - 1
font.family: M.Theme.iconFontFamily
MouseArea {
id: dismissArea
anchors.fill: parent
anchors.margins: -4
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: _dismissAnim.start()
}
}
SequentialAnimation {
id: _dismissAnim
ParallelAnimation {
NumberAnimation {
target: notifItem
property: "x"
to: menuWindow.panelWidth
duration: 200
easing.type: Easing.InCubic
}
NumberAnimation {
target: notifItem
property: "opacity"
to: 0
duration: 200
easing.type: Easing.InCubic
}
}
NumberAnimation {
target: notifItem
property: "_heightScale"
to: 0
duration: 150
easing.type: Easing.OutCubic
}
ScriptAction {
script: {
if (!notifItem._skipDismiss)
M.NotifService.dismiss(notifItem.modelData.id);
}
}
}
MouseArea {
id: notifArea
anchors.fill: parent
z: -1
hoverEnabled: true
acceptedButtons: Qt.RightButton
onClicked: _dismissAnim.start()
} }
} }
} // Repeater }
} // Column }
} // Flickable
} // Item // Urgency accent
Rectangle {
anchors.left: parent.left
anchors.leftMargin: 4
anchors.top: parent.top
anchors.topMargin: 4
anchors.bottom: parent.bottom
anchors.bottomMargin: 4
width: 2
radius: 1
color: {
const u = notifItem.modelData.urgency;
return u === NotificationUrgency.Critical ? M.Theme.base08 : u === NotificationUrgency.Low ? M.Theme.base04 : M.Theme.base0D;
}
}
Image {
id: ncIcon
anchors.left: parent.left
anchors.leftMargin: 14
anchors.top: parent.top
anchors.topMargin: 6
width: 24
height: 24
source: notifItem.modelData.image || notifItem.modelData.appIcon || ""
visible: status === Image.Ready
fillMode: Image.PreserveAspectFit
sourceSize: Qt.size(24, 24)
asynchronous: true
}
Column {
id: notifContent
anchors.left: ncIcon.visible ? ncIcon.right : parent.left
anchors.right: dismissBtn.left
anchors.top: parent.top
anchors.leftMargin: ncIcon.visible ? 6 : 14
anchors.topMargin: 6
spacing: 1
// App + time
Row {
width: parent.width
Text {
text: notifItem.modelData.appName || "Notification"
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
elide: Text.ElideRight
width: parent.width - ageText.width - 4
}
Text {
id: ageText
text: {
const diff = Math.floor((Date.now() - notifItem.modelData.time) / 60000);
if (diff < 1)
return "now";
if (diff < 60)
return diff + "m";
if (diff < 1440)
return Math.floor(diff / 60) + "h";
return Math.floor(diff / 1440) + "d";
}
color: M.Theme.base03
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
}
}
Text {
width: parent.width
text: notifItem.modelData.summary || ""
color: M.Theme.base05
font.pixelSize: M.Theme.fontSize
font.family: M.Theme.fontFamily
font.bold: true
elide: Text.ElideRight
}
Text {
width: parent.width
text: notifItem.modelData.body || ""
color: M.Theme.base04
font.pixelSize: M.Theme.fontSize - 1
font.family: M.Theme.fontFamily
wrapMode: Text.WordWrap
maximumLineCount: 2
elide: Text.ElideRight
visible: text !== ""
}
// Actions
Row {
spacing: 4
visible: notifItem.modelData.actions && notifItem.modelData.actions.length > 0
Repeater {
model: notifItem.modelData.actions || []
delegate: Rectangle {
required property var modelData
width: actText.implicitWidth + 10
height: actText.implicitHeight + 4
radius: M.Theme.radius
color: actArea.containsMouse ? M.Theme.base02 : "transparent"
border.color: M.Theme.base03
border.width: 1
Text {
id: actText
anchors.centerIn: parent
text: parent.modelData.text
color: M.Theme.base0D
font.pixelSize: M.Theme.fontSize - 2
font.family: M.Theme.fontFamily
}
MouseArea {
id: actArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
parent.modelData.invoke();
M.NotifService.dismiss(notifItem.modelData.id);
}
}
}
}
}
}
// Dismiss button
Text {
id: dismissBtn
anchors.right: parent.right
anchors.rightMargin: 10
anchors.top: parent.top
anchors.topMargin: 8
text: "\uF00D"
color: dismissArea.containsMouse ? M.Theme.base08 : M.Theme.base03
font.pixelSize: M.Theme.fontSize - 1
font.family: M.Theme.iconFontFamily
MouseArea {
id: dismissArea
anchors.fill: parent
anchors.margins: -4
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: _dismissAnim.start()
}
}
SequentialAnimation {
id: _dismissAnim
ParallelAnimation {
NumberAnimation {
target: notifItem
property: "x"
to: menuWindow.panelWidth
duration: 200
easing.type: Easing.InCubic
}
NumberAnimation {
target: notifItem
property: "opacity"
to: 0
duration: 200
easing.type: Easing.InCubic
}
}
NumberAnimation {
target: notifItem
property: "_heightScale"
to: 0
duration: 150
easing.type: Easing.OutCubic
}
ScriptAction {
script: {
if (!notifItem._skipDismiss)
M.NotifService.dismiss(notifItem.modelData.id);
}
}
}
MouseArea {
id: notifArea
anchors.fill: parent
z: -1
hoverEnabled: true
acceptedButtons: Qt.RightButton
onClicked: _dismissAnim.start()
}
}
}
// Empty state // Empty state
Text { Text {