Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolCrop Class Reference

#include <kis_tool_crop.h>

+ Inheritance diagram for KisToolCrop:

Public Types

enum  CropToolType { ImageCropType , CanvasCropType , LayerCropType , FrameCropType }
 
- Public Types inherited from KisTool
enum  { FLAG_USES_CUSTOM_PRESET =0x01 , FLAG_USES_CUSTOM_COMPOSITEOP =0x02 , FLAG_USES_CUSTOM_SIZE =0x04 }
 
enum  AlternateAction {
  ChangeSize = AlternateChangeSize , ChangeSizeSnap = AlternateChangeSizeSnap , SampleFgNode = AlternateSampleFgNode , SampleBgNode = AlternateSampleBgNode ,
  SampleFgImage = AlternateSampleFgImage , SampleBgImage = AlternateSampleBgImage , Secondary = AlternateSecondary , Third = AlternateThird ,
  Fourth = AlternateFourth , Fifth = AlternateFifth , NONE = 10000
}
 
enum  NodePaintAbility {
  VECTOR , CLONE , PAINT , UNPAINTABLE ,
  MYPAINTBRUSH_UNPAINTABLE
}
 
enum  ToolAction {
  Primary , AlternateChangeSize , AlternateChangeSizeSnap , AlternateSampleFgNode ,
  AlternateSampleBgNode , AlternateSampleFgImage , AlternateSampleBgImage , AlternateSecondary ,
  AlternateThird , AlternateFourth , AlternateFifth , Alternate_NONE = 10000
}
 

Public Slots

void activate (const QSet< KoShape * > &shapes) override
 
void crop ()
 
void deactivate () override
 
void requestRedoDuringStroke () override
 
void requestStrokeCancellation () override
 
void requestStrokeEnd () override
 
void requestUndoDuringStroke () override
 
void setAllowGrow (bool g)
 
void setCropHeight (int y)
 
void setCropType (CropToolType cropType)
 
void setCropTypeLegacy (int cropType)
 
void setCropTypeSelectable (bool selectable)
 
void setCropWidth (int x)
 
void setCropX (int x)
 
void setCropY (int y)
 
void setDecoration (int i)
 
void setGrowCenter (bool g)
 
void setLockHeight (bool lock)
 
void setLockRatio (bool lock)
 
void setLockWidth (bool lock)
 
void setRatio (double ratio)
 
void showSizeOnCanvas ()
 
void slotRectChanged ()
 
- Public Slots inherited from KisTool
void activate (const QSet< KoShape * > &shapes) override
 
void canvasResourceChanged (int key, const QVariant &res) override
 
void deactivate () override
 
virtual void updateSettingsViews ()
 
- Public Slots inherited from KoToolBase
virtual void activate (const QSet< KoShape * > &shapes)
 
virtual void deactivate ()
 
virtual void documentResourceChanged (int key, const QVariant &res)
 
virtual void repaintDecorations ()
 
virtual void requestRedoDuringStroke ()
 
virtual void requestStrokeCancellation ()
 
virtual void requestStrokeEnd ()
 
virtual void requestUndoDuringStroke ()
 
void setStatusText (const QString &statusText)
 
void updateOptionsWidgetIcons ()
 

Signals

void canGrowChanged (bool value)
 
void cropHeightChanged (int value)
 
void cropTypeChanged (int value)
 
void cropTypeSelectableChanged ()
 
void cropWidthChanged (int value)
 
void cropXChanged (int value)
 
void cropYChanged (int value)
 
void decorationChanged (int value)
 
void isCenteredChanged (bool value)
 
void lockHeightChanged (bool value)
 
void lockRatioChanged (bool value)
 
void lockWidthChanged (bool value)
 
void ratioChanged (double value)
 
- Signals inherited from KisTool
void isActiveChanged (bool isActivated)
 
- Signals inherited from KoToolBase
void activateTool (const QString &id)
 
void cursorChanged (const QCursor &cursor)
 
void selectionChanged (bool hasSelection)
 
void statusTextChanged (const QString &statusText)
 
void textModeChanged (bool inTextMode)
 

Public Member Functions

bool allowGrow () const
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void beginPrimaryDoubleClickAction (KoPointerEvent *event) override
 
void canvasResourceChanged (int key, const QVariant &res) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
QWidget * createOptionWidget () override
 
int cropHeight () const
 
CropToolType cropType () const
 
bool cropTypeSelectable () const
 
int cropWidth () const
 
int cropX () const
 
int cropY () const
 
int decoration () const
 
void endPrimaryAction (KoPointerEvent *event) override
 
bool growCenter () const
 
 KisToolCrop (KoCanvasBase *canvas)
 
bool lockHeight () const
 
bool lockRatio () const
 
bool lockWidth () const
 
void mouseMoveEvent (KoPointerEvent *e) override
 
void paint (QPainter &painter, const KoViewConverter &converter) override
 
QMenu * popupActionsMenu () override
 
double ratio () const
 
 ~KisToolCrop () override
 
- Public Member Functions inherited from KisTool
virtual void activateAlternateAction (AlternateAction action)
 
virtual void activatePrimaryAction ()
 
virtual bool alternateActionSupportsHiResEvents (AlternateAction action) const
 
virtual void beginAlternateAction (KoPointerEvent *event, AlternateAction action)
 
virtual void beginAlternateDoubleClickAction (KoPointerEvent *event, AlternateAction action)
 
virtual void continueAlternateAction (KoPointerEvent *event, AlternateAction action)
 
virtual void deactivateAlternateAction (AlternateAction action)
 
virtual void deactivatePrimaryAction ()
 
void deleteSelection () override
 
virtual void endAlternateAction (KoPointerEvent *event, AlternateAction action)
 
virtual int flags () const
 
