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

#include <kis_tool_polyline_base.h>

+ Inheritance diagram for KisToolPolylineBase:

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 Member Functions

void activate (const QSet< KoShape * > &shapes) override
 
void beginAlternateAction (KoPointerEvent *event, AlternateAction action) override
 
void beginPrimaryAction (KoPointerEvent *event) override
 
void beginPrimaryDoubleClickAction (KoPointerEvent *event) override
 
void deactivate () override
 
void endPrimaryAction (KoPointerEvent *event) override
 
bool eventFilter (QObject *obj, QEvent *event) override
 
 KisToolPolylineBase (KoCanvasBase *canvas, KisToolPolylineBase::ToolType type, const QCursor &cursor=KisCursor::load("tool_polygon_cursor.png", 6, 6))
 
void mouseMoveEvent (KoPointerEvent *event) override
 
void paint (QPainter &gc, const KoViewConverter &converter) override
 
KisPopupWidgetInterfacepopupWidget () override
 
void requestStrokeCancellation () override
 
void requestStrokeEnd () override
 
- 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 mousePressEvent (KoPointerEvent *event) override
 
void mouseReleaseEvent (KoPointerEvent *event) override
 
 ~KisToolPaint () override
 
- Public Member Functions inherited from KisTool
virtual bool alternateActionSupportsHiResEvents (AlternateAction action) const
 
virtual void beginAlternateDoubleClickAction (KoPointerEvent *event, AlternateAction action)
 
virtual void continuePrimaryAction (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
 
virtual void keyPressEvent (QKeyEvent *event)
 
virtual void keyReleaseEvent (QKeyEvent *event)
 
 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

virtual void finishPolyline (const QVector< QPointF > &points)=0
 
- 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 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
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)
 

Private Slots

void undoSelection ()
 
void undoSelectionOrCancel ()
 

Private Member Functions

void cancelStroke ()
 
QRectF dragBoundingRect ()
 
void endStroke ()
 
void updateArea ()
 

Private Attributes

bool m_closeSnappingActivated
 
QPointF m_dragEnd
 
bool m_dragging
 
QPointF m_dragStart
 
vQPointF m_points
 
ToolType m_type
 

Additional Inherited Members

- 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 requestUndoDuringStroke ()
 
void setStatusText (const QString &statusText)
 
void updateOptionsWidgetIcons ()
 
- 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)
 
- 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 ()
 
- 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
 
- Properties inherited from KisTool
bool isActive
 

Detailed Description

Definition at line 13 of file kis_tool_polyline_base.h.

Member Enumeration Documentation

◆ ToolType

Enumerator
PAINT 
SELECT 

Definition at line 17 of file kis_tool_polyline_base.h.

Constructor & Destructor Documentation

◆ KisToolPolylineBase()

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

Definition at line 30 of file kis_tool_polyline_base.cpp.

32 m_dragging(false),
33 m_type(type),
35{
36 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas);
37
38 connect(kritaCanvas->viewManager()->canvasResourceProvider(), SIGNAL(sigEffectiveCompositeOpChanged()), SLOT(resetCursorStyle()));
39}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisViewManager * viewManager() const
KisToolShape(KoCanvasBase *canvas, const QCursor &cursor)
KisCanvasResourceProvider * canvasResourceProvider()
virtual void resetCursorStyle()
Definition kis_tool.cc:613
QCursor cursor
Definition kis_tool.cc:64
KisCanvas2 * canvas

References Private::canvas, KisViewManager::canvasResourceProvider(), connect(), KisTool::resetCursorStyle(), and KisCanvas2::viewManager().

Member Function Documentation

◆ activate()

void KisToolPolylineBase::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< __KisToolSelectPolygonalLocal >.

Definition at line 42 of file kis_tool_polyline_base.cpp.

43{
45 connect(action("undo_polygon_selection"), SIGNAL(triggered()), SLOT(undoSelectionOrCancel()), Qt::UniqueConnection);
46
47 KisInputManager *inputManager = (static_cast<KisCanvas2*>(canvas()))->globalInputManager();
48 if (inputManager) {
49 inputManager->attachPriorityEventFilter(this);
50 }
51}
Central object to manage canvas input.
void attachPriorityEventFilter(QObject *filter, int priority=0)
attachPriorityEventFilter
void activate(const QSet< KoShape * > &shapes) override
QAction * action(const QString &name) const

References KoToolBase::action(), KisToolShape::activate(), KisInputManager::attachPriorityEventFilter(), Private::canvas, connect(), and undoSelectionOrCancel().

◆ beginAlternateAction()

void KisToolPolylineBase::beginAlternateAction ( KoPointerEvent * event,
AlternateAction action )
overridevirtual

Reimplemented from KisToolPaint.

Reimplemented in KisToolSelectBase< __KisToolSelectPolygonalLocal >.

Definition at line 161 of file kis_tool_polyline_base.cpp.

162{
163 if ((action != ChangeSize && action != ChangeSizeSnap) || !m_dragging) {
165 }
166
168 m_points.append(m_points.first());
169 }
170 endStroke();
171}
void beginAlternateAction(KoPointerEvent *event, AlternateAction action) override
@ ChangeSizeSnap
Definition kis_tool.h:136
@ ChangeSize
Definition kis_tool.h:135

References KoToolBase::action(), KisToolPaint::beginAlternateAction(), KisTool::ChangeSize, KisTool::ChangeSizeSnap, endStroke(), m_closeSnappingActivated, m_dragging, and m_points.

◆ beginPrimaryAction()

void KisToolPolylineBase::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< __KisToolSelectPolygonalLocal >.

Definition at line 107 of file kis_tool_polyline_base.cpp.

108{
109 Q_UNUSED(event);
110 NodePaintAbility paintability = nodePaintAbility();
111 if ((m_type == PAINT && (!nodeEditable() || paintability == UNPAINTABLE || paintability == KisToolPaint::CLONE || paintability == KisToolPaint::MYPAINTBRUSH_UNPAINTABLE)) ||
112 (m_type == SELECT && !selectionEditable())) {
113
114 if (paintability == KisToolPaint::CLONE){
115 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
116 QString message = i18n("This tool cannot paint on clone layers. Please select a paint or vector layer or mask.");
117 kiscanvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
118 }
119
120 if (paintability == KisToolPaint::MYPAINTBRUSH_UNPAINTABLE) {
121 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
122 QString message = i18n("The MyPaint Brush Engine is not available for this colorspace");
123 kiscanvas->viewManager()->showFloatingMessage(message, koIcon("object-locked"));
124 }
125
126 event->ignore();
127 return;
128 }
129
131
133 m_points.append(m_points.first());
134 endStroke();
135 } else {
136 beginShape();
137 m_dragging = true;
138 }
139}
void setMode(ToolMode mode) override
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
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 KisToolShape::beginShape(), Private::canvas, KisTool::CLONE, endStroke(), koIcon, m_closeSnappingActivated, m_dragging, m_points, m_type, KisTool::MYPAINTBRUSH_UNPAINTABLE, KisTool::nodeEditable(), KisTool::nodePaintAbility(), PAINT, KisTool::PAINT_MODE, SELECT, KisTool::selectionEditable(), KisToolPaint::setMode(), KisViewManager::showFloatingMessage(), KisTool::UNPAINTABLE, and KisCanvas2::viewManager().

◆ beginPrimaryDoubleClickAction()

void KisToolPolylineBase::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 153 of file kis_tool_polyline_base.cpp.

154{
155 endStroke();
156
157 // this action will have no continuation
158 event->ignore();
159}

References endStroke().

◆ cancelStroke()

void KisToolPolylineBase::cancelStroke ( )
private

Definition at line 291 of file kis_tool_polyline_base.cpp.

