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 var urgency: (notification.urgency ?? notification.hints["urgency"]) != null ? (notification.urgency ?? notification.hints["urgency"]) + 1 : 0
|
||||||
|
|
||||||
property bool closing: false
|
property bool closing: false
|
||||||
|
property int _hoveredActionCount: 0
|
||||||
|
|
||||||
property real duration: (
|
property real duration: (
|
||||||
notification.expireTimeout > 0 ? notification.expireTimeout*1000 :
|
notification.expireTimeout > 0 ? notification.expireTimeout*1000 :
|
||||||
@@ -217,6 +218,8 @@ Rectangle {
|
|||||||
spacing: Config.spacing
|
spacing: Config.spacing
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: Config.spacing
|
anchors.margins: Config.spacing
|
||||||
|
// Expose root to delegates without direct id lookup (avoids ReferenceError inside Repeater)
|
||||||
|
property var bodyRoot: root
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
id: notificationActionRepeater
|
id: notificationActionRepeater
|
||||||
@@ -224,13 +227,28 @@ Rectangle {
|
|||||||
|
|
||||||
delegate: MouseArea{
|
delegate: MouseArea{
|
||||||
id: actionMouseArea
|
id: actionMouseArea
|
||||||
width: actionsRow.width/notification.actions.length
|
width: parent.width / parent.bodyRoot.notification.actions.length
|
||||||
height: actionRectangle.height
|
height: actionRectangle.height
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
cursorShape: Qt.PointingHandCursor
|
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 {
|
Rectangle {
|
||||||
id: actionRectangle
|
id: actionRectangle
|
||||||
width: parent.width
|
width: parent.width
|
||||||
@@ -265,7 +283,7 @@ Rectangle {
|
|||||||
mouse.accepted=true
|
mouse.accepted=true
|
||||||
modelData.invoke()
|
modelData.invoke()
|
||||||
// resident check is allready in .invoke()
|
// resident check is allready in .invoke()
|
||||||
root.closeNotification(false)
|
parent.bodyRoot.closeNotification(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,6 +316,8 @@ Rectangle {
|
|||||||
width: parent.width - inlineReplyButtonMouseArea.width
|
width: parent.width - inlineReplyButtonMouseArea.width
|
||||||
height: inlineReplyButtonText.height
|
height: inlineReplyButtonText.height
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
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
|
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
|
placeholderTextColor: inlineReplyTextField.activeFocus ? Colors.secondary_fg : Colors.secondary
|
||||||
@@ -370,7 +390,7 @@ Rectangle {
|
|||||||
from: 1.0
|
from: 1.0
|
||||||
to: 0.0
|
to: 0.0
|
||||||
duration: root.duration
|
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)
|
onFinished: root.closeNotification(false)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user