Notification: add app icon support

This commit is contained in:
Ly-sec 2025-09-04 13:38:39 +02:00
parent 291cd5130d
commit 4229721774
2 changed files with 85 additions and 48 deletions

View file

@ -93,10 +93,10 @@ Variants {
model: notificationModel model: notificationModel
delegate: Rectangle { delegate: Rectangle {
width: 360 * scaling width: 360 * scaling
height: Math.max(80 * scaling, contentColumn.implicitHeight + (Style.marginM * 2 * scaling)) height: Math.max(80 * scaling, contentRow.implicitHeight + (Style.marginL * 2 * scaling))
clip: true clip: true
radius: Style.radiusM * scaling radius: Style.radiusL * scaling
border.color: Color.mPrimary border.color: Color.applyOpacity(Color.mOutline, "33")
border.width: Math.max(1, Style.borderS * scaling) border.width: Math.max(1, Style.borderS * scaling)
color: Color.mSurface color: Color.mSurface
@ -156,55 +156,88 @@ Variants {
} }
} }
Column { RowLayout {
id: contentColumn id: contentRow
anchors.fill: parent anchors.fill: parent
anchors.margins: Style.marginM * scaling anchors.margins: Style.marginL * scaling
spacing: Style.marginS * scaling spacing: Style.marginL * scaling
RowLayout { // Right: header on top, then avatar + texts
ColumnLayout {
id: textColumn
spacing: Style.marginS * scaling spacing: Style.marginS * scaling
NText { Layout.fillWidth: true
text: (model.appName || model.desktopEntry) || "Unknown App"
color: Color.mSecondary
font.pointSize: Style.fontSizeXS * scaling
}
Rectangle {
width: 6 * scaling
height: 6 * scaling
radius: Style.radiusXS * scaling
color: (model.urgency === NotificationUrgency.Critical) ? Color.mError : (model.urgency === NotificationUrgency.Low) ? Color.mOnSurface : Color.mPrimary
Layout.alignment: Qt.AlignVCenter
}
Item {
Layout.fillWidth: true
}
NText {
text: NotificationService.formatTimestamp(model.timestamp)
color: Color.mOnSurface
font.pointSize: Style.fontSizeXS * scaling
}
}
NText { RowLayout {
text: model.summary || "No summary" spacing: Style.marginS * scaling
font.pointSize: Style.fontSizeL * scaling id: appHeaderRow
font.weight: Style.fontWeightBold NText {
color: Color.mOnSurface text: `${(model.appName || model.desktopEntry)
wrapMode: Text.Wrap || "Unknown App"} · ${NotificationService.formatTimestamp(model.timestamp)}`
width: 300 * scaling color: Color.mSecondary
maximumLineCount: 3 font.pointSize: Style.fontSizeXS * scaling
elide: Text.ElideRight }
} Rectangle {
width: 6 * scaling
height: 6 * scaling
radius: Style.radiusXS * scaling
color: (model.urgency === NotificationUrgency.Critical) ? Color.mError : (model.urgency === NotificationUrgency.Low) ? Color.mOnSurface : Color.mPrimary
Layout.alignment: Qt.AlignVCenter
}
Item {
Layout.fillWidth: true
}
}
NText { RowLayout {
text: model.body || "" id: bodyRow
font.pointSize: Style.fontSizeXS * scaling spacing: Style.marginM * scaling
color: Color.mOnSurface
wrapMode: Text.Wrap NImageCircled {
width: 300 * scaling id: appAvatar
maximumLineCount: 5 Layout.preferredWidth: 40 * scaling
elide: Text.ElideRight Layout.preferredHeight: 40 * scaling
Layout.alignment: Qt.AlignTop
// Start avatar aligned with body (below the summary)
anchors.topMargin: textContent.childrenRect.y
imagePath: Icons.iconFromName(model.appIcon, "application-x-executable")
fallbackIcon: "apps"
borderColor: Color.transparent
borderWidth: 0
visible: imagePath && imagePath !== ""
}
Column {
id: textContent
spacing: Style.marginS * scaling
Layout.fillWidth: true
// Ensure a concrete width so text wraps
width: (textColumn.width - (appAvatar.visible ? (appAvatar.width + Style.marginM * scaling) : 0))
NText {
text: model.summary || "No summary"
font.pointSize: Style.fontSizeL * scaling
font.weight: Style.fontWeightMedium
color: Color.mOnSurface
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
Layout.fillWidth: true
width: parent.width
maximumLineCount: 3
elide: Text.ElideRight
}
NText {
text: model.body || ""
font.pointSize: Style.fontSizeM * scaling
color: Color.mOnSurface
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
Layout.fillWidth: true
width: parent.width
maximumLineCount: 5
elide: Text.ElideRight
}
}
}
} }
// Actions removed // Actions removed
@ -213,7 +246,9 @@ Variants {
NIconButton { NIconButton {
icon: "close" icon: "close"
tooltipText: "Close" tooltipText: "Close"
sizeRatio: 0.8 // Compact target (~24dp) and glyph (~16dp)
sizeRatio: 0.75
fontPointSize: 16
anchors.top: parent.top anchors.top: parent.top
anchors.right: parent.right anchors.right: parent.right
anchors.margins: Style.marginS * scaling anchors.margins: Style.marginS * scaling

View file

@ -116,6 +116,8 @@ Singleton {
"summary": notification.summary, "summary": notification.summary,
"body": notification.body, "body": notification.body,
"appName": notification.appName, "appName": notification.appName,
"image": notification.image,
"appIcon": notification.appIcon,
"urgency": notification.urgency, "urgency": notification.urgency,
"timestamp": new Date() "timestamp": new Date()
}) })