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,60 +3,103 @@ 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
scale: root.reorderingApps && !drag.target ? 0.6 : 1
Behavior on scale { property int idx: index
NumberAnimation { property int oldIdx: -1
duration: units.shortDuration onIdxChanged: {
easing.type: Easing.InOutQuad if (oldIdx < 0) {
oldIdx = idx;
return;
} }
} delegateItem.x = ((oldIdx % 4) * GridView.view.cellWidth) - ((idx % 4) * GridView.view.cellWidth);
onClicked: { delegateItem.y = (Math.floor(oldIdx / 4) * GridView.view.cellHeight) - (Math.floor(idx / 4) * GridView.view.cellHeight);
console.log("Clicked: " + model.ApplicationStorageIdRole) if (!delegateItem.drag.target) {
appListModel.runApplication(model.ApplicationStorageIdRole) translAnim.running = true;
}
onPressAndHold: {
delegateRoot.drag.target = delegateRoot;
root.reorderingApps = true;
}
onReleased: {
delegateRoot.drag.target = null;
root.reorderingApps = false;
}
onPositionChanged: {
if (delegateRoot.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)));
} }
oldIdx = idx;
} }
PlasmaCore.IconItem {
id: icon NumberAnimation {
anchors.centerIn: parent id: translAnim
width: parent.height / 2 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 height: width
source: model.ApplicationIconRole scale: root.reorderingApps && !drag.target ? 0.6 : 1
} Behavior on scale {
NumberAnimation {
PlasmaComponents.Label { duration: units.shortDuration
id: label easing.type: Easing.InOutQuad
visible: text.length > 0 }
anchors {
top: icon.bottom
left: icon.left
right: icon.right
} }
wrapMode: Text.WordWrap onXChanged: {
horizontalAlignment: Qt.AlignHCenter oldX = x
verticalAlignment: Qt.AlignVCenter oldY = y
maximumLineCount: 2 }
onClicked: {
console.log("Clicked: " + model.ApplicationStorageIdRole)
appListModel.runApplication(model.ApplicationStorageIdRole)
oldX = x
oldY = y
}
onPressAndHold: {
delegateItem.drag.target = delegateItem;
root.reorderingApps = true;
}
onReleased: {
delegateItem.drag.target = null;
root.reorderingApps = false;
text: model.ApplicationNameRole translAnim.running = true
font.pixelSize: theme.smallestFont.pixelSize }
color: PlasmaCore.ColorScope.textColor onPositionChanged: {
if (delegateItem.drag.target) {
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)));
}
}
PlasmaCore.IconItem {
id: icon
anchors.centerIn: parent
width: parent.height / 2
height: width
source: model.ApplicationIconRole
}
PlasmaComponents.Label {
id: label
visible: text.length > 0
anchors {
top: icon.bottom
left: icon.left
right: icon.right
}
wrapMode: Text.WordWrap
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
maximumLineCount: 2
text: model.ApplicationNameRole
font.pixelSize: theme.smallestFont.pixelSize
color: PlasmaCore.ColorScope.textColor
}
} }
} }