Commit 2becaa4e authored by Niccolò Venerandi's avatar Niccolò Venerandi
Browse files

Revert "containments/panel: iterate all items between start index and end index when pressed"

This reverts commit b0c4dde0.


(cherry picked from commit d57a38e2)
parent 1e547fe7
Pipeline #247264 canceled with stage
in 33 seconds
......@@ -50,7 +50,18 @@ MouseArea {
currentApplet.x = mouse.x - configurationArea.startDragOffset;
}
processMouseMoveEvent(mouse);
var item = currentLayout.childAt(mouse.x, mouse.y);
if (item && item.applet !== placeHolder) {
var posInItem = mapToItem(item, mouse.x, mouse.y);
if ((!root.isHorizontal && posInItem.y < item.height/3) ||
(root.isHorizontal && posInItem.x < item.width/3)) {
root.layoutManager.move(item, placeHolder.parent.index+1)
} else if ((!root.isHorizontal && posInItem.y > 2*item.height/3) ||
(root.isHorizontal && posInItem.x > 2*item.width/3)) {
root.layoutManager.move(item, placeHolder.parent.index)
}
}
} else {
var item = currentLayout.childAt(mouse.x, mouse.y);
......@@ -109,69 +120,6 @@ MouseArea {
onCanceled: finishDragOperation()
function processMouseMoveEvent(mouse) {
const item = currentLayout.childAt(mouse.x, mouse.y);
if (!item || item.applet === placeHolder) {
return;
}
const startIndex = placeHolder.parent.index;
const endIndex = item.index;
if (startIndex === endIndex) {
return;
}
const posInItem = mapToItem(item, mouse.x, mouse.y);
// MouseArea doesn't send events for every single pixel along the path
if ((!root.isHorizontal && posInItem.y < item.height/3) ||
(root.isHorizontal && posInItem.x < item.width/3)) {
// Example: startIndex = 0, endIndex = 2
// Before: [placeHolder] [startIndex+1 (←)] [endIndex (not changed)]
// After: [startIndex+1] [placeHolder] [endIndex (not changed)]
if (startIndex + 1 < endIndex) { // move right, and at least over 1 applet
for (let i = startIndex + 1; i < endIndex; ++i) {
root.layoutManager.moveIndex(i, i - 1);
}
// Example: startIndex = 2, endIndex = 0
// Before: [endIndex (→)] [startIndex - 1 (→)] [placeHolder]
// After: [placeHolder] [endIndex] [startIndex - 1]
} else if (startIndex > endIndex) { // move left
for (let i = startIndex - 1; i >= endIndex; --i) {
root.layoutManager.moveIndex(i, i + 1);
}
}
} else if ((!root.isHorizontal && posInItem.y > 2*item.height/3) ||
(root.isHorizontal && posInItem.x > 2*item.width/3)) {
// Example: startIndex = 0, endIndex = 2
// Before: [placeHolder] [startIndex+1 (←)] [endIndex (←)]
// After: [startIndex+1] [endIndex] [placeHolder]
if (startIndex < endIndex) { // move right
for (let i = startIndex + 1; i <= endIndex; ++i) {
root.layoutManager.moveIndex(i, i - 1);
}
// Example: startIndex = 2, endIndex = 0
// Before: [endIndex (not changed)] [startIndex - 1 (→)] [placeHolder]
// After: [endIndex (not changed)] [placeHolder] [startIndex - 1]
} else if (startIndex - 1 > endIndex) { // move left, and at least over 1 applet
for (let i = startIndex - 1; i > endIndex; --i) {
root.layoutManager.moveIndex(i, i + 1);
}
}
} else { // In the middle
if (startIndex + 1 < endIndex) { // move right, and at least over 1 applet
for (let i = startIndex + 1; i < endIndex; ++i) {
root.layoutManager.moveIndex(i, i - 1);
}
} else if (startIndex - 1 > endIndex) { // move left, and at least over 1 applet
for (let i = startIndex - 1; i > endIndex; --i) {
root.layoutManager.moveIndex(i, i + 1);
}
}
}
}
function finishDragOperation() {
root.dragAndDropping = false
if (!currentApplet) {
......
......@@ -149,14 +149,3 @@ function move(applet, end) {
appletsModel.move(start, target, 1)
save()
}
function moveIndex(oldIndex, newIndex) {
if (oldIndex === newIndex || newIndex < 0 || newIndex >= appletsModel.count) {
return;
}
const applet = layout.children[oldIndex]
applet.oldX = applet.x
applet.oldY = applet.y
appletsModel.move(oldIndex, newIndex, 1)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment