mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
a new central LauncherDragManager.qml
a central place to manage the dragging around of launchers and reparent between their 3 possible parents
This commit is contained in:
parent
1fd5e92794
commit
851ff2bd05
6 changed files with 163 additions and 64 deletions
|
|
@ -33,9 +33,7 @@ ContainmentLayoutManager.ItemContainer {
|
|||
z: dragging ? 1 : 0
|
||||
|
||||
property var modelData: typeof model !== "undefined" ? model : null
|
||||
property ContainmentLayoutManager.ItemContainer beforeItem
|
||||
property Item container
|
||||
property ContainmentLayoutManager.ItemContainer before
|
||||
|
||||
leftPadding: units.smallSpacing * 2
|
||||
topPadding: units.smallSpacing * 2
|
||||
|
|
@ -47,72 +45,53 @@ ContainmentLayoutManager.ItemContainer {
|
|||
editModeCondition: ContainmentLayoutManager.ItemContainer.AfterPressAndHold//model.ApplicationOnDesktopRole ? ContainmentLayoutManager.ItemContainer.AfterPressAndHold: ContainmentLayoutManager.ItemContainer.Manual
|
||||
onEditModeChanged: {//FIXME: remove
|
||||
plasmoid.editMode = editMode
|
||||
if (!editMode) {
|
||||
root.forceLayout();
|
||||
}
|
||||
}
|
||||
onDragActiveChanged: {
|
||||
if (dragActive) {
|
||||
if (container) {
|
||||
container.showSpacerBefore(delegate);
|
||||
}
|
||||
launcherDragManager.showSpacer(delegate, 0, 0);
|
||||
print("AAAH, BENGALAAAAH")
|
||||
return;
|
||||
}
|
||||
|
||||
plasmoid.editMode = false;
|
||||
editMode = false;
|
||||
if (container) {
|
||||
container.forceLayout();
|
||||
container.hideSpacer();
|
||||
}
|
||||
}
|
||||
|
||||
onParentChanged: {
|
||||
if (container) {
|
||||
plasmoid.nativeInterface.orderItems(delegate, before);
|
||||
}
|
||||
}
|
||||
|
||||
onUserDrag: {
|
||||
// newPosition
|
||||
var newRow = 0;
|
||||
|
||||
var newContainer = launcherDragManager.containerForItem(delegate, dragCenter.x, dragCenter.y);
|
||||
|
||||
// Put it in the favorites strip
|
||||
if (favoriteStrip.contains(favoriteStrip.mapFromItem(delegate, dragCenter.x, dragCenter.y))) {
|
||||
if (newContainer == favoriteStrip) {
|
||||
var pos = favoriteStrip.mapFromItem(delegate, 0, 0);
|
||||
newRow = Math.floor((pos.x + dragCenter.x) / delegate.width);
|
||||
before = favoriteStrip.flow.childAt(delegate.x + dragCenter.x, delegate.y + dragCenter.y);
|
||||
|
||||
plasmoid.nativeInterface.applicationListModel.setFavoriteItem(index, true);
|
||||
|
||||
|
||||
// Put it on desktop
|
||||
} else if (appletsLayout.contains(appletsLayout.mapFromItem(delegate, dragCenter.x, dragCenter.y))) {
|
||||
} 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
|
||||
before = null;
|
||||
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);
|
||||
|
||||
newRow = Math.round(applicationsFlow.width / delegate.width) * Math.floor((delegate.y + dragCenter.y) / delegate.height) + Math.floor((delegate.x + dragCenter.x) / delegate.width) + favoriteStrip.count;
|
||||
before = applicationsFlow.childAt(delegate.x + dragCenter.x, delegate.y + dragCenter.y);
|
||||
}
|
||||
|
||||
launcherDragManager.showSpacer(delegate, dragCenter.x, dragCenter.y);
|
||||
|
||||
plasmoid.nativeInterface.applicationListModel.setDesktopItem(index, false);
|
||||
|
||||
plasmoid.nativeInterface.applicationListModel.moveItem(modelData.index, newRow);
|
||||
|
||||
if (container) {
|
||||
container.showSpacerBefore(before);
|
||||
}
|
||||
|
||||
//delegate.x = newPosition.x;
|
||||
}
|
||||
|
||||
contentItem: MouseArea {
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ import org.kde.kquickcontrolsaddons 2.0
|
|||
LauncherContainer {
|
||||
id: root
|
||||
|
||||
property Controls.Control launcherGrid
|
||||
|
||||
readonly property int count: flow.width / launcherGrid.cellWidth
|
||||
|
||||
flow.flow: Flow.TopToBottom
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ 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
|
||||
|
||||
Controls.Control {
|
||||
id: root
|
||||
|
|
@ -32,21 +33,12 @@ Controls.Control {
|
|||
readonly property int reservedSpaceForLabel: metrics.height
|
||||
property int availableCellHeight: units.iconSizes.huge + reservedSpaceForLabel
|
||||
|
||||
property ContainmentLayoutManager.AppletsLayout appletsLayout
|
||||
property Controls.Control launcherGrid
|
||||
property Controls.Control favoriteStrip
|
||||
|
||||
property alias flow: applicationsFlow
|
||||
|
||||
function forceLayout() {
|
||||
applicationsFlow.forceLayout();
|
||||
}
|
||||
|
||||
function showSpacerBefore(item) {
|
||||
spacer.parent = applicationsFlow
|
||||
plasmoid.nativeInterface.orderItems(spacer, item);
|
||||
}
|
||||
|
||||
function hideSpacer() {
|
||||
spacer.parent = flowParent;
|
||||
}
|
||||
|
||||
implicitWidth: contentItem.implicitWidth + frame.margins.top + frame.margins.bottom
|
||||
implicitHeight: contentItem.implicitHeight + frame.margins.top + frame.margins.bottom
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* Copyright 2019 Marco Martin <mart@kde.org>
|
||||
*
|
||||
* 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) {
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -37,9 +37,6 @@ LauncherContainer {
|
|||
readonly property int cellWidth: root.flow.width / Math.floor(root.flow.width / ((availableCellHeight - reservedSpaceForLabel) + units.smallSpacing*4))
|
||||
readonly property int cellHeight: availableCellHeight - topPadding
|
||||
|
||||
property ContainmentLayoutManager.AppletsLayout appletsLayout
|
||||
property FavoriteStrip favoriteStrip
|
||||
|
||||
|
||||
Repeater {
|
||||
model: plasmoid.nativeInterface.applicationListModel
|
||||
|
|
@ -58,33 +55,18 @@ LauncherContainer {
|
|||
}
|
||||
parent: {
|
||||
if (model.ApplicationOnDesktopRole) {
|
||||
var pos = appletsLayout.mapFromItem(delegate, 0, 0);
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
return appletsLayout;
|
||||
}
|
||||
if (model.ApplicationFavoriteRole) {
|
||||
if (editMode) {
|
||||
var pos = favoriteStrip.contentItem.mapFromItem(delegate, 0, 0);
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
return favoriteStrip.contentItem;
|
||||
} else {
|
||||
var pos = favoriteStrip.flow.mapFromItem(delegate, 0, 0);
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
return favoriteStrip.flow;
|
||||
}
|
||||
}
|
||||
if (editMode) {
|
||||
var pos = flowParent.mapFromItem(delegate, 0, 0);
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
return flowParent;
|
||||
} else {
|
||||
var pos = root.flow.mapFromItem(delegate, 0, 0);
|
||||
x = pos.x;
|
||||
y = pos.y;
|
||||
return root.flow;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,13 @@ Text {
|
|||
}
|
||||
}
|
||||
|
||||
Launcher.LauncherDragManager {
|
||||
id: launcherDragManager
|
||||
appletsLayout: appletsLayout
|
||||
launcherGrid: launcher
|
||||
favoriteStrip: favoriteStrip
|
||||
}
|
||||
|
||||
Flickable {
|
||||
id: mainFlickable
|
||||
anchors {
|
||||
|
|
@ -152,6 +159,7 @@ Text {
|
|||
placeHolder: ContainmentLayoutManager.PlaceHolder {}
|
||||
}
|
||||
}
|
||||
|
||||
Launcher.LauncherGrid {
|
||||
id: launcher
|
||||
Layout.fillWidth: true
|
||||
|
|
@ -161,6 +169,7 @@ Text {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Launcher.FavoriteStrip {
|
||||
id: favoriteStrip
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
|
|
|||
Loading…
Reference in a new issue