HTile: handle menu key press, open context menu
This commit is contained in:
parent
c35894e4c8
commit
10eeb662af
|
@ -11,6 +11,7 @@ HButton {
|
||||||
Keys.onEnterPressed: leftClicked()
|
Keys.onEnterPressed: leftClicked()
|
||||||
Keys.onReturnPressed: leftClicked()
|
Keys.onReturnPressed: leftClicked()
|
||||||
Keys.onSpacePressed: leftClicked()
|
Keys.onSpacePressed: leftClicked()
|
||||||
|
Keys.onMenuPressed: doRightClick(false)
|
||||||
|
|
||||||
|
|
||||||
signal leftClicked()
|
signal leftClicked()
|
||||||
|
@ -21,8 +22,20 @@ HButton {
|
||||||
property bool compact: window.settings.compactMode
|
property bool compact: window.settings.compactMode
|
||||||
property real contentOpacity: 1
|
property real contentOpacity: 1
|
||||||
|
|
||||||
property alias contextMenu: contextMenuLoader.sourceComponent
|
property Component contextMenu: null
|
||||||
readonly property alias contextMenuLoader: contextMenuLoader
|
|
||||||
|
|
||||||
|
function openMenu(atCursor=true) {
|
||||||
|
if (! contextMenu) return
|
||||||
|
const menu = contextMenu.createObject(tile)
|
||||||
|
menu.closed.connect(() => menu.destroy())
|
||||||
|
atCursor ? menu.popup() : menu.popup(tile.width / 2, tile.height / 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
function doRightClick(menuAtCursor=true) {
|
||||||
|
rightClicked()
|
||||||
|
openMenu(menuAtCursor)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Behavior on topPadding { HNumberAnimation {} }
|
Behavior on topPadding { HNumberAnimation {} }
|
||||||
|
@ -37,30 +50,11 @@ HButton {
|
||||||
TapHandler {
|
TapHandler {
|
||||||
acceptedButtons: Qt.RightButton
|
acceptedButtons: Qt.RightButton
|
||||||
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Pen
|
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Pen
|
||||||
onTapped: {
|
onTapped: doRightClick()
|
||||||
rightClicked()
|
|
||||||
if (contextMenu) contextMenuLoader.active = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TapHandler {
|
TapHandler {
|
||||||
acceptedPointerTypes: PointerDevice.Finger | PointerDevice.Pen
|
acceptedPointerTypes: PointerDevice.Finger | PointerDevice.Pen
|
||||||
onLongPressed: {
|
onLongPressed: doRightClick()
|
||||||
rightClicked()
|
|
||||||
if (contextMenu) contextMenuLoader.active = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Connections {
|
|
||||||
enabled: contextMenuLoader.status === Loader.Ready
|
|
||||||
target: contextMenuLoader.item
|
|
||||||
|
|
||||||
function onClosed() { contextMenuLoader.active = false }
|
|
||||||
}
|
|
||||||
|
|
||||||
HLoader {
|
|
||||||
id: contextMenuLoader
|
|
||||||
active: false
|
|
||||||
onLoaded: item.popup()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ HTile {
|
||||||
icon.name: "device-action-menu"
|
icon.name: "device-action-menu"
|
||||||
toolTip.text: qsTr("Rename, verify or sign out")
|
toolTip.text: qsTr("Rename, verify or sign out")
|
||||||
backgroundColor: "transparent"
|
backgroundColor: "transparent"
|
||||||
onClicked: contextMenuLoader.active = true
|
onClicked: deviceTile.openMenu()
|
||||||
|
|
||||||
Layout.fillHeight: true
|
Layout.fillHeight: true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user