Skip to content

Helpers

app.ui.qt.widgets.preview.layer_bbox.helpers

View source code

Low-level bbox helper math for hit-testing and clamping.

These helpers are intentionally primitive operations reused by higher-level interaction and widget facade logic.

See Also

Layer: Presentation. Context: Contains concrete Qt presentation components and supporting utilities.

get_drag_mode_for_rect_at_pos(rect: QRect, pos: QPoint) -> DragMode

Identify the resize handle nearest to a pointer position.

PARAMETER DESCRIPTION
rect

Bounding rectangle whose handles are hit-tested.

TYPE: QRect

pos

Pointer position in the same widget coordinate space.

TYPE: QPoint

RETURNS DESCRIPTION
DragMode

Matching handle mode, or DragMode.NONE when no handle is hit.

clamp_rect_to_pixmap(rect: QRect, pixmap_rect: QRect) -> QRect

Clamp a rectangle to the pixmap bounds.

PARAMETER DESCRIPTION
rect

Rectangle to keep inside the displayed image area.

TYPE: QRect

pixmap_rect

Bounds of the displayed image.

TYPE: QRect

RETURNS DESCRIPTION
QRect

Normalized rectangle shifted back within the image bounds.

apply_clamped_drag_deltas(mode: DragMode, pr: QRect, x1: int, x2: int, y1: int, y2: int, dx: int, dy: int) -> QRect

Apply clamped drag deltas.

PARAMETER DESCRIPTION
mode

Active handle being dragged.

TYPE: DragMode

pr

Rectangle limiting the resulting coordinates.

TYPE: QRect

x1

Starting left coordinate.

TYPE: int

x2

Starting right coordinate.

TYPE: int

y1

Starting top coordinate.

TYPE: int

y2

Starting bottom coordinate.

TYPE: int

dx

Horizontal pointer displacement from drag start.

TYPE: int

dy

Vertical pointer displacement from drag start.

TYPE: int

RETURNS DESCRIPTION
QRect

Normalized rectangle after moving the selected edge or corner, clamped to pr.

clamp_point_to_rect(point: QPoint, r: QRect) -> QPoint

Clamp a point to the rectangle bounds.

PARAMETER DESCRIPTION
point

Point to constrain.

TYPE: QPoint

r

Rectangle defining the allowed coordinate range.

TYPE: QRect

RETURNS DESCRIPTION
QPoint

Point with x and y independently clamped to r.