Add user menu that is opened via right-clicking/long-tapped on avatar

We can un-clutter our message context menu, which we had to share
with user actions. (Even though we only had one so far.) I added one new
user-specific action which allows you to quickly mention the user in
chat. Otherwise you would've had to copy their username or use the
completion menu.

It's convergent on mobile, it still has the hover indicator and it also
is available through the AuthorComponent.

BUG: 486252
This commit is contained in:
Joshua Goins
2025-05-15 15:01:52 -04:00
parent 6ef7acc8e5
commit d059195e92
9 changed files with 111 additions and 34 deletions

View File

@@ -41,21 +41,43 @@ RowLayout {
implicitHeight: Math.max(nameButton.implicitHeight, timeLabel.implicitHeight)
QQC2.AbstractButton {
QQC2.Label {
id: nameButton
contentItem: QQC2.Label {
text: root.author.disambiguatedName
color: root.author.color
textFormat: Text.PlainText
font.weight: Font.Bold
elide: Text.ElideRight
text: root.author.disambiguatedName
color: root.author.color
textFormat: Text.PlainText
font.weight: Font.Bold
elide: Text.ElideRight
function openUserMenu(): void {
const menu = Qt.createComponent("org.kde.neochat", "UserMenu").createObject(root, {
connection: root.connection,
window: QQC2.ApplicationWindow.window as Kirigami.ApplicationWindow,
author: root.author,
});
menu.popup(root);
}
Accessible.name: contentItem.text
onClicked: RoomManager.resolveResource(root.author.uri)
HoverHandler {
cursorShape: Qt.PointingHandCursor
}
// tapping to open profile
TapHandler {
onTapped: RoomManager.resolveResource(root.author.uri)
}
// right-clicking/long-press for context menu
TapHandler {
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
acceptedButtons: Qt.RightButton
onTapped: nameButton.openUserMenu()
}
TapHandler {
acceptedDevices: PointerDevice.TouchScreen
onTapped: nameButton.openUserMenu()
}
}
Item {
Layout.fillWidth: true
@@ -73,16 +95,4 @@ RowLayout {
id: timeHoverHandler
}
}
TapHandler {
acceptedButtons: Qt.LeftButton
acceptedDevices: PointerDevice.TouchScreen
onLongPressed: RoomManager.viewEventMenu(root.eventId, root.Message.room, root.author, root.Message.selectedText, root.Message.hoveredLink);
}
TapHandler {
acceptedButtons: Qt.RightButton
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
gesturePolicy: TapHandler.WithinBounds
onTapped: RoomManager.viewEventMenu(root.eventId, root.Message.room, root.author, root.Message.selectedText, root.Message.hoveredLink);
}
}

View File

@@ -142,14 +142,6 @@ KirigamiComponents.ConvergentContextMenu {
}
}
component ShowUserAction: Kirigami.Action {
text: i18nc("@action:inmenu", "Show User")
icon.name: "username-copy"
onTriggered: {
RoomManager.resolveResource(author.id)
}
}
component PinMessageAction: Kirigami.Action {
readonly property bool pinned: currentRoom.isEventPinned(root.eventId)

View File

@@ -94,8 +94,6 @@ DelegateContextMenu {
DelegateContextMenu.ReportMessageAction {}
DelegateContextMenu.ShowUserAction {}
Kirigami.Action {
separator: true
visible: viewSourceAction.visible

View File

@@ -149,6 +149,7 @@ MessageDelegateBase {
TapHandler {
acceptedButtons: Qt.RightButton
gesturePolicy: TapHandler.ReleaseWithinBounds
onTapped: _private.showMessageMenu()
}
@@ -159,7 +160,7 @@ MessageDelegateBase {
}
}
avatarComponent: KirigamiComponents.AvatarButton {
avatarComponent: KirigamiComponents.Avatar {
id: avatar
implicitWidth: Kirigami.Units.gridUnit + Kirigami.Units.largeSpacing * 2
implicitHeight: width
@@ -170,7 +171,34 @@ MessageDelegateBase {
asynchronous: true
QQC2.ToolTip.text: root.author.htmlSafeDisambiguatedName
onClicked: RoomManager.resolveResource(root.author.uri)
function openUserMenu(): void {
const menu = Qt.createComponent("org.kde.neochat", "UserMenu").createObject(root, {
connection: root.connection,
window: QQC2.ApplicationWindow.window as Kirigami.ApplicationWindow,
author: root.author,
});
menu.popup(root);
}
HoverHandler {
cursorShape: Qt.PointingHandCursor
}
// tapping to open profile
TapHandler {
onTapped: RoomManager.resolveResource(root.author.uri)
}
// right-clicking/long-press for context menu
TapHandler {
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
acceptedButtons: Qt.RightButton
onTapped: avatar.openUserMenu()
}
TapHandler {
acceptedDevices: PointerDevice.TouchScreen
onTapped: avatar.openUserMenu()
}
}
sectionComponent: SectionDelegate {

View File

@@ -102,7 +102,6 @@ DelegateContextMenu {
}
DelegateContextMenu.PinMessageAction {}
DelegateContextMenu.ReportMessageAction {}
DelegateContextMenu.ShowUserAction {}
Kirigami.Action {
separator: true
visible: viewSourceAction.visible