notifs: extract NotifCard shared component (background, progress, urgency bar, icon, text, dismiss button)
This commit is contained in:
parent
d6b1a7ae58
commit
a502faef19
3 changed files with 271 additions and 364 deletions
|
|
@ -47,9 +47,29 @@ PanelWindow {
|
|||
x: 320
|
||||
clip: true
|
||||
|
||||
readonly property real _targetHeight: contentCol.height + 16
|
||||
readonly property real _targetHeight: _card.implicitHeight
|
||||
property real _heightScale: 0
|
||||
|
||||
// Glow on critical — layer effect composites everything including NotifCard
|
||||
layer.enabled: popupItem.modelData.urgency === NotificationUrgency.Critical
|
||||
layer.effect: MultiEffect {
|
||||
shadowEnabled: true
|
||||
shadowColor: M.Theme.base08
|
||||
shadowBlur: 0.6
|
||||
shadowVerticalOffset: 0
|
||||
shadowHorizontalOffset: 0
|
||||
}
|
||||
|
||||
M.NotifCard {
|
||||
id: _card
|
||||
anchors.fill: parent
|
||||
notif: popupItem.modelData
|
||||
showAppName: true
|
||||
iconSize: 36
|
||||
bodyMaxLines: 3
|
||||
onDismissRequested: popupItem.animateDismiss(true)
|
||||
}
|
||||
|
||||
property bool _entered: false
|
||||
Component.onCompleted: {
|
||||
if (popupCol._knownIds[modelData.id]) {
|
||||
|
|
@ -105,180 +125,6 @@ PanelWindow {
|
|||
}
|
||||
}
|
||||
|
||||
// Background
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: M.Theme.base01
|
||||
opacity: Math.max(M.Theme.barOpacity, 0.9)
|
||||
radius: M.Theme.radius
|
||||
|
||||
// Progress fill as background
|
||||
Rectangle {
|
||||
visible: (popupItem.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, (popupItem.modelData.hints?.value ?? 0) / 100))
|
||||
color: M.Theme.base02
|
||||
radius: parent.radius
|
||||
|
||||
Behavior on width {
|
||||
NumberAnimation {
|
||||
duration: 200
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Urgency accent bar
|
||||
Rectangle {
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
width: 3
|
||||
radius: M.Theme.radius
|
||||
color: {
|
||||
const u = popupItem.modelData.urgency;
|
||||
return u === NotificationUrgency.Critical ? M.Theme.base08 : u === NotificationUrgency.Low ? M.Theme.base04 : M.Theme.base0D;
|
||||
}
|
||||
}
|
||||
|
||||
// Glow on critical
|
||||
layer.enabled: popupItem.modelData.urgency === NotificationUrgency.Critical
|
||||
layer.effect: MultiEffect {
|
||||
shadowEnabled: true
|
||||
shadowColor: M.Theme.base08
|
||||
shadowBlur: 0.6
|
||||
shadowVerticalOffset: 0
|
||||
shadowHorizontalOffset: 0
|
||||
}
|
||||
|
||||
Image {
|
||||
id: notifIcon
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 14
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 8
|
||||
width: 36
|
||||
height: 36
|
||||
source: {
|
||||
const img = popupItem.modelData.image;
|
||||
if (img)
|
||||
return img;
|
||||
const ic = popupItem.modelData.appIcon;
|
||||
if (!ic)
|
||||
return "";
|
||||
return (ic.startsWith("/") || ic.startsWith("file://")) ? ic : Quickshell.iconPath(ic, "dialog-information");
|
||||
}
|
||||
visible: status === Image.Ready
|
||||
fillMode: Image.PreserveAspectFit
|
||||
sourceSize: Qt.size(36, 36)
|
||||
asynchronous: true
|
||||
}
|
||||
|
||||
Column {
|
||||
id: contentCol
|
||||
anchors.left: notifIcon.visible ? notifIcon.right : parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.margins: 8
|
||||
anchors.leftMargin: notifIcon.visible ? 8 : 14
|
||||
spacing: 2
|
||||
|
||||
// App name + time
|
||||
Row {
|
||||
width: parent.width
|
||||
Text {
|
||||
text: popupItem.modelData.appName || "Notification"
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
width: parent.width - timeLabel.width
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
Text {
|
||||
id: timeLabel
|
||||
text: {
|
||||
const diff = Math.floor((Date.now() - popupItem.modelData.time) / 1000);
|
||||
if (diff < 5)
|
||||
return "now";
|
||||
if (diff < 60)
|
||||
return diff + "s";
|
||||
return Math.floor(diff / 60) + "m";
|
||||
}
|
||||
color: M.Theme.base03
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
}
|
||||
|
||||
// Summary
|
||||
Text {
|
||||
width: parent.width
|
||||
text: popupItem.modelData.summary || ""
|
||||
color: M.Theme.base05
|
||||
font.pixelSize: M.Theme.fontSize
|
||||
font.family: M.Theme.fontFamily
|
||||
font.bold: true
|
||||
elide: Text.ElideRight
|
||||
wrapMode: Text.WordWrap
|
||||
maximumLineCount: 2
|
||||
}
|
||||
|
||||
// Body
|
||||
Text {
|
||||
width: parent.width
|
||||
text: popupItem.modelData.body || ""
|
||||
color: M.Theme.base04
|
||||
font.pixelSize: M.Theme.fontSize - 1
|
||||
font.family: M.Theme.fontFamily
|
||||
elide: Text.ElideRight
|
||||
wrapMode: Text.WordWrap
|
||||
maximumLineCount: 3
|
||||
visible: text !== ""
|
||||
}
|
||||
|
||||
// Actions
|
||||
Row {
|
||||
spacing: 6
|
||||
visible: popupItem.modelData.actions.length > 0
|
||||
|
||||
Repeater {
|
||||
model: popupItem.modelData.actions
|
||||
|
||||
delegate: Rectangle {
|
||||
required property var modelData
|
||||
width: actionText.implicitWidth + 12
|
||||
height: actionText.implicitHeight + 6
|
||||
radius: M.Theme.radius
|
||||
color: actionArea.containsMouse ? M.Theme.base02 : M.Theme.base01
|
||||
border.color: M.Theme.base03
|
||||
border.width: 1
|
||||
|
||||
Text {
|
||||
id: actionText
|
||||
anchors.centerIn: parent
|
||||
text: parent.modelData.text
|
||||
color: M.Theme.base0D
|
||||
font.pixelSize: M.Theme.fontSize - 2
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: actionArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: {
|
||||
parent.modelData.invoke();
|
||||
M.NotifService.dismiss(popupItem.modelData.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property bool _fullDismiss: false
|
||||
|
||||
function animateDismiss(full) {
|
||||
|
|
@ -292,7 +138,6 @@ PanelWindow {
|
|||
|
||||
SequentialAnimation {
|
||||
id: slideOut
|
||||
// Swipe right
|
||||
ParallelAnimation {
|
||||
NumberAnimation {
|
||||
target: popupItem
|
||||
|
|
@ -309,7 +154,6 @@ PanelWindow {
|
|||
easing.type: Easing.InCubic
|
||||
}
|
||||
}
|
||||
// Collapse height so items below float up
|
||||
NumberAnimation {
|
||||
target: popupItem
|
||||
property: "_heightScale"
|
||||
|
|
@ -322,6 +166,7 @@ PanelWindow {
|
|||
}
|
||||
}
|
||||
|
||||
// Click anywhere to dismiss (left = popup only, right = full dismiss)
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
z: -1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue