Fix HTile left/right click handling

This commit is contained in:
miruka 2019-09-14 18:52:43 -04:00
parent c6395ff940
commit 76ffdfd28a
4 changed files with 21 additions and 14 deletions

View File

@ -4,6 +4,9 @@ import QtQuick.Layouts 1.12
HButton { HButton {
id: tile id: tile
signal leftClicked()
signal rightClicked()
default property var additionalItems: [] default property var additionalItems: []
readonly property alias title: title readonly property alias title: title
@ -69,10 +72,16 @@ HButton {
children: [image, details].concat(additionalItems) children: [image, details].concat(additionalItems)
} }
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: leftClicked()
}
TapHandler { TapHandler {
enabled: contextMenu.count > 0
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onTapped: contextMenu.popup() onTapped: {
rightClicked()
if (contextMenu.count > 0) contextMenu.popup()
}
} }
} }

View File

@ -4,7 +4,7 @@ import QtQuick.Layouts 1.12
HTile { HTile {
id: tile id: tile
onActivated: view.currentIndex = model.index onActivated: view.currentIndex = model.index
onClicked: { onLeftClicked: {
view.highlightRangeMode = ListView.NoHighlightRange view.highlightRangeMode = ListView.NoHighlightRange
view.highlightMoveDuration = 0 view.highlightMoveDuration = 0
activated() activated()
@ -31,9 +31,4 @@ HTile {
// Component.onCompleted won't work for this // Component.onCompleted won't work for this
onTriggered: if (shouldBeCurrent) view.currentIndex = model.index onTriggered: if (shouldBeCurrent) view.currentIndex = model.index
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: if (contextMenu.count > 0) contextMenu.popup()
}
} }

View File

@ -76,6 +76,12 @@ Column {
null, 4) null, 4)
} }
function openContextMenu() {
contextMenu.media = eventDelegate.hoveredMediaTypeUrl
contextMenu.link = eventContent.hoveredLink
contextMenu.popup()
}
Daybreak { Daybreak {
visible: dayBreak visible: dayBreak
@ -98,11 +104,7 @@ Column {
TapHandler { TapHandler {
acceptedButtons: Qt.RightButton acceptedButtons: Qt.RightButton
onTapped: { onTapped: openContextMenu()
contextMenu.media = eventDelegate.hoveredMediaTypeUrl
contextMenu.link = eventContent.hoveredLink
contextMenu.popup()
}
} }
HMenu { HMenu {

View File

@ -8,7 +8,8 @@ HTile {
theme.chat.message.thumbnailWidth, theme.chat.message.thumbnailWidth,
) )
onClicked: Qt.openUrlExternally(fileUrl) onLeftClicked: Qt.openUrlExternally(fileUrl)
onRightClicked: eventDelegate.openContextMenu()
onHoveredChanged: onHoveredChanged:
eventDelegate.hoveredMediaTypeUrl = eventDelegate.hoveredMediaTypeUrl =