bool isActive () const
 
 KisTool (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseDoubleClickEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
void mouseTripleClickEvent (KoPointerEvent *event) override
 
virtual void newActivationWithExternalSource (KisPaintDeviceSP externalSource)
 newActivationWithExternalSource Makes sure that the tool is active and starts a new stroke, which will be able to access the pixels from the specified external source.
 
KisTool::NodePaintAbility nodePaintAbility ()
 
virtual bool primaryActionSupportsHiResEvents () const
 
virtual bool supportsPaintingAssistants () const
 
 ~KisTool () override
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KoToolBase
QAction * action (const QString &name) const
 
KoCanvasBasecanvas () const
 Returns the canvas the tool is working on.
 
virtual void copy () const
 
QCursor cursor () const
 return the last emitted cursor
 
virtual void customMoveEvent (KoPointerEvent *event)
 
virtual void customPressEvent (KoPointerEvent *event)
 
virtual void customReleaseEvent (KoPointerEvent *event)
 
virtual void cut ()
 
virtual QRectF decorationsRect () const
 
int decorationThickness () const
 decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen magnification, thus the HiDPI settings. Note: to use this effectively, also set the pen to isCosmetic(true);
 
virtual void deselect ()
 deselect the tool should clear the selection if it has one.
 
virtual void dragLeaveEvent (QDragLeaveEvent *event)
 
virtual void dragMoveEvent (QDragMoveEvent *event, const QPointF &point)
 
virtual void dropEvent (QDropEvent *event, const QPointF &point)
 
virtual void explicitUserStrokeEndRequest ()
 explicitUserStrokeEndRequest is called by the input manager when the user presses Enter key or any equivalent. This callback comes before requestStrokeEnd(), which comes from a different source.
 
KoToolFactoryBasefactory () const
 
virtual void focusInEvent (QFocusEvent *event)
 
virtual void focusOutEvent (QFocusEvent *event)
 
virtual bool hasSelection ()
 
virtual void inputMethodEvent (QInputMethodEvent *event)
 
virtual QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 
bool isInTextMode () const
 
bool isOpacityPresetMode () const
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual bool paste ()
 
virtual KisPopupWidgetInterfacepopupWidget ()
 
virtual bool selectAll ()
 selectAll select all data the tool can select.
 
virtual KoToolSelectionselection ()
 
Q_INVOKABLE QString toolId () const
 
virtual bool wantsAutoScroll () const
 
 ~KoToolBase () override
 

Properties

int cropHeight
 
CropToolType cropType
 
bool cropTypeSelectable
 
int cropWidth
 
int cropX
 
int cropY
 
int decoration
 
bool lockHeight
 
bool lockRatio
 
bool lockWidth
 
double ratio
 
- Properties inherited from KisTool
bool isActive
 

Private Types

enum  handleType {
  None = 0 , UpperLeft = 1 , UpperRight = 2 , LowerLeft = 3 ,
  LowerRight = 4 , Upper = 5 , Lower = 6 , Left = 7 ,
  Right = 8 , Inside = 9
}
 

Private Member Functions

QRectF borderLineRect ()
 
QRectF boundingRect ()
 
void cancelStroke ()
 
void doCanvasUpdate (const QRect &updateRect)
 
void drawDecorationLine (QPainter *p, DecorationLine *decorLine, QRectF rect)
 
QPainterPath handlesPath ()
 
QRectF leftHandleRect (QRectF cropBorderRect)
 
QRectF lowerHandleRect (QRectF cropBorderRect)
 
QRectF lowerLeftHandleRect (QRectF cropBorderRect)
 
QRectF lowerRightHandleRect (QRectF cropBorderRect)
 
qint32 mouseOnHandle (const QPointF currentViewPoint)
 
void paintOutlineWithHandles (QPainter &gc)
 
 Q_ENUMS (CropToolType)
 
QRectF rightHandleRect (QRectF cropBorderRect)
 
void setMoveResizeCursor (qint32 handle)
 
bool tryContinueLastCropAction ()
 
QRectF upperHandleRect (QRectF cropBorderRect)
 
QRectF upperLeftHandleRect (QRectF cropBorderRect)
 
QRectF upperRightHandleRect (QRectF cropBorderRect)
 

Private Attributes

KisActionapplyCrop {nullptr}
 
KisActioncenterToggleOption {nullptr}
 
KConfigGroup configGroup
 
KisActiongrowToggleOption {nullptr}
 
KisActionlockHeightToggleOption {nullptr}
 
KisActionlockRatioToggleOption {nullptr}
 
KisActionlockWidthToggleOption {nullptr}
 
QScopedPointer< QMenu > m_contextMenu
 
CropToolType m_cropType {ImageCropType}
 
bool m_cropTypeSelectable {false}
 
int m_decoration {1}
 
QList< DecorationLine * > m_decorations
 
QPointF m_dragOffsetDoc
 
QPoint m_dragStart
 
KisConstrainedRect m_finalRect
 
qint32 m_handleSize {13}
 
bool m_haveCropSelection {false}
 
QRect m_initialDragRect
 
QRect m_lastCanvasUpdateRect
 
qint32 m_mouseOnHandleType {0}
 
bool m_resettingStroke {false}
 
KisToolCropConfigWidgetoptionsWidget {nullptr}
 

Additional Inherited Members

- Static Public Member Functions inherited from KisTool
static AlternateAction actionToAlternateAction (ToolAction action)
 
- Public Attributes inherited from KisTool
KoColor currentBgColor
 
float currentExposure {1.0}
 
KoColor currentFgColor
 
KisFilterConfigurationSP currentGenerator
 
KoAbstractGradientSP currentGradient
 
KoPatternSP currentPattern
 
QCursor cursor
 
bool m_isActive {false}
 
ToolMode m_mode {HOVER_MODE}
 
QWidget * optionWidget {0}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Types inherited from KisTool
enum  ToolMode : int {
  HOVER_MODE , PAINT_MODE , SECONDARY_PAINT_MODE , MIRROR_AXIS_SETUP_MODE ,
  GESTURE_MODE , PAN_MODE , OTHER , OTHER_1
}
 
- Protected Slots inherited from KisTool
virtual void resetCursorStyle ()
 
- Protected Member Functions inherited from KisTool
bool blockUntilOperationsFinished ()
 
void blockUntilOperationsFinishedForced ()
 
QPointF convertDocumentToWidget (const QPointF &pt)
 
QPoint convertToImagePixelCoordFloored (KoPointerEvent *e)
 
QPointF convertToPixelCoord (const QPointF &pt)
 
QPointF convertToPixelCoord (KoPointerEvent *e)
 
QPointF convertToPixelCoordAndAlignOnWidget (const QPointF &pt)
 
QPointF convertToPixelCoordAndSnap (const QPointF &pt, const QPointF &offset=QPointF())
 
QPointF convertToPixelCoordAndSnap (KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
 
QRectF convertToPt (const QRectF &rect)
 
qreal convertToPt (qreal value)
 
KoColor currentBgColor ()
 
KoColor currentFgColor ()
 
KisFilterConfigurationSP currentGenerator ()
 
KoAbstractGradientSP currentGradient ()
 
KisImageWSP currentImage ()
 
KisNodeSP currentNode () const
 
KisPaintOpPresetSP currentPaintOpPreset ()
 
KoPatternSP currentPattern ()
 
QCursor cursor () const
 
KisImageWSP image () const
 
virtual bool listeningToModifiers ()
 
virtual void listenToModifiers (bool listen)
 
virtual ToolMode mode () const
 
bool nodeEditable ()
 Checks checks if the current node is editable.
 
bool overrideCursorIfNotEditable ()
 Override the cursor appropriately if current node is not editable.
 
void paintToolOutline (QPainter *painter, const KisOptimizedBrushOutline &path)
 
KisOptimizedBrushOutline pixelToView (const KisOptimizedBrushOutline &path) const
 
QPainterPath pixelToView (const QPainterPath &pixelPath) const
 Convert a pixel path into a view path.
 
QPointF pixelToView (const QPoint &pixelCoord) const
 
QPointF pixelToView (const QPointF &pixelCoord) const
 Convert a floating point pixel coordinate into a view coordinate.
 
QPolygonF pixelToView (const QPolygonF &pixelPolygon) const
 Convert a pixel polygon into a view path.
 
QRectF pixelToView (const QRectF &pixelRect) const
 Convert a pixel rectangle into a view rectangle.
 
KisNodeList selectedNodes () const
 
bool selectionEditable ()
 Checks checks if the selection is editable, only applies to local selection as global selection is always editable.
 
void setCursor (const QCursor &cursor)
 
virtual void setMode (ToolMode mode)
 
void updateCanvasPixelRect (const QRectF &pixelRect)
 Update the canvas for the given rectangle in image pixel coordinates.
 
void updateCanvasViewRect (const QRectF &viewRect)
 Update the canvas for the given rectangle in view coordinates.
 
QPointF viewToPixel (const QPointF &viewCoord) const
 
QPointF widgetCenterInWidgetPixels ()
 
- Protected Member Functions inherited from KoToolBase
virtual QList< QPointer< QWidget > > createOptionWidgets ()
 
int grabSensitivity () const
 Convenience function to get the current grab sensitivity.
 
qreal handleDocRadius () const
 
QRectF handleGrabRect (const QPointF &position) const
 
QRectF handlePaintRect (const QPointF &position) const
 
int handleRadius () const
 Convenience function to get the current handle radius.
 
bool isActivated () const
 
 KoToolBase (KoToolBasePrivate &dd)
 
KoPointerEventlastDeliveredPointerEvent () const
 
void setAbstractResource (KoAbstractCanvasResourceInterfaceSP abstractResource)
 
void setConverter (KoDerivedResourceConverterSP converter)
 
void setIsOpacityPresetMode (bool value)
 
void setMaskSyntheticEvents (bool value)
 
void setTextMode (bool value)
 
QHash< int, KoAbstractCanvasResourceInterfaceSPtoolAbstractResources ()
 
QHash< int, KoDerivedResourceConverterSPtoolConverters ()
 
void useCursor (const QCursor &cursor)
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 

Detailed Description

Crop tool

Definition at line 36 of file kis_tool_crop.h.

Member Enumeration Documentation

◆ CropToolType

Enumerator
ImageCropType 
CanvasCropType 
LayerCropType 
FrameCropType 

Definition at line 54 of file kis_tool_crop.h.

◆ handleType

Enumerator
None 
UpperLeft 
UpperRight 
LowerLeft 
LowerRight 
Upper 
Lower 
Left 
Right 
Inside 

Definition at line 190 of file kis_tool_crop.h.

190 {
191 None = 0,
192 UpperLeft = 1,
193 UpperRight = 2,
194 LowerLeft = 3,
195 LowerRight = 4,
196 Upper = 5,
197 Lower = 6,
198 Left = 7,
199 Right = 8,
200 Inside = 9
201 };

Constructor & Destructor Documentation

◆ KisToolCrop()

KisToolCrop::KisToolCrop ( KoCanvasBase * canvas)

Definition at line 96 of file kis_tool_crop.cc.

97 : KisTool(canvas, KisCursor::load("tool_crop_cursor.png", 6, 6))
98{
99 setObjectName("tool_crop");
100 m_handleSize = 13;
101 m_haveCropSelection = false;
102 m_cropTypeSelectable = false;
104 m_decoration = 1;
105
106 connect(&m_finalRect, SIGNAL(sigValuesChanged()), SLOT(slotRectChanged()));
107 connect(&m_finalRect, SIGNAL(sigLockValuesChanged()), SLOT(slotRectChanged()));
108
109 // context menu options (mirrors tool options)
110 m_contextMenu.reset(new QMenu());
111 applyCrop = new KisAction(i18n("Crop"));
112
113 centerToggleOption = new KisAction(i18n("Center"));
114 centerToggleOption->setCheckable(true);
115
116 growToggleOption = new KisAction(i18nc("Grow as in crop tool", "Grow"));
117 growToggleOption->setCheckable(true);
118
119 lockWidthToggleOption = new KisAction(i18n("Lock Width"));
120 lockWidthToggleOption->setCheckable(true);
121
122 lockHeightToggleOption = new KisAction(i18n("Lock Height"));
123 lockHeightToggleOption->setCheckable(true);
124
125 lockRatioToggleOption = new KisAction(i18n("Lock Ratio"));
126 lockRatioToggleOption->setCheckable(true);
127}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
static QCursor load(const QString &cursorName, int hotspotX=-1, int hotspotY=-1)
KisAction * lockRatioToggleOption
void slotRectChanged()
bool m_cropTypeSelectable
KisAction * centerToggleOption
KisAction * lockHeightToggleOption
CropToolType m_cropType
qint32 m_handleSize
bool m_haveCropSelection
KisAction * applyCrop
KisAction * growToggleOption
QScopedPointer< QMenu > m_contextMenu
KisAction * lockWidthToggleOption
KisConstrainedRect m_finalRect
KisTool(KoCanvasBase *canvas, const QCursor &cursor)
Definition kis_tool.cc:78
KisCanvas2 * canvas

References applyCrop, centerToggleOption, connect(), growToggleOption, ImageCropType, lockHeightToggleOption, lockRatioToggleOption, lockWidthToggleOption, m_contextMenu, m_cropType, m_cropTypeSelectable, m_decoration, m_finalRect, m_handleSize, m_haveCropSelection, and slotRectChanged().

◆ ~KisToolCrop()

KisToolCrop::~KisToolCrop ( )
override

Member Function Documentation

◆ activate

void KisToolCrop::activate ( const QSet< KoShape * > & shapes)
overrideslot

Definition at line 139 of file kis_tool_crop.cc.

140{
141
142 KisTool::activate(shapes);
143 configGroup = KSharedConfig::openConfig()->group(toolId()); // save settings to kritarc
144
145 KisResourcesSnapshotSP resources =
146 new KisResourcesSnapshot(image(), currentNode(), this->canvas()->resourceManager());
147
148
149 // load settings from configuration
150 setGrowCenter(configGroup.readEntry("growCenter", false));
151 setAllowGrow(configGroup.readEntry("allowGrow", true));
152
153 // Default: thirds decoration
154 setDecoration(configGroup.readEntry("decoration", 1));
155
156 // Default: crop the entire image
157 setCropType(CropToolType(configGroup.readEntry("cropType", 0)));
158
160
161 KisSelectionSP sel = resources->activeSelection();
162 if (sel) {
163 m_haveCropSelection = true;
165 }
166 useCursor(cursor());
167
168 //pixel layer
169 if(resources->currentNode() && resources->currentNode()->paintDevice()) {
171 }
172 //vector layer
173 else {
176 }
178 }
179 connect(&m_finalRect, SIGNAL(sigValuesChanged()), SLOT(showSizeOnCanvas()));
180}
void setRectInitial(const QRect &rect)
void setCropRect(const QRect &cropRect)
The KisResourcesSnapshot class takes a snapshot of the various resources like colors and settings use...
KisSelectionSP activeSelection() const
void setAllowGrow(bool g)
void setGrowCenter(bool g)
void setCropType(CropToolType cropType)
void setDecoration(int i)
KConfigGroup configGroup
void showSizeOnCanvas()
void setCropTypeSelectable(bool selectable)
Q_INVOKABLE QString toolId() const
void useCursor(const QCursor &cursor)
#define bounds(x, a, b)
virtual KisPaintDeviceSP paintDevice() const =0
QRect selectedExactRect() const
Slow, but exact way of determining the rectangle that encloses the selection.
KisNodeSP currentNode() const
Definition kis_tool.cc:370
void activate(const QSet< KoShape * > &shapes) override
Definition kis_tool.cc:93
KisImageWSP image() const
Definition kis_tool.cc:332
QCursor cursor
Definition kis_tool.cc:64

References KisTool::activate(), KisResourcesSnapshot::activeSelection(), bounds, Private::canvas, CanvasCropType, configGroup, connect(), KisResourcesSnapshot::currentNode(), KisTool::currentNode(), KisTool::cursor, KisTool::image(), ImageCropType, m_cropType, m_finalRect, m_haveCropSelection, KisBaseNode::paintDevice(), KisSelection::selectedExactRect(), setAllowGrow(), KisConstrainedRect::setCropRect(), setCropType(), setCropTypeSelectable(), setDecoration(), setGrowCenter(), KisConstrainedRect::setRectInitial(), showSizeOnCanvas(), KoToolBase::toolId(), and KoToolBase::useCursor().

◆ allowGrow()

bool KisToolCrop::allowGrow ( ) const

Definition at line 668 of file kis_tool_crop.cc.

669{
670 return m_finalRect.canGrow();
671}

References KisConstrainedRect::canGrow(), and m_finalRect.

◆ beginPrimaryAction()

void KisToolCrop::beginPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when a primary action for the tool is started. The event stores the original event that started the stroke. The event is accepted by default. If the tool decides to ignore this particular action (e.g. when the node is not editable), it should call event->ignore(). Then no further continuePrimaryAction() or endPrimaryAction() will be called until the next user action.

Reimplemented from KisTool.

Definition at line 271 of file kis_tool_crop.cc.

272{
275
276 const QPointF imagePoint = convertToPixelCoord(event);
278
281 QPointF snapDocPoint = image()->pixelToDocument(snapPoint);
282 m_dragOffsetDoc = snapDocPoint - event->point;
283 } else {
284 m_dragOffsetDoc = QPointF();
285 }
286
287 QPointF snappedPoint = convertToPixelCoordAndSnap(event, m_dragOffsetDoc);
288
289 m_dragStart = snappedPoint.toPoint();
290 m_resettingStroke = false;
291
294 const int initialWidth = m_finalRect.widthLocked() ? m_finalRect.rect().width() : 1;
295 const int initialHeight = m_finalRect.heightLocked() ? m_finalRect.rect().height() : 1;
296 const QRect initialRect = QRect(m_dragStart, QSize(initialWidth, initialHeight));
297 m_finalRect.setRectInitial(initialRect);
298 m_initialDragRect = initialRect;
300 m_resettingStroke = true;
301 } else {
303 }
304}
QPointF handleSnapPoint(HandleType handle, const QPointF &cursorPos)
QPointF pixelToDocument(const QPointF &pixelCoord) const
QRect bounds() const override
bool m_resettingStroke
QRect m_lastCanvasUpdateRect
QRect m_initialDragRect
qint32 mouseOnHandle(const QPointF currentViewPoint)
QPoint m_dragStart
qint32 m_mouseOnHandleType
QPointF m_dragOffsetDoc
QPointF convertToPixelCoord(KoPointerEvent *e)
Definition kis_tool.cc:189
QPointF pixelToView(const QPoint &pixelCoord) const
Definition kis_tool.cc:269
@ PAINT_MODE
Definition kis_tool.h:300
QPointF convertToPixelCoordAndSnap(KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
Definition kis_tool.cc:214
virtual void setMode(ToolMode mode)
Definition kis_tool.cc:403

References KisImage::bounds(), bounds, KisTool::convertToPixelCoord(), KisTool::convertToPixelCoordAndSnap(), KisConstrainedRect::Creation, KisConstrainedRect::handleSnapPoint(), KisConstrainedRect::heightLocked(), KisTool::image(), m_dragOffsetDoc, m_dragStart, m_finalRect, m_haveCropSelection, m_initialDragRect, m_lastCanvasUpdateRect, m_mouseOnHandleType, m_resettingStroke, mouseOnHandle(), KisConstrainedRect::None, None, KisTool::PAINT_MODE, KisImage::pixelToDocument(), KisTool::pixelToView(), KisConstrainedRect::rect(), KisConstrainedRect::setCropRect(), KisTool::setMode(), KisConstrainedRect::setRectInitial(), and KisConstrainedRect::widthLocked().

◆ beginPrimaryDoubleClickAction()

void KisToolCrop::beginPrimaryDoubleClickAction ( KoPointerEvent * event)
overridevirtual

The same as beginPrimaryAction(), but called when the stroke is started by a double-click

See also
beginPrimaryAction()

Reimplemented from KisTool.

Definition at line 397 of file kis_tool_crop.cc.

398{
400
401 // this action will have no continuation
402 event->ignore();
403}

References crop(), and m_haveCropSelection.

◆ borderLineRect()

QRectF KisToolCrop::borderLineRect ( )
private

Definition at line 410 of file kis_tool_crop.cc.

411{
412 QRectF borderRect = pixelToView(m_finalRect.rect());
413
414 // Draw the border line right next to the crop rectangle perimeter.
416
417 return borderRect;
418}
#define HALF_BORDER_LINE_WIDTH

References HALF_BORDER_LINE_WIDTH, m_finalRect, KisTool::pixelToView(), and KisConstrainedRect::rect().

◆ boundingRect()

QRectF KisToolCrop::boundingRect ( )
private

Definition at line 895 of file kis_tool_crop.cc.

896{
897 QRectF rect = handlesPath().boundingRect();
899 return rect;
900}
QPainterPath handlesPath()
#define HANDLE_BORDER_LINE_WIDTH

References HANDLE_BORDER_LINE_WIDTH, and handlesPath().

◆ cancelStroke()

void KisToolCrop::cancelStroke ( )
private

Definition at line 182 of file kis_tool_crop.cc.

183{
184 m_haveCropSelection = false;
185 useCursor(cursor());
187}
void doCanvasUpdate(const QRect &updateRect)

References bounds, KisTool::cursor, doCanvasUpdate(), KisTool::image(), m_haveCropSelection, and KoToolBase::useCursor().

◆ canGrowChanged

void KisToolCrop::canGrowChanged ( bool value)
signal

◆ canvasResourceChanged()

void KisToolCrop::canvasResourceChanged ( int key,
const QVariant & res )
overridevirtual

This method is called whenever a property in the resource provider associated with the canvas this tool belongs to changes. An example is currently selected foreground color.

Reimplemented from KoToolBase.

Definition at line 215 of file kis_tool_crop.cc.

216{
218
219 //pixel layer
220 if(currentNode() && currentNode()->paintDevice()) {
222 }
223 //vector layer
224 else {
227 }
229 }
230}
void canvasResourceChanged(int key, const QVariant &res) override
Definition kis_tool.cc:139

References CanvasCropType, KisTool::canvasResourceChanged(), KisTool::currentNode(), ImageCropType, m_cropType, setCropType(), and setCropTypeSelectable().

◆ continuePrimaryAction()

void KisToolCrop::continuePrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is in progress of pointer movement. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 306 of file kis_tool_crop.cc.

307{
309
310 const QPointF pos = convertToPixelCoordAndSnap(event, m_dragOffsetDoc);
311 const QPoint drag = pos.toPoint() - m_dragStart;
312
314}
void moveHandle(HandleType handle, const QPoint &offset, const QRect &oldRect)
#define CHECK_MODE_SANITY_OR_RETURN(_mode)
Definition kis_tool.h:27

References CHECK_MODE_SANITY_OR_RETURN, KisTool::convertToPixelCoordAndSnap(), m_dragOffsetDoc, m_dragStart, m_finalRect, m_initialDragRect, m_mouseOnHandleType, KisConstrainedRect::moveHandle(), and KisTool::PAINT_MODE.

◆ createOptionWidget()

QWidget * KisToolCrop::createOptionWidget ( )
overridevirtual

Reimplement this if your tool actually has an option widget. Sets the option widget to 0 by default.

Reimplemented from KisTool.

Definition at line 732 of file kis_tool_crop.cc.

733{
735 // See https://bugs.kde.org/show_bug.cgi?id=316896
736 QWidget *specialSpacer = new QWidget(optionsWidget);
737 specialSpacer->setObjectName("SpecialSpacer");
738 specialSpacer->setFixedSize(0, 0);
739 optionsWidget->layout()->addWidget(specialSpacer);
740
741 Q_CHECK_PTR(optionsWidget);
742 optionsWidget->setObjectName(toolId() + " option widget");
743
744 connect(optionsWidget->bnCrop, SIGNAL(clicked()), this, SLOT(crop()));
745
746 connect(optionsWidget, SIGNAL(cropTypeChanged(int)), this, SLOT(setCropTypeLegacy(int)));
747 connect(optionsWidget, SIGNAL(cropXChanged(int)), this, SLOT(setCropX(int)));
748 connect(optionsWidget, SIGNAL(cropYChanged(int)), this, SLOT(setCropY(int)));
749 connect(optionsWidget, SIGNAL(cropHeightChanged(int)), this, SLOT(setCropHeight(int)));
750 connect(optionsWidget, SIGNAL(lockHeightChanged(bool)), this, SLOT(setLockHeight(bool)));
751 connect(optionsWidget, SIGNAL(cropWidthChanged(int)), this, SLOT(setCropWidth(int)));
752 connect(optionsWidget, SIGNAL(lockWidthChanged(bool)), this, SLOT(setLockWidth(bool)));
753 connect(optionsWidget, SIGNAL(ratioChanged(double)), this, SLOT(setRatio(double)));
754 connect(optionsWidget, SIGNAL(lockRatioChanged(bool)), this, SLOT(setLockRatio(bool)));
755 connect(optionsWidget, SIGNAL(decorationChanged(int)), this, SLOT(setDecoration(int)));
756 connect(optionsWidget, SIGNAL(allowGrowChanged(bool)), this, SLOT(setAllowGrow(bool)));
757 connect(optionsWidget, SIGNAL(growCenterChanged(bool)), this, SLOT(setGrowCenter(bool)));
758
759 optionsWidget->setFixedHeight(optionsWidget->sizeHint().height());
760
761 connect(applyCrop, SIGNAL(triggered(bool)), this, SLOT(crop()));
762 connect(centerToggleOption, SIGNAL(triggered(bool)), this, SLOT(setGrowCenter(bool)));
763 connect(growToggleOption, SIGNAL(triggered(bool)), this, SLOT(setAllowGrow(bool)));
764 connect(lockWidthToggleOption, SIGNAL(triggered(bool)), this, SLOT(setLockWidth(bool)));
765 connect(lockHeightToggleOption, SIGNAL(triggered(bool)), this, SLOT(setLockHeight(bool)));
766 connect(lockRatioToggleOption, SIGNAL(triggered(bool)), this, SLOT(setLockRatio(bool)));
767
768 return optionsWidget;
769}
void cropWidthChanged(int value)
void setLockHeight(bool lock)
void setCropHeight(int y)
void decorationChanged(int value)
void setCropX(int x)
void cropTypeChanged(int value)
void ratioChanged(double value)
void setCropTypeLegacy(int cropType)
void cropXChanged(int value)
KisToolCropConfigWidget * optionsWidget
void setRatio(double ratio)
void lockRatioChanged(bool value)
void cropYChanged(int value)
void setCropWidth(int x)
void cropHeightChanged(int value)
void setCropY(int y)
void lockHeightChanged(bool value)
void setLockWidth(bool lock)
void lockWidthChanged(bool value)
void setLockRatio(bool lock)

References applyCrop, centerToggleOption, connect(), crop(), cropHeightChanged(), cropTypeChanged(), cropWidthChanged(), cropXChanged(), cropYChanged(), decorationChanged(), growToggleOption, lockHeightChanged(), lockHeightToggleOption, lockRatioChanged(), lockRatioToggleOption, lockWidthChanged(), lockWidthToggleOption, optionsWidget, ratioChanged(), setAllowGrow(), setCropHeight(), setCropTypeLegacy(), setCropWidth(), setCropX(), setCropY(), setDecoration(), setGrowCenter(), setLockHeight(), setLockRatio(), setLockWidth(), setRatio(), and KoToolBase::toolId().

◆ crop

void KisToolCrop::crop ( )
slot

Definition at line 458 of file kis_tool_crop.cc.

459{
461 if (m_finalRect.rect().isEmpty()) return;
462
463 const bool imageCrop = m_cropType == ImageCropType || m_cropType == CanvasCropType;
464
465 if (!imageCrop) {
466 //Cropping layer
467 if (!nodeEditable()) {
468 return;
469 }
470 }
471
472 m_haveCropSelection = false;
473 useCursor(cursor());
474
475 QRect cropRect = m_finalRect.rect();
476
477 // The visitor adds the undo steps to the macro
478 if (imageCrop || !currentNode()->paintDevice()) {
479 if (m_cropType == CanvasCropType) {
480 currentImage()->resizeImage(cropRect);
481 } else {
482 currentImage()->cropImage(cropRect);
483 }
484 } else {
486 }
487}
void resizeImage(const QRect &newRect)
start asynchronous operation on resizing the image
Definition kis_image.cc:865
void cropNode(KisNodeSP node, const QRect &newRect, const bool activeFrameOnly=false)
start asynchronous operation on cropping a subtree of nodes starting at node
Definition kis_image.cc:931
void cropImage(const QRect &newRect)
start asynchronous operation on cropping the image
Definition kis_image.cc:870
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
KisImageWSP currentImage()
Definition kis_tool.cc:393
bool nodeEditable()
Checks checks if the current node is editable.
Definition kis_tool.cc:651

References CanvasCropType, KisImage::cropImage(), KisImage::cropNode(), KisTool::currentImage(), KisTool::currentNode(), KisTool::cursor, FrameCropType, ImageCropType, KIS_ASSERT_RECOVER_RETURN, m_cropType, m_finalRect, m_haveCropSelection, KisTool::nodeEditable(), KisConstrainedRect::rect(), KisImage::resizeImage(), and KoToolBase::useCursor().

◆ cropHeight()

int KisToolCrop::cropHeight ( ) const

Definition at line 644 of file kis_tool_crop.cc.

645{
646 return m_finalRect.rect().height();
647}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropHeightChanged

void KisToolCrop::cropHeightChanged ( int value)
signal

◆ cropType()

KisToolCrop::CropToolType KisToolCrop::cropType ( ) const

Definition at line 505 of file kis_tool_crop.cc.

506{
507 return m_cropType;
508}

References m_cropType.

◆ cropTypeChanged

void KisToolCrop::cropTypeChanged ( int value)
signal

◆ cropTypeSelectable()

bool KisToolCrop::cropTypeSelectable ( ) const

Definition at line 518 of file kis_tool_crop.cc.

519{
521}

References m_cropTypeSelectable.

◆ cropTypeSelectableChanged

void KisToolCrop::cropTypeSelectableChanged ( )
signal

◆ cropWidth()

int KisToolCrop::cropWidth ( ) const

Definition at line 616 of file kis_tool_crop.cc.

617{
618 return m_finalRect.rect().width();
619}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropWidthChanged

void KisToolCrop::cropWidthChanged ( int value)
signal

◆ cropX()

int KisToolCrop::cropX ( ) const

Definition at line 578 of file kis_tool_crop.cc.

579{
580 return m_finalRect.rect().x();
581}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropXChanged

void KisToolCrop::cropXChanged ( int value)
signal

◆ cropY()

int KisToolCrop::cropY ( ) const

Definition at line 598 of file kis_tool_crop.cc.

599{
600 return m_finalRect.rect().y();
601}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropYChanged

void KisToolCrop::cropYChanged ( int value)
signal

◆ deactivate

void KisToolCrop::deactivate ( )
overrideslot

Definition at line 189 of file kis_tool_crop.cc.

190{
191 cancelStroke();
193}
void cancelStroke()
void deactivate() override
Definition kis_tool.cc:131

References cancelStroke(), and KisTool::deactivate().

◆ decoration()

int KisToolCrop::decoration ( ) const

Definition at line 523 of file kis_tool_crop.cc.

524{
525 return m_decoration;
526}

References m_decoration.

◆ decorationChanged

void KisToolCrop::decorationChanged ( int value)
signal

◆ doCanvasUpdate()

void KisToolCrop::doCanvasUpdate ( const QRect & updateRect)
private

Definition at line 540 of file kis_tool_crop.cc.

541{
543 m_lastCanvasUpdateRect = updateRect;
544}
void updateCanvasViewRect(const QRectF &viewRect)
Update the canvas for the given rectangle in view coordinates.
Definition kis_tool.cc:327

References m_lastCanvasUpdateRect, and KisTool::updateCanvasViewRect().

◆ drawDecorationLine()

void KisToolCrop::drawDecorationLine ( QPainter * p,
DecorationLine * decorLine,
QRectF rect )
private

Definition at line 902 of file kis_tool_crop.cc.

903{
904 QPointF start = rect.topLeft();
905 QPointF end = rect.topLeft();
906 qreal small = qMin(rect.width(), rect.height());
907 qreal large = qMax(rect.width(), rect.height());
908
909 switch (decorLine->startXRelation) {
911 start.setX(start.x() + decorLine->start.x() * rect.width());
912 break;
914 start.setX(start.x() + decorLine->start.x() * rect.height());
915 break;
917 start.setX(start.x() + decorLine->start.x() * small);
918 break;
920 start.setX(start.x() + decorLine->start.x() * large);
921 break;
922 }
923
924 switch (decorLine->startYRelation) {
926 start.setY(start.y() + decorLine->start.y() * rect.width());
927 break;
929 start.setY(start.y() + decorLine->start.y() * rect.height());
930 break;
932 start.setY(start.y() + decorLine->start.y() * small);
933 break;
935 start.setY(start.y() + decorLine->start.y() * large);
936 break;
937 }
938
939 switch (decorLine->endXRelation) {
941 end.setX(end.x() + decorLine->end.x() * rect.width());
942 break;
944 end.setX(end.x() + decorLine->end.x() * rect.height());
945 break;
947 end.setX(end.x() + decorLine->end.x() * small);
948 break;
950 end.setX(end.x() + decorLine->end.x() * large);
951 break;
952 }
953
954 switch (decorLine->endYRelation) {
956 end.setY(end.y() + decorLine->end.y() * rect.width());
957 break;
959 end.setY(end.y() + decorLine->end.y() * rect.height());
960 break;
962 end.setY(end.y() + decorLine->end.y() * small);
963 break;
965 end.setY(end.y() + decorLine->end.y() * large);
966 break;
967 }
968
969 p->drawLine(start, end);
970}
const Params2D p
Relation endYRelation
Relation startXRelation
Relation endXRelation
Relation startYRelation

References DecorationLine::end, DecorationLine::endXRelation, DecorationLine::endYRelation, DecorationLine::Height, DecorationLine::Largest, p, DecorationLine::Smallest, DecorationLine::start, DecorationLine::startXRelation, DecorationLine::startYRelation, and DecorationLine::Width.

◆ endPrimaryAction()

void KisToolCrop::endPrimaryAction ( KoPointerEvent * event)
overridevirtual

Called by KisToolProxy when the primary action is being finished, that is while mouseRelease or tabletRelease event. If the tool has ignored the event in beginPrimaryAction(), this method will not be called.

Reimplemented from KisTool.

Definition at line 351 of file kis_tool_crop.cc.

352{
355
356 QRectF viewCropRect = pixelToView(m_finalRect.rect());
357 const bool haveValidRect =
358 viewCropRect.width() > m_handleSize &&
359 viewCropRect.height() > m_handleSize;
360
361
362 if (!m_haveCropSelection && !haveValidRect) {
365 m_haveCropSelection = true;
366 }
367 } else if (m_resettingStroke && !haveValidRect) {
369 m_haveCropSelection = false;
370 } else {
371 m_haveCropSelection = true;
372 }
373
375
378}
bool tryContinueLastCropAction()
void setMoveResizeCursor(qint32 handle)
@ HOVER_MODE
Definition kis_tool.h:299

References KisImage::bounds(), bounds, CHECK_MODE_SANITY_OR_RETURN, KisTool::convertToPixelCoordAndSnap(), KisTool::HOVER_MODE, KisTool::image(), m_dragOffsetDoc, m_finalRect, m_handleSize, m_haveCropSelection, m_lastCanvasUpdateRect, m_resettingStroke, mouseOnHandle(), KisConstrainedRect::normalize(), KisTool::PAINT_MODE, KisTool::pixelToView(), KisConstrainedRect::rect(), KisTool::setMode(), setMoveResizeCursor(), KisConstrainedRect::setRectInitial(), and tryContinueLastCropAction().

◆ growCenter()

bool KisToolCrop::growCenter ( ) const

Definition at line 683 of file kis_tool_crop.cc.

684{
685 return m_finalRect.centered();
686}

References KisConstrainedRect::centered(), and m_finalRect.

◆ handlesPath()

QPainterPath KisToolCrop::handlesPath ( )
private

Definition at line 811 of file kis_tool_crop.cc.

812{
813 QRectF cropBorderRect = borderLineRect();
814 QPainterPath path;
815
816 path.addRect(upperLeftHandleRect(cropBorderRect));
817 path.addRect(upperRightHandleRect(cropBorderRect));
818 path.addRect(lowerLeftHandleRect(cropBorderRect));
819 path.addRect(lowerRightHandleRect(cropBorderRect));
820 path.addRect(upperHandleRect(cropBorderRect));
821 path.addRect(lowerHandleRect(cropBorderRect));
822 path.addRect(leftHandleRect(cropBorderRect));
823 path.addRect(rightHandleRect(cropBorderRect));
824
825 return path;
826}
QRectF lowerRightHandleRect(QRectF cropBorderRect)
QRectF upperRightHandleRect(QRectF cropBorderRect)
QRectF lowerLeftHandleRect(QRectF cropBorderRect)
QRectF upperHandleRect(QRectF cropBorderRect)
QRectF leftHandleRect(QRectF cropBorderRect)
QRectF borderLineRect()
QRectF rightHandleRect(QRectF cropBorderRect)
QRectF lowerHandleRect(QRectF cropBorderRect)
QRectF upperLeftHandleRect(QRectF cropBorderRect)

References borderLineRect(), leftHandleRect(), lowerHandleRect(), lowerLeftHandleRect(), lowerRightHandleRect(), rightHandleRect(), upperHandleRect(), upperLeftHandleRect(), and upperRightHandleRect().

◆ isCenteredChanged

void KisToolCrop::isCenteredChanged ( bool value)
signal

◆ leftHandleRect()

QRectF KisToolCrop::leftHandleRect ( QRectF cropBorderRect)
private

Definition at line 806 of file kis_tool_crop.cc.

