diff --git a/containments/homescreen2/package/contents/ui/launcher/Delegate.qml b/containments/homescreen2/package/contents/ui/launcher/Delegate.qml index e0e008b..925ee96 100644 --- a/containments/homescreen2/package/contents/ui/launcher/Delegate.qml +++ b/containments/homescreen2/package/contents/ui/launcher/Delegate.qml @@ -1,147 +1,146 @@ /* * Copyright 2019 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA. */ import QtQuick 2.4 import QtQuick.Layouts 1.1 import QtQuick.Controls 2.3 as Controls import org.kde.plasma.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager ContainmentLayoutManager.ItemContainer { id: delegate z: dragging ? 1 : 0 property var modelData: typeof model !== "undefined" ? model : null property Item container leftPadding: units.smallSpacing * 2 topPadding: units.smallSpacing * 2 rightPadding: units.smallSpacing * 2 bottomPadding: units.smallSpacing * 2 opacity: dragging ? 0.4 : 1 editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold//model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual onEditModeChanged: {//FIXME: remove plasmoid.editMode = editMode } onDragActiveChanged: { if (dragActive) { launcherDragManager.showSpacer(delegate, 0, 0); -print("AAAH, BENGALAAAAH") return; } plasmoid.editMode = false; editMode = false; } onUserDrag: { // newPosition var newRow = 0; 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.setFavoriteItem(index, true); // Put it on desktop } else if (newContainer == appletsLayout) { var pos = appletsLayout.mapFromItem(delegate, 0, 0); plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, true); 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.setFavoriteItem(index, false); plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false); } launcherDragManager.showSpacer(delegate, dragCenter.x, dragCenter.y); plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false); plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow); } contentItem: MouseArea { onClicked: { if (modelData.ApplicationStartupNotifyRole) { clickFedbackAnimation.target = delegate; clickFedbackAnimation.running = true; feedbackWindow.title = modelData.ApplicationNameRole; feedbackWindow.state = "open"; } plasmoid.nativeInterface.applicationListModel.runApplication(modelData.ApplicationStorageIdRole); } ColumnLayout { anchors.fill: parent spacing: 0 PlasmaCore.IconItem { id: icon Layout.alignment: Qt.AlignHCenter | Qt.AlignTop Layout.fillWidth: true Layout.preferredHeight: parent.height - root.reservedSpaceForLabel source: modelData ? modelData.ApplicationIconRole : "" scale: root.reorderingApps && dragDelegate && !dragging ? 0.6 : 1 Behavior on scale { NumberAnimation { duration: units.longDuration easing.type: Easing.InOutQuad } } } PlasmaComponents.Label { id: label visible: text.length > 0 Layout.fillWidth: true Layout.fillHeight: true wrapMode: Text.WordWrap horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignTop maximumLineCount: 2 elide: Text.ElideRight text: modelData ? modelData.ApplicationNameRole : "" font.pixelSize: theme.defaultFont.pixelSize color: PlasmaCore.ColorScope.textColor } } } } diff --git a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml index 7719074..78e7a1e 100644 --- a/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml +++ b/containments/homescreen2/package/contents/ui/launcher/LauncherDragManager.qml @@ -1,139 +1,145 @@ /* * Copyright 2019 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.4 import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager QtObject { id: root property ContainmentLayoutManager.AppletsLayout appletsLayout property LauncherGrid launcherGrid property FavoriteStrip favoriteStrip readonly property Item spacer: Item { width: units.gridUnit * 4 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 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 = container.contentItem.mapFromItem(item, 0, 0); if (container == appletsLayout) { item.parent = container; } else { 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 showSpacer(item, dragCenterX, dragCenterY) { var container = containerForItem(item, dragCenterX, dragCenterY); raiseContainer(container); var child = container.flow.childAt(item.x + dragCenterX, item.y + dragCenterX); + if (!child) { return; } - changeContainer(item, container); if (container == appletsLayout) { + changeContainer(item, container); return; } spacer.visible = false; spacer.parent = container.flow if (item.x + dragCenterX < child.x + child.width / 2) { plasmoid.nativeInterface.orderItems(spacer, child); } else { plasmoid.nativeInterface.orderItems(child, spacer); } + + changeContainer(item, container); + + print(spacer.parent+" "+child.parent) + spacer.visible = true; } function positionItem(item, dragCenterX, dragCenterY) { var container = containerForItem(item, dragCenterX, dragCenterY); raiseContainer(container); if (container == appletsLayout) { return; } spacer.visible = false; spacer.parent = container.contentItem; var child = container.flow.childAt(item.x + dragCenterX, item.y + dragCenterX); if (!child) { return; } putInContainerLayout(item, container); if (item.x + dragCenterX < child.x + child.width / 2) { plasmoid.nativeInterface.orderItems(item, child); } else { plasmoid.nativeInterface.orderItems(child, item); } } }