moment/src/gui/Base/HTile/HTile.qml

66 lines
1.6 KiB
QML
Raw Normal View History

// SPDX-License-Identifier: LGPL-3.0-or-later
import QtQuick 2.12
import ".."
HButton {
id: tile
property bool compact: window.settings.compactMode
property real contentOpacity: 1
property Component contextMenu: null
signal leftClicked()
2020-07-19 20:20:53 -04:00
signal middleClicked()
signal rightClicked()
signal longPressed()
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)
}
topPadding: padded ? spacing / (compact ? 4 : 2) : 0
bottomPadding: topPadding
Keys.onEnterPressed: leftClicked()
Keys.onReturnPressed: leftClicked()
Keys.onSpacePressed: leftClicked()
Keys.onMenuPressed: doRightClick(false)
2020-05-01 00:55:34 -04:00
Behavior on topPadding { HNumberAnimation {} }
Behavior on bottomPadding { HNumberAnimation {} }
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: leftClicked()
onLongPressed: tile.longPressed()
}
2020-07-19 20:20:53 -04:00
TapHandler {
acceptedButtons: Qt.MiddleButton
onTapped: middleClicked()
onLongPressed: tile.middleClicked()
}
TapHandler {
acceptedButtons: Qt.RightButton
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Pen
onTapped: doRightClick()
}
TapHandler {
acceptedPointerTypes: PointerDevice.Finger | PointerDevice.Pen
onLongPressed: doRightClick()
}
}