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
This commit is contained in:
Tobias Fella
2022-07-09 23:36:50 +02:00
parent a75048761b
commit 8257a9d65e
6 changed files with 27 additions and 47 deletions

View File

@@ -18,6 +18,9 @@ TimelineContainer {
id: audioDelegate id: audioDelegate
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
onOpenContextMenu: openFileContext(model, audioDelegate)
hoverComponent: hoverActions hoverComponent: hoverActions
innerObject: Control { innerObject: Control {
Layout.fillWidth: true Layout.fillWidth: true
@@ -29,15 +32,6 @@ TimelineContainer {
autoLoad: false autoLoad: false
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: openFileContext(model, parent)
}
TapHandler {
acceptedButtons: Qt.LeftButton
onLongPressed: openFileContext(model, parent)
}
contentItem: ColumnLayout { contentItem: ColumnLayout {
RowLayout { RowLayout {
ToolButton { ToolButton {

View File

@@ -19,6 +19,8 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
onOpenContextMenu: openFileContext(model, fileDelegate)
readonly property bool downloaded: progressInfo && progressInfo.completed readonly property bool downloaded: progressInfo && progressInfo.completed
function saveFileAs() { function saveFileAs() {
@@ -129,14 +131,5 @@ TimelineContainer {
} }
} }
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: openFileContext(model, parent)
}
TapHandler {
acceptedButtons: Qt.LeftButton
onLongPressed: openFileContext(model, parent)
}
} }
} }

View File

@@ -18,6 +18,8 @@ TimelineContainer {
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
onOpenContextMenu: openFileContext(model, imageDelegate)
property var content: model.content property var content: model.content
readonly property bool isAnimated: contentType === "image/gif" readonly property bool isAnimated: contentType === "image/gif"
@@ -83,11 +85,6 @@ TimelineContainer {
} }
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: openFileContext(model, parent)
}
TapHandler { TapHandler {
acceptedButtons: Qt.LeftButton acceptedButtons: Qt.LeftButton
onLongPressed: openFileContext(model, parent) onLongPressed: openFileContext(model, parent)

View File

@@ -14,22 +14,14 @@ TimelineContainer {
id: messageDelegate id: messageDelegate
property bool isEmote: false property bool isEmote: false
onOpenContextMenu: openMessageContext(model, parent.selectedText, Controller.plainText(label.textDocument))
onReplyClicked: ListView.view.goToEvent(eventID) onReplyClicked: ListView.view.goToEvent(eventID)
hoverComponent: hoverActions hoverComponent: hoverActions
innerObject: RichLabel { innerObject: RichLabel {
id: label
isEmote: messageDelegate.isEmote isEmote: messageDelegate.isEmote
Layout.maximumWidth: messageDelegate.contentMaxWidth Layout.maximumWidth: messageDelegate.bubbleMaxWidth
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))
}
} }
} }

View File

@@ -12,13 +12,15 @@ import NeoChat.Component 1.0
import NeoChat.Dialog 1.0 import NeoChat.Dialog 1.0
QQC2.ItemDelegate { QQC2.ItemDelegate {
id: messageDelegate id: timelineContainer
default property alias innerObject : column.children default property alias innerObject : column.children
// readonly property bool failed: marks == EventStatus.SendingFailed // readonly property bool failed: marks == EventStatus.SendingFailed
property bool isEmote: false property bool isEmote: false
property bool cardBackground: true property bool cardBackground: true
signal openContextMenu
// The bubble and delegate widths are allowed to grow once the ListView gets beyond a certain size // 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 // 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 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 rightMargin: showUserMessageOnRight ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing
} }
// HACK: anchoring didn't reset anchors.right when switching from parent.right to undefined reliably // 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" state: showUserMessageOnRight ? "userMessageOnRight" : "userMessageOnLeft"
// states for anchor animations on window resize // states for anchor animations on window resize
@@ -253,7 +255,7 @@ QQC2.ItemDelegate {
background: Item { background: Item {
Rectangle { Rectangle {
visible: messageDelegate.hovered visible: timelineContainer.hovered
color: Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.15) color: Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.15)
radius: Kirigami.Units.smallSpacing radius: Kirigami.Units.smallSpacing
anchors.fill: parent anchors.fill: parent
@@ -293,4 +295,14 @@ QQC2.ItemDelegate {
visible: active visible: active
sourceComponent: ReactionDelegate { } sourceComponent: ReactionDelegate { }
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: timelineContainer.openContextMenu()
}
TapHandler {
acceptedButtons: Qt.LeftButton
onLongPressed: timelineContainer.openContextMenu()
}
} }

View File

@@ -26,6 +26,8 @@ TimelineContainer {
property bool supportStreaming: true property bool supportStreaming: true
readonly property int maxWidth: 1000 // TODO messageListView.width readonly property int maxWidth: 1000 // TODO messageListView.width
onOpenContextMenu: openFileContext(model, vid)
onDownloadedChanged: { onDownloadedChanged: {
if (downloaded) { if (downloaded) {
vid.source = progressInfo.localPath vid.source = progressInfo.localPath
@@ -121,16 +123,6 @@ TimelineContainer {
videoDelegate.downloadAndPlay() videoDelegate.downloadAndPlay()
} }
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: openFileContext(model, parent)
}
TapHandler {
acceptedButtons: Qt.LeftButton
onLongPressed: openFileContext(model, parent)
}
} }
function downloadAndPlay() { function downloadAndPlay() {