feat(widget-editor): resize square with shift (#4030)

port 2.0
This commit is contained in:
Huỳnh Thiện Lộc authored and GitHub committed 2026-10-30 09:09:00 -04:00
1 parent fd137f0c81
commit bca7513825
3 files changed
+19 -7

No files matched your search

@@ -183,13 +183,25 @@ QtObject {
return Qt.point(newX, newY);
}
function dragResizeTo(startWidth, startHeight, dx, dy) {
let newW = Math.max(minWidth, Math.min(startWidth + dx, screenWidth - widgetX));
let newH = Math.max(minHeight, Math.min(startHeight + dy, screenHeight - widgetY));
function dragResizeTo(startWidth, startHeight, dx, dy, squareResize = false) {
const maxWidth = screenWidth - widgetX;
const maxHeight = screenHeight - widgetY;
let newW = Math.max(minWidth, Math.min(startWidth + dx, maxWidth));
let newH = Math.max(minHeight, Math.min(startHeight + dy, maxHeight));
if (gridEnabled) {
newW = Math.max(minWidth, snapToGrid(newW));
newH = Math.max(minHeight, snapToGrid(newH));
}
if (squareResize) {
squareSnapped = true;
const minSize = Math.max(minWidth, minHeight);
const maxSquare = Math.min(maxWidth, maxHeight);
let size = Math.min(Math.max(newW, newH), maxSquare);
if (gridEnabled && size < Math.max(newW, newH))
size = Math.floor(size / gridSize) * gridSize;
size = Math.max(minSize, size);
return Qt.size(size, size);
}
if (!forceSquare) {
squareSnapped = Math.abs(newW - newH) <= (gridEnabled ? gridSize / 2 : Theme.spacingL);
if (!squareSnapped)
@@ -242,9 +242,9 @@ Item {
}
resizing = true;
}
onResizeMoved: (px, py) => {
onResizeMoved: (px, py, modifiers) => {
const current = chrome.mapToItem(root.hostLayer, px, py);
const next = geometry.dragResizeTo(startWidth, startHeight, current.x - startPos.x, current.y - startPos.y);
const next = geometry.dragResizeTo(startWidth, startHeight, current.x - startPos.x, current.y - startPos.y, !!(modifiers & Qt.ShiftModifier));
geometry.dragOverrideW = next.width;
geometry.dragOverrideH = next.height;
}
+2 -2
View File
@@ -41,7 +41,7 @@ Item {
signal optionsRequested(var anchor)
signal resizeStarted(real px, real py, int signX)
signal resizeCanceled
signal resizeMoved(real px, real py)
signal resizeMoved(real px, real py, int modifiers)
signal resizeEnded
component HitMask: Item {
@@ -195,7 +195,7 @@ Item {
if (!pressed)
return;
const p = mapToItem(root, mouse.x, mouse.y);
root.resizeMoved(p.x - root.contentInset, p.y - root.contentInset);
root.resizeMoved(p.x - root.contentInset, p.y - root.contentInset, mouse.modifiers);
}
onReleased: root.resizeEnded()
onCanceled: root.resizeCanceled()