mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-07-26 06:14:45 +00:00
better behavior on dragging, add autoscroll
This commit is contained in:
parent
dab083c37b
commit
490bfdc928
2 changed files with 66 additions and 14 deletions
|
|
@ -10,20 +10,26 @@ Item {
|
||||||
|
|
||||||
property int idx: index
|
property int idx: index
|
||||||
property int oldIdx: -1
|
property int oldIdx: -1
|
||||||
|
|
||||||
|
//animate index change
|
||||||
onIdxChanged: {
|
onIdxChanged: {
|
||||||
|
if (delegateItem.drag.target != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (oldIdx < 0) {
|
if (oldIdx < 0) {
|
||||||
oldIdx = idx;
|
oldIdx = idx;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delegateItem.x = ((oldIdx % 4) * GridView.view.cellWidth) - ((idx % 4) * GridView.view.cellWidth);
|
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);
|
delegateItem.y = (Math.floor(oldIdx / 4) * GridView.view.cellHeight) - (Math.floor(idx / 4) * GridView.view.cellHeight);
|
||||||
if (!delegateItem.drag.target) {
|
|
||||||
translAnim.running = true;
|
translAnim.running = true;
|
||||||
}
|
|
||||||
oldIdx = idx;
|
oldIdx = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NumberAnimation {
|
NumberAnimation {
|
||||||
id: translAnim
|
id: translAnim
|
||||||
duration: units.longDuration
|
duration: units.longDuration
|
||||||
|
|
@ -34,22 +40,37 @@ Item {
|
||||||
}
|
}
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: delegateItem
|
id: delegateItem
|
||||||
property int oldX
|
|
||||||
property int oldY
|
|
||||||
width: applicationsView.cellWidth
|
width: applicationsView.cellWidth
|
||||||
height: width
|
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 {
|
||||||
duration: units.shortDuration
|
duration: units.longDuration
|
||||||
easing.type: Easing.InOutQuad
|
easing.type: Easing.InOutQuad
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onXChanged: {
|
states: [
|
||||||
oldX = x
|
State {
|
||||||
oldY = y
|
when: delegateItem.drag.target != null
|
||||||
|
ParentChange {
|
||||||
|
target: delegateItem
|
||||||
|
parent: delegateRoot.parent
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
function updateRow() {
|
||||||
|
var pos = mapToItem(delegateRoot.parent, 0, 0);
|
||||||
|
|
||||||
|
var newRow = (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));
|
||||||
|
|
||||||
|
if (model.ApplicationOriginalRowRole != newRow) {
|
||||||
|
appListModel.moveItem(model.ApplicationOriginalRowRole, newRow);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
console.log("Clicked: " + model.ApplicationStorageIdRole)
|
console.log("Clicked: " + model.ApplicationStorageIdRole)
|
||||||
appListModel.runApplication(model.ApplicationStorageIdRole)
|
appListModel.runApplication(model.ApplicationStorageIdRole)
|
||||||
|
|
@ -57,20 +78,35 @@ Item {
|
||||||
oldY = y
|
oldY = y
|
||||||
}
|
}
|
||||||
onPressAndHold: {
|
onPressAndHold: {
|
||||||
|
delegateRoot.GridView.view.draggingItem = delegateItem;
|
||||||
delegateItem.drag.target = delegateItem;
|
delegateItem.drag.target = delegateItem;
|
||||||
root.reorderingApps = true;
|
root.reorderingApps = true;
|
||||||
}
|
}
|
||||||
onReleased: {
|
onReleased: {
|
||||||
|
delegateRoot.GridView.view.draggingItem = delegateItem;
|
||||||
delegateItem.drag.target = null;
|
delegateItem.drag.target = null;
|
||||||
root.reorderingApps = false;
|
root.reorderingApps = false;
|
||||||
|
|
||||||
translAnim.running = true
|
translAnim.running = true;
|
||||||
|
autoScrollTimer.running = false;
|
||||||
}
|
}
|
||||||
onPositionChanged: {
|
onPositionChanged: {
|
||||||
if (delegateItem.drag.target) {
|
if (!autoScrollTimer.running && delegateItem.drag.target) {
|
||||||
var pos = mapToItem(delegateRoot.parent, 0, 0);
|
updateRow();
|
||||||
|
|
||||||
appListModel.moveItem(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)));
|
var screenPos = mapToItem(delegateRoot.GridView.view, 0, 0);
|
||||||
|
|
||||||
|
if (applicationsView.contentY > 0 && screenPos.y < root.height / 4) {
|
||||||
|
autoScrollTimer.scrollDown = false;
|
||||||
|
autoScrollTimer.running = true;
|
||||||
|
} else if (!applicationsView.atYEnd && screenPos.y > 3 * (root.height / 4)) {
|
||||||
|
autoScrollTimer.scrollDown = true;
|
||||||
|
autoScrollTimer.running = true;
|
||||||
|
} else {
|
||||||
|
autoScrollTimer.running = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
autoScrollTimer.running = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,20 @@ Item {
|
||||||
id: appListModel
|
id: appListModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: autoScrollTimer
|
||||||
|
property bool scrollDown: true
|
||||||
|
repeat: true
|
||||||
|
interval: 10
|
||||||
|
onTriggered: {
|
||||||
|
applicationsView.contentY += scrollDown ? 8 : -8;
|
||||||
|
if (applicationsView.draggingItem) {
|
||||||
|
applicationsView.draggingItem.y += scrollDown ? 8 : -8;
|
||||||
|
|
||||||
|
applicationsView.draggingItem.updateRow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Containment.onAppletAdded: {
|
Containment.onAppletAdded: {
|
||||||
var container = appletContainerComponent.createObject(appletsSpace.layout)
|
var container = appletContainerComponent.createObject(appletsSpace.layout)
|
||||||
container.visible = true
|
container.visible = true
|
||||||
|
|
@ -92,6 +106,8 @@ Item {
|
||||||
right: parent.right
|
right: parent.right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property Item draggingItem
|
||||||
|
|
||||||
cellWidth: root.buttonHeight
|
cellWidth: root.buttonHeight
|
||||||
cellHeight: cellWidth
|
cellHeight: cellWidth
|
||||||
model: appListModel
|
model: appListModel
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue