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 ()
 
void updateDecorationColors ()
 
- 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 the Enter key or any equivalent key. 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}
 
QColor m_black {Qt::black}
 
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}
 
QColor m_transparentBlack {Qt::black}
 
QColor m_transparentGrey {QColor(200, 200, 200, 40)}
 
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 191 of file kis_tool_crop.h.

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

Constructor & Destructor Documentation

◆ KisToolCrop()

KisToolCrop::KisToolCrop ( KoCanvasBase * canvas)

Definition at line 97 of file kis_tool_crop.cc.

98 : KisTool(canvas, KisCursor::loadWithSize("tool_crop_cursor.svg", 32, 32, 6, 6))
99{
100 setObjectName("tool_crop");
101 m_handleSize = 13;
102 m_haveCropSelection = false;
103 m_cropTypeSelectable = false;
105 m_decoration = 1;
106
107 connect(&m_finalRect, SIGNAL(sigValuesChanged()), SLOT(slotRectChanged()));
108 connect(&m_finalRect, SIGNAL(sigLockValuesChanged()), SLOT(slotRectChanged()));
109
110 // context menu options (mirrors tool options)
111 m_contextMenu.reset(new QMenu());
112 applyCrop = new KisAction(i18n("Crop"));
113
114 centerToggleOption = new KisAction(i18n("Center"));
115 centerToggleOption->setCheckable(true);
116
117 growToggleOption = new KisAction(i18nc("Grow as in crop tool", "Grow"));
118 growToggleOption->setCheckable(true);
119
120 lockWidthToggleOption = new KisAction(i18n("Lock Width"));
121 lockWidthToggleOption->setCheckable(true);
122
123 lockHeightToggleOption = new KisAction(i18n("Lock Height"));
124 lockHeightToggleOption->setCheckable(true);
125
126 lockRatioToggleOption = new KisAction(i18n("Lock Ratio"));
127 lockRatioToggleOption->setCheckable(true);
128
129 KisCanvas2 *kisCanvas =dynamic_cast<KisCanvas2*>(canvas);
130 if (kisCanvas) {
131 connect(kisCanvas->displayColorConverter(), SIGNAL(displayConfigurationChanged()), this, SLOT(updateDecorationColors()));
132 }
134}
KisDisplayColorConverter displayColorConverter
static QCursor loadWithSize(const QString &cursorName, int width, int height, int hotspotX=-1, int hotspotY=-1)
KisAction * lockRatioToggleOption
void slotRectChanged()
bool m_cropTypeSelectable
KisAction * centerToggleOption
KisAction * lockHeightToggleOption
CropToolType m_cropType
void updateDecorationColors()
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, Private::canvas, centerToggleOption, KisCanvas2::displayColorConverter, growToggleOption, ImageCropType, lockHeightToggleOption, lockRatioToggleOption, lockWidthToggleOption, m_contextMenu, m_cropType, m_cropTypeSelectable, m_decoration, m_finalRect, m_handleSize, m_haveCropSelection, slotRectChanged(), and updateDecorationColors().

◆ ~KisToolCrop()

KisToolCrop::~KisToolCrop ( )
override

Member Function Documentation

◆ activate

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

Definition at line 146 of file kis_tool_crop.cc.

147{
148
149 KisTool::activate(shapes);
150 configGroup = KSharedConfig::openConfig()->group(toolId()); // save settings to kritarc
151
152 KisResourcesSnapshotSP resources =
153 new KisResourcesSnapshot(image(), currentNode(), this->canvas()->resourceManager());
154
155
156 // load settings from configuration
157 setGrowCenter(configGroup.readEntry("growCenter", false));
158 setAllowGrow(configGroup.readEntry("allowGrow", true));
159
160 // Default: thirds decoration
161 setDecoration(configGroup.readEntry("decoration", 1));
162
163 // Default: crop the entire image
164 setCropType(CropToolType(configGroup.readEntry("cropType", 0)));
165
167
168 KisSelectionSP sel = resources->activeSelection();
169 if (sel) {
170 m_haveCropSelection = true;
172 }
173 useCursor(cursor());
174
175 //pixel layer
176 if(resources->currentNode() && resources->currentNode()->paintDevice()) {
178 }
179 //vector layer
180 else {
183 }
185 }
186 connect(&m_finalRect, SIGNAL(sigValuesChanged()), SLOT(showSizeOnCanvas()));
187}
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, 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 694 of file kis_tool_crop.cc.

695{
696 return m_finalRect.canGrow();
697}

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 278 of file kis_tool_crop.cc.

