feat: refactor: add helpers for summary/body placement in NotificationBody

This commit is contained in:
Hannes
2026-09-01 23:59:36 +02:00
parent 2df40a2a76
commit b59eb012ba
4 changed files with 237 additions and 194 deletions
+59 -35
View File
@@ -16,6 +16,14 @@ Rectangle {
// When used in history overview we don't want auto-timeout or click-to-close
property bool isHistory: false
// Helpers to handle summary/body placement
// - "Message:" title is always static (fixed bug where appName replaced it when image existed)
// - If notification only has summary and no body, show summary on the right side
property bool hasBody: notification.body !== undefined && notification.body !== null && String(notification.body).trim() !== ""
property bool hasSummary: notification.summary !== undefined && notification.summary !== null && String(notification.summary).trim() !== ""
property bool showSummaryOnLeft: hasSummary && hasBody
property bool showSummaryOnRight: hasSummary && !hasBody
property real duration: isHistory ? 0 : (
notification.expireTimeout > 0 ? notification.expireTimeout*1000 :
urgency ? urgency * 2000 :
@@ -26,12 +34,13 @@ Rectangle {
implicitWidth: screen.width/7
// implicitHeight: screen.height/7
implicitHeight: contentRowRectangle.height+(actionRowRectangle.visible?actionRowRectangle.height:0)+(inlineReplyRectangle.visible?inlineReplyRectangle.height:0)+(progressBar.visible?progressBar.height:0)
implicitHeight: contentRowRectangle.height+(actionRowRectangle.visible?actionRowRectangle.height:0)+(inlineReplyRectangle.visible?inlineReplyRectangle.height:0)+(progressBar.visible?progressBar
.height:0)
color: textBGColor
border.width: Config.border_width
border.color: textColor
radius: isHistory ? Config.radius : 0
radius: isHistory ? Config.small_radius : 0
clip: isHistory
property color textColor: urgency != 3 ? Colors.primary : Colors.tertiary
@@ -73,7 +82,6 @@ Rectangle {
height: Math.max(iconRectangle.height, contentRectangle.height)+contentRow.anchors.margins*2
width: parent.width
color: "transparent"
radius: isHistory ? Config.radius : 0
border.width: Config.border_width
border.color: textColor
@@ -83,26 +91,26 @@ Rectangle {
anchors.right: parent.right
anchors.margins: Config.spacing
width: closeIconText.implicitHeight + Config.spacing
height: closeIconText.implicitHeight + Config.spacing
width: closeIconText.implicitHeight
height: closeIconText.implicitHeight
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
Rectangle {
anchors.fill: parent
radius: Config.radius
color: parent.containsMouse ? Colors.errorContainer : "transparent"
color: parent.containsMouse ? "red" : "transparent"
border.width: Config.border_width
border.color: parent.containsMouse ? Colors.error : textColor
border.color: parent.containsMouse ? "white" : textColor
Text {
id: closeIconText
anchors.centerIn: parent
text: ""; // or "✕"
text: ""; // or "✕"
font.family: Config.font
font.pixelSize: Config.screen_height_to_font_small(screen.height)
color: parent.parent.containsMouse ? Colors.error_fg : textColor
font.pixelSize: Config.screen_height_to_font_medium(screen.height)
color: parent.parent.containsMouse ? "white" : textColor
}
}
onClicked: function(mouse){
@@ -154,10 +162,10 @@ Rectangle {
Text {
id: summaryText
// height: implicitHeight + font.pixelSize + Config.spacing
text: root.notification.summary
visible: root.notification.summary ? true : false
// Only show summary under icon when both summary and body exist.
// If only summary exists (no body), it will be shown on the right instead.
visible: root.showSummaryOnLeft
width: iconColumn.width
font.family: Config.font
font.pixelSize: Config.screen_height_to_font_small(screen.height)
@@ -173,37 +181,54 @@ Rectangle {
Rectangle{
id: contentRectangle
width: root.width - iconColumn.width - contentRow.spacing - contentRow.anchors.margins*2
height: iconRectangle.height
height: Math.max(iconRectangle.height, contentBodyColumn.implicitHeight)
color: "transparent"
Column {
id: contentBodyColumn
width: parent.width
height: Math.max(childrenRect.height, iconRectangle.height)
spacing: Config.spacing
Text {
id: bodyTitleText
text: {
if (notification.image) return notification.appName.charAt(0).toUpperCase() + notification.appName.slice(1)
return "Message:"
Item {
id: titleTextItem
width: parent.width-closingMouseArea.width
height: closingMouseArea.height
Text {
id: bodyTitleText
anchors.centerIn: parent
text: (!notification.appName || !notification.appName.split(".").pop()
? "Message"
: notification.appName.split(".").pop().charAt(0).toUpperCase()
+ notification.appName.split(".").pop().slice(1))
font.family: Config.font
font.bold: true
font.pixelSize: Config.screen_height_to_font_medium(screen.height)
color: textColor
}
font.family: Config.font
font.bold: true
font.pixelSize: closingMouseArea.height //Config.screen_height_to_font_small(screen.height)
color: textColor
}
Rectangle {
width: parent.width
height: Math.max(iconRectangle.height - titleTextItem.height - contentBodyColumn.spacing, 64)
color: textBGColor
radius: Config.screen_big_radius_fun(screen.height)
border.width: Config.border_width
border.color: textColor
Item{
anchors.fill: parent
anchors.margins: Config.spacing
Text {
id: bodyText
// If only summary exists (no body), show summary on the right instead of left
text: root.hasBody ? root.notification.body : (root.showSummaryOnRight ? root.notification.summary : "")
visible: root.hasBody || root.showSummaryOnRight
Text {
id: bodyText
text: root.notification.body
visible: root.notification.body ? true : false
width: contentBodyColumn.width
font.family: Config.font
font.pixelSize: Config.screen_height_to_font_tiny(screen.height)
color: textColor
wrapMode: Text.Wrap
width: parent.width - 2*parent.anchors.margins
font.family: Config.font
font.pixelSize: Config.screen_height_to_font_tiny(screen.height)
color: textColor
wrapMode: Text.Wrap
}
}
}
}
}
@@ -396,7 +421,6 @@ Rectangle {
to: 0.0
duration: root.duration
paused: (mouseArea.containsMouse || closingMouseArea.containsMouse || inlineReplyButtonMouseArea.containsMouse || root._hoveredActionCount > 0 || inlineReplyTextField.hovered || inlineReplyTextField.activeFocus) && !isHistory
onFinished: root.closeNotification(false)
}
}