Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolRectangleBase Class Referenceabstract

#include <kis_tool_rectangle_base.h>

+ Inheritance diagram for KisToolRectangleBase:

Public Types

enum  ToolType { PAINT , SELECT }
 
- 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 constraintsChanged (bool forceRatio, bool forceWidth, bool forceHeight, float ratio, float width, float height)
 
void requestStrokeCancellation () override
 
void requestStrokeEnd () override
 
void roundCornersChanged (int rx, int ry)
 
- Public Slots inherited from KisToolShape
void activate (const QSet< KoShape * > &shapes) override
 
virtual void fillSettingChanged (int value)
 
virtual void outlineSettingChanged (int value)
 
virtual void patternRotationSettingChanged (qreal value)
 
virtual void patternScaleSettingChanged (qreal value)
 
- Public Slots inherited from KisToolPaint
void activate (const QSet< KoShape * > &shapes) override
 
void deactivate () override
 
- 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 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 rectangleChanged (const QRectF &newRect)
 
void sigRequestReloadConfig ()
 
- Signals inherited from KisToolPaint
void sigPaintingFinished ()
 
- 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

void activate (const QSet< KoShape * > &shapes) override
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void continuePrimaryAction (KoPointerEvent *event) override
 
QList< QPointer< QWidget > > createOptionWidgets () override
 
void deactivate () override
 
void endPrimaryAction (KoPointerEvent *event) override
 
void keyPressEvent (QKeyEvent *event) override
 
void keyReleaseEvent (QKeyEvent *event) override
 
 KisToolRectangleBase (KoCanvasBase *canvas, KisToolRectangleBase::ToolType type, const QCursor &cursor=KisCursor::load("tool_rectangle_cursor.png", 6, 6))
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 
void showSize ()
 
- Public Member Functions inherited from KisToolShape
int flags () const override
 
 KisToolShape (KoCanvasBase *canvas, const QCursor &cursor)
 
 ~KisToolShape () override
 
