// SPDX-FileCopyrightText: 2020 Black Hat // SPDX-FileCopyrightText: 2024 James Graham // SPDX-License-Identifier: GPL-3.0-only import QtQuick import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.neochat /** * @brief A component to show rich text from a message. */ TextEdit { id: root /** * @brief The display text of the message. */ required property string display /** * @brief Whether this message is replying to another. */ property bool isReply: false /** * @brief Regex for detecting a message with a spoiler. */ readonly property var hasSpoiler: /data-mx-spoiler/g /** * @brief Whether a spoiler should be revealed. */ property bool spoilerRevealed: !hasSpoiler.test(display) /** * @brief The maximum width that the bubble's content can be. */ property real maxContentWidth: -1 /** * @brief Request a context menu be show for the message. */ signal showMessageMenu Layout.fillWidth: true Layout.fillHeight: true Layout.maximumWidth: root.maxContentWidth ListView.onReused: Qt.binding(() => !hasSpoiler.test(display)) persistentSelection: true text: "" + display color: Kirigami.Theme.textColor selectedTextColor: Kirigami.Theme.highlightedTextColor selectionColor: Kirigami.Theme.highlightColor font { pointSize: !root.isReply && QmlUtils.isEmoji(display) ? Kirigami.Theme.defaultFont.pointSize * 4 : Kirigami.Theme.defaultFont.pointSize family: QmlUtils.isEmoji(display) ? 'emoji' : Kirigami.Theme.defaultFont.family } selectByMouse: !Kirigami.Settings.isMobile readOnly: true wrapMode: Text.Wrap textFormat: Text.RichText onLinkActivated: link => { spoilerRevealed = true; RoomManager.resolveResource(link, "join"); } onHoveredLinkChanged: if (hoveredLink.length > 0 && hoveredLink !== "1") { applicationWindow().hoverLinkIndicator.text = hoveredLink; } else { applicationWindow().hoverLinkIndicator.text = ""; } HoverHandler { cursorShape: (root.hoveredLink || !spoilerRevealed) ? Qt.PointingHandCursor : Qt.IBeamCursor } TapHandler { enabled: !root.hoveredLink && !spoilerRevealed onTapped: spoilerRevealed = true } TapHandler { enabled: !root.hoveredLink acceptedButtons: Qt.LeftButton onLongPressed: root.showMessageMenu() } }