2 import QtQuick.Controls 2.15
3 import QtQuick.Shapes 1.15
8 property int cellSize: 20
9 property int snapDistance: 5
11 property int rows: height / cellSize
12 property int columns: width / cellSize
14 function snapPosition(point) {
15 var snappedX = Math.round(point.x / snapGrid.cellSize) * snapGrid.cellSize;
16 var snappedY = Math.round(point.y / snapGrid.cellSize) * snapGrid.cellSize;
19 Math.abs(point.x - snappedX) > snapGrid.snapDistance ? point.x : snappedX,
20 Math.abs(point.y - snappedY) > snapGrid.snapDistance ? point.y : snappedY);
24 var snapped = Math.round(x / snapGrid.cellSize) * snapGrid.cellSize;
25 return Math.abs(x - snapped) > snapGrid.snapDistance ? x : snapped;
29 var snapped = Math.round(y / snapGrid.cellSize) * snapGrid.cellSize;
30 return Math.abs(y - snapped) > snapGrid.snapDistance ? y : snapped;
38 startY: snapGrid.cellSize * index
39 strokeColor:
"#eeeeee"
42 y: snapGrid.cellSize * index
49 model: snapGrid.columns
52 startX: snapGrid.cellSize * index
54 strokeColor:
"#eeeeee"
56 x: snapGrid.cellSize * index