QElectroTech 0.200.1-dev
Loading...
Searching...
No Matches
CropAreaWidget Class Reference

The CropAreaWidget class Displays the image scaled to fit a reasonable dialog size, with a draggable, resizable crop rectangle overlaid on top – the area outside it dimmed, the usual visual convention for "this part goes away" during a crop, so it's never ambiguous which region survives. All internal geometry (the crop rect, drag handling, hit-testing) works in display-space pixel coordinates; only cropRect() converts back to the original, full-resolution image's own coordinates for the caller, the same original-vs-display distinction already used for colour sampling in ImageTransparentColorDialog. More...

#include <imagecropdialog.h>

Inherits QWidget.

Collaboration diagram for CropAreaWidget:
Collaboration graph

Public Slots

void resetToFullImage ()
 CropAreaWidget::resetToFullImage.

Signals

void cropRectChanged ()

Public Member Functions

 CropAreaWidget (const QImage &sourceImage, const QRect &initialCropRect=QRect(), QWidget *parent=nullptr)
 CropAreaWidget::CropAreaWidget.
QRect cropRect () const
 CropAreaWidget::cropRect.

Protected Member Functions

void paintEvent (QPaintEvent *event) override
 CropAreaWidget::paintEvent Draws the image, dims everything outside the crop rect (four strips around it, rather than one overlay with a hole cut out of it, since that would need a more involved clip/composition setup for no real benefit here), then the rect's own dashed border and its eight handles.
void mousePressEvent (QMouseEvent *event) override
void mouseMoveEvent (QMouseEvent *event) override
void mouseReleaseEvent (QMouseEvent *event) override

Private Types

enum class  DragMode {
  None , Move , ResizeN , ResizeS ,
  ResizeE , ResizeW , ResizeNE , ResizeNW ,
  ResizeSE , ResizeSW
}

Private Member Functions

DragMode handleAt (const QPoint &pos) const
 CropAreaWidget::handleAt.
void applyDrag (const QPoint &pos)
 CropAreaWidget::applyDrag Recomputes m_cropRect from m_dragStartRect plus however far pos has moved from m_dragStartPos, according to m_dragMode – always clamped to stay within the displayed image and never smaller than MIN_CROP_SIZE, so the rect can never escape its bounds or collapse to nothing while being dragged.

Private Attributes

QImage m_source
qreal m_displayScale = 1.0
QRect m_displayImageRect
QRect m_cropRect
DragMode m_dragMode = DragMode::None
QPoint m_dragStartPos
QRect m_dragStartRect

Static Private Attributes

static constexpr int HANDLE_SIZE = 8
static constexpr int MIN_CROP_SIZE = 16

Detailed Description

The CropAreaWidget class Displays the image scaled to fit a reasonable dialog size, with a draggable, resizable crop rectangle overlaid on top – the area outside it dimmed, the usual visual convention for "this part goes away" during a crop, so it's never ambiguous which region survives. All internal geometry (the crop rect, drag handling, hit-testing) works in display-space pixel coordinates; only cropRect() converts back to the original, full-resolution image's own coordinates for the caller, the same original-vs-display distinction already used for colour sampling in ImageTransparentColorDialog.

Member Enumeration Documentation

◆ DragMode

enum class CropAreaWidget::DragMode
strongprivate
Enumerator
None 
Move 
ResizeN 
ResizeS 
ResizeE 
ResizeW 
ResizeNE 
ResizeNW 
ResizeSE 
ResizeSW 

Constructor & Destructor Documentation

◆ CropAreaWidget()

CropAreaWidget::CropAreaWidget ( const QImage & sourceImage,
const QRect & initialCropRect = QRect(),
QWidget * parent = nullptr )
explicit

CropAreaWidget::CropAreaWidget.

Parameters
sourceImagethe full, uncropped image to crop from
initialCropRecta previously-chosen crop rectangle, in sourceImage's own coordinates, to start from – an empty (default-constructed) QRect means "no previous crop", i.e. start covering the whole image.
sourceImagethe full-resolution image to crop
initialCropRecta previously-chosen crop rect (in sourceImage's own coordinates), or an empty QRect to start covering the whole image
parent

Member Function Documentation

◆ applyDrag()

void CropAreaWidget::applyDrag ( const QPoint & pos)
private

CropAreaWidget::applyDrag Recomputes m_cropRect from m_dragStartRect plus however far pos has moved from m_dragStartPos, according to m_dragMode – always clamped to stay within the displayed image and never smaller than MIN_CROP_SIZE, so the rect can never escape its bounds or collapse to nothing while being dragged.

Parameters
poscurrent widget-space mouse position
Here is the caller graph for this function:

◆ cropRect()

QRect CropAreaWidget::cropRect ( ) const

CropAreaWidget::cropRect.

The current crop rectangle, in the original image's own coordinates (not display-space) – always clamped to the image's own bounds and never degenerate (zero width/height).

Returns
the crop rectangle in the original, full-resolution image's own coordinates – m_cropRect itself is display-space only.

◆ cropRectChanged

void CropAreaWidget::cropRectChanged ( )
signal
Here is the caller graph for this function:

◆ handleAt()

CropAreaWidget::DragMode CropAreaWidget::handleAt ( const QPoint & pos) const
private

CropAreaWidget::handleAt.

Parameters
poswidget-space position to test
Returns
whichever handle (or the rect's own interior, for moving) pos is close enough to, or DragMode::None if it's not near anything
Here is the caller graph for this function:

◆ mouseMoveEvent()

void CropAreaWidget::mouseMoveEvent ( QMouseEvent * event)
overrideprotected
Here is the call graph for this function:

◆ mousePressEvent()

void CropAreaWidget::mousePressEvent ( QMouseEvent * event)
overrideprotected
Here is the call graph for this function:

◆ mouseReleaseEvent()

void CropAreaWidget::mouseReleaseEvent ( QMouseEvent * event)
overrideprotected

◆ paintEvent()

void CropAreaWidget::paintEvent ( QPaintEvent * event)
overrideprotected

CropAreaWidget::paintEvent Draws the image, dims everything outside the crop rect (four strips around it, rather than one overlay with a hole cut out of it, since that would need a more involved clip/composition setup for no real benefit here), then the rect's own dashed border and its eight handles.

◆ resetToFullImage

void CropAreaWidget::resetToFullImage ( )
slot

CropAreaWidget::resetToFullImage.

Resets the crop rectangle back to covering the entire image – the direct answer to "I want to undo the crop, not just adjust it", since dragging every handle back out by hand to exactly the original extent is needlessly fiddly.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ HANDLE_SIZE

int CropAreaWidget::HANDLE_SIZE = 8
staticconstexprprivate

◆ m_cropRect

QRect CropAreaWidget::m_cropRect
private

◆ m_displayImageRect

QRect CropAreaWidget::m_displayImageRect
private

◆ m_displayScale

qreal CropAreaWidget::m_displayScale = 1.0
private

◆ m_dragMode

DragMode CropAreaWidget::m_dragMode = DragMode::None
private

◆ m_dragStartPos

QPoint CropAreaWidget::m_dragStartPos
private

◆ m_dragStartRect

QRect CropAreaWidget::m_dragStartRect
private

◆ m_source

QImage CropAreaWidget::m_source
private

◆ MIN_CROP_SIZE

int CropAreaWidget::MIN_CROP_SIZE = 16
staticconstexprprivate

The documentation for this class was generated from the following files: