mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-28 14:43: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
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,54 +27,53 @@ 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
|
Controls.Label {
|
||||||
topPadding: frame.margins.top
|
id: metrics
|
||||||
rightPadding: frame.margins.right
|
text: "M\nM"
|
||||||
bottomPadding: frame.margins.bottom
|
visible: false
|
||||||
|
|
||||||
background: PlasmaCore.FrameSvgItem {
|
|
||||||
id: frame
|
|
||||||
imagePath: "widgets/background"
|
|
||||||
anchors.fill: parent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contentItem: Item {
|
Item {
|
||||||
id: flowParent
|
id: spacer
|
||||||
|
width: units.gridUnit * 4
|
||||||
|
height: width
|
||||||
|
}
|
||||||
|
|
||||||
implicitWidth: applicationsFlow.implicitWidth
|
Controls.Control {
|
||||||
implicitHeight: applicationsFlow.implicitHeight
|
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
|
leftPadding: frameSvg.margins.left
|
||||||
Controls.Label {
|
topPadding: frameSvg.margins.top
|
||||||
id: metrics
|
rightPadding: frameSvg.margins.right
|
||||||
text: "M\nM"
|
bottomPadding: frameSvg.margins.bottom
|
||||||
visible: false
|
|
||||||
}
|
|
||||||
|
|
||||||
Item {
|
background: PlasmaCore.FrameSvgItem {
|
||||||
id: spacer
|
id: frameSvg
|
||||||
width: units.gridUnit * 4
|
imagePath: "widgets/background"
|
||||||
height: width
|
|
||||||
}
|
|
||||||
|
|
||||||
Flow {
|
|
||||||
id: applicationsFlow
|
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
}
|
||||||
|
|
||||||
|
contentItem: Flow {
|
||||||
|
id: applicationsFlow
|
||||||
|
|
||||||
spacing: 0
|
spacing: 0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,22 +107,15 @@ QtObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeContainer(item, container) {
|
function changeContainer(item, container) {
|
||||||
var pos;
|
var pos = container.mapFromItem(item, 0, 0);
|
||||||
|
item.parent = container;
|
||||||
if (container == appletsLayout) {
|
|
||||||
pos = container.mapFromItem(item, 0, 0);
|
|
||||||
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;
|
||||||
|
|
@ -134,24 +127,25 @@ QtObject {
|
||||||
item.y = pos.y;
|
item.y = pos.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
return favoriteStrip.flow;
|
||||||
if (model.ApplicationLocationRole == ApplicationListModel.Favorites) {
|
default:
|
||||||
if (editMode) {
|
|
||||||
return favoriteStrip.contentItem;
|
|
||||||
} else {
|
|
||||||
return favoriteStrip.flow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (editMode) {
|
|
||||||
return flowParent;
|
|
||||||
} else {
|
|
||||||
return root.flow;
|
return root.flow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue