Commit a1a8e002 authored by Marco Martin's avatar Marco Martin

Item dragging now perfect

parent 30c06679
......@@ -37,12 +37,5 @@ LauncherContainer {
height: launcherGrid.cellHeight + topPadding + bottomPadding
implicitWidth: launcherGrid.cellWidth * Math.max(1, plasmoid.nativeInterface.applicationListModel.favoriteCount) + leftPadding + rightPadding
Behavior on width {
NumberAnimation {
duration: units.longDuration
easing.type: Easing.InOutQuad
}
}
frame.implicitWidth: launcherGrid.cellWidth * Math.max(1, plasmoid.nativeInterface.applicationListModel.favoriteCount) + frame.leftPadding + frame.rightPadding
}
......@@ -27,54 +27,53 @@ import org.kde.kquickcontrolsaddons 2.0
import org.kde.plasma.private.containmentlayoutmanager 1.0 as ContainmentLayoutManager
Controls.Control {
Item {
id: root
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 Item launcherGrid
property Item favoriteStrip
property alias frame: frame
property alias flow: applicationsFlow
implicitWidth: contentItem.implicitWidth + frame.margins.top + frame.margins.bottom
implicitHeight: contentItem.implicitHeight + frame.margins.top + frame.margins.bottom
implicitWidth: frame.implicitWidth
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
Controls.Label {
id: metrics
text: "M\nM"
visible: false
}
contentItem: Item {
id: flowParent
implicitWidth: applicationsFlow.implicitWidth
implicitHeight: applicationsFlow.implicitHeight
//NOTE: TextMetrics can't handle multi line
Controls.Label {
id: metrics
text: "M\nM"
visible: false
}
Item {
id: spacer
width: units.gridUnit * 4
height: width
}
Item {
id: spacer
width: units.gridUnit * 4
height: width
Controls.Control {
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
}
Flow {
contentItem: Flow {
id: applicationsFlow
anchors.fill: parent
spacing: 0
......
......@@ -107,22 +107,15 @@ QtObject {
}
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;
}
var pos = container.mapFromItem(item, 0, 0);
item.parent = container;
item.x = pos.x;
item.y = pos.y;
}
function putInContainerLayout(item, container) {
var pos = container.contentItem.mapFromItem(item, 0, 0);
var pos = container.flow.mapFromItem(item, 0, 0);
if (container == appletsLayout) {
item.parent = container;
......@@ -134,24 +127,25 @@ QtObject {
item.y = pos.y;
}
function nearestChild (item, dragCenterX, dragCenterY, container) {
function nearestChild(item, dragCenterX, dragCenterY, container) {
var distance = Number.POSITIVE_INFINITY;
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) {
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)));
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) {
child = candidate;
break;
}
}
// Search Right
// 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)));
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) {
child = candidate;
break;
......@@ -191,7 +185,9 @@ QtObject {
spacer.visible = false;
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);
} else {
plasmoid.nativeInterface.stackAfter(spacer, child);
......@@ -213,7 +209,7 @@ QtObject {
}
spacer.visible = false;
spacer.parent = container.contentItem;
spacer.parent = container;
var child = nearestChild(item, dragCenterX, dragCenterY, container);
......
......@@ -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 cellHeight: availableCellHeight - topPadding
readonly property int cellHeight: availableCellHeight
frame.width: width
Repeater {
model: plasmoid.nativeInterface.applicationListModel
......@@ -48,21 +49,12 @@ LauncherContainer {
height: root.cellHeight
parent: {
if (model.ApplicationLocationRole == ApplicationListModel.Desktop) {
switch (model.ApplicationLocationRole) {
case ApplicationListModel.Desktop:
return appletsLayout;
}
if (model.ApplicationLocationRole == ApplicationListModel.Favorites) {
if (editMode) {
return favoriteStrip.contentItem;
} else {
return favoriteStrip.flow;
}
}
if (editMode) {
return flowParent;
} else {
case ApplicationListModel.Favorites:
return favoriteStrip.flow;
default:
return root.flow;
}
}
......
......@@ -174,8 +174,11 @@ Text {
Launcher.FavoriteStrip {
id: favoriteStrip
anchors.horizontalCenter: parent.horizontalCenter
width: Math.min(root.width, implicitWidth)
anchors {
left: parent.left
right: parent.right
}
appletsLayout: appletsLayout
launcherGrid: launcher
y: Math.max(0, root.height - height - mainFlickable.contentY)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment