| 
									
										
										
										
											2020-09-23 19:57:54 -04:00
										 |  |  | // Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
 | 
					
						
							| 
									
										
										
										
											2020-03-30 15:03:35 -04:00
										 |  |  | // SPDX-License-Identifier: LGPL-3.0-or-later
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import QtQuick 2.12 | 
					
						
							|  |  |  | import ".." | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HButton { | 
					
						
							|  |  |  |     id: tile | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-07 20:12:32 -04:00
										 |  |  |     property bool compact: window.settings.General.compact | 
					
						
							| 
									
										
										
										
											2020-03-30 15:03:35 -04:00
										 |  |  |     property real contentOpacity: 1 | 
					
						
							| 
									
										
										
										
											2020-07-09 21:33:51 -04:00
										 |  |  |     property Component contextMenu: null | 
					
						
							| 
									
										
										
										
											2020-09-30 13:51:21 -04:00
										 |  |  |     property HMenu openedMenu: null | 
					
						
							| 
									
										
										
										
											2020-07-09 21:33:51 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-12 00:25:57 -04:00
										 |  |  |     signal leftClicked() | 
					
						
							| 
									
										
										
										
											2020-07-19 20:20:53 -04:00
										 |  |  |     signal middleClicked() | 
					
						
							| 
									
										
										
										
											2020-07-12 00:25:57 -04:00
										 |  |  |     signal rightClicked() | 
					
						
							|  |  |  |     signal longPressed() | 
					
						
							| 
									
										
										
										
											2020-07-09 21:33:51 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     function openMenu(atCursor=true) { | 
					
						
							|  |  |  |         if (! contextMenu) return | 
					
						
							| 
									
										
										
										
											2020-09-30 13:51:21 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (openedMenu) { | 
					
						
							|  |  |  |             openedMenu.close() | 
					
						
							|  |  |  |             return | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         openedMenu = contextMenu.createObject(tile) | 
					
						
							|  |  |  |         openedMenu.closed.connect(() => openedMenu.destroy()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         atCursor ? | 
					
						
							|  |  |  |         openedMenu.popup() : | 
					
						
							|  |  |  |         openedMenu.popup(tile.width / 2, tile.height / 2) | 
					
						
							| 
									
										
										
										
											2020-07-09 21:33:51 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     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() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-19 20:20:53 -04:00
										 |  |  |     TapHandler { | 
					
						
							|  |  |  |         acceptedButtons: Qt.MiddleButton | 
					
						
							|  |  |  |         onTapped: middleClicked() | 
					
						
							|  |  |  |         onLongPressed: tile.middleClicked() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-30 15:03:35 -04:00
										 |  |  |     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
										 |  |  |     } | 
					
						
							|  |  |  | } |