Item dragging now perfect

This commit is contained in:
Marco Martin 2019-08-23 12:54:19 +02:00
parent 30c06679ae
commit a1a8e00201
5 changed files with 58 additions and 75 deletions

View file

@ -37,12 +37,5 @@ LauncherContainer {
height: launcherGrid.cellHeight + topPadding + bottomPadding height: launcherGrid.cellHeight + topPadding + bottomPadding
implicitWidth: launcherGrid.cellWidth * Math.max(1, plasmoid.nativeInterface.applicationListModel.favoriteCount) + leftPadding + rightPadding frame.implicitWidth: launcherGrid.cellWidth * Math.max(1, plasmoid.nativeInterface.applicationListModel.favoriteCount) + frame.leftPadding + frame.rightPadding
Behavior on width {
NumberAnimation {
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
} }

View file

@ -27,39 +27,22 @@ import org.kde.kquickcontrolsaddons 2.0
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
Controls.Control { Item {
id: root id: root
readonly property int reservedSpaceForLabel: metrics.height readonly property int reservedSpaceForLabel: metrics.height
property int availableCellHeight: units.iconSizes.huge + reservedSpaceForLabel property int availableCellHeight: units.iconSizes.huge + reservedSpaceForLabel
property ContainmentLayoutManager.AppletsLayout appletsLayout property ContainmentLayoutManager.AppletsLayout appletsLayout
property Controls.Control launcherGrid property Item launcherGrid
property Controls.Control favoriteStrip property Item favoriteStrip
property alias frame: frame
property alias flow: applicationsFlow property alias flow: applicationsFlow
implicitWidth: contentItem.implicitWidth + frame.margins.top + frame.margins.bottom implicitWidth: frame.implicitWidth
implicitHeight: contentItem.implicitHeight + frame.margins.top + frame.margins.bottom implicitHeight: frame.implicitHeight
leftPadding: frame.margins.left
topPadding: frame.margins.top
rightPadding: frame.margins.right
bottomPadding: frame.margins.bottom
background: PlasmaCore.FrameSvgItem {
id: frame
imagePath: "widgets/background"
anchors.fill: parent
}
contentItem: Item {
id: flowParent
implicitWidth: applicationsFlow.implicitWidth
implicitHeight: applicationsFlow.implicitHeight
//NOTE: TextMetrics can't handle multi line
Controls.Label { Controls.Label {
id: metrics id: metrics
text: "M\nM" text: "M\nM"
@ -72,9 +55,25 @@ Controls.Control {
height: width height: width
} }
Flow { Controls.Control {
id: applicationsFlow id: frame
anchors.centerIn: parent
implicitWidth: contentItem.implicitWidth + frameSvg.margins.top + frameSvg.margins.bottom
implicitHeight: contentItem.implicitHeight + frameSvg.margins.top + frameSvg.margins.bottom
leftPadding: frameSvg.margins.left
topPadding: frameSvg.margins.top
rightPadding: frameSvg.margins.right
bottomPadding: frameSvg.margins.bottom
background: PlasmaCore.FrameSvgItem {
id: frameSvg
imagePath: "widgets/background"
anchors.fill: parent anchors.fill: parent
}
contentItem: Flow {
id: applicationsFlow
spacing: 0 spacing: 0

View file

@ -107,22 +107,15 @@ QtObject {
} }
function changeContainer(item, container) { function changeContainer(item, container) {
var pos; var pos = container.mapFromItem(item, 0, 0);
if (container == appletsLayout) {
pos = container.mapFromItem(item, 0, 0);
item.parent = container; item.parent = container;
} else {
pos = container.contentItem.mapFromItem(item, 0, 0);
item.parent = container.contentItem;
}
item.x = pos.x; item.x = pos.x;
item.y = pos.y; item.y = pos.y;
} }
function putInContainerLayout(item, container) { function putInContainerLayout(item, container) {
var pos = container.contentItem.mapFromItem(item, 0, 0); var pos = container.flow.mapFromItem(item, 0, 0);
if (container == appletsLayout) { if (container == appletsLayout) {
item.parent = container; item.parent = container;
@ -137,21 +130,22 @@ QtObject {
function nearestChild(item, dragCenterX, dragCenterY, container) { function nearestChild(item, dragCenterX, dragCenterY, container) {
var distance = Number.POSITIVE_INFINITY; var distance = Number.POSITIVE_INFINITY;
var child; var child;
var pos = container.flow.mapFromItem(item, dragCenterX, dragCenterY);
// Search Left // Search Right
for (var i = 0; i < item.width * 2; i += item.width/2) { for (var i = 0; i < item.width * 2; i += item.width/2) {
var candidate = container.flow.childAt( var candidate = container.flow.childAt(
Math.min(container.flow.width, Math.max(0, item.x + dragCenterX + i)), Math.min(container.flow.width, Math.max(0, pos.x + i)),
Math.min(container.flow.height-1, Math.max(0, item.y + dragCenterY))); Math.min(container.flow.height-1, Math.max(0, pos.y)));
if (candidate && i < distance) { if (candidate && i < distance) {
child = candidate; child = candidate;
break; break;
} }
} }
// Search Right // Search Left
for (var i = 0; i < item.width * 2; i += item.width/2) { 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))); var candidate = container.flow.childAt(Math.min(container.flow.width, Math.max(0, pos.x - i)), Math.min(container.flow.height-1, Math.max(0, pos.y)));
if (candidate && i < distance) { if (candidate && i < distance) {
child = candidate; child = candidate;
break; break;
@ -191,7 +185,9 @@ QtObject {
spacer.visible = false; spacer.visible = false;
spacer.parent = container.flow spacer.parent = container.flow
if (item.x + dragCenterX < child.x + child.width / 2) { var pos = container.flow.mapFromItem(item, dragCenterX, dragCenterY);
if (pos.x < child.x + child.width / 2) {
plasmoid.nativeInterface.stackBefore(spacer, child); plasmoid.nativeInterface.stackBefore(spacer, child);
} else { } else {
plasmoid.nativeInterface.stackAfter(spacer, child); plasmoid.nativeInterface.stackAfter(spacer, child);
@ -213,7 +209,7 @@ QtObject {
} }
spacer.visible = false; spacer.visible = false;
spacer.parent = container.contentItem; spacer.parent = container;
var child = nearestChild(item, dragCenterX, dragCenterY, container); var child = nearestChild(item, dragCenterX, dragCenterY, container);

View file

@ -37,8 +37,9 @@ LauncherContainer {
readonly property int cellWidth: root.flow.width / Math.floor(root.flow.width / ((availableCellHeight - reservedSpaceForLabel) + units.smallSpacing*4)) readonly property int cellWidth: root.flow.width / Math.floor(root.flow.width / ((availableCellHeight - reservedSpaceForLabel) + units.smallSpacing*4))
readonly property int cellHeight: availableCellHeight - topPadding readonly property int cellHeight: availableCellHeight
frame.width: width
Repeater { Repeater {
model: plasmoid.nativeInterface.applicationListModel model: plasmoid.nativeInterface.applicationListModel
@ -48,21 +49,12 @@ LauncherContainer {
height: root.cellHeight height: root.cellHeight
parent: { parent: {
if (model.ApplicationLocationRole == ApplicationListModel.Desktop) { switch (model.ApplicationLocationRole) {
case ApplicationListModel.Desktop:
return appletsLayout; return appletsLayout;
} case ApplicationListModel.Favorites:
if (model.ApplicationLocationRole == ApplicationListModel.Favorites) {
if (editMode) {
return favoriteStrip.contentItem;
} else {
return favoriteStrip.flow; return favoriteStrip.flow;
} default:
}
if (editMode) {
return flowParent;
} else {
return root.flow; return root.flow;
} }
} }

View file

@ -174,8 +174,11 @@ Text {
Launcher.FavoriteStrip { Launcher.FavoriteStrip {
id: favoriteStrip id: favoriteStrip
anchors.horizontalCenter: parent.horizontalCenter anchors {
width: Math.min(root.width, implicitWidth) left: parent.left
right: parent.right
}
appletsLayout: appletsLayout
launcherGrid: launcher launcherGrid: launcher
y: Math.max(0, root.height - height - mainFlickable.contentY) y: Math.max(0, root.height - height - mainFlickable.contentY)
} }