279{
282
283 const QPointF imagePoint = convertToPixelCoord(event);
285
288 QPointF snapDocPoint = image()->pixelToDocument(snapPoint);
289 m_dragOffsetDoc = snapDocPoint - event->point;
290 } else {
291 m_dragOffsetDoc = QPointF();
292 }
293
294 QPointF snappedPoint = convertToPixelCoordAndSnap(event, m_dragOffsetDoc);
295
296 m_dragStart = snappedPoint.toPoint();
297 m_resettingStroke = false;
298
301 const int initialWidth = m_finalRect.widthLocked() ? m_finalRect.rect().width() : 1;
302 const int initialHeight = m_finalRect.heightLocked() ? m_finalRect.rect().height() : 1;
303 const QRect initialRect = QRect(m_dragStart, QSize(initialWidth, initialHeight));
304 m_finalRect.setRectInitial(initialRect);
305 m_initialDragRect = initialRect;
307 m_resettingStroke = true;
308 } else {
310 }
311}
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 404 of file kis_tool_crop.cc.

405{
407
408 // this action will have no continuation
409 event->ignore();
410}

References crop(), and m_haveCropSelection.

◆ borderLineRect()

QRectF KisToolCrop::borderLineRect ( )
private

Definition at line 417 of file kis_tool_crop.cc.

418{
419 QRectF borderRect = pixelToView(m_finalRect.rect());
420
421 // Draw the border line right next to the crop rectangle perimeter.
423
424 return borderRect;
425}
#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 921 of file kis_tool_crop.cc.

922{
923 QRectF rect = handlesPath().boundingRect();
925 return rect;
926}
QPainterPath handlesPath()
#define HANDLE_BORDER_LINE_WIDTH

References HANDLE_BORDER_LINE_WIDTH, and handlesPath().

◆ cancelStroke()

void KisToolCrop::cancelStroke ( )
private

Definition at line 189 of file kis_tool_crop.cc.

190{
191 m_haveCropSelection = false;
192 useCursor(cursor());
194}
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 222 of file kis_tool_crop.cc.

223{
225
226 //pixel layer
227 if(currentNode() && currentNode()->paintDevice()) {
229 }
230 //vector layer
231 else {
234 }
236 }
237}
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 313 of file kis_tool_crop.cc.

314{
316
317 const QPointF pos = convertToPixelCoordAndSnap(event, m_dragOffsetDoc);
318 const QPoint drag = pos.toPoint() - m_dragStart;
319
321}
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 758 of file kis_tool_crop.cc.

759{
761 // See https://bugs.kde.org/show_bug.cgi?id=316896
762 QWidget *specialSpacer = new QWidget(optionsWidget);
763 specialSpacer->setObjectName("SpecialSpacer");
764 specialSpacer->setFixedSize(0, 0);
765 optionsWidget->layout()->addWidget(specialSpacer);
766
767 Q_CHECK_PTR(optionsWidget);
768 optionsWidget->setObjectName(toolId() + " option widget");
769
770 connect(optionsWidget->bnCrop, SIGNAL(clicked()), this, SLOT(crop()));
771
772 connect(optionsWidget, SIGNAL(cropTypeChanged(int)), this, SLOT(setCropTypeLegacy(int)));
773 connect(optionsWidget, SIGNAL(cropXChanged(int)), this, SLOT(setCropX(int)));
774 connect(optionsWidget, SIGNAL(cropYChanged(int)), this, SLOT(setCropY(int)));
775 connect(optionsWidget, SIGNAL(cropHeightChanged(int)), this, SLOT(setCropHeight(int)));
776 connect(optionsWidget, SIGNAL(lockHeightChanged(bool)), this, SLOT(setLockHeight(bool)));
777 connect(optionsWidget, SIGNAL(cropWidthChanged(int)), this, SLOT(setCropWidth(int)));
778 connect(optionsWidget, SIGNAL(lockWidthChanged(bool)), this, SLOT(setLockWidth(bool)));
779 connect(optionsWidget, SIGNAL(ratioChanged(double)), this, SLOT(setRatio(double)));
780 connect(optionsWidget, SIGNAL(lockRatioChanged(bool)), this, SLOT(setLockRatio(bool)));
781 connect(optionsWidget, SIGNAL(decorationChanged(int)), this, SLOT(setDecoration(int)));
782 connect(optionsWidget, SIGNAL(allowGrowChanged(bool)), this, SLOT(setAllowGrow(bool)));
783 connect(optionsWidget, SIGNAL(growCenterChanged(bool)), this, SLOT(setGrowCenter(bool)));
784
785 optionsWidget->setFixedHeight(optionsWidget->sizeHint().height());
786
787 connect(applyCrop, SIGNAL(triggered(bool)), this, SLOT(crop()));
788 connect(centerToggleOption, SIGNAL(triggered(bool)), this, SLOT(setGrowCenter(bool)));
789 connect(growToggleOption, SIGNAL(triggered(bool)), this, SLOT(setAllowGrow(bool)));
790 connect(lockWidthToggleOption, SIGNAL(triggered(bool)), this, SLOT(setLockWidth(bool)));
791 connect(lockHeightToggleOption, SIGNAL(triggered(bool)), this, SLOT(setLockHeight(bool)));
792 connect(lockRatioToggleOption, SIGNAL(triggered(bool)), this, SLOT(setLockRatio(bool)));
793
794 return optionsWidget;
795}
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, 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 465 of file kis_tool_crop.cc.

