Files
neochat/src/messagecontent/AuthorComponent.qml

103 lines
2.7 KiB
QML

// SPDX-FileCopyrightText: 2024 James Graham <james.h.graham@protonmail.com>
// SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
import QtQuick
import QtQuick.Controls as QQC2
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.neochat
RowLayout {
id: root
/**
* @brief The matrix ID of the message event.
*/
required property string eventId
/**
* @brief The message author.
*
* A NeochatRoomMember object (which is just a QML safe wrapper around
* Quotient::RoomMember).
*
* @sa NeochatRoomMember, Quotient::RoomMember
*/
required property NeochatRoomMember author
/**
* @brief The timestamp of the event as a neoChatDateTime.
*/
required property neoChatDateTime dateTime
Layout.fillWidth: true
Layout.maximumWidth: Message.maxContentWidth
implicitHeight: Math.max(nameButton.implicitHeight, timeLabel.implicitHeight)
spacing: Kirigami.Units.mediumSpacing
QQC2.Label {
id: nameButton
text: root.author?.disambiguatedName ?? ""
color: root.author?.color ?? ""
textFormat: Text.PlainText
font.weight: Font.Bold
elide: Text.ElideRight
clip: true // Intentional to limit insane Unicode in display names
Layout.fillWidth: true
Layout.maximumWidth: nameButton.implicitWidth + Kirigami.Units.smallSpacing
function openUserMenu(): void {
const menu = Qt.createComponent("org.kde.neochat", "UserMenu").createObject(root, {
window: QQC2.ApplicationWindow.window as Kirigami.ApplicationWindow,
author: root.author
});
menu.popup(root.QQC2.Overlay.overlay);
}
// tapping to open profile
TapHandler {
onTapped: RoomManager.resolveResource(root.author.uri)
}
// right-clicking/long-press for context menu
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.RightButton
cursorShape: Qt.PointingHandCursor
onPressed: nameButton.openUserMenu()
}
TapHandler {
acceptedDevices: PointerDevice.TouchScreen
onTapped: nameButton.openUserMenu()
}
}
QQC2.Label {
id: timeLabel
text: root.dateTime.shortRelativeDateTime
horizontalAlignment: Text.AlignRight
color: Kirigami.Theme.disabledTextColor
QQC2.ToolTip.visible: timeHoverHandler.hovered
QQC2.ToolTip.text: root.dateTime.longDateTime
QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
HoverHandler {
id: timeHoverHandler
}
}
Item {
Layout.fillWidth: true
}
}