From 8a2d7edbb792758945c253b2c467bd17efd2a4aa Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 7 Apr 2021 18:41:58 +0200 Subject: [PATCH] respect screen boundaries --- .../ui/launcher/HomeScreenContents.qml | 58 ++++++++++++++++++- .../ui/launcher/LauncherDragManager.qml | 10 +++- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/containments/homescreen/package/contents/ui/launcher/HomeScreenContents.qml b/containments/homescreen/package/contents/ui/launcher/HomeScreenContents.qml index 61463cf6..6470ccb8 100644 --- a/containments/homescreen/package/contents/ui/launcher/HomeScreenContents.qml +++ b/containments/homescreen/package/contents/ui/launcher/HomeScreenContents.qml @@ -163,7 +163,7 @@ DragDrop.DropArea { : ContainmentLayoutManager.AppletsLayout.AfterPressAndHold // Sets the containment in edit mode when we go in edit mode as well - onEditModeChanged: plasmoid.editMode = editMode + onEditModeChanged: plasmoid.editMode = editMode; minimumItemWidth: units.gridUnit * 3 minimumItemHeight: minimumItemWidth @@ -183,8 +183,64 @@ DragDrop.DropArea { onEditModeChanged: { launcherDragManager.active = dragActive || editMode; } + + property real dragCenterX + property real dragCenterY + + editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold + onDragActiveChanged: { launcherDragManager.active = dragActive || editMode; + if (dragActive) { + // Must be 0, 0 as at this point dragCenterX and dragCenterY are on the drag before" + launcherDragManager.startDrag(appletContainer); + launcherDragManager.currentlyDraggedDelegate = appletContainer; + } else { + launcherDragManager.dropItem(appletContainer, dragCenterX, dragCenterY); + plasmoid.editMode = false; + editMode = false; + launcherRepeater.stopScrollRequested(); + launcherDragManager.currentlyDraggedDelegate = null; + forceActiveFocus(); + } + } + onUserDrag: { + dragCenterX = dragCenter.x; + dragCenterY = dragCenter.y; + launcherDragManager.dragItem(appletContainer, dragCenter.x, dragCenter.y); + + var pos = plasmoid.fullRepresentationItem.mapFromItem(appletContainer, dragCenter.x, dragCenter.y); + + //SCROLL LEFT + if (pos.x < units.gridUnit) { + launcherRepeater.scrollLeftRequested(); + //SCROLL RIGHT + } else if (pos.x > mainFlickable.width - units.gridUnit) { + launcherRepeater.scrollRightRequested(); + //DON't SCROLL + } else { + launcherRepeater.stopScrollRequested(); + } + + appletContainer.x = Math.max(0, Math.min(mainFlickable.width - appletContainer.width, appletContainer.x)); + } + Connections { + target: dropArea + function onWidthChanged () { + if (Math.floor((appletContainer.x) / mainFlickable.width) < Math.floor((appletContainer.x + appletContainer.width/2) / mainFlickable.width)) { + print("should go next") + appletsLayout.releaseSpace(appletContainer); + appletContainer.x = Math.floor((appletContainer.x + appletContainer.width) / mainFlickable.width) * mainFlickable.width; + appletsLayout.positionItem(appletContainer); + } else if (Math.floor((appletContainer.x + appletContainer.width/2) / mainFlickable.width) < Math.floor((appletContainer.x + appletContainer.width) / mainFlickable.width)) { + print("should go previous") + appletsLayout.releaseSpace(appletContainer); + appletContainer.x = Math.ceil(appletContainer.x / mainFlickable.width) * mainFlickable.width - appletContainer.width; + appletsLayout.positionItem(appletContainer); + } else { + print("good where it is") + } + } } } diff --git a/containments/homescreen/package/contents/ui/launcher/LauncherDragManager.qml b/containments/homescreen/package/contents/ui/launcher/LauncherDragManager.qml index e4347bbc..78f01b50 100644 --- a/containments/homescreen/package/contents/ui/launcher/LauncherDragManager.qml +++ b/containments/homescreen/package/contents/ui/launcher/LauncherDragManager.qml @@ -15,7 +15,7 @@ Item { property ContainmentLayoutManager.AppletsLayout appletsLayout property FavoriteStrip favoriteStrip - property HomeDelegate currentlyDraggedDelegate + property ContainmentLayoutManager.ItemContainer currentlyDraggedDelegate property bool active property QtObject model: plasmoid.nativeInterface.applicationListModel @@ -160,7 +160,9 @@ Item { } function containerForItem(item, dragCenterX, dragCenterY) { - if (favoriteStrip.contains(Qt.point(0,favoriteStrip.frame.mapFromItem(item, dragCenterX, dragCenterY).y)) + if (!item.modelData) { + return appletsLayout; + } else if (favoriteStrip.contains(Qt.point(0,favoriteStrip.frame.mapFromItem(item, dragCenterX, dragCenterY).y)) && (item.modelData.applicationLocation == ApplicationListModel.Favorites || root.model.favoriteCount < root.model.maxFavoriteCount)) { return favoriteStrip; @@ -274,7 +276,9 @@ Item { raiseContainer(container); if (container == appletsLayout) { - root.model.setLocation(item.modelData.index, ApplicationListModel.Desktop); + if (item.modelData) { + root.model.setLocation(item.modelData.index, ApplicationListModel.Desktop); + } var pos = appletsLayout.mapFromItem(item, 0, 0); item.parent = appletsLayout; item.x = pos.x;