2020-03-30 15:03:35 -04:00
|
|
|
// 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
|
2020-07-09 21:33:51 -04:00
|
|
|
property Component contextMenu: null
|
|
|
|
|
2020-07-12 00:25:57 -04:00
|
|
|
signal leftClicked()
|
|
|
|
signal rightClicked()
|
|
|
|
signal longPressed()
|
2020-07-09 21:33:51 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2020-03-30 15:03:35 -04:00
|
|
|
|
|
|
|
|
2020-07-12 00:25:57 -04:00
|
|
|
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 {} }
|
|
|
|
|
2020-03-30 15:03:35 -04:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
onTapped: leftClicked()
|
|
|
|
onLongPressed: tile.longPressed()
|
|
|
|
}
|
|
|
|
|
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
acceptedPointerTypes: PointerDevice.GenericPointer | PointerDevice.Pen
|
2020-07-09 21:33:51 -04:00
|
|
|
onTapped: doRightClick()
|
2020-03-30 15:03:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TapHandler {
|
|
|
|
acceptedPointerTypes: PointerDevice.Finger | PointerDevice.Pen
|
2020-07-09 21:33:51 -04:00
|
|
|
onLongPressed: doRightClick()
|
2020-03-30 15:03:35 -04:00
|
|
|
}
|
|
|
|
}
|