moment/src/qml/Base/HSelectableLabelContainer.qml

78 lines
2.0 KiB
QML
Raw Normal View History

import QtQuick 2.12
import "../utils.js" as Utils
FocusScope {
signal deselectAll()
property bool reversed: false
readonly property bool dragging: pointHandler.active || dragHandler.active
property bool selecting: false
2019-09-01 17:40:48 +10:00
property real selectionStart: -1
property real 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,
]
readonly property string joinedSelection: {
let toCopy = []
for (let key of Object.keys(selectedTexts).sort()) {
2019-09-01 17:40:48 +10: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])
}
if (reversed) toCopy.reverse()
2019-09-01 17:40:48 +10:00
return toCopy.join("").trim()
}
readonly property alias dragPoint: dragHandler.centroid
readonly property alias dragPosition: dragHandler.centroid.position
function clearSelection() {
selecting = false
selectionStart = -1
selectionEnd = -1
selectionStartPosition = Qt.point(-1, -1)
selectionEndPosition = Qt.point(-1, -1)
deselectAll()
}
Item { id: dragCursor }
DragHandler {
id: dragHandler
target: dragCursor
onActiveChanged: {
if (active) {
target.Drag.active = true
} else {
target.Drag.drop()
target.Drag.active = false
selecting = false
}
}
}
PointHandler {
id: pointHandler
}
TapHandler {
acceptedButtons: Qt.LeftButton
onTapped: clearSelection()
}
}