Fix text selection start drag delay
This commit is contained in:
parent
b17a958906
commit
d998b471f0
|
@ -131,6 +131,12 @@ TextEdit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PointHandler {
|
||||||
|
onActiveChanged:
|
||||||
|
active ? container.dragStarted() : container.dragStopped()
|
||||||
|
onPointChanged: container.dragPointChanged(point)
|
||||||
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: label
|
anchors.fill: label
|
||||||
acceptedButtons: Qt.NoButton
|
acceptedButtons: Qt.NoButton
|
||||||
|
|
|
@ -3,11 +3,13 @@ import "../utils.js" as Utils
|
||||||
|
|
||||||
FocusScope {
|
FocusScope {
|
||||||
signal deselectAll()
|
signal deselectAll()
|
||||||
|
signal dragStarted()
|
||||||
|
signal dragStopped()
|
||||||
|
signal dragPointChanged(var eventPoint)
|
||||||
|
|
||||||
|
|
||||||
property bool reversed: false
|
property bool reversed: false
|
||||||
|
|
||||||
readonly property bool dragging: pointHandler.active || dragHandler.active
|
|
||||||
property bool selecting: false
|
property bool selecting: false
|
||||||
property real selectionStart: -1
|
property real selectionStart: -1
|
||||||
property real selectionEnd: -1
|
property real selectionEnd: -1
|
||||||
|
@ -36,8 +38,22 @@ FocusScope {
|
||||||
return toCopy.join("").trim()
|
return toCopy.join("").trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly property alias dragPoint: dragHandler.centroid
|
|
||||||
readonly property alias dragPosition: dragHandler.centroid.position
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function clearSelection() {
|
function clearSelection() {
|
||||||
|
@ -50,28 +66,21 @@ FocusScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Item { id: dragCursor }
|
// PointHandler and TapHandler won't activate if the press occurs inside
|
||||||
|
// a label child, so we need a Point/TapHandler inside them too.
|
||||||
DragHandler {
|
|
||||||
id: dragHandler
|
|
||||||
target: dragCursor
|
|
||||||
onActiveChanged: {
|
|
||||||
if (active) {
|
|
||||||
target.Drag.active = true
|
|
||||||
} else {
|
|
||||||
target.Drag.drop()
|
|
||||||
target.Drag.active = false
|
|
||||||
selecting = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PointHandler {
|
PointHandler {
|
||||||
|
// We don't use a DragHandler because they have an unchangable minimum
|
||||||
|
// drag distance before they activate.
|
||||||
id: pointHandler
|
id: pointHandler
|
||||||
|
onActiveChanged: active ? dragStarted() : dragStopped()
|
||||||
|
onPointChanged: dragPointChanged(point)
|
||||||
}
|
}
|
||||||
|
|
||||||
TapHandler {
|
TapHandler {
|
||||||
acceptedButtons: Qt.LeftButton
|
acceptedButtons: Qt.LeftButton
|
||||||
onTapped: clearSelection()
|
onTapped: clearSelection()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item { id: draggedItem }
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,22 +13,22 @@ Rectangle {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
reversed: eventList.verticalLayoutDirection == ListView.BottomToTop
|
reversed: eventList.verticalLayoutDirection == ListView.BottomToTop
|
||||||
|
|
||||||
onDragPositionChanged: {
|
DragHandler {
|
||||||
let left = dragPoint.pressedButtons & Qt.LeftButton
|
target: null
|
||||||
let vel = dragPoint.velocity.y
|
onActiveChanged: if (! active) dragFlicker.speed = 0
|
||||||
|
onCentroidChanged: {
|
||||||
let boost = 20 * (
|
let left = centroid.pressedButtons & Qt.LeftButton
|
||||||
dragPosition.y < 50 ?
|
let vel = centroid.velocity.y
|
||||||
-dragPosition.y : -(height - dragPosition.y)
|
let pos = centroid.position.y
|
||||||
)
|
let dist = Math.min(selectableLabelContainer.height / 4, 50)
|
||||||
|
let boost = 20 * (pos < dist ? -pos : -(height - pos))
|
||||||
|
|
||||||
dragFlicker.speed =
|
dragFlicker.speed =
|
||||||
dragPosition.x == 0 && dragPosition.y == 0 ? 0 :
|
left && vel && pos < dist ? 1000 + boost :
|
||||||
left && vel && dragPosition.y < 50 ? 1000 + boost:
|
left && vel && pos > height - dist ? -1000 + -boost :
|
||||||
left && vel && dragPosition.y > height - 50 ? -1000 + -boost :
|
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: dragFlicker
|
id: dragFlicker
|
||||||
|
|
Loading…
Reference in New Issue
Block a user