466{
468 if (m_finalRect.rect().isEmpty()) return;
469
470 const bool imageCrop = m_cropType == ImageCropType || m_cropType == CanvasCropType;
471
472 if (!imageCrop) {
473 //Cropping layer
474 if (!nodeEditable()) {
475 return;
476 }
477 }
478
479 m_haveCropSelection = false;
480 useCursor(cursor());
481
482 QRect cropRect = m_finalRect.rect();
483
484 // The visitor adds the undo steps to the macro
485 if (imageCrop || !currentNode()->paintDevice()) {
486 if (m_cropType == CanvasCropType) {
487 currentImage()->resizeImage(cropRect);
488 } else {
489 currentImage()->cropImage(cropRect);
490 }
491 } else {
493 }
494}
void resizeImage(const QRect &newRect)
start asynchronous operation on resizing the image
Definition kis_image.cc:866
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:987
void cropImage(const QRect &newRect)
start asynchronous operation on cropping the image
Definition kis_image.cc:871
#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 665 of file kis_tool_crop.cc.

666{
667 return m_finalRect.rect().height();
668}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropHeightChanged

void KisToolCrop::cropHeightChanged ( int value)
signal

◆ cropType()

KisToolCrop::CropToolType KisToolCrop::cropType ( ) const

Definition at line 512 of file kis_tool_crop.cc.

513{
514 return m_cropType;
515}

References m_cropType.

◆ cropTypeChanged

void KisToolCrop::cropTypeChanged ( int value)
signal

◆ cropTypeSelectable()

bool KisToolCrop::cropTypeSelectable ( ) const

Definition at line 525 of file kis_tool_crop.cc.

526{
528}

References m_cropTypeSelectable.

◆ cropTypeSelectableChanged

void KisToolCrop::cropTypeSelectableChanged ( )
signal

◆ cropWidth()

int KisToolCrop::cropWidth ( ) const

Definition at line 637 of file kis_tool_crop.cc.

638{
639 return m_finalRect.rect().width();
640}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropWidthChanged

void KisToolCrop::cropWidthChanged ( int value)
signal

◆ cropX()

int KisToolCrop::cropX ( ) const

Definition at line 599 of file kis_tool_crop.cc.

600{
601 return m_finalRect.rect().x();
602}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropXChanged

void KisToolCrop::cropXChanged ( int value)
signal

◆ cropY()

int KisToolCrop::cropY ( ) const

Definition at line 619 of file kis_tool_crop.cc.

620{
621 return m_finalRect.rect().y();
622}

References m_finalRect, and KisConstrainedRect::rect().

◆ cropYChanged

void KisToolCrop::cropYChanged ( int value)
signal

◆ deactivate

void KisToolCrop::deactivate ( )
overrideslot

Definition at line 196 of file kis_tool_crop.cc.

197{
198 cancelStroke();
200}
void cancelStroke()
void deactivate() override
Definition kis_tool.cc:131

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

◆ decoration()

int KisToolCrop::decoration ( ) const

Definition at line 530 of file kis_tool_crop.cc.

531{
532 return m_decoration;
533}

References m_decoration.

◆ decorationChanged

void KisToolCrop::decorationChanged ( int value)
signal

◆ doCanvasUpdate()

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

Definition at line 547 of file kis_tool_crop.cc.

548{
550 m_lastCanvasUpdateRect = updateRect;
551}
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 928 of file kis_tool_crop.cc.

929{
930 QPointF start = rect.topLeft();
931 QPointF end = rect.topLeft();
932 qreal small = qMin(rect.width(), rect.height());
933 qreal large = qMax(rect.width(), rect.height());
934
935 switch (decorLine->startXRelation) {
937 start.setX(start.x() + decorLine->start.x() * rect.width());
938 break;
940 start.setX(start.x() + decorLine->start.x() * rect.height());
941 break;
943 start.setX(start.x() + decorLine->start.x() * small);
944 break;
946 start.setX(start.x() + decorLine->start.x() * large);
947 break;
948 }
949
950 switch (decorLine->startYRelation) {
952 start.setY(start.y() + decorLine->start.y() * rect.width());
953 break;
955 start.setY(start.y() + decorLine->start.y() * rect.height());
956 break;
958 start.setY(start.y() + decorLine->start.y() * small);
959 break;
961 start.setY(start.y() + decorLine->start.y() * large);
962 break;
963 }
964
965 switch (decorLine->endXRelation) {
967 end.setX(end.x() + decorLine->end.x() * rect.width());
968 break;
970 end.setX(end.x() + decorLine->end.x() * rect.height());
971 break;
973 end.setX(end.x() + decorLine->end.x() * small);
974 break;
976 end.setX(end.x() + decorLine->end.x() * large);
977 break;
978 }
979
980 switch (decorLine->endYRelation) {
982 end.setY(end.y() + decorLine->end.y() * rect.width());
983 break;
985 end.setY(end.y() + decorLine->end.y() * rect.height());
986 break;
988 end.setY(end.y() + decorLine->end.y() * small);
989 break;
991 end.setY(end.y() + decorLine->end.y() * large);
992 break;
993 }
994
995 p->drawLine(start, end);
996}
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 358 of file kis_tool_crop.cc.

359{
362
363 QRectF viewCropRect = pixelToView(m_finalRect.rect());
364 const bool haveValidRect =
365 viewCropRect.width() > m_handleSize &&
366 viewCropRect.height() > m_handleSize;
367
368
369 if (!m_haveCropSelection && !haveValidRect) {
372 m_haveCropSelection = true;
373 }
374 } else if (m_resettingStroke && !haveValidRect) {
376 m_haveCropSelection = false;
377 } else {
378 m_haveCropSelection = true;
379 }
380
382
385}
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 709 of file kis_tool_crop.cc.

710{
711 return m_finalRect.centered();
712}

References KisConstrainedRect::centered(), and m_finalRect.

◆ handlesPath()

QPainterPath KisToolCrop::handlesPath ( )
private

Definition at line 837 of file kis_tool_crop.cc.

838{
839 QRectF cropBorderRect = borderLineRect();
840 QPainterPath path;
841
842 path.addRect(upperLeftHandleRect(cropBorderRect));
843 path.addRect(upperRightHandleRect(cropBorderRect));
844 path.addRect(lowerLeftHandleRect(cropBorderRect));
845 path.addRect(lowerRightHandleRect(cropBorderRect));
846 path.addRect(upperHandleRect(cropBorderRect));
847 path.addRect(lowerHandleRect(cropBorderRect));
848 path.addRect(leftHandleRect(cropBorderRect));
849 path.addRect(rightHandleRect(cropBorderRect));
850
851 return path;
852}
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 832 of file kis_tool_crop.cc.

833{
834 return QRectF(cropBorderRect.left() - m_handleSize / 2.0, cropBorderRect.top() + (cropBorderRect.height() - m_handleSize) / 2.0, m_handleSize, m_handleSize);
835}

References m_handleSize.

◆ lockHeight()

bool KisToolCrop::lockHeight ( ) const

Definition at line 675 of file kis_tool_crop.cc.

676{
677 return m_finalRect.heightLocked();
678}

References KisConstrainedRect::heightLocked(), and m_finalRect.

◆ lockHeightChanged

void KisToolCrop::lockHeightChanged ( bool value)
signal

◆ lockRatio()

bool KisToolCrop::lockRatio ( ) const

Definition at line 737 of file kis_tool_crop.cc.

738{
739 return m_finalRect.ratioLocked();
740}

References m_finalRect, and KisConstrainedRect::ratioLocked().

◆ lockRatioChanged

void KisToolCrop::lockRatioChanged ( bool value)
signal

◆ lockWidth()

bool KisToolCrop::lockWidth ( ) const

Definition at line 647 of file kis_tool_crop.cc.

648{
649 return m_finalRect.widthLocked();
650}

References m_finalRect, and KisConstrainedRect::widthLocked().

◆ lockWidthChanged

void KisToolCrop::lockWidthChanged ( bool value)
signal

◆ lowerHandleRect()

QRectF KisToolCrop::lowerHandleRect ( QRectF cropBorderRect)
private

Definition at line 817 of file kis_tool_crop.cc.

818{
819 return QRectF(cropBorderRect.left() + (cropBorderRect.width() - m_handleSize) / 2.0 , cropBorderRect.bottom() - m_handleSize / 2.0, m_handleSize, m_handleSize);
820}

References m_handleSize.

◆ lowerLeftHandleRect()

QRectF KisToolCrop::lowerLeftHandleRect ( QRectF cropBorderRect)
private

Definition at line 807 of file kis_tool_crop.cc.

808{
809 return QRectF(cropBorderRect.left() - m_handleSize / 2.0 , cropBorderRect.bottom() - m_handleSize / 2.0, m_handleSize, m_handleSize);
810}

References m_handleSize.

◆ lowerRightHandleRect()

QRectF KisToolCrop::lowerRightHandleRect ( QRectF cropBorderRect)
private

Definition at line 797 of file kis_tool_crop.cc.

798{
799 return QRectF(cropBorderRect.right() - m_handleSize / 2.0, cropBorderRect.bottom() - m_handleSize / 2.0, m_handleSize, m_handleSize);
800}

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 387 of file kis_tool_crop.cc.

388{
389 QPointF pos = convertToPixelCoordAndSnap(event);
390
391 if (m_haveCropSelection) { //if the crop selection is set
392 //set resize cursor if we are on one of the handles
393 if(mode() == KisTool::PAINT_MODE) {
394 //keep the same cursor as the one we clicked with
396 }else{
397 //hovering
398 qint32 type = mouseOnHandle(pixelToView(pos));
400 }
401 }
402}
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 854 of file kis_tool_crop.cc.

855{
856 QRectF borderRect = borderLineRect();
857 qint32 handleType = None;
858
859 if (!m_haveCropSelection) {
860 return None;
861 }
862
863 if (upperLeftHandleRect(borderRect).contains(currentViewPoint)) {
865 } else if (lowerLeftHandleRect(borderRect).contains(currentViewPoint)) {
867 } else if (upperRightHandleRect(borderRect).contains(currentViewPoint)) {
869 } else if (lowerRightHandleRect(borderRect).contains(currentViewPoint)) {
871 } else if (upperHandleRect(borderRect).contains(currentViewPoint)) {
873 } else if (lowerHandleRect(borderRect).contains(currentViewPoint)) {
875 } else if (leftHandleRect(borderRect).contains(currentViewPoint)) {
877 } else if (rightHandleRect(borderRect).contains(currentViewPoint)) {
879 } else if (borderRect.contains(currentViewPoint)) {
881 }
882
883 return handleType;
884}

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 239 of file kis_tool_crop.cc.

240{
241 Q_UNUSED(converter);
243}
void paintOutlineWithHandles(QPainter &gc)

References paintOutlineWithHandles().

◆ paintOutlineWithHandles()

void KisToolCrop::paintOutlineWithHandles ( QPainter & gc)
private

Definition at line 429 of file kis_tool_crop.cc.

430{
432 gc.save();
433
434 QRectF wholeImageRect = pixelToView(image()->bounds());
435 QRectF borderRect = borderLineRect();
436
437 QPainterPath path;
438
439 path.addRect(wholeImageRect);
440 path.addRect(borderRect);
441 gc.setPen(Qt::NoPen);
442 gc.setBrush(m_transparentBlack);
443 gc.drawPath(path);
444
445 // Handles
446 QPen pen(Qt::SolidLine);
448 pen.setColor(m_black);
449 pen.setCosmetic(true);
450 gc.setPen(pen);
451 gc.setBrush(m_transparentGrey);
452 gc.drawPath(handlesPath());
453
454 gc.setClipRect(borderRect, Qt::IntersectClip);
455
456 if (m_decoration > 0) {
457 for (int i = decorsIndex[m_decoration-1]; i<decorsIndex[m_decoration]; i++) {
458 drawDecorationLine(&gc, &(decors[i]), borderRect);
459 }
460 }
461 gc.restore();
462 }
463}
QColor m_transparentBlack
QColor m_transparentGrey
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 ...
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_black, m_decoration, m_haveCropSelection, m_transparentBlack, m_transparentGrey, KisTool::mode(), 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 245 of file kis_tool_crop.cc.

246{
247 if (m_contextMenu) {
248 // Sync state of context menu toggles with state of Tool Options toggles
249 centerToggleOption->setChecked(growCenter());
250 growToggleOption->setChecked(allowGrow());
251 lockWidthToggleOption->setChecked(lockWidth());
252 lockHeightToggleOption->setChecked(lockHeight());
253 lockRatioToggleOption->setChecked(lockRatio());
254
255 m_contextMenu->clear();
256
257 m_contextMenu->addSection(i18n("Crop Tool Actions"));
258 m_contextMenu->addSeparator();
259
260 if (m_haveCropSelection) { // can't crop if there is no selection
261 m_contextMenu->addAction(applyCrop);
262 m_contextMenu->addSeparator();
263 }
264
267
268 m_contextMenu->addSeparator();
269
273 }
274
275 return m_contextMenu.data();
276}
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 727 of file kis_tool_crop.cc.

728{
729 return m_finalRect.ratio();
730}

References m_finalRect, and KisConstrainedRect::ratio().

◆ ratioChanged

void KisToolCrop::ratioChanged ( double value)
signal

◆ requestRedoDuringStroke

void KisToolCrop::requestRedoDuringStroke ( )
overrideslot

Definition at line 217 of file kis_tool_crop.cc.

218{
219 cancelStroke();
220}

References cancelStroke().

◆ requestStrokeCancellation

void KisToolCrop::requestStrokeCancellation ( )
overrideslot

Definition at line 207 of file kis_tool_crop.cc.

208{
209 cancelStroke();
210}

References cancelStroke().

◆ requestStrokeEnd

void KisToolCrop::requestStrokeEnd ( )
overrideslot

Definition at line 202 of file kis_tool_crop.cc.

203{
205}

References crop(), and m_haveCropSelection.

◆ requestUndoDuringStroke

void KisToolCrop::requestUndoDuringStroke ( )
overrideslot

Definition at line 212 of file kis_tool_crop.cc.

213{
214 cancelStroke();
215}

References cancelStroke().

◆ rightHandleRect()

QRectF KisToolCrop::rightHandleRect ( QRectF cropBorderRect)
private

Definition at line 822 of file kis_tool_crop.cc.

823{
824 return QRectF(cropBorderRect.right() - m_handleSize / 2.0 , cropBorderRect.top() + (cropBorderRect.height() - m_handleSize) / 2.0, m_handleSize, m_handleSize);
825}

References m_handleSize.

◆ setAllowGrow

void KisToolCrop::setAllowGrow ( bool g)
slot

Definition at line 680 of file kis_tool_crop.cc.

681{
684 configGroup.writeEntry("allowGrow", g);
685
686 // Do a dummy move for the crop area to snap back to the canvas if grow is no longer allowed
687 if (!g) {
689 }
690
691 Q_EMIT canGrowChanged(g);
692}
void setCanGrow(bool value)
void canGrowChanged(bool value)

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

◆ setCropHeight

void KisToolCrop::setCropHeight ( int y)
slot

◆ setCropType

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

Definition at line 501 of file kis_tool_crop.cc.

502{
503 if(m_cropType == cropType)
504 return;
506
507 configGroup.writeEntry("cropType", static_cast<int>(cropType));
508
510}
CropToolType cropType

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

◆ setCropTypeLegacy

void KisToolCrop::setCropTypeLegacy ( int cropType)
slot

Definition at line 496 of file kis_tool_crop.cc.

497{
499}

References cropType, and setCropType().

◆ setCropTypeSelectable

void KisToolCrop::setCropTypeSelectable ( bool selectable)
slot

Definition at line 517 of file kis_tool_crop.cc.

518{
519 if(selectable == m_cropTypeSelectable)
520 return;
521 m_cropTypeSelectable = selectable;
523}
void cropTypeSelectableChanged()

References cropTypeSelectableChanged(), and m_cropTypeSelectable.

◆ setCropWidth

void KisToolCrop::setCropWidth ( int x)
slot

◆ setCropX

void KisToolCrop::setCropX ( int x)
slot

Definition at line 584 of file kis_tool_crop.cc.

585{
586 if(x == m_finalRect.rect().x())
587 return;
588
589 if (!m_haveCropSelection) {
590 m_haveCropSelection = true;
592 }
593
594 QPoint offset = m_finalRect.rect().topLeft();
595 offset.setX(x);
596 m_finalRect.setOffset(offset);
597}
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 604 of file kis_tool_crop.cc.

605{
606 if(y == m_finalRect.rect().y())
607 return;
608
609 if (!m_haveCropSelection) {
610 m_haveCropSelection = true;
612 }
613
614 QPoint offset = m_finalRect.rect().topLeft();
615 offset.setY(y);
616 m_finalRect.setOffset(offset);
617}

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 535 of file kis_tool_crop.cc.

536{
537 // This shouldn't happen, but safety first
538 if(i < 0 || i > DECORATION_COUNT)
539 return;
540 m_decoration = i;
543
544 configGroup.writeEntry("decoration", i);
545}
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 699 of file kis_tool_crop.cc.

700{
702
703
704 configGroup.writeEntry("growCenter", value);
705
706 Q_EMIT isCenteredChanged(value);
707}
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 670 of file kis_tool_crop.cc.

671{
673}
void setHeightLocked(bool value)

References m_finalRect, and KisConstrainedRect::setHeightLocked().

◆ setLockRatio

void KisToolCrop::setLockRatio ( bool lock)
slot

Definition at line 732 of file kis_tool_crop.cc.

733{
735}
void setRatioLocked(bool value)

