1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-08-15 21:49:28 +03:00

fix #226,add applets correctly in Fill mode

This commit is contained in:
Michail Vourlakos
2017-03-05 18:53:43 +02:00
parent b14c50ad07
commit fd97a93e6d
2 changed files with 123 additions and 23 deletions

View File

@ -25,7 +25,7 @@ var root;
var plasmoid;
var lastSpacer;
var childFoundId = 11;
var inRestore=false;
function restore() {
@ -178,16 +178,21 @@ function removeApplet (applet) {
//insert item2 before item1
function insertBefore(item1, item2) {
return insertBeforeForLayout(layout, item1, item2);
}
//insert item2 before item1
function insertBeforeForLayout(tLayout, item1, item2) {
if (item1 === item2) {
return;
return -1;
}
var removed = new Array();
var child;
var i;
for (i = layout.children.length - 1; i >= 0; --i) {
child = layout.children[i];
for (i = tLayout.children.length - 1; i >= 0; --i) {
child = tLayout.children[i];
removed.push(child);
child.parent = root;
@ -196,27 +201,33 @@ function insertBefore(item1, item2) {
}
}
item2.parent = layout;
item2.parent = tLayout;
for (var j = removed.length - 1; j >= 0; --j) {
removed[j].parent = layout;
removed[j].parent = tLayout;
}
return i;
}
//insert item2 after item1
function insertAfter(item1, item2) {
return insertAfterForLayout(layout, item1, item2);
}
//insert item2 after item1
function insertAfterForLayout(tLayout, item1, item2) {
if (item1 === item2) {
return;
return -1;
}
var removed = new Array();
var child;
var i;
for (i = layout.children.length - 1; i >= 0; --i) {
child = layout.children[i];
for (i = tLayout.children.length - 1; i >= 0; --i) {
child = tLayout.children[i];
//never ever insert after lastSpacer
if (child === lastSpacer && item1 === lastSpacer) {
removed.push(child);
@ -224,8 +235,8 @@ function insertAfter(item1, item2) {
break;
} else if (child === item1) {
//Already in position, do nothing
if (layout.children[i+1] === item2) {
return;
if (tLayout.children[i+1] === item2) {
return -1;
}
break;
}
@ -234,15 +245,16 @@ function insertAfter(item1, item2) {
child.parent = root;
}
item2.parent = layout;
item2.parent = tLayout;
for (var j = removed.length - 1; j >= 0; --j) {
removed[j].parent = layout;
removed[j].parent = tLayout;
}
return i;
}
function insertAtIndex(item, position) {
var addToEnd = false;
if (position < 0 || (position > layout.children.length)) {
@ -339,3 +351,86 @@ function insertAtCoordinates(item, x, y) {
return insertAfter(child, item);
}
}
//this is used only for the start and end layouts
function insertAtLayoutCoordinates(tLayout, item, x, y) {
if (root.isHorizontal) {
y = tLayout.height / 2;
} else {
x = tLayout.width / 2;
}
var child = tLayout.childAt(x, y);
//if we got a place inside the space between 2 applets, we have to find it manually
if (!child) {
if (root.isHorizontal) {
for (var i = 0; i < tLayout.children.length; ++i) {
var candidate = tLayout.children[i];
if (x >= candidate.x && x < candidate.x + candidate.width + tLayout.rowSpacing) {
child = candidate;
break;
}
}
} else {
for (var i = 0; i < tLayout.children.length; ++i) {
var candidate = tLayout.children[i];
if (y >= candidate.x && y < candidate.y + candidate.height + tLayout.columnSpacing) {
child = candidate;
break;
}
}
}
}
//already in position
if (child === item) {
//
return childFoundId;
}
if (!child) {
// check if dragging takes place after the end of the layout
var neededSpace = 1.5 * root.realSize;
if ( (((root.isVertical && (y - neededSpace) <= tLayout.height) && y>=0)
||(root.Horizontal && (x - neededSpace) <= tLayout.width) && x>=0)
&& tLayout.children.length>0 ){
child = tLayout.children[layout.children.length-1];
// check if dragging takes place before the start of the layout
} else if ( ((root.isVertical && (y >= -neededSpace) && (y<=neededSpace))
||(root.Horizontal && (x >= -neededSpace) && (x<=neededSpace)))
&& tLayout.children.length>0 ){
child = tLayout.children[0];
} else {
return -1;
//child = tLayout.children[0];
}
} else {
item.parent = root;
}
if ((root.isVertical && y < child.y + child.height/2) ||
(root.isHorizontal && x < child.x + child.width/2)) {
return insertBeforeForLayout(tLayout, child, item);
} else {
return insertAfterForLayout(tLayout, child, item);
}
}
function insertAtCoordinates2(item, x, y) {
var pos = -1;
if (!root.editMode) {
var layoutPosS = layoutS.mapFromItem(root, x, y);
pos = insertAtLayoutCoordinates(layoutS, item, layoutPosS.x, layoutPosS.y);
if (pos === -1){
var layoutPosE = layoutE.mapFromItem(root, x, y);
pos = insertAtLayoutCoordinates(layoutE, item, layoutPosE.x, layoutPosE.y);
}
}
if (pos!==childFoundId && pos === -1) {
var layoutPos = layout.mapFromItem(root, x, y);
insertAtCoordinates(item, layoutPos.x, layoutPos.y);
}
}

View File

@ -439,8 +439,9 @@ DragDrop.DropArea {
slotAnimationsNeedLength(1);
}
var relevantLayout = mainLayout.mapFromItem(root, event.x, event.y);
LayoutManager.insertAtCoordinates(dndSpacer, relevantLayout.x, relevantLayout.y)
//var relevantLayout = mainLayout.mapFromItem(root, event.x, event.y);
//LayoutManager.insertAtCoordinates2(dndSpacer, relevantLayout.x, relevantLayout.y)
LayoutManager.insertAtCoordinates2(dndSpacer, event.x, event.y)
dndSpacer.opacity = 1;
}
@ -449,8 +450,9 @@ DragDrop.DropArea {
return;
}
var relevantLayout = mainLayout.mapFromItem(root, event.x, event.y);
LayoutManager.insertAtCoordinates(dndSpacer, relevantLayout.x, relevantLayout.y)
//var relevantLayout = mainLayout.mapFromItem(root, event.x, event.y);
//LayoutManager.insertAtCoordinates2(dndSpacer, relevantLayout.x, relevantLayout.y)
LayoutManager.insertAtCoordinates2(dndSpacer, event.x, event.y)
dndSpacer.opacity = 1;
}
@ -466,8 +468,9 @@ DragDrop.DropArea {
}
onDrop: {
var relevantLayout = mainLayout.mapFromItem(root, event.x, event.y);
plasmoid.processMimeData(event.mimeData, relevantLayout.x, relevantLayout.y);
//var relevantLayout = mainLayout.mapFromItem(root, event.x, event.y);
//plasmoid.processMimeData(event.mimeData, relevantLayout.x, relevantLayout.y);
plasmoid.processMimeData(event.mimeData, event.x, event.y);
event.accept(event.proposedAction);
if (confirmedDragEntered) {
@ -476,7 +479,7 @@ DragDrop.DropArea {
}
dndSpacer.opacity = 0;
dndSpacer.parent = root;
// dndSpacer.parent = root;
}
onLatteAppletChanged: {
@ -655,13 +658,15 @@ DragDrop.DropArea {
function addContainerInLayout(container, applet, x, y){
// Is there a DND placeholder? Replace it!
if (dndSpacer.parent === mainLayout) {
LayoutManager.insertBefore(dndSpacer, container);
if ( (dndSpacer.parent === mainLayout)
|| (dndSpacer.parent === startLayout)
|| (dndSpacer.parent===endLayout)) {
LayoutManager.insertBeforeForLayout(dndSpacer.parent, dndSpacer, container);
dndSpacer.parent = root;
return;
// If the provided position is valid, use it.
} else if (x >= 0 && y >= 0) {
var index = LayoutManager.insertAtCoordinates(container, x , y);
var index = LayoutManager.insertAtCoordinates2(container, x , y);
// Fall through to determining an appropriate insert position.
} else {