292{
293 if (!m_dragging) return;
294
295 m_dragging = false;
296 m_points.clear();
298 updateArea();
299 endShape();
300}
virtual void endShape()

References KisToolShape::endShape(), m_closeSnappingActivated, m_dragging, m_points, and updateArea().

◆ deactivate()

void KisToolPolylineBase::deactivate ( )
overridevirtual

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

See also
activate()

Reimplemented from KoToolBase.

Reimplemented in KisToolSelectBase< __KisToolSelectPolygonalLocal >.

Definition at line 53 of file kis_tool_polyline_base.cpp.

54{
55 disconnect(action("undo_polygon_selection"), 0, this, 0);
57
58 KisInputManager *inputManager = (static_cast<KisCanvas2*>(canvas()))->globalInputManager();
59 if (inputManager) {
60 inputManager->detachPriorityEventFilter(this);
61 }
62
64}
void detachPriorityEventFilter(QObject *filter)
detachPriorityEventFilter
virtual void deactivate()

References KoToolBase::action(), cancelStroke(), Private::canvas, KoToolBase::deactivate(), and KisInputManager::detachPriorityEventFilter().

◆ dragBoundingRect()

QRectF KisToolPolylineBase::dragBoundingRect ( )
private

Definition at line 302 of file kis_tool_polyline_base.cpp.

303{
304 QRectF rect = pixelToView(QRectF(m_dragStart, m_dragEnd).normalized());
306 return rect;
307}
#define PREVIEW_LINE_WIDTH
QPointF pixelToView(const QPoint &pixelCoord) const
Definition kis_tool.cc:269

References m_dragEnd, m_dragStart, KisTool::pixelToView(), and PREVIEW_LINE_WIDTH.

◆ endPrimaryAction()

void KisToolPolylineBase::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< __KisToolSelectPolygonalLocal >.

Definition at line 141 of file kis_tool_polyline_base.cpp.

142{
145
146 if(m_dragging) {
149 m_points.append(m_dragStart);
150 }
151}
#define CHECK_MODE_SANITY_OR_RETURN(_mode)
Definition kis_tool.h:27
@ HOVER_MODE
Definition kis_tool.h:299
QPointF convertToPixelCoordAndSnap(KoPointerEvent *e, const QPointF &offset=QPointF(), bool useModifiers=true)
Definition kis_tool.cc:214

References CHECK_MODE_SANITY_OR_RETURN, KisTool::convertToPixelCoordAndSnap(), KisTool::HOVER_MODE, m_dragEnd, m_dragging, m_dragStart, m_points, KisTool::PAINT_MODE, and KisToolPaint::setMode().

◆ endStroke()

void KisToolPolylineBase::endStroke ( )
private

Definition at line 277 of file kis_tool_polyline_base.cpp.

278{
279 if (!m_dragging) return;
280
281 m_dragging = false;
282 if(m_points.count() > 1) {
284 }
285 m_points.clear();
287 updateArea();
288 endShape();
289}
virtual void finishPolyline(const QVector< QPointF > &points)=0

References KisToolShape::endShape(), finishPolyline(), m_closeSnappingActivated, m_dragging, m_points, and updateArea().

◆ eventFilter()

bool KisToolPolylineBase::eventFilter ( QObject * obj,
QEvent * event )
override

Definition at line 83 of file kis_tool_polyline_base.cpp.

84{
85 Q_UNUSED(obj);
86
87 if (!m_dragging) {
88 return false;
89 }
90 if (event->type() == QEvent::MouseButtonPress ||
91 event->type() == QEvent::MouseButtonDblClick) {
92 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
93 if (mouseEvent->button() == Qt::RightButton) {
95 return true;
96 }
97 } else if (event->type() == QEvent::TabletPress) {
98 QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
99 if (tabletEvent->button() == Qt::RightButton) {
101 return true;
102 }
103 }
104 return false;
105}

References m_dragging, and undoSelectionOrCancel().

◆ finishPolyline()

virtual void KisToolPolylineBase::finishPolyline ( const QVector< QPointF > & points)
protectedpure virtual

◆ mouseMoveEvent()

void KisToolPolylineBase::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 KisToolPaint.

Reimplemented in KisToolSelectBase< __KisToolSelectPolygonalLocal >.

Definition at line 173 of file kis_tool_polyline_base.cpp.

174{
175 if (m_dragging && !m_points.empty()) {
176 // erase old lines on canvas
177 QRectF updateRect = dragBoundingRect();
178 // get current mouse position
180 // draw new lines on canvas
181 updateRect |= dragBoundingRect();
182 updateCanvasViewRect(updateRect);
183
184
185 QPointF basePoint = pixelToView(m_points.first());
187 m_points.size() > 1 &&
188 (basePoint - pixelToView(m_dragEnd)).manhattanLength() < SNAPPING_THRESHOLD;
189
192 } else {
194 }
195}
virtual void requestUpdateOutline(const QPointF &outlineDocPoint, const KoPointerEvent *event)
void mouseMoveEvent(KoPointerEvent *event) override
QPointF point
The point in document coordinates.
#define SNAPPING_HANDLE_RADIUS
#define SNAPPING_THRESHOLD
void updateCanvasViewRect(const QRectF &viewRect)
Update the canvas for the given rectangle in view coordinates.
Definition kis_tool.cc:327

References KisTool::convertToPixelCoordAndSnap(), dragBoundingRect(), m_closeSnappingActivated, m_dragEnd, m_dragging, m_points, KisToolPaint::mouseMoveEvent(), KisTool::pixelToView(), KoPointerEvent::point, PREVIEW_LINE_WIDTH, KisToolPaint::requestUpdateOutline(), SNAPPING_HANDLE_RADIUS, SNAPPING_THRESHOLD, and KisTool::updateCanvasViewRect().

◆ paint()

void KisToolPolylineBase::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 229 of file kis_tool_polyline_base.cpp.

230{
231 Q_UNUSED(converter);
232
233 if (!canvas() || !currentImage())
234 return;
235
236 QPointF start, end;
237 QPointF startPos;
238 QPointF endPos;
239
240 QPainterPath path;
241 if (m_dragging && !m_points.empty()) {
242 startPos = pixelToView(m_dragStart);
243 endPos = pixelToView(m_dragEnd);
244 path.moveTo(startPos);
245 path.lineTo(endPos);
246 }
247
248 for (vQPointF::iterator it = m_points.begin(); it != m_points.end(); ++it) {
249
250 if (it == m_points.begin()) {
251 start = (*it);
252 } else {
253 end = (*it);
254
255 startPos = pixelToView(start);
256 endPos = pixelToView(end);
257 path.moveTo(startPos);
258 path.lineTo(endPos);
259 start = end;
260 }
261 }
262
264 QPointF basePoint = pixelToView(m_points.first());
265 path.addEllipse(basePoint, SNAPPING_HANDLE_RADIUS, SNAPPING_HANDLE_RADIUS);
266 }
267
268 paintToolOutline(&gc, path);
269 KisToolPaint::paint(gc,converter);
270}
void paint(QPainter &gc, const KoViewConverter &converter) override
KisImageWSP currentImage()
Definition kis_tool.cc:393
void paintToolOutline(QPainter *painter, const KisOptimizedBrushOutline &path)
Definition kis_tool.cc:589

References Private::canvas, KisTool::currentImage(), m_closeSnappingActivated, m_dragEnd, m_dragging, m_dragStart, m_points, KisToolPaint::paint(), KisTool::paintToolOutline(), KisTool::pixelToView(), and SNAPPING_HANDLE_RADIUS.

◆ popupWidget()

KisPopupWidgetInterface * KisToolPolylineBase::popupWidget ( )
overridevirtual
Returns
a widget with useful controls to be popped up on top of the canvas. Will not be called if popupActionsMenu() does not return null.

Reimplemented from KisToolPaint.