References m_finalRect, and KisConstrainedRect::setRatioLocked().

◆ setLockWidth

void KisToolCrop::setLockWidth ( bool lock)
slot

Definition at line 642 of file kis_tool_crop.cc.

643{
645}
void setWidthLocked(bool value)

References m_finalRect, and KisConstrainedRect::setWidthLocked().

◆ setMoveResizeCursor()

void KisToolCrop::setMoveResizeCursor ( qint32 handle)
private

Definition at line 886 of file kis_tool_crop.cc.

887{
888 QCursor cursorType;
889
890 switch (handle) {
891 case(UpperLeft):
892 case(LowerRight):
893 cursorType = KisCursor::sizeFDiagCursor();
894 break;
895 case(LowerLeft):
896 case(UpperRight):
897 cursorType = KisCursor::sizeBDiagCursor();
898 break;
899 case(Upper):
900 case(Lower):
901 cursorType = KisCursor::sizeVerCursor();
902 break;
903 case(Left):
904 case(Right):
905 cursorType = KisCursor::sizeHorCursor();
906 break;
907 case(Inside):
908 cursorType = KisCursor::sizeAllCursor();
909 break;
910 default:
912 cursorType = KisCursor::arrowCursor();
913 } else {
914 cursorType = cursor();
915 }
916 break;
917 }
918 useCursor(cursorType);
919}
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 742 of file kis_tool_crop.cc.

