Skip to content

Commit

Permalink
Working movable items in the item viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
ASxa86 committed Feb 17, 2025
1 parent 6fdc039 commit 1eb7fb0
Showing 1 changed file with 62 additions and 1 deletion.
63 changes: 62 additions & 1 deletion module/aspire/ItemView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,76 @@ Item {
property: "scale"
}

DragHandler {
id: dragHandler
acceptedButtons: Qt.MiddleButton
}

BoundaryRule on scale {
minimum: 0.5 / 100.0
maximum: 7000 / 100.0
}
}

MouseArea {
id: mouseArea

anchors.fill: parent
cursorShape: dragHandler.active || current !== null ? Qt.SizeAllCursor : Qt.ArrowCursor

property Item root: loader.item
property Item current: null
property point point: Qt.point(0, 0)

onPressed: (event) => {
if (root === null) {
return;
}

intersect(root, Qt.point(event.x, event.y));

if (current !== null) {
point = Qt.point(event.x, event.y);
}
}

onPositionChanged: (event) => {
if (current === null) {
return;
}

drag.target: container
let p = current.parent;
const start = p.mapFromItem(mouseArea, point);
const end = p.mapFromItem(mouseArea, Qt.point(event.x, event.y));
const delta = Qt.point(end.x - start.x, end.y - start.y);
current.x += delta.x;
current.y += delta.y;
point = Qt.point(event.x, event.y);
}

onReleased: {
current = null;
point = Qt.point(0, 0);
}

function intersect(parent, point) {
for (let i = 0; i < parent.children.length; i++) {
let child = parent.children[i];

intersect(child, point);

if (current !== null) {
return;
}

let pos = child.mapFromItem(mouseArea, point);

if (child.contains(pos)) {
current = child;
return;
}

}
}
}
}

0 comments on commit 1eb7fb0

Please sign in to comment.