animate index reordering

This commit is contained in:
Marco Martin 2015-03-05 15:32:44 +01:00
parent ba089aa1dd
commit d09c3beafb

View file

@ -3,10 +3,41 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kio 1.0 as Kio import org.kde.kio 1.0 as Kio
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
MouseArea { Item {
id: delegateRoot id: delegateRoot
width: applicationsView.cellWidth width: applicationsView.cellWidth
height: width height: width
property int idx: index
property int oldIdx: -1
onIdxChanged: {
if (oldIdx < 0) {
oldIdx = idx;
return;
}
delegateItem.x = ((oldIdx % 4) * GridView.view.cellWidth) - ((idx % 4) * GridView.view.cellWidth);
delegateItem.y = (Math.floor(oldIdx / 4) * GridView.view.cellHeight) - (Math.floor(idx / 4) * GridView.view.cellHeight);
if (!delegateItem.drag.target) {
translAnim.running = true;
}
oldIdx = idx;
}
NumberAnimation {
id: translAnim
duration: units.longDuration
easing.type: Easing.InOutQuad
target: delegateItem
properties: "x,y"
to: 0
}
MouseArea {
id: delegateItem
property int oldX
property int oldY
width: applicationsView.cellWidth
height: width
scale: root.reorderingApps && !drag.target ? 0.6 : 1 scale: root.reorderingApps && !drag.target ? 0.6 : 1
Behavior on scale { Behavior on scale {
NumberAnimation { NumberAnimation {
@ -14,21 +45,32 @@ MouseArea {
easing.type: Easing.InOutQuad easing.type: Easing.InOutQuad
} }
} }
onXChanged: {
oldX = x
oldY = y
}
onClicked: { onClicked: {
console.log("Clicked: " + model.ApplicationStorageIdRole) console.log("Clicked: " + model.ApplicationStorageIdRole)
appListModel.runApplication(model.ApplicationStorageIdRole) appListModel.runApplication(model.ApplicationStorageIdRole)
oldX = x
oldY = y
} }
onPressAndHold: { onPressAndHold: {
delegateRoot.drag.target = delegateRoot; delegateItem.drag.target = delegateItem;
root.reorderingApps = true; root.reorderingApps = true;
} }
onReleased: { onReleased: {
delegateRoot.drag.target = null; delegateItem.drag.target = null;
root.reorderingApps = false; root.reorderingApps = false;
translAnim.running = true
} }
onPositionChanged: { onPositionChanged: {
if (delegateRoot.drag.target) { if (delegateItem.drag.target) {
appListModel.setOrder(model.ApplicationOriginalRowRole, (Math.round(GridView.view.width / GridView.view.cellWidth) * Math.round(delegateRoot.y / GridView.view.cellHeight) + Math.round(delegateRoot.x / GridView.view.cellWidth))); var pos = mapToItem(delegateRoot.parent, 0, 0);
appListModel.setOrder(model.ApplicationOriginalRowRole, (Math.round(delegateRoot.GridView.view.width / delegateRoot.GridView.view.cellWidth) * Math.round(pos.y / delegateRoot.GridView.view.cellHeight) + Math.round(pos.x / delegateRoot.GridView.view.cellWidth)));
} }
} }
@ -59,4 +101,5 @@ MouseArea {
font.pixelSize: theme.smallestFont.pixelSize font.pixelSize: theme.smallestFont.pixelSize
color: PlasmaCore.ColorScope.textColor color: PlasmaCore.ColorScope.textColor
} }
}
} }