refactor: Introduce _hoveredActionCount for notification action hover tracking, avoiding direct 'root' lookup and improving code readability.
This commit is contained in:
@@ -14,6 +14,7 @@ Rectangle {
|
||||
property var urgency: (notification.urgency ?? notification.hints["urgency"]) != null ? (notification.urgency ?? notification.hints["urgency"]) + 1 : 0
|
||||
|
||||
property bool closing: false
|
||||
property int _hoveredActionCount: 0
|
||||
|
||||
property real duration: (
|
||||
notification.expireTimeout > 0 ? notification.expireTimeout*1000 :
|
||||
@@ -217,6 +218,8 @@ Rectangle {
|
||||
spacing: Config.spacing
|
||||
anchors.fill: parent
|
||||
anchors.margins: Config.spacing
|
||||
// Expose root to delegates without direct id lookup (avoids ReferenceError inside Repeater)
|
||||
property var bodyRoot: root
|
||||
|
||||
Repeater {
|
||||
id: notificationActionRepeater
|
||||
@@ -224,13 +227,28 @@ Rectangle {
|
||||
|
||||
delegate: MouseArea{
|
||||
id: actionMouseArea
|
||||
width: actionsRow.width/notification.actions.length
|
||||
width: parent.width / parent.bodyRoot.notification.actions.length
|
||||
height: actionRectangle.height
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
onContainsMouseChanged: {
|
||||
// Track hover for pause logic via parent's bodyRoot (avoids direct 'root' lookup)
|
||||
const body = parent.bodyRoot
|
||||
if (!body) return
|
||||
if (containsMouse) body._hoveredActionCount++
|
||||
else body._hoveredActionCount = Math.max(0, body._hoveredActionCount - 1)
|
||||
}
|
||||
|
||||
Component.onDestruction: {
|
||||
if (containsMouse && parent && parent.bodyRoot) {
|
||||
const body = parent.bodyRoot
|
||||
body._hoveredActionCount = Math.max(0, body._hoveredActionCount - 1)
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: actionRectangle
|
||||
width: parent.width
|
||||
@@ -265,7 +283,7 @@ Rectangle {
|
||||
mouse.accepted=true
|
||||
modelData.invoke()
|
||||
// resident check is allready in .invoke()
|
||||
root.closeNotification(false)
|
||||
parent.bodyRoot.closeNotification(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,6 +316,8 @@ Rectangle {
|
||||
width: parent.width - inlineReplyButtonMouseArea.width
|
||||
height: inlineReplyButtonText.height
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
hoverEnabled: true
|
||||
activeFocusOnTab: true
|
||||
|
||||
placeholderText: notification.hints["x-kde-reply-placeholder-text"] != null ? notification.hints["x-kde-reply-placeholder-text"] : notification.inlineReplyPlaceholder
|
||||
placeholderTextColor: inlineReplyTextField.activeFocus ? Colors.secondary_fg : Colors.secondary
|
||||
@@ -370,7 +390,7 @@ Rectangle {
|
||||
from: 1.0
|
||||
to: 0.0
|
||||
duration: root.duration
|
||||
paused: mouseArea.containsMouse || closingMouseArea.containsMouse || inlineReplyButtonMouseArea.containsMouse
|
||||
paused: mouseArea.containsMouse || closingMouseArea.containsMouse || inlineReplyButtonMouseArea.containsMouse || root._hoveredActionCount > 0 || inlineReplyTextField.hovered || inlineReplyTextField.activeFocus
|
||||
|
||||
onFinished: root.closeNotification(false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user