From 8257a9d65e2eecae75bedcce00527525fd6551f9 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Sat, 9 Jul 2022 23:36:50 +0200 Subject: [PATCH] Refactor delegates and improve context menu opening This unifies the context menu opening and makes sure that clicking *anywhere* on the delegate opens the context menu, not just on the content --- .../Component/Timeline/AudioDelegate.qml | 12 +++--------- .../Component/Timeline/FileDelegate.qml | 11 ++--------- .../Component/Timeline/ImageDelegate.qml | 7 ++----- .../Component/Timeline/MessageDelegate.qml | 14 +++----------- .../Component/Timeline/TimelineContainer.qml | 18 +++++++++++++++--- .../Component/Timeline/VideoDelegate.qml | 12 ++---------- 6 files changed, 27 insertions(+), 47 deletions(-) diff --git a/imports/NeoChat/Component/Timeline/AudioDelegate.qml b/imports/NeoChat/Component/Timeline/AudioDelegate.qml index 158bc381f..517cd48b9 100644 --- a/imports/NeoChat/Component/Timeline/AudioDelegate.qml +++ b/imports/NeoChat/Component/Timeline/AudioDelegate.qml @@ -18,6 +18,9 @@ TimelineContainer { id: audioDelegate onReplyClicked: ListView.view.goToEvent(eventID) + + onOpenContextMenu: openFileContext(model, audioDelegate) + hoverComponent: hoverActions innerObject: Control { Layout.fillWidth: true @@ -29,15 +32,6 @@ TimelineContainer { autoLoad: false } - TapHandler { - acceptedButtons: Qt.RightButton - onTapped: openFileContext(model, parent) - } - TapHandler { - acceptedButtons: Qt.LeftButton - onLongPressed: openFileContext(model, parent) - } - contentItem: ColumnLayout { RowLayout { ToolButton { diff --git a/imports/NeoChat/Component/Timeline/FileDelegate.qml b/imports/NeoChat/Component/Timeline/FileDelegate.qml index ae36003ae..03e29ae60 100644 --- a/imports/NeoChat/Component/Timeline/FileDelegate.qml +++ b/imports/NeoChat/Component/Timeline/FileDelegate.qml @@ -19,6 +19,8 @@ TimelineContainer { onReplyClicked: ListView.view.goToEvent(eventID) hoverComponent: hoverActions + onOpenContextMenu: openFileContext(model, fileDelegate) + readonly property bool downloaded: progressInfo && progressInfo.completed function saveFileAs() { @@ -129,14 +131,5 @@ TimelineContainer { } } } - - TapHandler { - acceptedButtons: Qt.RightButton - onTapped: openFileContext(model, parent) - } - TapHandler { - acceptedButtons: Qt.LeftButton - onLongPressed: openFileContext(model, parent) - } } } diff --git a/imports/NeoChat/Component/Timeline/ImageDelegate.qml b/imports/NeoChat/Component/Timeline/ImageDelegate.qml index fb5f6f6e5..e0d76bde0 100644 --- a/imports/NeoChat/Component/Timeline/ImageDelegate.qml +++ b/imports/NeoChat/Component/Timeline/ImageDelegate.qml @@ -18,6 +18,8 @@ TimelineContainer { onReplyClicked: ListView.view.goToEvent(eventID) hoverComponent: hoverActions + onOpenContextMenu: openFileContext(model, imageDelegate) + property var content: model.content readonly property bool isAnimated: contentType === "image/gif" @@ -83,11 +85,6 @@ TimelineContainer { } } - TapHandler { - acceptedButtons: Qt.RightButton - onTapped: openFileContext(model, parent) - } - TapHandler { acceptedButtons: Qt.LeftButton onLongPressed: openFileContext(model, parent) diff --git a/imports/NeoChat/Component/Timeline/MessageDelegate.qml b/imports/NeoChat/Component/Timeline/MessageDelegate.qml index 9d6882488..fcdba1c4c 100644 --- a/imports/NeoChat/Component/Timeline/MessageDelegate.qml +++ b/imports/NeoChat/Component/Timeline/MessageDelegate.qml @@ -14,22 +14,14 @@ TimelineContainer { id: messageDelegate property bool isEmote: false + onOpenContextMenu: openMessageContext(model, parent.selectedText, Controller.plainText(label.textDocument)) onReplyClicked: ListView.view.goToEvent(eventID) hoverComponent: hoverActions innerObject: RichLabel { + id: label isEmote: messageDelegate.isEmote - Layout.maximumWidth: messageDelegate.contentMaxWidth - - TapHandler { - acceptedButtons: Qt.RightButton - onTapped: openMessageContext(model, parent.selectedText, Controller.plainText(parent.textDocument)) - } - - TapHandler { - acceptedButtons: Qt.LeftButton - onLongPressed: openMessageContext(model, parent.selectedText, Controller.plainText(parent.textDocument)) - } + Layout.maximumWidth: messageDelegate.bubbleMaxWidth } } diff --git a/imports/NeoChat/Component/Timeline/TimelineContainer.qml b/imports/NeoChat/Component/Timeline/TimelineContainer.qml index a17f52c9a..29a09ad73 100644 --- a/imports/NeoChat/Component/Timeline/TimelineContainer.qml +++ b/imports/NeoChat/Component/Timeline/TimelineContainer.qml @@ -12,13 +12,15 @@ import NeoChat.Component 1.0 import NeoChat.Dialog 1.0 QQC2.ItemDelegate { - id: messageDelegate + id: timelineContainer default property alias innerObject : column.children // readonly property bool failed: marks == EventStatus.SendingFailed property bool isEmote: false property bool cardBackground: true + signal openContextMenu + // The bubble and delegate widths are allowed to grow once the ListView gets beyond a certain size // extraWidth defines this as the excess after a certain ListView width, capped to a max value readonly property int extraWidth: messageListView.width >= Kirigami.Units.gridUnit * 46 ? Math.min((messageListView.width - Kirigami.Units.gridUnit * 46), Kirigami.Units.gridUnit * 20) : 0 @@ -148,7 +150,7 @@ QQC2.ItemDelegate { rightMargin: showUserMessageOnRight ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing } // HACK: anchoring didn't reset anchors.right when switching from parent.right to undefined reliably - width: Config.compactLayout ? messageDelegate.width - (Config.showAvatarInTimeline ? Kirigami.Units.gridUnit * 2 : 0) + Kirigami.Units.largeSpacing * 2 : implicitWidth + width: Config.compactLayout ? timelineContainer.width - (Config.showAvatarInTimeline ? Kirigami.Units.gridUnit * 2 : 0) + Kirigami.Units.largeSpacing * 2 : implicitWidth state: showUserMessageOnRight ? "userMessageOnRight" : "userMessageOnLeft" // states for anchor animations on window resize @@ -253,7 +255,7 @@ QQC2.ItemDelegate { background: Item { Rectangle { - visible: messageDelegate.hovered + visible: timelineContainer.hovered color: Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.15) radius: Kirigami.Units.smallSpacing anchors.fill: parent @@ -293,4 +295,14 @@ QQC2.ItemDelegate { visible: active sourceComponent: ReactionDelegate { } } + + TapHandler { + acceptedButtons: Qt.RightButton + onTapped: timelineContainer.openContextMenu() + } + + TapHandler { + acceptedButtons: Qt.LeftButton + onLongPressed: timelineContainer.openContextMenu() + } } diff --git a/imports/NeoChat/Component/Timeline/VideoDelegate.qml b/imports/NeoChat/Component/Timeline/VideoDelegate.qml index fd8d6d0c3..c540bd619 100644 --- a/imports/NeoChat/Component/Timeline/VideoDelegate.qml +++ b/imports/NeoChat/Component/Timeline/VideoDelegate.qml @@ -26,6 +26,8 @@ TimelineContainer { property bool supportStreaming: true readonly property int maxWidth: 1000 // TODO messageListView.width + onOpenContextMenu: openFileContext(model, vid) + onDownloadedChanged: { if (downloaded) { vid.source = progressInfo.localPath @@ -121,16 +123,6 @@ TimelineContainer { videoDelegate.downloadAndPlay() } } - - TapHandler { - acceptedButtons: Qt.RightButton - onTapped: openFileContext(model, parent) - } - - TapHandler { - acceptedButtons: Qt.LeftButton - onLongPressed: openFileContext(model, parent) - } } function downloadAndPlay() {