Reimplemented in KisToolSelectBase< __KisToolSelectPolygonalLocal >.

Definition at line 76 of file kis_tool_polyline_base.cpp.

77{
78 return m_dragging || m_type == SELECT ? nullptr : KisToolShape::popupWidget();
79}
virtual KisPopupWidgetInterface * popupWidget()
Definition KoToolBase.h:340

References m_dragging, m_type, KoToolBase::popupWidget(), and SELECT.

◆ requestStrokeCancellation()

void KisToolPolylineBase::requestStrokeCancellation ( )
overridevirtual

Called when the user requested the cancellation of the current stroke. If you tool supports cancelling, override this method and do the needed work there

Reimplemented from KoToolBase.

Definition at line 71 of file kis_tool_polyline_base.cpp.

72{
74}

References cancelStroke().

◆ requestStrokeEnd()

void KisToolPolylineBase::requestStrokeEnd ( )
overridevirtual

Called when the image decided that the stroke should better be ended. If you tool supports long strokes, override this method and do the needed work there

Reimplemented from KoToolBase.

Definition at line 66 of file kis_tool_polyline_base.cpp.

67{
68 endStroke();
69}

References endStroke().

◆ undoSelection

void KisToolPolylineBase::undoSelection ( )
privateslot

Definition at line 197 of file kis_tool_polyline_base.cpp.

198{
199 if (m_dragging) {
200 // Initialize with the dragging segment's rect
201 QRectF updateRect = dragBoundingRect();
202
203 if (m_points.size() > 1) {
204 // Add the rect for the last segment
205 const QRectF lastSegmentRect =
206 pixelToView(QRectF(m_points.last(), m_points.at(m_points.size() - 2)).normalized())
208 updateRect = updateRect.united(lastSegmentRect);
209
210 m_points.pop_back();
211 }
212 m_dragStart = m_points.last();
213
214 // Add the new dragging segment's rect
215 updateRect = updateRect.united(dragBoundingRect());
216 updateCanvasViewRect(updateRect);
217 }
218}

References dragBoundingRect(), m_dragging, m_dragStart, m_points, KisTool::pixelToView(), PREVIEW_LINE_WIDTH, and KisTool::updateCanvasViewRect().

◆ undoSelectionOrCancel

void KisToolPolylineBase::undoSelectionOrCancel ( )
privateslot

Definition at line 220 of file kis_tool_polyline_base.cpp.

221{
222 if (m_points.size() > 1) {
224 } else {
225 cancelStroke();
226 }
227}

References cancelStroke(), m_points, and undoSelection().

◆ updateArea()

void KisToolPolylineBase::updateArea ( )
private

Definition at line 272 of file kis_tool_polyline_base.cpp.

273{
275}
#define bounds(x, a, b)
void updateCanvasPixelRect(const QRectF &pixelRect)
Update the canvas for the given rectangle in image pixel coordinates.
Definition kis_tool.cc:322
KisImageWSP image() const
Definition kis_tool.cc:332

References bounds, KisTool::image(), and KisTool::updateCanvasPixelRect().

Member Data Documentation

◆ m_closeSnappingActivated

bool KisToolPolylineBase::m_closeSnappingActivated
private

Definition at line 60 of file kis_tool_polyline_base.h.

◆ m_dragEnd

QPointF KisToolPolylineBase::m_dragEnd
private

Definition at line 56 of file kis_tool_polyline_base.h.

◆ m_dragging

bool KisToolPolylineBase::m_dragging
private

Definition at line 57 of file kis_tool_polyline_base.h.

◆ m_dragStart

QPointF KisToolPolylineBase::m_dragStart
private

Definition at line 55 of file kis_tool_polyline_base.h.

◆ m_points

vQPointF KisToolPolylineBase::m_points
private

Definition at line 58 of file kis_tool_polyline_base.h.

◆ m_type

ToolType KisToolPolylineBase::m_type
private

Definition at line 59 of file kis_tool_polyline_base.h.


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