Skip to content

Commit f481ba1

Browse files
committed
Refactor: [ResizeMouseArea]移动到[DelResizeMouseArea].
1 parent a21bc5f commit f481ba1

File tree

11 files changed

+413
-388
lines changed

11 files changed

+413
-388
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.16)
22

3-
project(ResizeMouseArea VERSION 1.0 LANGUAGES CXX)
3+
project(DelResizeMouseArea VERSION 1.0 LANGUAGES CXX)
44

55
set(CMAKE_AUTOMOC ON)
66
set(CMAKE_AUTORCC ON)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import QtQuick 2.15
2+
3+
MouseArea {
4+
id: root
5+
6+
property var target: undefined
7+
property real minimumX: Number.NaN
8+
property real maximumX: Number.NaN
9+
property real minimumY: Number.NaN
10+
property real maximumY: Number.NaN
11+
12+
QtObject {
13+
id: __private
14+
property point startPos: Qt.point(0, 0)
15+
property point offsetPos: Qt.point(0, 0)
16+
}
17+
18+
onClicked: (mouse) => mouse.accepted = false;
19+
onPressed:
20+
(mouse) => {
21+
__private.startPos = Qt.point(mouse.x, mouse.y);
22+
cursorShape = Qt.SizeAllCursor;
23+
}
24+
onReleased:
25+
(mouse) => {
26+
__private.startPos = Qt.point(mouse.x, mouse.y);
27+
cursorShape = Qt.ArrowCursor;
28+
}
29+
onPositionChanged:
30+
(mouse) => {
31+
if (pressed) {
32+
__private.offsetPos = Qt.point(mouse.x - __private.startPos.x, mouse.y - __private.startPos.y);
33+
if (target) {
34+
// x
35+
if (minimumX != Number.NaN && minimumX > (target.x + __private.offsetPos.x)) {
36+
target.x = minimumX;
37+
} else if (maximumX != Number.NaN && maximumX < (target.x + __private.offsetPos.x)) {
38+
target.x = maximumX;
39+
} else {
40+
target.x = target.x + __private.offsetPos.x;
41+
}
42+
// y
43+
if (minimumY != Number.NaN && minimumY > (target.y + __private.offsetPos.y)) {
44+
target.y = minimumY;
45+
} else if (maximumY != Number.NaN && maximumY < (target.y + __private.offsetPos.y)) {
46+
target.y = maximumY;
47+
} else {
48+
target.y = target.y + __private.offsetPos.y;
49+
}
50+
}
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)