Make mask drag expand current selection

This commit is contained in:
easyz committed 2026-03-25 23:23:40 +08:00
1 parent 1efdf4dbad
commit 0249f652a3
2 files changed
+59 -6

No files matched your search

+51 -1
View File
@@ -6,8 +6,12 @@ QtObject {
property rect area: Qt.rect(0, 0, 0, 0)
property rect initialArea: Qt.rect(0, 0, 0, 0)
property point dragOffset: Qt.point(0, 0)
property string dragMode: "none" // none | select | move
property string dragMode: "none" // none | select | move | expand
property var coordinateItem: null
property bool expandLeft: false
property bool expandRight: false
property bool expandTop: false
property bool expandBottom: false
readonly property rect localArea: {
if (!coordinateItem)
@@ -102,6 +106,22 @@ QtObject {
initialArea = area
}
function beginExpand(ax, ay) {
const bounds = getNormalizedRectBounds(area)
if (!bounds.isValid) {
beginSelection(ax, ay)
return
}
dragMode = "expand"
initialArea = Qt.rect(bounds.left, bounds.top, bounds.width, bounds.height)
area = initialArea
expandLeft = ax < bounds.left
expandRight = ax > bounds.right
expandTop = ay < bounds.top
expandBottom = ay > bounds.bottom
}
function updateMove(ax, ay) {
const dx = ax - dragOffset.x
const dy = ay - dragOffset.y
@@ -126,6 +146,28 @@ QtObject {
)
}
function updateExpand(ax, ay) {
const bounds = getNormalizedRectBounds(initialArea)
if (!bounds.isValid)
return
let left = bounds.left
let right = bounds.right
let top = bounds.top
let bottom = bounds.bottom
if (expandLeft)
left = Math.min(ax, right)
if (expandRight)
right = Math.max(ax, left)
if (expandTop)
top = Math.min(ay, bottom)
if (expandBottom)
bottom = Math.max(ay, top)
area = Qt.rect(left, top, right - left, bottom - top)
}
function normalizeCurrentArea() {
const bounds = getNormalizedRectBounds(area)
if (bounds.isValid) {
@@ -136,6 +178,10 @@ QtObject {
function endInteraction() {
dragMode = "none"
expandLeft = false
expandRight = false
expandTop = false
expandBottom = false
}
function reset() {
@@ -143,5 +189,9 @@ QtObject {
initialArea = Qt.rect(0, 0, 0, 0)
dragOffset = Qt.point(0, 0)
dragMode = "none"
expandLeft = false
expandRight = false
expandTop = false
expandBottom = false
}
}
+8 -5
View File
@@ -116,11 +116,8 @@ Window {
tool.visible = false
resizeHandleGroup.visible = false
hideTextEditor()
var winRect = O_ScreenCapture.windowAtPoint(ax, ay)
highlightRect = winRect.width > 0
? Qt.rect(winRect.x, winRect.y, winRect.width, winRect.height)
: Qt.rect(0, 0, 0, 0)
selectionOverlay.beginSelection(ax, ay)
highlightRect = Qt.rect(0, 0, 0, 0)
selectionOverlay.beginExpand(ax, ay)
return
}
@@ -155,6 +152,12 @@ Window {
if (dragMode === "select") {
selectionOverlay.updateSelection(ax, ay, modifiers)
if (tool.visible) tool.visible = false
return
}
if (dragMode === "expand") {
selectionOverlay.updateExpand(ax, ay)
if (tool.visible) tool.visible = false
}
}