807{
808 return QRectF(cropBorderRect.left() - m_handleSize / 2.0, cropBorderRect.top() + (cropBorderRect.height() - m_handleSize) / 2.0, m_handleSize, m_handleSize);
809}

References m_handleSize.

◆ lockHeight()

bool KisToolCrop::lockHeight ( ) const

Definition at line 654 of file kis_tool_crop.cc.

655{
656 return m_finalRect.heightLocked();
657}

References KisConstrainedRect::heightLocked(), and m_finalRect.

◆ lockHeightChanged

void KisToolCrop::lockHeightChanged ( bool value)
signal

◆ lockRatio()

bool KisToolCrop::lockRatio ( ) const

Definition at line 711 of file kis_tool_crop.cc.

712{
713 return m_finalRect.ratioLocked();
714}

References m_finalRect, and KisConstrainedRect::ratioLocked().

◆ lockRatioChanged

void KisToolCrop::lockRatioChanged ( bool value)
signal

◆ lockWidth()

bool KisToolCrop::lockWidth ( ) const

Definition at line 626 of file kis_tool_crop.cc.

627{
628 return m_finalRect.widthLocked();
629}

References m_finalRect, and KisConstrainedRect::widthLocked().

◆ lockWidthChanged

void KisToolCrop::lockWidthChanged ( bool value)
signal

◆ lowerHandleRect()

QRectF KisToolCrop::lowerHandleRect ( QRectF cropBorderRect)
private

Definition at line 791 of file kis_tool_crop.cc.

792{
793 return QRectF(cropBorderRect.left() + (cropBorderRect.width() - m_handleSize) / 2.0 , cropBorderRect.bottom() - m_handleSize / 2.0, m_handleSize, m_handleSize);
794}

References m_handleSize.

◆ lowerLeftHandleRect()

QRectF KisToolCrop::lowerLeftHandleRect ( QRectF cropBorderRect)
private

Definition at line 781 of file kis_tool_crop.cc.

782{
783 return QRectF(cropBorderRect.left() - m_handleSize / 2.0 , cropBorderRect.bottom() - m_handleSize / 2.0, m_handleSize, m_handleSize);
784}

References m_handleSize.

◆ lowerRightHandleRect()

QRectF KisToolCrop::lowerRightHandleRect ( QRectF cropBorderRect)
private

Definition at line 771 of file kis_tool_crop.cc.

772{
773 return QRectF(cropBorderRect.right() - m_handleSize / 2.0, cropBorderRect.bottom() - m_handleSize / 2.0, m_handleSize, m_handleSize);
774}

References m_handleSize.

◆ mouseMoveEvent()

void KisToolCrop::mouseMoveEvent ( KoPointerEvent * event)
overridevirtual

Called when the mouse or stylus moved over the canvas. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus move

Reimplemented from KisTool.

Definition at line 380 of file kis_tool_crop.cc.

381{
382 QPointF pos = convertToPixelCoordAndSnap(event);
383
384 if (m_haveCropSelection) { //if the crop selection is set
385 //set resize cursor if we are on one of the handles
386 if(mode() == KisTool::PAINT_MODE) {
387 //keep the same cursor as the one we clicked with
389 }else{
390 //hovering
391 qint32 type = mouseOnHandle(pixelToView(pos));
393 }
394 }
395}
virtual ToolMode mode() const
Definition kis_tool.cc:407

References KisTool::convertToPixelCoordAndSnap(), m_haveCropSelection, m_mouseOnHandleType, KisTool::mode(), mouseOnHandle(), KisTool::PAINT_MODE, KisTool::pixelToView(), and setMoveResizeCursor().

◆ mouseOnHandle()

qint32 KisToolCrop::mouseOnHandle ( const QPointF currentViewPoint)
private

Definition at line 828 of file kis_tool_crop.cc.

829{
830 QRectF borderRect = borderLineRect();
831 qint32 handleType = None;
832
833 if (!m_haveCropSelection) {
834 return None;
835 }
836
837 if (upperLeftHandleRect(borderRect).contains(currentViewPoint)) {
839 } else if (lowerLeftHandleRect(borderRect).contains(currentViewPoint)) {
841 } else if (upperRightHandleRect(borderRect).contains(currentViewPoint)) {
843 } else if (lowerRightHandleRect(borderRect).contains(currentViewPoint)) {
845 } else if (upperHandleRect(borderRect).contains(currentViewPoint)) {
847 } else if (lowerHandleRect(borderRect).contains(currentViewPoint)) {
849 } else if (leftHandleRect(borderRect).contains(currentViewPoint)) {
851 } else if (rightHandleRect(borderRect).contains(currentViewPoint)) {
853 } else if (borderRect.contains(currentViewPoint)) {
855 }
856
857 return handleType;
858}

References borderLineRect(), Inside, Left, leftHandleRect(), Lower, lowerHandleRect(), LowerLeft, lowerLeftHandleRect(), LowerRight, lowerRightHandleRect(), m_haveCropSelection, None, Right, rightHandleRect(), Upper, upperHandleRect(), UpperLeft, upperLeftHandleRect(), UpperRight, and upperRightHandleRect().

◆ paint()

void KisToolCrop::paint ( QPainter & painter,
const KoViewConverter & converter )
overridevirtual

Called by the canvas to paint any decorations that the tool deems needed. The painter has the top left of the canvas as its origin.

Parameters
painterused for painting the shape
converterto convert between internal and view coordinates.

Implements KoToolBase.

Definition at line 232 of file kis_tool_crop.cc.

233{
234 Q_UNUSED(converter);
236}
void paintOutlineWithHandles(QPainter &gc)

References paintOutlineWithHandles().

◆ paintOutlineWithHandles()

void KisToolCrop::paintOutlineWithHandles ( QPainter & gc)
private

Definition at line 422 of file kis_tool_crop.cc.

423{
425 gc.save();
426
427 QRectF wholeImageRect = pixelToView(image()->bounds());
428 QRectF borderRect = borderLineRect();
429
430 QPainterPath path;
431
432 path.addRect(wholeImageRect);
433 path.addRect(borderRect);
434 gc.setPen(Qt::NoPen);
435 gc.setBrush(QColor(0, 0, 0, OUTSIDE_CROP_ALPHA));
436 gc.drawPath(path);
437
438 // Handles
439 QPen pen(Qt::SolidLine);
441 pen.setColor(Qt::black);
442 pen.setCosmetic(true);
443 gc.setPen(pen);
444 gc.setBrush(QColor(200, 200, 200, OUTSIDE_CROP_ALPHA));
445 gc.drawPath(handlesPath());
446
447 gc.setClipRect(borderRect, Qt::IntersectClip);
448
449 if (m_decoration > 0) {
450 for (int i = decorsIndex[m_decoration-1]; i<decorsIndex[m_decoration]; i++) {
451 drawDecorationLine(&gc, &(decors[i]), borderRect);
452 }
453 }
454 gc.restore();
455 }
456}
void drawDecorationLine(QPainter *p, DecorationLine *decorLine, QRectF rect)
int decorationThickness() const
decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen ...
#define OUTSIDE_CROP_ALPHA
DecorationLine decors[20]
const int decorsIndex[DECORATION_COUNT]

References borderLineRect(), bounds, Private::canvas, KoToolBase::decorationThickness(), decors, decorsIndex, drawDecorationLine(), HANDLE_BORDER_LINE_WIDTH, handlesPath(), KisTool::image(), m_decoration, m_haveCropSelection, KisTool::mode(), OUTSIDE_CROP_ALPHA, KisTool::PAINT_MODE, and KisTool::pixelToView().

◆ popupActionsMenu()

QMenu * KisToolCrop::popupActionsMenu ( )
overridevirtual
Returns
a menu with context-aware actions for the current selection. If the returned value is null, no context menu is shown.

Reimplemented from KoToolBase.

Definition at line 238 of file kis_tool_crop.cc.

239{
240 if (m_contextMenu) {
241 // Sync state of context menu toggles with state of Tool Options toggles
242 centerToggleOption->setChecked(growCenter());
243 growToggleOption->setChecked(allowGrow());
244 lockWidthToggleOption->setChecked(lockWidth());
245 lockHeightToggleOption->setChecked(lockHeight());
246 lockRatioToggleOption->setChecked(lockRatio());
247
248 m_contextMenu->clear();
249
250 m_contextMenu->addSection(i18n("Crop Tool Actions"));
251 m_contextMenu->addSeparator();
252
253 if (m_haveCropSelection) { // can't crop if there is no selection
254 m_contextMenu->addAction(applyCrop);
255 m_contextMenu->addSeparator();
256 }
257
260
261 m_contextMenu->addSeparator();
262
266 }
267
268 return m_contextMenu.data();
269}
bool growCenter() const
bool allowGrow() const

