diff --git a/containments/homescreen2/package/contents/ui/launcher/Delegate.qml b/containments/homescreen2/package/contents/ui/launcher/Delegate.qml index 6e44d468..72b01d95 100644 --- a/containments/homescreen2/package/contents/ui/launcher/Delegate.qml +++ b/containments/homescreen2/package/contents/ui/launcher/Delegate.qml @@ -46,57 +46,25 @@ ContainmentLayoutManager.ItemContainer { property real dragCenterX property real dragCenterY - editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold//model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual + editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold onEditModeChanged: {//FIXME: remove plasmoid.editMode = editMode } onDragActiveChanged: { if (dragActive) { // Must be 0, 0 as at this point dragCenterX and dragCenterY are on the drag before" - launcherDragManager.showSpacer(delegate, 0, 0); + launcherDragManager.startDrag(delegate); } else { - launcherDragManager.positionItem(delegate, dragCenterX, dragCenterY); + launcherDragManager.dropItem(delegate, dragCenterX, dragCenterY); plasmoid.editMode = false; editMode = false; } } onUserDrag: { - // newPosition - var newRow = 0; - dragCenterX = dragCenter.x; dragCenterY = dragCenter.y; - var newContainer = launcherDragManager.containerForItem(delegate, dragCenter.x, dragCenter.y); - - // Put it in the favorites strip - if (newContainer == favoriteStrip) { - var pos = favoriteStrip.mapFromItem(delegate, 0, 0); - newRow = Math.floor((pos.x + dragCenter.x) / delegate.width); - - plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Favorites); - - // Put it on desktop - } else if (newContainer == appletsLayout) { - var pos = appletsLayout.mapFromItem(delegate, 0, 0); - plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Desktop); - print("!!!!!!!!!!!!"+pos.x+" "+pos.y) - // delegate.x = pos.x - // delegate.y = pos.y - return; - - // Put it in the general view - } else { - newRow = Math.round(newContainer.flow.width / delegate.width) * Math.floor((delegate.y + dragCenter.y) / delegate.height) + Math.floor((delegate.x + dragCenter.x) / delegate.width) + favoriteStrip.count; - - plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Grid); - } - - launcherDragManager.showSpacer(delegate, dragCenter.x, dragCenter.y); - - plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false); - - plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow); + launcherDragManager.dragItem(delegate, index, dragCenter.x, dragCenter.y); } contentItem: MouseArea { diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml index b7c8c8ba..f32e738b 100644 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml +++ b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml @@ -21,6 +21,8 @@ import QtQuick 2.4 import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager +import org.kde.phone.homescreen 1.0 + QtObject { id: root @@ -33,152 +35,203 @@ QtObject { height: width } - function raiseContainer(container) { - container.z = 1; - - if (container == appletsLayout) { - launcherGrid.z = 0; - favoriteStrip.z = 0; - } else if (container == favoriteStrip) { - appletsLayout.z = 0; - launcherGrid.z = 0; - } else { - appletsLayout.z = 0; - favoriteStrip.z = 0; - } + function startDrag(item) { + internal.showSpacer(item, 0, 0); } - function containerForItem(item, dragCenterX, dragCenterY) { - if (favoriteStrip.contains(favoriteStrip.mapFromItem(item, dragCenterX, dragCenterY))) { - return favoriteStrip; - } else if (appletsLayout.contains(appletsLayout.mapFromItem(item, dragCenterX, dragCenterY))) { - return appletsLayout; - } else { - return launcherGrid; - } - } + function dragItem(delegate, index, dragCenterX, dragCenterY) { + // newPosition + var newRow = 0; - function changeContainer(item, container) { - var pos; -print("$$$$$$$$"+container) - if (container == appletsLayout) { - pos = container.mapFromItem(item, 0, 0); - item.parent = container; - } else { - pos = container.contentItem.mapFromItem(item, 0, 0); - item.parent = container.contentItem; - } + var newContainer = internal.containerForItem(delegate, dragCenterX, dragCenterY); - item.x = pos.x; - item.y = pos.y; - } + // Put it in the favorites strip + if (newContainer == favoriteStrip) { + var pos = favoriteStrip.mapFromItem(delegate, 0, 0); + newRow = Math.floor((pos.x + dragCenterX) / delegate.width); - function putInContainerLayout(item, container) { - var pos = container.contentItem.mapFromItem(item, 0, 0); -print("££££££££££££££££"+container) - if (container == appletsLayout) { - item.parent = container; - } else { - item.parent = container.flow; - } + plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Favorites); - item.x = pos.x; - item.y = pos.y; - } + internal.showSpacer(delegate, dragCenterX, dragCenterY); + plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow); - function nearestChild (item, dragCenterX, dragCenterY, container) { - var distance = Number.POSITIVE_INFINITY; - var child; - - // Search Left - for (var i = 0; i < item.width * 2; i += item.width/2) { - var candidate = container.flow.childAt( - Math.min(container.flow.width, Math.max(0, item.x + dragCenterX + i)), - Math.min(container.flow.height-1, Math.max(0, item.y + dragCenterY))); - if (candidate && i < distance) { - child = candidate; - break; - } - } - - // Search Right - for (var i = 0; i < item.width * 2; i += item.width/2) { - var candidate = container.flow.childAt(Math.min(container.flow.width, Math.max(0, item.x + dragCenterX - i)), Math.min(container.flow.height-1, Math.max(0, item.y + dragCenterY))); - if (candidate && i < distance) { - child = candidate; - break; - } - } - - if (!child) { - if (item.y < container.flow.height/2) { - child = container.flow.children[0]; - } else { - child = container.flow.children[container.flow.children.length - 1]; - } - } - - return child; - } - - function showSpacer(item, dragCenterX, dragCenterY) { - var container = containerForItem(item, dragCenterX, dragCenterY); - - raiseContainer(container); -print("&&&&&&&&&&&"+container) - if (container == appletsLayout) { - spacer.visible = false; - changeContainer(item, container); + // Put it on desktop + } else if (newContainer == appletsLayout) { + var pos = appletsLayout.mapFromItem(delegate, 0, 0); + plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Desktop); + + internal.showSpacer(delegate, dragCenterX, dragCenterY); return; + + // Put it in the general view + } else { + newRow = Math.round(newContainer.flow.width / delegate.width) * Math.floor((delegate.y + dragCenterY) / delegate.height) + Math.floor((delegate.x + dragCenterX) / delegate.width) + favoriteStrip.count; + + plasmoid.nativeInterface.applicationListModel.setLocation(index, ApplicationListModel.Grid); + + internal.showSpacer(delegate, dragCenterX, dragCenterY); + plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow); } - var child = nearestChild(item, dragCenterX, dragCenterY, container); + internal.showSpacer(delegate, dragCenterX, dragCenterY); + plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow); + } + + function dropItem(item, dragCenterX, dragCenterY) { + internal.positionItem(item, dragCenterX, dragCenterY); + } + + // Those should never be accessed from outside + property QtObject __internal: QtObject { + id: internal + function raiseContainer(container) { + container.z = 1; + + if (container == appletsLayout) { + launcherGrid.z = 0; + favoriteStrip.z = 0; + } else if (container == favoriteStrip) { + appletsLayout.z = 0; + launcherGrid.z = 0; + } else { + appletsLayout.z = 0; + favoriteStrip.z = 0; + } + } + + function containerForItem(item, dragCenterX, dragCenterY) { + if (favoriteStrip.contains(favoriteStrip.mapFromItem(item, dragCenterX, dragCenterY))) { + return favoriteStrip; + } else if (appletsLayout.contains(appletsLayout.mapFromItem(item, dragCenterX, dragCenterY))) { + return appletsLayout; + } else { + return launcherGrid; + } + } + + function changeContainer(item, container) { + var pos; + + if (container == appletsLayout) { + pos = container.mapFromItem(item, 0, 0); + item.parent = container; + } else { + pos = container.contentItem.mapFromItem(item, 0, 0); + item.parent = container.contentItem; + } + + item.x = pos.x; + item.y = pos.y; + } + + function putInContainerLayout(item, container) { + var pos = container.contentItem.mapFromItem(item, 0, 0); + + if (container == appletsLayout) { + item.parent = container; + } else { + item.parent = container.flow; + } + + item.x = pos.x; + item.y = pos.y; + } + + function nearestChild (item, dragCenterX, dragCenterY, container) { + var distance = Number.POSITIVE_INFINITY; + var child; + + // Search Left + for (var i = 0; i < item.width * 2; i += item.width/2) { + var candidate = container.flow.childAt( + Math.min(container.flow.width, Math.max(0, item.x + dragCenterX + i)), + Math.min(container.flow.height-1, Math.max(0, item.y + dragCenterY))); + if (candidate && i < distance) { + child = candidate; + break; + } + } + + // Search Right + for (var i = 0; i < item.width * 2; i += item.width/2) { + var candidate = container.flow.childAt(Math.min(container.flow.width, Math.max(0, item.x + dragCenterX - i)), Math.min(container.flow.height-1, Math.max(0, item.y + dragCenterY))); + if (candidate && i < distance) { + child = candidate; + break; + } + } + + if (!child) { + if (item.y < container.flow.height/2) { + child = container.flow.children[0]; + } else { + child = container.flow.children[container.flow.children.length - 1]; + } + } + + return child; + } + + function showSpacer(item, dragCenterX, dragCenterY) { + var container = containerForItem(item, dragCenterX, dragCenterY); + + raiseContainer(container); + + if (container == appletsLayout) { + spacer.visible = false; + changeContainer(item, container); + return; + } + + var child = nearestChild(item, dragCenterX, dragCenterY, container); + + if (!child) { + spacer.visible = false; + spacer.parent = container.flow + return; + } - if (!child) { spacer.visible = false; spacer.parent = container.flow - return; + + if (item.x + dragCenterX < child.x + child.width / 2) { + plasmoid.nativeInterface.stackBefore(spacer, child); + } else { + plasmoid.nativeInterface.stackAfter(spacer, child); + } + + changeContainer(item, container); + + spacer.visible = true; } - spacer.visible = false; - spacer.parent = container.flow + function positionItem(item, dragCenterX, dragCenterY) { + var container = containerForItem(item, dragCenterX, dragCenterY); - if (item.x + dragCenterX < child.x + child.width / 2) { - plasmoid.nativeInterface.stackBefore(spacer, child); - } else { - plasmoid.nativeInterface.stackAfter(spacer, child); - } + raiseContainer(container); - changeContainer(item, container); + if (container == appletsLayout) { + appletsLayout.positionItem(item); + return; + } - spacer.visible = true; - } + spacer.visible = false; + spacer.parent = container.contentItem; - function positionItem(item, dragCenterX, dragCenterY) { - var container = containerForItem(item, dragCenterX, dragCenterY); + var child = nearestChild(item, dragCenterX, dragCenterY, container); - raiseContainer(container); + if (!child) { + putInContainerLayout(item, container); + return; + } - if (container == appletsLayout) { - return; - } - - spacer.visible = false; - spacer.parent = container.contentItem; - - var child = nearestChild(item, dragCenterX, dragCenterY, container); - - if (!child) { - putInContainerLayout(item, container); - return; - } - - if (item.x + dragCenterX < child.x + child.width / 2) { - putInContainerLayout(item, container); - plasmoid.nativeInterface.stackBefore(item, child); - } else { - putInContainerLayout(item, container); - plasmoid.nativeInterface.stackAfter(item, child); + if (item.x + dragCenterX < child.x + child.width / 2) { + putInContainerLayout(item, container); + plasmoid.nativeInterface.stackBefore(item, child); + } else { + putInContainerLayout(item, container); + plasmoid.nativeInterface.stackAfter(item, child); + } } } }