Refactor the hoverActions

This commit is contained in:
Tobias Fella
2021-04-09 22:25:43 +02:00
parent 7f63b58067
commit 71fcc20943
2 changed files with 17 additions and 25 deletions

View File

@@ -34,8 +34,6 @@ QQC2.ItemDelegate {
topPadding: 0
bottomPadding: 0
property alias hoveredBubble: controlContainer.hovered
//height: mainColumn.childrenRect.height + (readMarker ? Kirigami.Units.smallSpacing : 0)
//height: mainColumn.implicitHeight + (readMarker ? Kirigami.Units.smallSpacing : 0)
@@ -53,21 +51,9 @@ QQC2.ItemDelegate {
function updateHoverComponent() {
hoverComponent.x = column.mapToItem(page, hoverComponentX, hoverComponentY).x;
hoverComponent.y = column.mapToItem(page, hoverComponentX, hoverComponentY).y;
hoverComponent.hovered = Qt.binding(() => controlContainer.hovered);
hoverComponent.showEdit = author.id === Controller.activeConnection.localUserId && (model.eventType === "emote" || model.eventType === "message");
hoverComponent.bubble = controlContainer
hoverComponent.updateFunction = updateHoverComponent;
hoverComponent.editClicked = () => {
if (hoverComponent.showEdit) {
ChatBoxHelper.edit(message, formattedBody, eventId)
}
};
hoverComponent.replyClicked = () => {
ChatBoxHelper.replyToMessage(eventId, message, author);
};
hoverComponent.reacted = emoji => {
currentRoom.toggleReaction(eventId, emoji);
};
hoverComponent.event = model
}
contentItem: ColumnLayout {

View File

@@ -136,17 +136,15 @@ Kirigami.ScrollablePage {
}
Item {
id: hoverActions
property bool showEdit
property bool hovered: false
property var event
property bool showEdit: event && (event.author.id === Controller.activeConnection.localUserId && (event.eventType === "emote" || event.eventType === "message"))
property var bubble
property var hovered: bubble && bubble.hovered
visible: (hovered || hoverHandler.hovered) && !Kirigami.Settings.isMobile
property var updateFunction
property var editClicked
property var replyClicked
property var reacted
property alias childWidth: hoverActionsRow.width
property alias childHeight: hoverActionsRow.height
@@ -166,7 +164,9 @@ Kirigami.ScrollablePage {
onClicked: emojiDialog.open();
EmojiDialog {
id: emojiDialog
onReact: hoverActions.reacted(emoji)
onReact: {
page.currentRoom.toggleReaction(hoverActions.event.eventId, emoji);
}
}
}
QQC2.Button {
@@ -174,13 +174,19 @@ Kirigami.ScrollablePage {
QQC2.ToolTip.visible: hovered
visible: hoverActions.showEdit
icon.name: "document-edit"
onClicked: hoverActions.editClicked()
onClicked: {
if (hoverActions.showEdit) {
ChatBoxHelper.edit(hoverActions.event.message, hoverActions.event.formattedBody, hoverActions.event.eventId)
}
}
}
QQC2.Button {
QQC2.ToolTip.text: i18n("Reply")
QQC2.ToolTip.visible: hovered
icon.name: "mail-replied-symbolic"
onClicked: hoverActions.replyClicked()
onClicked: {
ChatBoxHelper.replyToMessage(hoverActions.event.eventId, hoverActions.event.message, hoverActions.event.author);
}
}
}
}