| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  | import QtQuick 2.12 | 
					
						
							| 
									
										
										
										
											2019-08-31 23:58:51 -04:00
										 |  |  | import "../utils.js" as Utils | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-01 00:27:42 -04:00
										 |  |  | FocusScope { | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  |     signal deselectAll() | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  |     signal dragStarted() | 
					
						
							|  |  |  |     signal dragStopped() | 
					
						
							|  |  |  |     signal dragPointChanged(var eventPoint) | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     property bool reversed: false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     property bool selecting: false | 
					
						
							| 
									
										
										
										
											2019-09-01 03:40:48 -04:00
										 |  |  |     property real selectionStart: -1 | 
					
						
							|  |  |  |     property real selectionEnd: -1 | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  |     property point selectionStartPosition: Qt.point(-1, -1) | 
					
						
							|  |  |  |     property point selectionEndPosition: Qt.point(-1, -1) | 
					
						
							|  |  |  |     property var selectedTexts: ({}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     readonly property var selectionInfo: [ | 
					
						
							|  |  |  |         selectionStart, selectionStartPosition, | 
					
						
							|  |  |  |         selectionEnd, selectionEndPosition, | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 23:58:51 -04:00
										 |  |  |     readonly property string joinedSelection: { | 
					
						
							|  |  |  |         let toCopy = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (let key of Object.keys(selectedTexts).sort()) { | 
					
						
							| 
									
										
										
										
											2019-09-01 03:40:48 -04:00
										 |  |  |             if (! selectedTexts[key]) continue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             // For some dumb reason, Object.keys convert the floats to strings
 | 
					
						
							|  |  |  |             toCopy.push(Number.isInteger(parseFloat(key)) ? "\n\n" : "\n") | 
					
						
							|  |  |  |             toCopy.push(selectedTexts[key]) | 
					
						
							| 
									
										
										
										
											2019-08-31 23:58:51 -04:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (reversed) toCopy.reverse() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-01 03:40:48 -04:00
										 |  |  |         return toCopy.join("").trim() | 
					
						
							| 
									
										
										
										
											2019-08-31 23:58:51 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-25 09:02:21 -04:00
										 |  |  |     onJoinedSelectionChanged: | 
					
						
							|  |  |  |         if (joinedSelection) Clipboard.selection = joinedSelection | 
					
						
							| 
									
										
										
										
											2019-10-25 08:49:19 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  |     onDragStarted: { | 
					
						
							|  |  |  |         draggedItem.Drag.active = true | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     onDragStopped: { | 
					
						
							|  |  |  |         draggedItem.Drag.drop() | 
					
						
							|  |  |  |         draggedItem.Drag.active = false | 
					
						
							|  |  |  |         selecting               = false | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     onDragPointChanged: { | 
					
						
							|  |  |  |         let pos = mapFromItem( | 
					
						
							|  |  |  |             mainUI, eventPoint.scenePosition.x, eventPoint.scenePosition.y, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         draggedItem.x = pos.x | 
					
						
							|  |  |  |         draggedItem.y = pos.y | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     function clearSelection() { | 
					
						
							|  |  |  |         selecting              = false | 
					
						
							|  |  |  |         selectionStart         = -1 | 
					
						
							|  |  |  |         selectionEnd           = -1 | 
					
						
							|  |  |  |         selectionStartPosition = Qt.point(-1, -1) | 
					
						
							|  |  |  |         selectionEndPosition   = Qt.point(-1, -1) | 
					
						
							|  |  |  |         deselectAll() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  |     // PointHandler and TapHandler won't activate if the press occurs inside
 | 
					
						
							|  |  |  |     // a label child, so we need a Point/TapHandler inside them too.
 | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-31 23:58:51 -04:00
										 |  |  |     PointHandler { | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  |         // We don't use a DragHandler because they have an unchangable minimum
 | 
					
						
							|  |  |  |         // drag distance before they activate.
 | 
					
						
							| 
									
										
										
										
											2019-08-31 23:58:51 -04:00
										 |  |  |         id: pointHandler | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  |         onActiveChanged: active ? dragStarted() : dragStopped() | 
					
						
							|  |  |  |         onPointChanged: dragPointChanged(point) | 
					
						
							| 
									
										
										
										
											2019-08-31 23:58:51 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  |     TapHandler { | 
					
						
							|  |  |  |         acceptedButtons: Qt.LeftButton | 
					
						
							|  |  |  |         onTapped: clearSelection() | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 15:42:48 -04:00
										 |  |  |     // This item will trigger the children labels's DropAreas
 | 
					
						
							| 
									
										
										
										
											2019-09-11 15:25:57 -04:00
										 |  |  |     Item { id: draggedItem } | 
					
						
							| 
									
										
										
										
											2019-08-30 11:17:13 -04:00
										 |  |  | } |