Reorganise HoverActions Code

Move most of the external code for hover actions into the component.
This commit is contained in:
James Graham
2023-10-19 19:38:57 +00:00
parent c7614caf41
commit 0029567c3a
2 changed files with 30 additions and 55 deletions

View File

@@ -17,6 +17,11 @@ import org.kde.neochat
QQC2.Control {
id: root
/**
* @brief The current message delegate the actions are being shown on.
*/
property var delegate: null
/**
* @brief The current room that user is viewing.
*/
@@ -25,38 +30,22 @@ QQC2.Control {
/**
* @brief Whether the actions should be shown.
*/
property bool showActions: false
readonly property bool showActions: delegate && delegate.hovered
/**
* @brief Whether the message has been sent from a verified matrix session.
* @brief Request that the chat bar be focussed.
*/
property bool verified: false
/**
* @brief Whether the edit button should be shown.
*/
property bool editable: false
/**
* @brief The react button has been clicked.
*/
signal reactClicked(string emoji)
/**
* @brief The edit button has been clicked.
*/
signal editClicked()
/**
* @brief The reply button has been clicked.
*/
signal replyClicked()
signal focusChatBar()
topPadding: 0
bottomPadding: 0
leftPadding: 0
rightPadding: 0
x: delegate ? delegate.x + delegate.bubbleX : 0
y: delegate ? delegate.mapToItem(parent, 0, 0).y + delegate.bubbleY - height + Kirigami.Units.smallSpacing : 0
width: delegate ? delegate.bubbleWidth : Kirigami.Units.gridUnit * 4
visible: (root.hovered || root.showActions || showActionsTimer.running) && !Kirigami.Settings.isMobile
onVisibleChanged: {
if (visible) {
@@ -78,7 +67,7 @@ QQC2.Control {
source: "security-high"
width: height
height: root.height
visible: root.verified
visible: root.delegate && root.delegate.verified
HoverHandler {
id: hover
}
@@ -100,15 +89,22 @@ QQC2.Control {
onTriggered: emojiDialog.open()
},
Kirigami.Action {
visible: root.delegate && root.delegate.author.isLocalUser && (root.delegate.delegateType === DelegateType.Emote || root.delegate.delegateType === DelegateType.Message)
text: i18n("Edit")
icon.name: "document-edit"
onTriggered: root.editClicked()
visible: root.editable
onTriggered: {
root.currentRoom.editCache.editId = root.delegate.eventId;
root.currentRoom.mainCache.replyId = "";
}
},
Kirigami.Action {
text: i18n("Reply")
icon.name: "mail-replied-symbolic"
onTriggered: root.replyClicked()
onTriggered: {
root.currentRoom.mainCache.replyId = root.delegate.eventId;
root.currentRoom.editCache.editId = "";
root.focusChatBar();
}
}
]
@@ -116,7 +112,12 @@ QQC2.Control {
id: emojiDialog
currentRoom: root.currentRoom
showQuickReaction: true
onChosen: (emoji) => root.reactClicked(emoji)
onChosen: (emoji) => {
root.currentRoom.toggleReaction(root.delegate.eventId, emoji);
if (!Kirigami.Settings.isMobile) {
root.focusChatBar();
}
}
}
}
}

View File

@@ -231,34 +231,8 @@ QQC2.ScrollView {
HoverActions {
id: hoverActions
property var delegate: null
x: delegate ? delegate.x + delegate.bubbleX : 0
y: delegate ? delegate.mapToItem(parent, 0, 0).y + delegate.bubbleY - height + Kirigami.Units.smallSpacing : 0
width: delegate ? delegate.bubbleWidth : Kirigami.Units.gridUnit * 4
currentRoom: root.currentRoom
showActions: delegate && delegate.hovered
verified: delegate && delegate.verified
editable: delegate && delegate.author.isLocalUser && (delegate.delegateType === DelegateType.Emote || delegate.delegateType === DelegateType.Message)
onReactClicked: (emoji) => {
root.currentRoom.toggleReaction(delegate.eventId, emoji);
if (!Kirigami.Settings.isMobile) {
root.focusChatBox();
}
}
onEditClicked: {
root.currentRoom.editCache.editId = delegate.eventId;
root.currentRoom.mainCache.replyId = "";
}
onReplyClicked: {
root.currentRoom.mainCache.replyId = delegate.eventId;
root.currentRoom.editCache.editId = "";
root.focusChatBox();
}
onFocusChatBar: root.focusChatBox()
}
onContentYChanged: {