References allowGrow(), applyCrop, centerToggleOption, growCenter(), growToggleOption, lockHeight, lockHeightToggleOption, lockRatio, lockRatioToggleOption, lockWidth, lockWidthToggleOption, m_contextMenu, and m_haveCropSelection.

◆ Q_ENUMS()

KisToolCrop::Q_ENUMS ( CropToolType )
private

◆ ratio()

double KisToolCrop::ratio ( ) const

Definition at line 701 of file kis_tool_crop.cc.

702{
703 return m_finalRect.ratio();
704}

References m_finalRect, and KisConstrainedRect::ratio().

◆ ratioChanged

void KisToolCrop::ratioChanged ( double value)
signal

◆ requestRedoDuringStroke

void KisToolCrop::requestRedoDuringStroke ( )
overrideslot

Definition at line 210 of file kis_tool_crop.cc.

211{
212 cancelStroke();
213}

References cancelStroke().

◆ requestStrokeCancellation

void KisToolCrop::requestStrokeCancellation ( )
overrideslot

Definition at line 200 of file kis_tool_crop.cc.

201{
202 cancelStroke();
203}

References cancelStroke().

◆ requestStrokeEnd

void KisToolCrop::requestStrokeEnd ( )
overrideslot

Definition at line 195 of file kis_tool_crop.cc.

196{
198}

References crop(), and m_haveCropSelection.

◆ requestUndoDuringStroke

void KisToolCrop::requestUndoDuringStroke ( )
overrideslot

Definition at line 205 of file kis_tool_crop.cc.

206{
207 cancelStroke();
208}

References cancelStroke().

◆ rightHandleRect()

QRectF KisToolCrop::rightHandleRect ( QRectF cropBorderRect)
private

Definition at line 796 of file kis_tool_crop.cc.

797{
798 return QRectF(cropBorderRect.right() - m_handleSize / 2.0 , cropBorderRect.top() + (cropBorderRect.height() - m_handleSize) / 2.0, m_handleSize, m_handleSize);
799}

References m_handleSize.

◆ setAllowGrow

void KisToolCrop::setAllowGrow ( bool g)
slot

Definition at line 659 of file kis_tool_crop.cc.

660{
663 configGroup.writeEntry("allowGrow", g);
664
665 Q_EMIT canGrowChanged(g);
666}
void setCanGrow(bool value)
void canGrowChanged(bool value)

References bounds, canGrowChanged(), configGroup, KisTool::image(), m_finalRect, KisConstrainedRect::setCanGrow(), and KisConstrainedRect::setCropRect().

◆ setCropHeight

void KisToolCrop::setCropHeight ( int y)
slot

◆ setCropType

void KisToolCrop::setCropType ( KisToolCrop::CropToolType cropType)
slot

Definition at line 494 of file kis_tool_crop.cc.

495{
496 if(m_cropType == cropType)
497 return;
499
500 configGroup.writeEntry("cropType", static_cast<int>(cropType));
501
503}
CropToolType cropType

References configGroup, cropType, cropTypeChanged(), and m_cropType.

◆ setCropTypeLegacy

void KisToolCrop::setCropTypeLegacy ( int cropType)
slot

Definition at line 489 of file kis_tool_crop.cc.

490{
492}

References cropType, and setCropType().

◆ setCropTypeSelectable

void KisToolCrop::setCropTypeSelectable ( bool selectable)
slot

Definition at line 510 of file kis_tool_crop.cc.

511{
512 if(selectable == m_cropTypeSelectable)
513 return;
514 m_cropTypeSelectable = selectable;
516}
void cropTypeSelectableChanged()

References cropTypeSelectableChanged(), and m_cropTypeSelectable.

◆ setCropWidth

void KisToolCrop::setCropWidth ( int x)
slot

◆ setCropX

void KisToolCrop::setCropX ( int x)
slot

Definition at line 563 of file kis_tool_crop.cc.

564{
565 if(x == m_finalRect.rect().x())
566 return;
567
568 if (!m_haveCropSelection) {
569 m_haveCropSelection = true;
571 }
572
573 QPoint offset = m_finalRect.rect().topLeft();
574 offset.setX(x);
575 m_finalRect.setOffset(offset);
576}
void setOffset(const QPoint &offset)

References bounds, KisTool::image(), m_finalRect, m_haveCropSelection, KisConstrainedRect::rect(), KisConstrainedRect::setOffset(), and KisConstrainedRect::setRectInitial().

◆ setCropY

void KisToolCrop::setCropY ( int y)
slot

Definition at line 583 of file kis_tool_crop.cc.

584{
585 if(y == m_finalRect.rect().y())
586 return;
587
588 if (!m_haveCropSelection) {
589 m_haveCropSelection = true;
591 }
592
593 QPoint offset = m_finalRect.rect().topLeft();
594 offset.setY(y);
595 m_finalRect.setOffset(offset);
596}

References bounds, KisTool::image(), m_finalRect, m_haveCropSelection, KisConstrainedRect::rect(), KisConstrainedRect::setOffset(), and KisConstrainedRect::setRectInitial().

◆ setDecoration

void KisToolCrop::setDecoration ( int i)
slot

Definition at line 528 of file kis_tool_crop.cc.

529{
530 // This shouldn't happen, but safety first
531 if(i < 0 || i > DECORATION_COUNT)
532 return;
533 m_decoration = i;
536
537 configGroup.writeEntry("decoration", i);
538}
QRectF boundingRect()
#define DECORATION_COUNT

References boundingRect(), configGroup, decoration, DECORATION_COUNT, decorationChanged(), m_decoration, and KisTool::updateCanvasViewRect().

◆ setGrowCenter

void KisToolCrop::setGrowCenter ( bool g)
slot

Definition at line 673 of file kis_tool_crop.cc.

674{
676
677
678 configGroup.writeEntry("growCenter", value);
679
680 Q_EMIT isCenteredChanged(value);
681}
float value(const T *src, size_t ch)
void setCentered(bool value)
void isCenteredChanged(bool value)

References configGroup, isCenteredChanged(), m_finalRect, KisConstrainedRect::setCentered(), and value().

◆ setLockHeight

void KisToolCrop::setLockHeight ( bool lock)
slot

Definition at line 649 of file kis_tool_crop.cc.

650{
652}
void setHeightLocked(bool value)

References m_finalRect, and KisConstrainedRect::setHeightLocked().

◆ setLockRatio

void KisToolCrop::setLockRatio ( bool lock)
slot

Definition at line 706 of file kis_tool_crop.cc.

707{
709}
void setRatioLocked(bool value)

References m_finalRect, and KisConstrainedRect::setRatioLocked().

◆ setLockWidth

void KisToolCrop::setLockWidth ( bool lock)
slot

Definition at line 621 of file kis_tool_crop.cc.

622{
624}
void setWidthLocked(bool value)

References m_finalRect, and KisConstrainedRect::setWidthLocked().

◆ setMoveResizeCursor()

void KisToolCrop::setMoveResizeCursor ( qint32 handle)
private

Definition at line 860 of file kis_tool_crop.cc.

861{
862 QCursor cursorType;
863
864 switch (handle) {
865 case(UpperLeft):
866 case(LowerRight):
867 cursorType = KisCursor::sizeFDiagCursor();
868 break;
869 case(LowerLeft):
870 case(UpperRight):
871 cursorType = KisCursor::sizeBDiagCursor();
872 break;
873 case(Upper):
874 case(Lower):
875 cursorType = KisCursor::sizeVerCursor();
876 break;
877 case(Left):
878 case(Right):
879 cursorType = KisCursor::sizeHorCursor();
880 break;
881 case(Inside):
882 cursorType = KisCursor::sizeAllCursor();
883 break;
884 default:
886 cursorType = KisCursor::arrowCursor();
887 } else {
888 cursorType = cursor();
889 }
890 break;
891 }
892 useCursor(cursorType);
893}
static QCursor sizeBDiagCursor()
Definition kis_cursor.cc:74
static QCursor sizeAllCursor()
Definition kis_cursor.cc:84
static QCursor sizeHorCursor()
Definition kis_cursor.cc:69
static QCursor sizeFDiagCursor()
Definition kis_cursor.cc:79
static QCursor arrowCursor()
Definition kis_cursor.cc:24
static QCursor sizeVerCursor()
Definition kis_cursor.cc:64

References KisCursor::arrowCursor(), KisTool::cursor, Inside, Left, Lower, LowerLeft, LowerRight, m_haveCropSelection, Right, KisCursor::sizeAllCursor(), KisCursor::sizeBDiagCursor(), KisCursor::sizeFDiagCursor(), KisCursor::sizeHorCursor(), KisCursor::sizeVerCursor(), Upper, UpperLeft, UpperRight, and KoToolBase::useCursor().

◆ setRatio

void KisToolCrop::setRatio ( double ratio)
slot

◆ showSizeOnCanvas

void KisToolCrop::showSizeOnCanvas ( )
slot

Definition at line 716 of file kis_tool_crop.cc.

