2019-08-31 01:17:13 +10:00
|
|
|
import QtQuick 2.12
|
2019-09-01 13:58:51 +10:00
|
|
|
import "../utils.js" as Utils
|
2019-08-31 01:17:13 +10:00
|
|
|
|
2019-09-01 14:27:42 +10:00
|
|
|
FocusScope {
|
|
|
|
onFocusChanged: if (! focus) clearSelection()
|
|
|
|
|
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
signal deselectAll()
|
|
|
|
|
|
|
|
|
|
|
|
property bool reversed: false
|
|
|
|
|
|
|
|
readonly property bool dragging: pointHandler.active || dragHandler.active
|
|
|
|
// onDraggingChanged: print(dragging)
|
|
|
|
property bool selecting: false
|
|
|
|
property int selectionStart: -1
|
|
|
|
property int selectionEnd: -1
|
|
|
|
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-09-01 13:58:51 +10:00
|
|
|
readonly property string joinedSelection: {
|
|
|
|
let toCopy = []
|
|
|
|
|
|
|
|
for (let key of Object.keys(selectedTexts).sort()) {
|
|
|
|
if (selectedTexts[key]) toCopy.push(selectedTexts[key])
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reversed) toCopy.reverse()
|
|
|
|
|
|
|
|
return toCopy.join("\n\n")
|
|
|
|
}
|
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
readonly property alias dragPoint: dragHandler.centroid
|
|
|
|
readonly property alias dragPosition: dragHandler.centroid.position
|
2019-09-01 13:58:51 +10:00
|
|
|
readonly property alias contextMenu: contextMenu
|
2019-08-31 01:17:13 +10:00
|
|
|
|
|
|
|
|
|
|
|
function clearSelection() {
|
|
|
|
selecting = false
|
|
|
|
selectionStart = -1
|
|
|
|
selectionEnd = -1
|
|
|
|
selectionStartPosition = Qt.point(-1, -1)
|
|
|
|
selectionEndPosition = Qt.point(-1, -1)
|
|
|
|
deselectAll()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item { id: dragPoint }
|
|
|
|
|
|
|
|
DragHandler {
|
|
|
|
id: dragHandler
|
|
|
|
target: dragPoint
|
|
|
|
onActiveChanged: {
|
|
|
|
if (active) {
|
|
|
|
target.Drag.active = true
|
|
|
|
} else {
|
|
|
|
target.Drag.drop()
|
|
|
|
target.Drag.active = false
|
|
|
|
selecting = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 13:58:51 +10:00
|
|
|
PointHandler {
|
|
|
|
id: pointHandler
|
|
|
|
}
|
|
|
|
|
2019-08-31 01:17:13 +10:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.LeftButton
|
|
|
|
onTapped: clearSelection()
|
2019-09-01 13:58:51 +10:00
|
|
|
onLongPressed: contextMenu.popup()
|
2019-08-31 01:17:13 +10:00
|
|
|
}
|
|
|
|
|
2019-09-01 13:58:51 +10:00
|
|
|
TapHandler {
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
onTapped: contextMenu.popup()
|
|
|
|
onLongPressed: contextMenu.popup()
|
|
|
|
}
|
|
|
|
|
|
|
|
HMenu {
|
|
|
|
id: contextMenu
|
|
|
|
|
|
|
|
HMenuItem {
|
|
|
|
icon.name: "copy"
|
|
|
|
text: qsTr("Copy")
|
|
|
|
enabled: Boolean(joinedSelection)
|
|
|
|
onTriggered: Utils.copyToClipboard(joinedSelection)
|
|
|
|
}
|
2019-08-31 01:17:13 +10:00
|
|
|
}
|
|
|
|
}
|