Warning, /network/neochat/src/qml/HoverActions.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 James Graham <james.h.graham@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.neochat
0010 
0011 /**
0012  * @brief A component that provides a set of actions when a message is hovered in the timeline.
0013  *
0014  * There is also an icon to show that a message has come from a verified device in
0015  * encrypted chats.
0016  */
0017 QQC2.Control {
0018     id: root
0019 
0020     /**
0021      * @brief The current message delegate the actions are being shown on.
0022      */
0023     property var delegate: null
0024 
0025     /**
0026      * @brief The current room that user is viewing.
0027      */
0028     required property NeoChatRoom currentRoom
0029 
0030     /**
0031      * @brief Whether the actions should be shown.
0032      */
0033     readonly property bool showActions: delegate && delegate.hovered
0034 
0035     /**
0036      * @brief Request that the chat bar be focussed.
0037      */
0038     signal focusChatBar
0039 
0040     topPadding: 0
0041     bottomPadding: 0
0042     leftPadding: 0
0043     rightPadding: 0
0044 
0045     x: delegate ? delegate.contentX + delegate.bubbleX : 0
0046     y: delegate ? delegate.mapToItem(parent, 0, 0).y + delegate.bubbleY - height + Kirigami.Units.smallSpacing : 0
0047     width: delegate ? delegate.bubbleWidth : Kirigami.Units.gridUnit * 4
0048 
0049     visible: (root.hovered || root.showActions || showActionsTimer.running) && !Kirigami.Settings.isMobile
0050     onVisibleChanged: {
0051         if (visible) {
0052             // HACK: delay disapearing by 200ms, otherwise this can create some glitches
0053             // See https://invent.kde.org/network/neochat/-/issues/333
0054             showActionsTimer.restart();
0055         }
0056     }
0057     Timer {
0058         id: showActionsTimer
0059         interval: 200
0060     }
0061 
0062     contentItem: RowLayout {
0063         Item {
0064             Layout.fillWidth: true
0065         }
0066         Kirigami.Icon {
0067             source: "security-high"
0068             width: height
0069             height: root.height
0070             visible: root.delegate && root.delegate.verified
0071             HoverHandler {
0072                 id: hover
0073             }
0074             QQC2.ToolTip.text: i18n("This message was sent from a verified device")
0075             QQC2.ToolTip.visible: hover.hovered
0076             QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
0077         }
0078         Kirigami.ActionToolBar {
0079             Layout.maximumWidth: maximumContentWidth + Kirigami.Units.largeSpacing
0080             rightPadding: Kirigami.Units.largeSpacing
0081             alignment: Qt.AlignRight
0082             flat: false
0083             display: QQC2.Button.IconOnly
0084 
0085             actions: [
0086                 Kirigami.Action {
0087                     text: i18n("React")
0088                     icon.name: "preferences-desktop-emoticons"
0089                     onTriggered: emojiDialog.open()
0090                 },
0091                 Kirigami.Action {
0092                     visible: root.delegate && root.delegate.author.isLocalUser && (root.delegate.delegateType === DelegateType.Emote || root.delegate.delegateType === DelegateType.Message) && !root.currentRoom.readOnly
0093                     text: i18n("Edit")
0094                     icon.name: "document-edit"
0095                     onTriggered: {
0096                         root.currentRoom.editCache.editId = root.delegate.eventId;
0097                         root.currentRoom.mainCache.replyId = "";
0098                     }
0099                 },
0100                 Kirigami.Action {
0101                     visible: !root.currentRoom.readOnly
0102                     text: i18n("Reply")
0103                     icon.name: "mail-replied-symbolic"
0104                     onTriggered: {
0105                         root.currentRoom.mainCache.replyId = root.delegate.eventId;
0106                         root.currentRoom.editCache.editId = "";
0107                         root.focusChatBar();
0108                     }
0109                 },
0110                 Kirigami.Action {
0111                     visible: !root.currentRoom.readOnly
0112                     text: i18n("Reply in Thread")
0113                     icon.name: "dialog-messages"
0114                     onTriggered: {
0115                         root.currentRoom.mainCache.replyId = root.delegate.eventId;
0116                         root.currentRoom.mainCache.threadId = root.delegate.isThreaded ? root.delegate.threadRoot : root.delegate.eventId;
0117                         root.currentRoom.editCache.editId = "";
0118                         root.focusChatBar();
0119                     }
0120                 }
0121             ]
0122 
0123             EmojiDialog {
0124                 id: emojiDialog
0125                 currentRoom: root.currentRoom
0126                 showQuickReaction: true
0127                 onChosen: emoji => {
0128                     root.currentRoom.toggleReaction(root.delegate.eventId, emoji);
0129                     if (!Kirigami.Settings.isMobile) {
0130                         root.focusChatBar();
0131                     }
0132                 }
0133             }
0134         }
0135     }
0136 }