Reorganise HoverActions Code
Move most of the external code for hover actions into the component.
This commit is contained in:
@@ -17,6 +17,11 @@ import org.kde.neochat
|
|||||||
QQC2.Control {
|
QQC2.Control {
|
||||||
id: root
|
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.
|
* @brief The current room that user is viewing.
|
||||||
*/
|
*/
|
||||||
@@ -25,38 +30,22 @@ QQC2.Control {
|
|||||||
/**
|
/**
|
||||||
* @brief Whether the actions should be shown.
|
* @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
|
signal focusChatBar()
|
||||||
|
|
||||||
/**
|
|
||||||
* @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()
|
|
||||||
|
|
||||||
topPadding: 0
|
topPadding: 0
|
||||||
bottomPadding: 0
|
bottomPadding: 0
|
||||||
leftPadding: 0
|
leftPadding: 0
|
||||||
rightPadding: 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
|
visible: (root.hovered || root.showActions || showActionsTimer.running) && !Kirigami.Settings.isMobile
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
@@ -78,7 +67,7 @@ QQC2.Control {
|
|||||||
source: "security-high"
|
source: "security-high"
|
||||||
width: height
|
width: height
|
||||||
height: root.height
|
height: root.height
|
||||||
visible: root.verified
|
visible: root.delegate && root.delegate.verified
|
||||||
HoverHandler {
|
HoverHandler {
|
||||||
id: hover
|
id: hover
|
||||||
}
|
}
|
||||||
@@ -100,15 +89,22 @@ QQC2.Control {
|
|||||||
onTriggered: emojiDialog.open()
|
onTriggered: emojiDialog.open()
|
||||||
},
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
|
visible: root.delegate && root.delegate.author.isLocalUser && (root.delegate.delegateType === DelegateType.Emote || root.delegate.delegateType === DelegateType.Message)
|
||||||
text: i18n("Edit")
|
text: i18n("Edit")
|
||||||
icon.name: "document-edit"
|
icon.name: "document-edit"
|
||||||
onTriggered: root.editClicked()
|
onTriggered: {
|
||||||
visible: root.editable
|
root.currentRoom.editCache.editId = root.delegate.eventId;
|
||||||
|
root.currentRoom.mainCache.replyId = "";
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Kirigami.Action {
|
Kirigami.Action {
|
||||||
text: i18n("Reply")
|
text: i18n("Reply")
|
||||||
icon.name: "mail-replied-symbolic"
|
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
|
id: emojiDialog
|
||||||
currentRoom: root.currentRoom
|
currentRoom: root.currentRoom
|
||||||
showQuickReaction: true
|
showQuickReaction: true
|
||||||
onChosen: (emoji) => root.reactClicked(emoji)
|
onChosen: (emoji) => {
|
||||||
|
root.currentRoom.toggleReaction(root.delegate.eventId, emoji);
|
||||||
|
if (!Kirigami.Settings.isMobile) {
|
||||||
|
root.focusChatBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,34 +231,8 @@ QQC2.ScrollView {
|
|||||||
|
|
||||||
HoverActions {
|
HoverActions {
|
||||||
id: 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
|
currentRoom: root.currentRoom
|
||||||
showActions: delegate && delegate.hovered
|
onFocusChatBar: root.focusChatBox()
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onContentYChanged: {
|
onContentYChanged: {
|
||||||
|
|||||||
Reference in New Issue
Block a user