717{
718 KisCanvas2 *kisCanvas =dynamic_cast<KisCanvas2*>(canvas());
719 Q_ASSERT(kisCanvas);
720 if(m_mouseOnHandleType == 9) {
721 kisCanvas->viewManager()->showFloatingMessage(i18n("X: %1\nY: %2"
722 , optionsWidget->intX->text(), optionsWidget->intY->text())
723 , QIcon(), 1000, KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
724 }
725 else {
726 kisCanvas->viewManager()->showFloatingMessage(i18n("Width: %1\nHeight: %2"
727 , optionsWidget->intWidth->text(), optionsWidget->intHeight->text())
728 , QIcon(), 1000, KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
729 }
730}
KisViewManager * viewManager() const
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas

References Private::canvas, KisFloatingMessage::High, m_mouseOnHandleType, optionsWidget, KisViewManager::showFloatingMessage(), and KisCanvas2::viewManager().

◆ slotRectChanged

◆ tryContinueLastCropAction()

bool KisToolCrop::tryContinueLastCropAction ( )
private

Definition at line 316 of file kis_tool_crop.cc.

317{
318 bool result = false;
319
320 const KUndo2Command *lastCommand = image()->undoAdapter()->presentCommand();
321 const KisCropSavedExtraData *data = 0;
322
323 if ((lastCommand = image()->undoAdapter()->presentCommand()) &&
324 (data = dynamic_cast<const KisCropSavedExtraData*>(lastCommand->extraData()))) {
325
326 bool cropImageConsistent =
330
331 bool cropLayerConsistent =
334 currentNode() == data->cropNode();
335
336
337 if (cropImageConsistent || cropLayerConsistent) {
339 image()->waitForDone();
340
342 m_haveCropSelection = true;
343
344 result = true;
345 }
346 }
347
348 return result;
349}
KUndo2CommandExtraData * extraData() const
KisUndoAdapter * undoAdapter() const
void waitForDone()
virtual void undoLastCommand()=0
virtual const KUndo2Command * presentCommand()=0

References KisCropSavedExtraData::CROP_IMAGE, KisCropSavedExtraData::CROP_LAYER, KisCropSavedExtraData::cropNode(), KisCropSavedExtraData::cropRect(), KisTool::currentNode(), KUndo2Command::extraData(), KisTool::image(), ImageCropType, LayerCropType, m_cropType, m_finalRect, m_haveCropSelection, KisUndoAdapter::presentCommand(), KisCropSavedExtraData::RESIZE_IMAGE, KisConstrainedRect::setRectInitial(), KisCropSavedExtraData::type(), KisImage::undoAdapter(), KisUndoAdapter::undoLastCommand(), and KisImage::waitForDone().

◆ upperHandleRect()

QRectF KisToolCrop::upperHandleRect ( QRectF cropBorderRect)
private

Definition at line 801 of file kis_tool_crop.cc.

802{
803 return QRectF(cropBorderRect.left() + (cropBorderRect.width() - m_handleSize) / 2.0 , cropBorderRect.top() - m_handleSize / 2.0, m_handleSize, m_handleSize);
804}

References m_handleSize.

◆ upperLeftHandleRect()

QRectF KisToolCrop::upperLeftHandleRect ( QRectF cropBorderRect)
private

Definition at line 786 of file kis_tool_crop.cc.

787{
788 return QRectF(cropBorderRect.left() - m_handleSize / 2.0, cropBorderRect.top() - m_handleSize / 2.0, m_handleSize, m_handleSize);
789}

References m_handleSize.

◆ upperRightHandleRect()

QRectF KisToolCrop::upperRightHandleRect ( QRectF cropBorderRect)
private

Definition at line 776 of file kis_tool_crop.cc.

777{
778 return QRectF(cropBorderRect.right() - m_handleSize / 2.0 , cropBorderRect.top() - m_handleSize / 2.0, m_handleSize, m_handleSize);
779}

References m_handleSize.

Member Data Documentation

◆ applyCrop

KisAction* KisToolCrop::applyCrop {nullptr}
private

Definition at line 183 of file kis_tool_crop.h.

183{nullptr};

◆ centerToggleOption

KisAction* KisToolCrop::centerToggleOption {nullptr}
private

Definition at line 184 of file kis_tool_crop.h.

184{nullptr};

◆ configGroup

KConfigGroup KisToolCrop::configGroup
private

Definition at line 179 of file kis_tool_crop.h.

◆ growToggleOption

KisAction* KisToolCrop::growToggleOption {nullptr}
private

Definition at line 185 of file kis_tool_crop.h.

185{nullptr};

◆ lockHeightToggleOption

KisAction* KisToolCrop::lockHeightToggleOption {nullptr}
private

Definition at line 187 of file kis_tool_crop.h.

187{nullptr};

◆ lockRatioToggleOption

KisAction* KisToolCrop::lockRatioToggleOption {nullptr}
private

Definition at line 188 of file kis_tool_crop.h.

188{nullptr};

◆ lockWidthToggleOption

KisAction* KisToolCrop::lockWidthToggleOption {nullptr}
private

Definition at line 186 of file kis_tool_crop.h.

186{nullptr};

◆ m_contextMenu

QScopedPointer<QMenu> KisToolCrop::m_contextMenu
private

Definition at line 182 of file kis_tool_crop.h.

◆ m_cropType

CropToolType KisToolCrop::m_cropType {ImageCropType}
private

Definition at line 172 of file kis_tool_crop.h.

◆ m_cropTypeSelectable

bool KisToolCrop::m_cropTypeSelectable {false}
private

Definition at line 173 of file kis_tool_crop.h.

173{false};

◆ m_decoration

int KisToolCrop::m_decoration {1}
private

Definition at line 175 of file kis_tool_crop.h.

175{1};

◆ m_decorations

QList<DecorationLine *> KisToolCrop::m_decorations
private

Definition at line 202 of file kis_tool_crop.h.

◆ m_dragOffsetDoc

QPointF KisToolCrop::m_dragOffsetDoc
private

Definition at line 206 of file kis_tool_crop.h.

◆ m_dragStart

QPoint KisToolCrop::m_dragStart
private

Definition at line 166 of file kis_tool_crop.h.

◆ m_finalRect

KisConstrainedRect KisToolCrop::m_finalRect
private

Definition at line 204 of file kis_tool_crop.h.

◆ m_handleSize

qint32 KisToolCrop::m_handleSize {13}
private

Definition at line 168 of file kis_tool_crop.h.

168{13};

◆ m_haveCropSelection

bool KisToolCrop::m_haveCropSelection {false}
private

Definition at line 169 of file kis_tool_crop.h.

169{false};

◆ m_initialDragRect

QRect KisToolCrop::m_initialDragRect
private

Definition at line 205 of file kis_tool_crop.h.

◆ m_lastCanvasUpdateRect

QRect KisToolCrop::m_lastCanvasUpdateRect
private

Definition at line 177 of file kis_tool_crop.h.

◆ m_mouseOnHandleType

qint32 KisToolCrop::m_mouseOnHandleType {0}
private

Definition at line 170 of file kis_tool_crop.h.

170{0};

◆ m_resettingStroke

bool KisToolCrop::m_resettingStroke {false}
private

Definition at line 176 of file kis_tool_crop.h.

176{false};

◆ optionsWidget

KisToolCropConfigWidget* KisToolCrop::optionsWidget {nullptr}
private

Definition at line 180 of file kis_tool_crop.h.

180{nullptr};

Property Documentation

◆ cropHeight

int KisToolCrop::cropHeight
readwrite

Definition at line 47 of file kis_tool_crop.h.

◆ cropType

CropToolType KisToolCrop::cropType
readwrite

Definition at line 41 of file kis_tool_crop.h.

◆ cropTypeSelectable

bool KisToolCrop::cropTypeSelectable
readwrite

Definition at line 42 of file kis_tool_crop.h.

◆ cropWidth

int KisToolCrop::cropWidth
readwrite

Definition at line 45 of file kis_tool_crop.h.

◆ cropX

int KisToolCrop::cropX
readwrite

Definition at line 43 of file kis_tool_crop.h.

◆ cropY

int KisToolCrop::cropY
readwrite

Definition at line 44 of file kis_tool_crop.h.

◆ decoration

int KisToolCrop::decoration
readwrite

Definition at line 51 of file kis_tool_crop.h.

◆ lockHeight

bool KisToolCrop::lockHeight
readwrite

Definition at line 48 of file kis_tool_crop.h.

◆ lockRatio

bool KisToolCrop::lockRatio
readwrite

Definition at line 50 of file kis_tool_crop.h.

◆ lockWidth

bool KisToolCrop::lockWidth
readwrite

Definition at line 46 of file kis_tool_crop.h.

◆ ratio

double KisToolCrop::ratio
readwrite

Definition at line 49 of file kis_tool_crop.h.


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