mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-30 15:07:49 -04:00
feat(widget-editor): resize square with shift (#4030)
port 2.0
(cherry picked from commit bca7513825)
This commit is contained in:
1 parent
921c036032
commit
82f8e00358
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;
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user