mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 06:33:09 +00:00
Item dragging now perfect
This commit is contained in:
parent
30c06679ae
commit
a1a8e00201
5 changed files with 58 additions and 75 deletions
|
|
@ -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
|
||||
Item {
|
||||
id: spacer
|
||||
width: units.gridUnit * 4
|
||||
height: width
|
||||
}
|
||||
|
||||
implicitWidth: applicationsFlow.implicitWidth
|
||||
implicitHeight: applicationsFlow.implicitHeight
|
||||
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
|
||||
|
||||
//NOTE: TextMetrics can't handle multi line
|
||||
Controls.Label {
|
||||
id: metrics
|
||||
text: "M\nM"
|
||||
visible: false
|
||||
}
|
||||
leftPadding: frameSvg.margins.left
|
||||
topPadding: frameSvg.margins.top
|
||||
rightPadding: frameSvg.margins.right
|
||||
bottomPadding: frameSvg.margins.bottom
|
||||
|
||||
Item {
|
||||
id: spacer
|
||||
width: units.gridUnit * 4
|
||||
height: width
|
||||
}
|
||||
|
||||
Flow {
|
||||
id: applicationsFlow
|
||||
background: PlasmaCore.FrameSvgItem {
|
||||
id: frameSvg
|
||||
imagePath: "widgets/background"
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
contentItem: Flow {
|
||||
id: applicationsFlow
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue