-
Notifications
You must be signed in to change notification settings - Fork 1
/
ResizeHandle.qml
74 lines (63 loc) · 1.98 KB
/
ResizeHandle.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import QtQuick 2.0
Item {
id: topLeft
property var target
property bool ignoreChange: false
property real xFactor: 0.0
property real yFactor: 0.0
property real widthFactor: 0.0
property real heightFactor: 0.0
property bool forceSquare: false
property alias cursorShape: mouseArea.cursorShape
width: 48
height: 48
// Rectangle {
// anchors.centerIn: parent
// width: parent.width
// height: width
// color: "blue"
// opacity: 0.4
//// radius: width * 0.5
// }
MouseArea {
id: mouseArea
property point previousPosition
anchors.fill: parent
onPositionChanged: {
var deltaX = mouse.x - previousPosition.x;
var deltaY = mouse.y - previousPosition.y;
var biggestIsX = Math.abs(deltaX) > Math.abs(deltaY);
if(forceSquare) {
if(biggestIsX) {
deltaX = widthFactor * heightFactor * deltaY;
} else {
deltaY = widthFactor * heightFactor * deltaX;
}
}
var newX = target.x + xFactor * deltaX;
var xDiff = target.x - newX;
target.x = newX;
var newWidth = target.width + widthFactor * deltaX;
if(newWidth > 32) {
target.width = newWidth;
}
if(forceSquare && !biggestIsX) {
previousPosition.y -= deltaY;
}
var newY = target.y + yFactor * deltaY;
var yDiff = target.y - newY;
target.y = newY;
var newHeight = target.height + heightFactor * deltaY;
if(newHeight > 32) {
target.height = newHeight;
}
if(forceSquare && biggestIsX) {
previousPosition.x -= deltaX;
}
}
onPressed: {
previousPosition.x = mouse.x
previousPosition.y = mouse.y
}
}
}