- Public Member Functions inherited from KisToolPaint
 KisToolPaint (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
KisPopupWidgetInterfacepopupWidget () override
 
 ~KisToolPaint () override
 
- Public Member Functions inherited from KisTool
virtual bool alternateActionSupportsHiResEvents (AlternateAction action) const
 
virtual void beginAlternateDoubleClickAction (KoPointerEvent *event, AlternateAction action)
 
virtual void beginPrimaryDoubleClickAction (KoPointerEvent *event)
 
void deleteSelection () override
 
bool isActive () const
 
 KisTool (KoCanvasBase *canvas, const QCursor &cursor)
 
void mouseDoubleClickEvent (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
 
 KoToolBase (KoCanvasBase *canvas)
 
bool maskSyntheticEvents () const
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual bool paste ()
 
virtual QMenu * popupActionsMenu ()
 
virtual bool selectAll ()
 selectAll select all data the tool can select.
 
virtual KoToolSelectionselection ()
 
Q_INVOKABLE QString toolId () const
 
virtual bool wantsAutoScroll () const
 
 ~KoToolBase () override
 

Protected Member Functions

void applyConstraints (QSizeF &area, bool overrideRatio)
 
void cancelStroke ()
 
virtual QRectF createRect (const QPointF &start, const QPointF &end)
 
QPainterPath drawX (const QPointF &pt)
 
void endStroke ()
 
virtual void finishRect (const QRectF &rect, qreal roundCornersX, qreal roundCornersY)=0
 
void getRotatedPath (QPainterPath &path, const QPointF &center, const qreal &angle)
 
qreal getRotationAngle ()
 
bool isFixedSize ()
 
virtual void paintRectangle (QPainter &gc, const QRectF &imageRect)
 
virtual bool showRoundCornersGUI () const
 
void updateArea ()
 
- Protected Member Functions inherited from KisToolShape
void addPathShape (KoPathShape *pathShape, const KUndo2MagicString &name)
 
void addShape (KoShape *shape)
 
virtual void beginShape ()
 
QWidget * createOptionWidget () override
 
qreal currentStrokeWidth () const
 
virtual void endShape ()
 
KisToolShapeUtils::FillStyle fillStyle ()
 
QTransform fillTransform ()
 
ShapeAddInfo shouldAddShape (KisNodeSP currentNode) const
 
KisToolShapeUtils::StrokeStyle strokeStyle ()
 
- Protected Member Functions inherited from KisToolPaint
void activateAlternateAction (AlternateAction action) override
 
void activatePrimaryAction () override
 
void addOptionWidgetLayout (QLayout *layout)
 Add the tool-specific layout to the default option widget layout.
 
virtual void addOptionWidgetOption (QWidget *control, QWidget *label=nullptr)
 Add a widget and a label to the current option widget layout.
 
void beginAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void canvasResourceChanged (int key, const QVariant &v) override
 
void continueAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void deactivateAlternateAction (AlternateAction action) override
 
void deactivatePrimaryAction () override
 
void enableControl (QWidget *control, bool value)
 
void endAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
virtual KisOptimizedBrushOutline getOutlinePath (const QPointF &documentPos, const KoPointerEvent *event, KisPaintOpSettings::OutlineMode outlineMode)
 
bool isEraser () const
 
bool isOutlineEnabled () const
 
bool isOutlineVisible () const
 
virtual QString quickHelp () const
 
virtual void requestUpdateOutline (const QPointF &outlineDocPoint, const KoPointerEvent *event)
 
void setMode (ToolMode mode) override
 
void setOutlineEnabled (bool enabled)
 
void setOutlineVisible (bool visible)
 
void setSupportOutline (bool supportOutline)
 
void showControl (QWidget *control, bool value)
 
- 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)
 
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
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

qreal m_angle
 
qreal m_angleBuffer
 
Qt::KeyboardModifiers m_currentModifiers
 
QPointF m_dragCenter
 
QPointF m_dragEnd
 
QPointF m_dragStart
 
float m_forcedHeight
 
float m_forcedRatio
 
float m_forcedWidth
 
bool m_isHeightForced
 
bool m_isRatioForced
 
bool m_isWidthForced
 
qreal m_referenceAngle
 
bool m_rotateActive
 
int m_roundCornersX
 
int m_roundCornersY
 
ToolType m_type
 
- Protected Attributes inherited from KisToolShape
KConfigGroup m_configGroup
 
- Protected Attributes inherited from KisToolPaint
KisOptimizedBrushOutline m_currentOutline
 
QRectF m_oldColorPreviewUpdateRect
 
QRectF m_oldOutlineRect
 
QPointF m_outlineDocPoint
 
bool m_paintOutline {false}
 
- Protected Attributes inherited from KoToolBase
KoToolBasePrivated_ptr
 

Additional Inherited Members

- Static Public Member Functions inherited from KisTool
static AlternateAction actionToAlternateAction (ToolAction action)
 
- Public Attributes inherited from KisToolShape
WdgGeometryOptionsm_shapeOptionsWidget
 
- 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 ()
 
- Properties inherited from KisTool
bool isActive
 

Detailed Description

Definition at line 13 of file kis_tool_rectangle_base.h.

Member Enumeration Documentation

◆ ToolType

Enumerator
PAINT 
SELECT 

Definition at line 29 of file kis_tool_rectangle_base.h.

Constructor & Destructor Documentation

◆ KisToolRectangleBase()

KisToolRectangleBase::KisToolRectangleBase ( KoCanvasBase * canvas,
KisToolRectangleBase::ToolType type,
const QCursor & cursor = KisCursor::load("tool_rectangle_cursor.png", 6, 6) )
explicit

Definition at line 23 of file kis_tool_rectangle_base.cpp.

25 , m_dragStart(0, 0)
26 , m_dragEnd(0, 0)
27 , m_type(type)
28 , m_isRatioForced(false)
29 , m_isWidthForced(false)
30 , m_isHeightForced(false)
31 , m_rotateActive(false)
32 , m_forcedRatio(1.0)
33 , m_forcedWidth(0)
38 , m_angle(0)
39 , m_angleBuffer(0)
40 , m_currentModifiers(Qt::NoModifier)
41{
42}
Qt::KeyboardModifiers m_currentModifiers
KisToolShape(KoCanvasBase *canvas, const QCursor &cursor)
QCursor cursor
Definition kis_tool.cc:64
KisCanvas2 * canvas

Member Function Documentation

◆ activate()

void KisToolRectangleBase::activate ( const QSet< KoShape * > & shapes)
overridevirtual

This method is called when this tool instance is activated. For any main window there is only one tool active at a time, which then gets all user input. Switching between tools will call deactivate on one and activate on the new tool allowing the tool to flush items (like a selection) when it is not in use.

Parameters
shapesthe set of shapes that are selected or suggested for editing by a selected shape for the tool to work on. Not all shapes will be meant for this tool.
See also
deactivate()

Reimplemented from KoToolBase.

Reimplemented in KisToolSelectBase< __KisToolSelectEllipticalLocal >, and KisToolSelectBase< __KisToolSelectRectangularLocal >.

Definition at line 110 of file kis_tool_rectangle_base.cpp.

111{
113
114 Q_EMIT sigRequestReloadConfig();
115}
void activate(const QSet< KoShape * > &shapes) override

References KisToolShape::activate(), and sigRequestReloadConfig().

◆ applyConstraints()

void KisToolRectangleBase::applyConstraints ( QSizeF & area,
bool overrideRatio )
protected

Definition at line 201 of file kis_tool_rectangle_base.cpp.

201 {
202 if (m_isWidthForced) {
203 area.setWidth(m_forcedWidth);
204 }
205 if (m_isHeightForced) {
206 area.setHeight(m_forcedHeight);
207 }
208
209 if (m_isHeightForced && m_isWidthForced) return;
210
211 if (m_isRatioForced || overrideRatio) {
212 float ratio = m_isRatioForced ? m_forcedRatio : 1.0f;
213
214 if (m_isWidthForced) {
215 area.setHeight(area.width() / ratio);
216 } else {
217 area.setWidth(area.height() * ratio);
218 }
219 }
220}

References m_forcedHeight, m_forcedRatio, m_forcedWidth, m_isHeightForced, m_isRatioForced, and m_isWidthForced.

◆ beginPrimaryAction()

void KisToolRectangleBase::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.

Reimplemented in KisToolSelectBase< __KisToolSelectEllipticalLocal >, and KisToolSelectBase< __KisToolSelectRectangularLocal >.

Definition at line 151 of file kis_tool_rectangle_base.cpp.

152{
153 NodePaintAbility paintability = nodePaintAbility();
154 if ((m_type == PAINT && (!nodeEditable() || paintability == UNPAINTABLE || paintability == KisToolPaint::CLONE || paintability == KisToolPaint::MYPAINTBRUSH_UNPAINTABLE)) || (m_type == SELECT && !selectionEditable())) {
155
156 if (paintability == KisToolPaint::CLONE){
157 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
158 QString message = i18n("This tool cannot paint on clone layers. Please select a paint or vector layer or mask.");
159 kiscanvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
160 }
161
162 if (paintability == KisToolPaint::MYPAINTBRUSH_UNPAINTABLE) {
163 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
164 QString message = i18n("The MyPaint Brush Engine is not available for this colorspace");
165 kiscanvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
166 }
167
168 event->ignore();
169 return;
170 }
172 beginShape();
173
174 m_currentModifiers = Qt::NoModifier;
175
176 QPointF pos = convertToPixelCoordAndSnap(event, QPointF(), false);
179 m_rotateActive = false;
180
181 QSizeF area = QSizeF(0,0);
182
183 applyConstraints(area, false);
184
185 m_dragEnd.setX(m_dragStart.x() + area.width());
186 m_dragEnd.setY(m_dragStart.y() + area.height());
187
188 m_dragCenter = QPointF((m_dragStart.x() + m_dragEnd.x()) / 2,
189 (m_dragStart.y() + m_dragEnd.y()) / 2);
190 showSize();
191 event->accept();
192}
KisViewManager * viewManager() const
void setMode(ToolMode mode) override
void applyConstraints(QSizeF &area, bool overrideRatio)
virtual void beginShape()
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
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
KisTool::NodePaintAbility nodePaintAbility()
Definition kis_tool.cc:539
bool nodeEditable()
Checks checks if the current node is editable.
Definition kis_tool.cc:651
@ PAINT_MODE
Definition kis_tool.h:300
QPointF convertToPixelCoordAndSnap(KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
Definition kis_tool.cc:214
bool selectionEditable()
Checks checks if the selection is editable, only applies to local selection as global selection is al...
Definition kis_tool.cc:696
NodePaintAbility
Definition kis_tool.h:148
@ MYPAINTBRUSH_UNPAINTABLE
Definition kis_tool.h:153
@ UNPAINTABLE
Definition kis_tool.h:152

References applyConstraints(), KisToolShape::beginShape(), Private::canvas, KisTool::CLONE, KisTool::convertToPixelCoordAndSnap(), koIcon, m_angle, m_angleBuffer, m_currentModifiers, m_dragCenter, m_dragEnd, m_dragStart, m_rotateActive, m_type, KisTool::MYPAINTBRUSH_UNPAINTABLE, KisTool::nodeEditable(), KisTool::nodePaintAbility(), PAINT, KisTool::PAINT_MODE, SELECT, KisTool::selectionEditable(), KisToolPaint::setMode(), KisViewManager::showFloatingMessage(), showSize(), KisTool::UNPAINTABLE, and KisCanvas2::viewManager().

◆ cancelStroke()

void KisToolRectangleBase::cancelStroke ( )
protected

◆ constraintsChanged

void KisToolRectangleBase::constraintsChanged ( bool forceRatio,
bool forceWidth,
bool forceHeight,
float ratio,
float width,
float height )
slot

Definition at line 70 of file kis_tool_rectangle_base.cpp.

71{
72 m_isWidthForced = forceWidth;
73 m_isHeightForced = forceHeight;
74 m_isRatioForced = forceRatio;
75
76 m_forcedHeight = height;
77 m_forcedWidth = width;
78 m_forcedRatio = ratio;
79
80 // Avoid division by zero in size calculations
81 if (ratio < 0.0001f)
82 m_isRatioForced = false;
83}

References m_forcedHeight, m_forcedRatio, m_forcedWidth, m_isHeightForced, m_isRatioForced, and m_isWidthForced.

◆ continuePrimaryAction()

void KisToolRectangleBase::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.

Reimplemented in KisToolSelectBase< __KisToolSelectEllipticalLocal >, and KisToolSelectBase< __KisToolSelectRectangularLocal >.

Definition at line 222 of file kis_tool_rectangle_base.cpp.

223{
225
226 bool constraintToggle = m_currentModifiers & Qt::ShiftModifier;
227 bool translateMode = m_currentModifiers & Qt::AltModifier;
228 bool expandFromCenter = m_currentModifiers & Qt::ControlModifier;
229
230 bool rotateMode = expandFromCenter && translateMode;
231 bool fixedSize = isFixedSize() && !constraintToggle;
232
233 QPointF pos = convertToPixelCoordAndSnap(event, QPointF(), false);
234
235 if (rotateMode) {
236 QPointF angleVector;
237 if (!m_rotateActive) {
238 m_rotateActive = true;
239 angleVector = (fixedSize)? m_dragEnd: pos;
240 angleVector -= m_dragStart;
241 m_referenceAngle = atan2(angleVector.y(), angleVector.x());
242 }
243 angleVector = pos - m_dragStart;
244 qreal a2 = atan2(angleVector.y(), angleVector.x());
246 } else {
247 m_rotateActive = false;
249 m_angleBuffer = 0;
250 }
251
252 if (fixedSize && !rotateMode) {
253 m_dragStart = pos;
254 } else if (translateMode && !rotateMode) {
255 QPointF trans = pos - m_dragEnd;
256 m_dragStart += trans;
257 m_dragEnd += trans;
258
259 }
260
261 QPointF diag = pos - m_dragStart;
262 QTransform t1, t2;
263 t1.rotateRadians(-getRotationAngle());
264 QPointF baseDiag = t1.map(diag);
265 QSizeF area = QSizeF(fabs(baseDiag.x()), fabs(baseDiag.y()));
266
267 bool overrideRatio = constraintToggle && !(m_isHeightForced || m_isWidthForced || m_isRatioForced);
268 if (!constraintToggle || overrideRatio) {
269 applyConstraints(area, overrideRatio);
270 }
271
272 baseDiag = QPointF(
273 (baseDiag.x() < 0) ? -area.width() : area.width(),
274 (baseDiag.y() < 0) ? -area.height() : area.height()
275 );
276
277 t2.rotateRadians(getRotationAngle());
278 diag = t2.map(baseDiag);
279
280 // resize around center point?
281 if (expandFromCenter && !fixedSize && !rotateMode) {
282 m_dragStart = m_dragCenter - diag / 2;
283 m_dragEnd = m_dragCenter + diag / 2;
284 } else {
285 m_dragEnd = m_dragStart + diag;
286 }
287
288 if(!translateMode) {
289 showSize();
290 }
291 else {
292 KisCanvas2 *kisCanvas =dynamic_cast<KisCanvas2*>(canvas());
293 KIS_ASSERT(kisCanvas);
294 kisCanvas->viewManager()->showFloatingMessage(i18n("X: %1 px\nY: %2 px"
295 , QString::number(m_dragStart.x(), 'f', 1)
296 , QString::number(m_dragStart.y(), 'f', 1)), QIcon(), 1000
297 , KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
298 }
299 updateArea();
300 m_dragCenter = QPointF((m_dragStart.x() + m_dragEnd.x()) / 2,
301 (m_dragStart.y() + m_dragEnd.y()) / 2);
302
304}
virtual void requestUpdateOutline(const QPointF &outlineDocPoint, const KoPointerEvent *event)
QPointF point
The point in document coordinates.
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
#define CHECK_MODE_SANITY_OR_RETURN(_mode)
Definition kis_tool.h:27
KRITAIMAGE_EXPORT qreal atan2(qreal y, qreal x)
atan2 replacement

References applyConstraints(), Private::canvas, CHECK_MODE_SANITY_OR_RETURN, KisTool::convertToPixelCoordAndSnap(), getRotationAngle(), KisFloatingMessage::High, isFixedSize(), KIS_ASSERT, m_angle, m_angleBuffer, m_currentModifiers, m_dragCenter, m_dragEnd, m_dragStart, m_isHeightForced, m_isRatioForced, m_isWidthForced, m_referenceAngle, m_rotateActive, KisTool::PAINT_MODE, KoPointerEvent::point, KisToolPaint::requestUpdateOutline(), KisViewManager::showFloatingMessage(), showSize(), updateArea(), and KisCanvas2::viewManager().

◆ createOptionWidgets()

QList< QPointer< QWidget > > KisToolRectangleBase::createOptionWidgets ( )
overridevirtual

Reimplemented from KoToolBase.

Definition at line 45 of file kis_tool_rectangle_base.cpp.

46{
48
51
52 if (widgetsList.size() > 0
53 && dynamic_cast<KisOptionCollectionWidget *>(
54 widgetsList.first().data())) {
55 KisOptionCollectionWidget *baseOptions =
56 dynamic_cast<KisOptionCollectionWidget *>(
57 widgetsList.first().data());
58 KisOptionCollectionWidgetWithHeader *sectionRectangle =
59 new KisOptionCollectionWidgetWithHeader(widget->windowTitle());
60 sectionRectangle->appendWidget("rectangleConstraintWidget", widget);
61 baseOptions->appendWidget("sectionRectangle", sectionRectangle);
62 } else {
63 widget->setContentsMargins(10, 10, 10, 10);
64 widgetsList.append(widget);
65 }
66
67 return widgetsList;
68}
Wrapper class around a KisOptionCollectionWidget that also provide a header with a title label and an...
void appendWidget(const QString &id, QWidget *widget)
Insert the given widget with the given id at the end of the list. The list widget takes ownership of ...
Class providing a list of widgets with some addons such as separators, orientation or individual widg...
void appendWidget(const QString &id, QWidget *widget)
Insert the given widget with the given id at the end of the list. The list widget takes ownership of ...
virtual bool showRoundCornersGUI() const
virtual QList< QPointer< QWidget > > createOptionWidgets()

References KisOptionCollectionWidget::appendWidget(), KisOptionCollectionWidgetWithHeader::appendWidget(), KoToolBase::createOptionWidgets(), and showRoundCornersGUI().

◆ createRect()

QRectF KisToolRectangleBase::createRect ( const QPointF & start,
const QPointF & end )
protectedvirtual

Definition at line 352 of file kis_tool_rectangle_base.cpp.

353{
354 QTransform t;
355 t.translate(start.x(), start.y());
356 t.rotateRadians(-getRotationAngle());
357 t.translate(-start.x(), -start.y());
358 const QTransform tInv = t.inverted();
359
360 const QPointF end1 = t.map(end);
361 const QPointF newStart(qRound(start.x()), qRound(start.y()));
362 const QPointF newEnd(qRound(end1.x()), qRound(end1.y()));
363 const QPointF newCenter = (newStart + newEnd) / 2.0;
364
365 QRectF result(newStart, newEnd);
366 result.moveCenter(tInv.map(newCenter));
367
368 return result.normalized();
369}

References getRotationAngle().

◆ deactivate()

void KisToolRectangleBase::deactivate ( )
overridevirtual

This method is called whenever this tool is no longer the active tool

See also
activate()

Reimplemented from KoToolBase.

Reimplemented in KisToolSelectBase< __KisToolSelectEllipticalLocal >, and KisToolSelectBase< __KisToolSelectRectangularLocal >.

Definition at line 117 of file kis_tool_rectangle_base.cpp.

118{
119 cancelStroke();
121}
virtual void deactivate()

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

◆ drawX()

QPainterPath KisToolRectangleBase::drawX ( const QPointF & pt)
protected

Definition at line 415 of file kis_tool_rectangle_base.cpp.

415 {
416 QPainterPath path;
417 path.moveTo(QPointF(pt.x() - 5.0, pt.y() - 5.0)); path.lineTo(QPointF(pt.x() + 5.0, pt.y() + 5.0));
418 path.moveTo(QPointF(pt.x() - 5.0, pt.y() + 5.0)); path.lineTo(QPointF(pt.x() + 5.0, pt.y() - 5.0));
419 return path;
420}

◆ endPrimaryAction()

void KisToolRectangleBase::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.

Reimplemented in KisToolSelectBase< __KisToolSelectEllipticalLocal >, and KisToolSelectBase< __KisToolSelectRectangularLocal >.

Definition at line 306 of file kis_tool_rectangle_base.cpp.

307{
309 // If the event was not originated by the user releasing the button
310 // (for example due to the canvas loosing focus), then we just cancel the
311 // operation. This prevents some issues with shapes being added after
312 // the image was closed while the shape was being made
313 if (event->spontaneous()) {
314 endStroke();
315 } else {
316 cancelStroke();
317 }
318 event->accept();
319}
bool spontaneous() const
return if this event was spontaneous (see QMouseEvent::spontaneous())

References cancelStroke(), CHECK_MODE_SANITY_OR_RETURN, endStroke(), KisTool::PAINT_MODE, and KoPointerEvent::spontaneous().

◆ endStroke()

void KisToolRectangleBase::endStroke ( )
protected

Definition at line 337 of file kis_tool_rectangle_base.cpp.

338{
340 updateArea();
342 endShape();
343}
virtual void finishRect(const QRectF &rect, qreal roundCornersX, qreal roundCornersY)=0
virtual QRectF createRect(const QPointF &start, const QPointF &end)

References createRect(), KisToolShape::endShape(), finishRect(), KisTool::HOVER_MODE, m_dragEnd, m_dragStart, m_roundCornersX, m_roundCornersY, KisToolPaint::setMode(), and updateArea().

◆ finishRect()

virtual void KisToolRectangleBase::finishRect ( const QRectF & rect,
qreal roundCornersX,
qreal roundCornersY )
protectedpure virtual

◆ getRotatedPath()

void KisToolRectangleBase::getRotatedPath ( QPainterPath & path,
const QPointF & center,
const qreal & angle )
protected

Definition at line 422 of file kis_tool_rectangle_base.cpp.

422 {
423 QTransform t;
424 t.translate(center.x(), center.y());
425 t.rotateRadians(angle);
426 t.translate(-center.x(), -center.y());
427
428 path = t.map(path);
429}

◆ getRotationAngle()

qreal KisToolRectangleBase::getRotationAngle ( )
protected

Definition at line 411 of file kis_tool_rectangle_base.cpp.

411 {
412 return m_angle + m_angleBuffer;
413}

References m_angle, and m_angleBuffer.

◆ isFixedSize()

bool KisToolRectangleBase::isFixedSize ( )
protected

Definition at line 194 of file kis_tool_rectangle_base.cpp.

194 {
195 if (m_isWidthForced && m_isHeightForced) return true;
196 if (m_isRatioForced && (m_isWidthForced || m_isHeightForced)) return true;
197
198 return false;
199}

References m_isHeightForced, m_isRatioForced, and m_isWidthForced.

◆ keyPressEvent()

void KisToolRectangleBase::keyPressEvent ( QKeyEvent * event)
overridevirtual

Called when a key is pressed. Implementors should call event->ignore() if they do not actually use the event. Default implementation ignores this event.

Parameters
eventstate and reason of this key press

Reimplemented from KoToolBase.

Reimplemented in KisToolSelectBase< __KisToolSelectEllipticalLocal >, and KisToolSelectBase< __KisToolSelectRectangularLocal >.

Definition at line 123 of file kis_tool_rectangle_base.cpp.

123 {
125
126 if (key == Qt::Key_Control) {
127 m_currentModifiers |= Qt::ControlModifier;
128 } else if (key == Qt::Key_Shift) {
129 m_currentModifiers |= Qt::ShiftModifier;
130 } else if (key == Qt::Key_Alt) {
131 m_currentModifiers |= Qt::AltModifier;
132 }
133
135}
static Qt::Key workaroundShiftAltMetaHell(const QKeyEvent *keyEvent)
virtual void keyPressEvent(QKeyEvent *event)

References KoToolBase::keyPressEvent(), m_currentModifiers, and KisExtendedModifiersMapper::workaroundShiftAltMetaHell().

◆ keyReleaseEvent()

void KisToolRectangleBase::keyReleaseEvent ( QKeyEvent * event)
overridevirtual

Called when a key is released Implementors should call event->ignore() if they do not actually use the event. Default implementation ignores this event.

Parameters
eventstate and reason of this key release

Reimplemented from KoToolBase.

Reimplemented in KisToolSelectBase< __KisToolSelectEllipticalLocal >, and KisToolSelectBase< __KisToolSelectRectangularLocal >.

Definition at line 137 of file kis_tool_rectangle_base.cpp.

137 {
139
140 if (key == Qt::Key_Control) {
141 m_currentModifiers &= ~Qt::ControlModifier;
142 } else if (key == Qt::Key_Shift) {
143 m_currentModifiers &= ~Qt::ShiftModifier;
144 } else if (key == Qt::Key_Alt) {
145 m_currentModifiers &= ~Qt::AltModifier;
146 }
147
149}
virtual void keyReleaseEvent(QKeyEvent *event)

References KoToolBase::keyReleaseEvent(), m_currentModifiers, and KisExtendedModifiersMapper::workaroundShiftAltMetaHell().

◆ paint()

void KisToolRectangleBase::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.

Reimplemented from KisToolPaint.

Definition at line 101 of file kis_tool_rectangle_base.cpp.

102{
103 if(mode() == KisTool::PAINT_MODE) {
105 }
106
107 KisToolPaint::paint(gc, converter);
108}
void paint(QPainter &gc, const KoViewConverter &converter) override
virtual void paintRectangle(QPainter &gc, const QRectF &imageRect)
virtual ToolMode mode() const
Definition kis_tool.cc:407

References createRect(), m_dragEnd, m_dragStart, KisTool::mode(), KisToolPaint::paint(), KisTool::PAINT_MODE, and paintRectangle().

◆ paintRectangle()

void KisToolRectangleBase::paintRectangle ( QPainter & gc,
const QRectF & imageRect )
protectedvirtual

Reimplemented in KisToolEllipseBase.

Definition at line 376 of file kis_tool_rectangle_base.cpp.

377{
379
380 const QRect viewRect = pixelToView(imageRect).toAlignedRect();
381
382 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
384
385 const KisCoordinatesConverter *converter = kritaCanvas->coordinatesConverter();
386 const qreal roundCornersX = converter->effectiveZoom() * m_roundCornersX;
387 const qreal roundCornersY = converter->effectiveZoom() * m_roundCornersY;
388
389 QPainterPath path;
390 if (m_roundCornersX > 0 || m_roundCornersY > 0) {
391 path.addRoundedRect(viewRect,
392 roundCornersX, roundCornersY);
393 } else {
394 path.addRect(viewRect);
395 }
396
397 getRotatedPath(path, viewRect.center(), getRotationAngle());
398 path.addPath(drawX(pixelToView(m_dragStart)));
399 path.addPath(drawX(pixelToView(m_dragCenter)));
400 paintToolOutline(&gc, path);
401}
KisCoordinatesConverter * coordinatesConverter
void getRotatedPath(QPainterPath &path, const QPointF &center, const qreal &angle)
QPainterPath drawX(const QPointF &pt)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
QPointF pixelToView(const QPoint &pixelCoord) const
Definition kis_tool.cc:269
void paintToolOutline(QPainter *painter, const KisOptimizedBrushOutline &path)
Definition kis_tool.cc:589

References Private::canvas, KisCanvas2::coordinatesConverter, drawX(), KisCoordinatesConverter::effectiveZoom(), getRotatedPath(), getRotationAngle(), KIS_ASSERT_RECOVER_RETURN, KIS_SAFE_ASSERT_RECOVER_RETURN, m_dragCenter, m_dragStart, m_roundCornersX, m_roundCornersY, KisTool::paintToolOutline(), and KisTool::pixelToView().

◆ rectangleChanged

void KisToolRectangleBase::rectangleChanged ( const QRectF & newRect)
signal

◆ requestStrokeCancellation

void KisToolRectangleBase::requestStrokeCancellation ( )
overrideslot

Definition at line 329 of file kis_tool_rectangle_base.cpp.

330{
331 if (mode() != KisTool::PAINT_MODE) {
332 return;
333 }
334 cancelStroke();
335}

References cancelStroke(), KisTool::mode(), and KisTool::PAINT_MODE.

◆ requestStrokeEnd

void KisToolRectangleBase::requestStrokeEnd ( )
overrideslot

Definition at line 321 of file kis_tool_rectangle_base.cpp.

322{
323 if (mode() != KisTool::PAINT_MODE) {
324 return;
325 }
326 endStroke();
327}

References endStroke(), KisTool::mode(), and KisTool::PAINT_MODE.

◆ roundCornersChanged

void KisToolRectangleBase::roundCornersChanged ( int rx,
int ry )
slot

Definition at line 85 of file kis_tool_rectangle_base.cpp.

86{
87 m_roundCornersX = rx;
88 m_roundCornersY = ry;
89}

References m_roundCornersX, and m_roundCornersY.

◆ showRoundCornersGUI()

bool KisToolRectangleBase::showRoundCornersGUI ( ) const
protectedvirtual

Reimplemented in KisToolEllipseBase.

Definition at line 371 of file kis_tool_rectangle_base.cpp.

372{
373 return true;
374}

◆ showSize()

void KisToolRectangleBase::showSize ( )

Definition at line 91 of file kis_tool_rectangle_base.cpp.

92{
93 KisCanvas2 *kisCanvas =dynamic_cast<KisCanvas2*>(canvas());
95 kisCanvas->viewManager()->showFloatingMessage(i18n("Width: %1 px\nHeight: %2 px"
97 , createRect(m_dragStart, m_dragEnd).height()), QIcon(), 1000
98 , KisFloatingMessage::High, Qt::AlignLeft | Qt::TextWordWrap | Qt::AlignVCenter);
99
100}

References Private::canvas, createRect(), KisFloatingMessage::High, KIS_SAFE_ASSERT_RECOVER_RETURN, m_dragEnd, m_dragStart, KisViewManager::showFloatingMessage(), and KisCanvas2::viewManager().

◆ sigRequestReloadConfig

void KisToolRectangleBase::sigRequestReloadConfig ( )
signal

◆ updateArea()

void KisToolRectangleBase::updateArea ( )
protected

Definition at line 403 of file kis_tool_rectangle_base.cpp.

403 {
404 const QRectF bound = createRect(m_dragStart, m_dragEnd);
405
406 canvas()->updateCanvas(convertToPt(bound).adjusted(-100, -100, +200, +200));
407
408 Q_EMIT rectangleChanged(bound);
409}
void updateCanvas(const QRectF &rc) override
void rectangleChanged(const QRectF &newRect)
QRectF convertToPt(const QRectF &rect)
Definition kis_tool.cc:252

References Private::canvas, KisTool::convertToPt(), createRect(), m_dragEnd, m_dragStart, rectangleChanged(), and KisCanvas2::updateCanvas().

Member Data Documentation

◆ m_angle

qreal KisToolRectangleBase::m_angle
protected

Definition at line 67 of file kis_tool_rectangle_base.h.

◆ m_angleBuffer

qreal KisToolRectangleBase::m_angleBuffer
protected

Definition at line 68 of file kis_tool_rectangle_base.h.

◆ m_currentModifiers

Qt::KeyboardModifiers KisToolRectangleBase::m_currentModifiers
protected

Definition at line 69 of file kis_tool_rectangle_base.h.

◆ m_dragCenter

QPointF KisToolRectangleBase::m_dragCenter
protected

Definition at line 52 of file kis_tool_rectangle_base.h.

◆ m_dragEnd

QPointF KisToolRectangleBase::m_dragEnd
protected

Definition at line 54 of file kis_tool_rectangle_base.h.

◆ m_dragStart

QPointF KisToolRectangleBase::m_dragStart
protected

Definition at line 53 of file kis_tool_rectangle_base.h.

◆ m_forcedHeight

float KisToolRectangleBase::m_forcedHeight
protected

Definition at line 63 of file kis_tool_rectangle_base.h.

◆ m_forcedRatio

float KisToolRectangleBase::m_forcedRatio
protected

Definition at line 61 of file kis_tool_rectangle_base.h.

◆ m_forcedWidth

float KisToolRectangleBase::m_forcedWidth
protected

Definition at line 62 of file kis_tool_rectangle_base.h.

◆ m_isHeightForced

bool KisToolRectangleBase::m_isHeightForced
protected

Definition at line 59 of file kis_tool_rectangle_base.h.

◆ m_isRatioForced

bool KisToolRectangleBase::m_isRatioForced
protected

Definition at line 57 of file kis_tool_rectangle_base.h.

◆ m_isWidthForced

bool KisToolRectangleBase::m_isWidthForced
protected

Definition at line 58 of file kis_tool_rectangle_base.h.

◆ m_referenceAngle

qreal KisToolRectangleBase::m_referenceAngle
protected

Definition at line 66 of file kis_tool_rectangle_base.h.

◆ m_rotateActive

bool KisToolRectangleBase::m_rotateActive
protected

Definition at line 60 of file kis_tool_rectangle_base.h.

◆ m_roundCornersX

int KisToolRectangleBase::m_roundCornersX
protected

Definition at line 64 of file kis_tool_rectangle_base.h.

◆ m_roundCornersY

int KisToolRectangleBase::m_roundCornersY
protected

Definition at line 65 of file kis_tool_rectangle_base.h.

◆ m_type

ToolType KisToolRectangleBase::m_type
protected

Definition at line 55 of file kis_tool_rectangle_base.h.


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