1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-07 14:05:38 -05:00

notifications: improve notification center

This commit is contained in:
bbedward
2025-07-25 16:52:58 -04:00
parent 98ddc2805b
commit e14afcefd4
11 changed files with 619 additions and 1203 deletions

View File

@@ -11,48 +11,62 @@ Rectangle {
property var notificationGroup
property bool expanded: NotificationService.expandedGroups[notificationGroup?.key] || false
property bool descriptionExpanded: false
width: parent.width
height: {
if (expanded && notificationGroup && notificationGroup.count >= 1) {
const baseHeight = (116 * notificationGroup.count) + (12 * (notificationGroup.count - 1));
const bottomMargin = notificationGroup.count === 1 ? 65 : (notificationGroup.count <= 3 ? 30 : -30);
return baseHeight + bottomMargin;
if (expanded) {
return expandedContent.height + 28;
}
return 116;
const baseHeight = 116;
if (descriptionExpanded && descriptionText.hasMoreText) {
const twoLineHeight = descriptionText.font.pixelSize * 1.2 * 2;
const extraHeight = descriptionText.contentHeight - twoLineHeight;
return baseHeight + extraHeight;
}
return baseHeight;
}
radius: Theme.cornerRadiusLarge
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.1)
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.3)
border.color: notificationGroup?.latestNotification?.urgency === 2 ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.3) : Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.05)
border.width: notificationGroup?.latestNotification?.urgency === 2 ? 2 : 1
clip: true
Rectangle {
width: 4
height: parent.height - 16
anchors.left: parent.left
anchors.leftMargin: 2
anchors.verticalCenter: parent.verticalCenter
radius: 2
color: Theme.primary
anchors.fill: parent
radius: parent.radius
visible: notificationGroup?.latestNotification?.urgency === 2
gradient: Gradient {
orientation: Gradient.Horizontal
GradientStop {
position: 0.0
color: Theme.primary
}
GradientStop {
position: 0.02
color: Theme.primary
}
GradientStop {
position: 0.021
color: "transparent"
}
}
opacity: 1.0
}
Item {
id: collapsedContent
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.topMargin: 12
anchors.leftMargin: 16
anchors.rightMargin: 16
anchors.rightMargin: 56
height: 92
visible: !expanded
Rectangle {
id: iconContainer
readonly property bool hasNotificationImage: notificationGroup?.latestNotification?.image && notificationGroup.latestNotification.image !== ""
width: 55
@@ -70,12 +84,10 @@ Rectangle {
source: {
if (parent.hasNotificationImage)
return notificationGroup.latestNotification.cleanImage;
if (notificationGroup?.latestNotification?.appIcon) {
const appIcon = notificationGroup.latestNotification.appIcon;
if (appIcon.startsWith("file://") || appIcon.startsWith("http://") || appIcon.startsWith("https://"))
return appIcon;
return Quickshell.iconPath(appIcon, "");
}
return "";
@@ -121,7 +133,7 @@ Rectangle {
anchors.left: iconContainer.right
anchors.leftMargin: 12
anchors.right: controlsContainer.left
anchors.right: parent.right
anchors.rightMargin: 0
anchors.top: parent.top
anchors.bottom: parent.bottom
@@ -132,7 +144,7 @@ Rectangle {
width: parent.width
height: parent.height
anchors.top: parent.top
anchors.topMargin: 2
anchors.topMargin: -4
Column {
width: parent.width
@@ -166,95 +178,42 @@ Rectangle {
}
Text {
text: {
let bodyText = notificationGroup?.latestNotification?.body || "";
const urlRegex = /(https?:\/\/[^\s]+)/g;
return bodyText.replace(urlRegex, '<a href="$1" style="color: ' + Theme.primary + '; text-decoration: underline;">$1</a>');
}
id: descriptionText
property string fullText: notificationGroup?.latestNotification?.body || ""
property bool hasMoreText: false
text: fullText
color: Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall
width: parent.width
elide: Text.ElideRight
maximumLineCount: (notificationGroup?.count || 0) > 1 ? 2 : 3
maximumLineCount: descriptionExpanded ? -1 : 2
wrapMode: Text.WordWrap
visible: text.length > 0
textFormat: Text.RichText
onLinkActivated: function(link) {
Qt.openUrlExternally(link);
textFormat: Text.PlainText
onContentHeightChanged: {
const singleLineHeight = font.pixelSize * 1.2;
const twoLineHeight = singleLineHeight * 2;
hasMoreText = descriptionText.contentHeight > twoLineHeight;
}
MouseArea {
anchors.fill: parent
cursorShape: parent.hasMoreText ? Qt.PointingHandCursor : Qt.ArrowCursor
enabled: parent.hasMoreText
onClicked: {
descriptionExpanded = !descriptionExpanded;
}
}
}
}
}
}
Item {
id: controlsContainer
anchors.right: parent.right
anchors.rightMargin: 0
anchors.top: parent.top
anchors.topMargin: 0
width: (notificationGroup?.count || 0) > 1 ? 40 : 20
height: 24
Rectangle {
anchors.left: parent.left
anchors.top: parent.top
width: 20
height: 20
radius: 10
color: expandArea.containsMouse ? Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) : "transparent"
visible: (notificationGroup?.count || 0) > 1
DankIcon {
anchors.centerIn: parent
name: expanded ? "expand_less" : "expand_more"
size: 14
color: Theme.surfaceText
}
MouseArea {
id: expandArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: NotificationService.toggleGroupExpansion(notificationGroup?.key || "")
}
}
Rectangle {
property bool isHovered: false
anchors.right: parent.right
anchors.top: parent.top
width: 20
height: 20
radius: 10
color: isHovered ? Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) : "transparent"
DankIcon {
name: "close"
size: 14
color: parent.isHovered ? Theme.primary : Theme.surfaceText
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: parent.isHovered = true
onExited: parent.isHovered = false
onClicked: NotificationService.dismissGroup(notificationGroup?.key || "")
}
}
}
}
Column {
id: expandedContent
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
@@ -271,6 +230,8 @@ Rectangle {
Row {
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: 56
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingS
@@ -280,6 +241,8 @@ Rectangle {
font.pixelSize: Theme.fontSizeLarge
font.weight: Font.Bold
anchors.verticalCenter: parent.verticalCenter
elide: Text.ElideRight
maximumLineCount: 1
}
Rectangle {
@@ -300,61 +263,6 @@ Rectangle {
}
}
Item {
width: 48
height: 24
anchors.right: parent.right
anchors.top: parent.top
anchors.topMargin: 2
Rectangle {
width: 20
height: 20
radius: 10
anchors.left: parent.left
color: collapseArea.containsMouse ? Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) : "transparent"
DankIcon {
anchors.centerIn: parent
name: "expand_less"
size: 14
color: Theme.surfaceText
}
MouseArea {
id: collapseArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: NotificationService.toggleGroupExpansion(notificationGroup?.key || "")
}
}
Rectangle {
width: 20
height: 20
radius: 10
anchors.right: parent.right
color: dismissAllArea.containsMouse ? Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) : "transparent"
DankIcon {
anchors.centerIn: parent
name: "close"
size: 14
color: Theme.surfaceText
}
MouseArea {
id: dismissAllArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: NotificationService.dismissGroup(notificationGroup?.key || "")
}
}
}
}
Column {
@@ -369,15 +277,33 @@ Rectangle {
readonly property bool messageExpanded: NotificationService.expandedMessages[modelData?.notification?.id] || false
width: parent.width
height: messageExpanded ? Math.min(120, 50 + (bodyText.contentHeight || 0)) : 80
height: {
const baseHeight = 120;
if (messageExpanded) {
const twoLineHeight = bodyText.font.pixelSize * 1.2 * 2;
if (bodyText.implicitHeight > twoLineHeight + 2) {
const extraHeight = bodyText.implicitHeight - twoLineHeight;
return baseHeight + extraHeight;
}
}
return baseHeight;
}
radius: Theme.cornerRadiusLarge
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.2)
color: "transparent"
border.color: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.05)
border.width: 1
Behavior on height {
NumberAnimation {
duration: Theme.shortDuration
easing.type: Theme.standardEasing
}
}
Item {
anchors.fill: parent
anchors.margins: 12
anchors.bottomMargin: 18
Rectangle {
id: messageIcon
@@ -388,7 +314,7 @@ Rectangle {
height: 32
radius: 16
anchors.left: parent.left
anchors.top: parent.top
anchors.verticalCenter: parent.verticalCenter
color: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1)
border.color: Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.2)
border.width: 1
@@ -428,26 +354,21 @@ Rectangle {
Column {
anchors.left: messageIcon.right
anchors.leftMargin: 12
anchors.right: messageControls.left
anchors.rightMargin: 0
anchors.right: parent.right
anchors.rightMargin: 12
anchors.top: parent.top
spacing: 4
anchors.topMargin: -2
spacing: 2
Text {
width: parent.width
text: {
const appName = modelData?.appName || "";
const timeStr = modelData?.timeStr || "";
if (timeStr.length > 0)
return appName + " • " + timeStr;
else
return appName;
}
text: modelData?.timeStr || ""
color: Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
elide: Text.ElideRight
maximumLineCount: 1
visible: text.length > 0
}
Text {
@@ -463,85 +384,94 @@ Rectangle {
Text {
id: bodyText
width: parent.width
text: {
let bodyText = modelData?.body || "";
if (messageExpanded)
bodyText = bodyText.length > 500 ? bodyText.substring(0, 497) + "..." : bodyText;
else
bodyText = bodyText.length > 80 ? bodyText.substring(0, 77) + "..." : bodyText;
const urlRegex = /(https?:\/\/[^\s]+)/g;
return bodyText.replace(urlRegex, '<a href="$1" style="color: ' + Theme.primary + '; text-decoration: underline;">$1</a>');
}
text: modelData?.body || ""
color: Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall
width: parent.width
elide: messageExpanded ? Text.ElideNone : Text.ElideRight
maximumLineCount: messageExpanded ? -1 : 2
wrapMode: Text.WordWrap
visible: text.length > 0
textFormat: Text.RichText
onLinkActivated: function(link) {
Qt.openUrlExternally(link);
}
}
}
Row {
id: messageControls
anchors.right: parent.right
anchors.rightMargin: -6
anchors.top: parent.top
spacing: 4
Rectangle {
width: 20
height: 20
radius: 10
color: expandMessageArea.containsMouse ? Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) : "transparent"
visible: (modelData?.body || "").length > 80
DankIcon {
anchors.centerIn: parent
name: {
const messageExpanded = NotificationService.expandedMessages[modelData?.notification?.id] || false;
return messageExpanded ? "expand_less" : "expand_more";
textFormat: Text.PlainText
MouseArea {
anchors.fill: parent
cursorShape: parent.truncated ? Qt.PointingHandCursor : Qt.ArrowCursor
enabled: parent.truncated || messageExpanded
onClicked: {
NotificationService.toggleMessageExpansion(modelData?.notification?.id || "");
}
size: 12
color: Theme.surfaceText
}
MouseArea {
id: expandMessageArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: NotificationService.toggleMessageExpansion(modelData?.notification?.id || "")
}
}
Rectangle {
width: 20
height: 20
radius: 10
color: closeMessageArea.containsMouse ? Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.08) : "transparent"
Row {
anchors.right: parent.right
spacing: 8
anchors.topMargin: 4
anchors.bottomMargin: 6
DankIcon {
anchors.centerIn: parent
name: "close"
size: 12
color: closeMessageArea.containsMouse ? Theme.primary : Theme.surfaceText
Repeater {
model: modelData?.actions || []
Rectangle {
property bool isHovered: false
width: Math.max(actionText.implicitWidth + 12, 50)
height: 24
radius: 4
color: isHovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
Text {
id: actionText
text: modelData.text || ""
color: parent.isHovered ? Theme.primary : Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
anchors.centerIn: parent
elide: Text.ElideRight
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: parent.isHovered = true
onExited: parent.isHovered = false
onClicked: {
if (modelData && modelData.invoke) {
modelData.invoke();
}
}
}
}
}
MouseArea {
id: closeMessageArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: NotificationService.dismissNotification(modelData)
Rectangle {
property bool isHovered: false
width: Math.max(dismissText.implicitWidth + 12, 50)
height: 24
radius: 4
color: isHovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
Text {
id: dismissText
text: "Dismiss"
color: parent.isHovered ? Theme.primary : Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: parent.isHovered = true
onExited: parent.isHovered = false
onClicked: NotificationService.dismissNotification(modelData)
}
}
}
}
@@ -551,49 +481,46 @@ Rectangle {
}
}
Rectangle {
property bool isHovered: false
Row {
visible: !expanded
anchors.right: dismissButton.left
anchors.rightMargin: 4
anchors.rightMargin: 8
anchors.bottom: parent.bottom
anchors.bottomMargin: 8
width: viewText.width + 16
height: viewText.height + 8
radius: 6
color: isHovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
Text {
id: viewText
text: "View"
color: parent.isHovered ? Theme.primary : Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: parent.isHovered = true
onExited: parent.isHovered = false
onClicked: {
if (notificationGroup?.latestNotification?.actions) {
for (const action of notificationGroup.latestNotification.actions) {
if (action.text && action.text.toLowerCase() === "view") {
if (action.invoke) {
action.invoke();
return;
}
spacing: 8
Repeater {
model: notificationGroup?.latestNotification?.actions || []
Rectangle {
property bool isHovered: false
width: Math.max(actionText.implicitWidth + 12, 50)
height: 24
radius: 4
color: isHovered ? Qt.rgba(Theme.primary.r, Theme.primary.g, Theme.primary.b, 0.1) : "transparent"
Text {
id: actionText
text: modelData.text || ""
color: parent.isHovered ? Theme.primary : Theme.surfaceVariantText
font.pixelSize: Theme.fontSizeSmall
font.weight: Font.Medium
anchors.centerIn: parent
elide: Text.ElideRight
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onEntered: parent.isHovered = true
onExited: parent.isHovered = false
onClicked: {
if (modelData && modelData.invoke) {
modelData.invoke();
}
}
if (notificationGroup.latestNotification.actions.length > 0) {
const firstAction = notificationGroup.latestNotification.actions[0];
if (firstAction.invoke)
firstAction.invoke();
}
}
}
}
@@ -604,6 +531,7 @@ Rectangle {
property bool isHovered: false
visible: !expanded
anchors.right: parent.right
anchors.rightMargin: 16
anchors.bottom: parent.bottom
@@ -640,16 +568,39 @@ Rectangle {
z: -1
}
Behavior on height {
SequentialAnimation {
PauseAnimation {
duration: 25
}
Item {
id: fixedControls
anchors.top: parent.top
anchors.right: parent.right
anchors.topMargin: 12
anchors.rightMargin: 16
width: 40
height: 24
NumberAnimation {
duration: Theme.mediumDuration
easing.type: Theme.emphasizedEasing
}
DankActionButton {
anchors.left: parent.left
anchors.top: parent.top
visible: (notificationGroup?.count || 0) > 1
iconName: expanded ? "expand_less" : "expand_more"
iconSize: 14
buttonSize: 20
onClicked: NotificationService.toggleGroupExpansion(notificationGroup?.key || "")
}
DankActionButton {
anchors.right: parent.right
anchors.top: parent.top
iconName: "close"
iconSize: 14
buttonSize: 20
onClicked: NotificationService.dismissGroup(notificationGroup?.key || "")
}
}
Behavior on height {
NumberAnimation {
duration: Theme.mediumDuration
easing.type: Theme.emphasizedEasing
}
}
}