743{
744 KisCanvas2 *kisCanvas =dynamic_cast<KisCanvas2*>(canvas());
745 Q_ASSERT(kisCanvas);
746 if(m_mouseOnHandleType == 9) {
747 kisCanvas->viewManager()->showFloatingMessage(i18n("X: %1\nY: %2"
748 , optionsWidget->intX->text(), optionsWidget->intY->text())
749 , QIcon(), 1000, KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
750 }
751 else {
752 kisCanvas->viewManager()->showFloatingMessage(i18n("Width: %1\nHeight: %2"
753 , optionsWidget->intWidth->text(), optionsWidget->intHeight->text())
754 , QIcon(), 1000, KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
755 }
756}
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 323 of file kis_tool_crop.cc.

324{
325 bool result = false;
326
327 const KUndo2Command *lastCommand = image()->undoAdapter()->presentCommand();
328 const KisCropSavedExtraData *data = 0;
329
330 if ((lastCommand = image()->undoAdapter()->presentCommand()) &&
331 (data = dynamic_cast<const KisCropSavedExtraData*>(lastCommand->extraData()))) {
332
333 bool cropImageConsistent =
337
338 bool cropLayerConsistent =
341 currentNode() == data->cropNode();
342
343
344 if (cropImageConsistent || cropLayerConsistent) {
346 image()->waitForDone();
347
349 m_haveCropSelection = true;
350
351 result = true;
352 }
353 }
354
355 return result;
356}
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().

◆ updateDecorationColors

void KisToolCrop::updateDecorationColors ( )
slot

Definition at line 570 of file kis_tool_crop.cc.

571{
572 KisCanvas2 *kisCanvas =dynamic_cast<KisCanvas2*>(canvas());
573 if (!kisCanvas) return;
574
575 KoColor c;
576 c.fromQColor(QColor(Qt::black));
578 c.fromQColor(QColor(0, 0, 0, OUTSIDE_CROP_ALPHA));
580 c.fromQColor(QColor(200, 200, 200, OUTSIDE_CROP_ALPHA));
582}
QColor convertColorToDisplayColorSpace(const KoColor color, bool applyOcio=false) const
convertColorToDisplayColorSpace This applies displayfiltering to the given KoColor,...
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
Definition KoColor.cpp:213
#define OUTSIDE_CROP_ALPHA

References Private::canvas, KisDisplayColorConverter::convertColorToDisplayColorSpace(), KisCanvas2::displayColorConverter, KoColor::fromQColor(), m_black, m_transparentBlack, m_transparentGrey, and OUTSIDE_CROP_ALPHA.

◆ upperHandleRect()

QRectF KisToolCrop::upperHandleRect ( QRectF cropBorderRect)
private

Definition at line 827 of file kis_tool_crop.cc.

828{
829 return QRectF(cropBorderRect.left() + (cropBorderRect.width() - m_handleSize) / 2.0 , cropBorderRect.top() - m_handleSize / 2.0, m_handleSize, m_handleSize);
830}

References m_handleSize.

◆ upperLeftHandleRect()

QRectF KisToolCrop::upperLeftHandleRect ( QRectF cropBorderRect)
private

Definition at line 812 of file kis_tool_crop.cc.

813{
814 return QRectF(cropBorderRect.left() - m_handleSize / 2.0, cropBorderRect.top() - m_handleSize / 2.0, m_handleSize, m_handleSize);
815}

References m_handleSize.

◆ upperRightHandleRect()

QRectF KisToolCrop::upperRightHandleRect ( QRectF cropBorderRect)
private

Definition at line 802 of file kis_tool_crop.cc.

803{
804 return QRectF(cropBorderRect.right() - m_handleSize / 2.0 , cropBorderRect.top() - m_handleSize / 2.0, m_handleSize, m_handleSize);
805}

References m_handleSize.

Member Data Documentation

◆ applyCrop

KisAction* KisToolCrop::applyCrop {nullptr}
private

Definition at line 184 of file kis_tool_crop.h.

184{nullptr};

◆ centerToggleOption

KisAction* KisToolCrop::centerToggleOption {nullptr}
private

Definition at line 185 of file kis_tool_crop.h.

185{nullptr};

◆ configGroup

KConfigGroup KisToolCrop::configGroup
private

Definition at line 180 of file kis_tool_crop.h.

◆ growToggleOption

KisAction* KisToolCrop::growToggleOption {nullptr}
private

Definition at line 186 of file kis_tool_crop.h.

186{nullptr};

◆ lockHeightToggleOption

KisAction* KisToolCrop::lockHeightToggleOption {nullptr}
private

Definition at line 188 of file kis_tool_crop.h.

188{nullptr};

◆ lockRatioToggleOption

KisAction* KisToolCrop::lockRatioToggleOption {nullptr}
private

Definition at line 189 of file kis_tool_crop.h.

189{nullptr};

◆ lockWidthToggleOption

KisAction* KisToolCrop::lockWidthToggleOption {nullptr}
private

Definition at line 187 of file kis_tool_crop.h.

187{nullptr};

◆ m_black

QColor KisToolCrop::m_black {Qt::black}
private

Definition at line 209 of file kis_tool_crop.h.

209{Qt::black};

◆ m_contextMenu

QScopedPointer<QMenu> KisToolCrop::m_contextMenu
private

Definition at line 183 of file kis_tool_crop.h.

◆ m_cropType

CropToolType KisToolCrop::m_cropType {ImageCropType}
private

Definition at line 173 of file kis_tool_crop.h.

◆ m_cropTypeSelectable

bool KisToolCrop::m_cropTypeSelectable {false}
private

Definition at line 174 of file kis_tool_crop.h.

174{false};

◆ m_decoration

int KisToolCrop::m_decoration {1}
private

Definition at line 176 of file kis_tool_crop.h.

176{1};

◆ m_decorations

QList<DecorationLine *> KisToolCrop::m_decorations
private

Definition at line 203 of file kis_tool_crop.h.

◆ m_dragOffsetDoc

QPointF KisToolCrop::m_dragOffsetDoc
private

Definition at line 207 of file kis_tool_crop.h.

◆ m_dragStart

QPoint KisToolCrop::m_dragStart
private

Definition at line 167 of file kis_tool_crop.h.

◆ m_finalRect

KisConstrainedRect KisToolCrop::m_finalRect
private

Definition at line 205 of file kis_tool_crop.h.

◆ m_handleSize

qint32 KisToolCrop::m_handleSize {13}
private

Definition at line 169 of file kis_tool_crop.h.

169{13};

◆ m_haveCropSelection

bool KisToolCrop::m_haveCropSelection {false}
private

Definition at line 170 of file kis_tool_crop.h.

170{false};

◆ m_initialDragRect

QRect KisToolCrop::m_initialDragRect
private

Definition at line 206 of file kis_tool_crop.h.

◆ m_lastCanvasUpdateRect

QRect KisToolCrop::m_lastCanvasUpdateRect
private

Definition at line 178 of file kis_tool_crop.h.

◆ m_mouseOnHandleType

qint32 KisToolCrop::m_mouseOnHandleType {0}
private

Definition at line 171 of file kis_tool_crop.h.

171{0};

◆ m_resettingStroke

bool KisToolCrop::m_resettingStroke {false}
private

Definition at line 177 of file kis_tool_crop.h.

177{false};

◆ m_transparentBlack

QColor KisToolCrop::m_transparentBlack {Qt::black}
private

Definition at line 210 of file kis_tool_crop.h.

210{Qt::black};

◆ m_transparentGrey

QColor KisToolCrop::m_transparentGrey {QColor(200, 200, 200, 40)}
private

Definition at line 211 of file kis_tool_crop.h.

211{QColor(200, 200, 200, 40)};

◆ optionsWidget

KisToolCropConfigWidget* KisToolCrop::optionsWidget {nullptr}
private

Definition at line 181 of file kis_tool_crop.h.

181{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: