添加拖拽调整选区大小支持

pull/5/head
柚子 4 years ago committed by GitHub
parent d9aa34c3db
commit 03d597b0d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,40 @@
import QtQuick 2.9
import QtQuick.Controls 2.0
Item {
id: root
property alias containsMouse: mouseArea.containsMouse
signal posChange(int xOffset, int yOffset)
implicitWidth: 12 //12
implicitHeight: 12 //12
property int posType: Qt.ArrowCursor
//5.10, qmlint
readonly property int posLeftTop: Qt.SizeFDiagCursor
readonly property int posLeftBottom: Qt.SizeBDiagCursor
readonly property int posRightTop: Qt.SizeBDiagCursor
readonly property int posRightBottom: Qt.SizeFDiagCursor
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
property int lastX: 0
property int lastY: 0
onContainsMouseChanged: {
if (containsMouse) {
cursorShape = posType;
} else {
cursorShape = Qt.ArrowCursor;
}
}
onPressedChanged: {
if (containsPress) {
lastX = mouseX;
lastY = mouseY;
}
}
onPositionChanged: {
if (pressed) {
posChange(mouseX - lastX, mouseY - lastY)
}
}
}
}

@ -0,0 +1,29 @@
import QtQuick 2.9
MouseArea {
id: root
property real lastX: 0
property real lastY: 0
property bool mask: false //mask false
property var control: parent //control parentxy
onPressed: {
lastX = mouseX;
lastY = mouseY;
}
onContainsMouseChanged: { //
if (containsMouse) {
cursorShape = Qt.SizeAllCursor;
} else {
cursorShape = Qt.ArrowCursor;
}
}
onPositionChanged: {
if (!mask && pressed && control)
{
control.x +=mouseX - lastX
control.y +=mouseY - lastY
}
}
}

@ -0,0 +1,62 @@
import QtQuick 2.7
import FishUI 1.0 as FishUI
Rectangle {
id: root
color: "transparent"
border.width: 2
border.color: FishUI.Theme.highlightColor
width: parent.width
height: parent.height
property var control: parent
DragRect {
posType: posLeftTop
onPosChange: {
//
if (control.x + xOffset < control.x + control.width)
control.x += xOffset;
if (control.y + yOffset < control.y + control.height)
control.y += yOffset;
if (control.width - xOffset > 0)
control.width-= xOffset;
if (control.height -yOffset > 0)
control.height -= yOffset;
}
}
DragRect {
posType: posRightTop
x: parent.width - width
onPosChange: {
//xOffset
if (control.width + xOffset > 0)
control.width += xOffset;
if (control.height - yOffset > 0)
control.height -= yOffset;
if (control.y + yOffset < control.y + control.height)
control.y += yOffset;
}
}
DragRect {
posType: posLeftBottom
y: parent.height - height
onPosChange: {
if (control.x + xOffset < control.x + control.width)
control.x += xOffset;
if (control.width - xOffset > 0)
control.width-= xOffset;
if (control.height + yOffset > 0)
control.height += yOffset;
}
}
DragRect {
posType: posRightBottom
x: parent.width - width
y: parent.height - height
onPosChange: {
if (control.width + xOffset > 0)
control.width += xOffset;
if (control.height + yOffset > 0)
control.height += yOffset;
}
}
}

@ -123,7 +123,7 @@ Item {
property int newX: 0 property int newX: 0
property int newY: 0 property int newY: 0
property var control: parent
z: 999 z: 999
height: 0 height: 0
width: 0 width: 0
@ -131,7 +131,6 @@ Item {
y: 0 y: 0
visible: false visible: false
clip: true clip: true
function reset() { function reset() {
selectLayer.x = 0 selectLayer.x = 0
selectLayer.y = 0 selectLayer.y = 0
@ -151,31 +150,14 @@ Item {
y: -selectLayer.y y: -selectLayer.y
} }
Rectangle { MoveArea {
anchors.fill: parent anchors.fill: parent
color: "transparent" control: parent
border.width: 2
border.color: FishUI.Theme.highlightColor
}
DragHandler {
target: selectLayer
xAxis.enabled: true
xAxis.minimum: control.x
xAxis.maximum: control.width - selectLayer.width
yAxis.enabled: true
yAxis.minimum: control.y
yAxis.maximum: control.height - selectLayer.height
} }
MouseArea { ResizeBorder {
id: selectLayerMouseArea control: parent
anchors.fill: parent anchors.fill: parent
cursorShape: Qt.SizeAllCursor
acceptedButtons: Qt.LeftButton
onDoubleClicked: control.save()
} }
} }
@ -328,4 +310,4 @@ Item {
} }
} }
} }
} }
Loading…
Cancel
Save