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

#include <KoToolBase.h>

+ Inheritance diagram for KoToolBase:

Public Slots

virtual void activate (const QSet< KoShape * > &shapes)
 
virtual void canvasResourceChanged (int key, const QVariant &res)
 
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 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

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 deleteSelection ()
 
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
 
virtual void mouseDoubleClickEvent (KoPointerEvent *event)
 
virtual void mouseMoveEvent (KoPointerEvent *event)=0
 
virtual void mousePressEvent (KoPointerEvent *event)=0
 
virtual void mouseReleaseEvent (KoPointerEvent *event)=0
 
virtual void mouseTripleClickEvent (KoPointerEvent *event)
 
QList< QPointer< QWidget > > optionWidgets ()
 
virtual void paint (QPainter &painter, const KoViewConverter &converter)=0
 
virtual bool paste ()
 
virtual QMenu * popupActionsMenu ()
 
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
 

Protected Member Functions

virtual QWidget * createOptionWidget ()
 
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

KoToolBasePrivated_ptr
 

Private Member Functions

 KoToolBase ()
 
 KoToolBase (const KoToolBase &)
 
KoToolBaseoperator= (const KoToolBase &)
 
void setFactory (KoToolFactoryBase *factory)
 

Friends

class KoToolManager
 

Detailed Description

Abstract base class for all tools. Tools can create or manipulate flake shapes, canvas state or any other thing that a user may wish to do to his document or his view on a document with a pointing device.

There exists an instance of every tool for every pointer device. These instances are managed by the toolmanager..

Definition at line 56 of file KoToolBase.h.

Constructor & Destructor Documentation

◆ KoToolBase() [1/4]

KoToolBase::KoToolBase ( KoCanvasBase * canvas)
explicit

Constructor, normally only called by the factory (see KoToolFactoryBase)

Parameters
canvasthe canvas interface this tool will work for.

Definition at line 42 of file KoToolBase.cpp.

43 : d_ptr(new KoToolBasePrivate(this, canvas))
44{
45 Q_D(KoToolBase);
46 d->connectSignals();
47}
KoToolBasePrivate * d_ptr
Definition KoToolBase.h:567
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.

◆ ~KoToolBase()

KoToolBase::~KoToolBase ( )
override

Definition at line 56 of file KoToolBase.cpp.

57{
58 delete d_ptr;
59}

References d_ptr.

◆ KoToolBase() [2/4]

KoToolBase::KoToolBase ( KoToolBasePrivate & dd)
protected

Definition at line 49 of file KoToolBase.cpp.

50 : d_ptr(&dd)
51{
52 Q_D(KoToolBase);
53 d->connectSignals();
54}

◆ KoToolBase() [3/4]

KoToolBase::KoToolBase ( )
private

◆ KoToolBase() [4/4]

KoToolBase::KoToolBase ( const KoToolBase & )
private

Member Function Documentation

◆ action()

QAction * KoToolBase::action ( const QString & name) const

Retrieve an action by name.

Definition at line 204 of file KoToolBase.cpp.

205{
206 Q_D(const KoToolBase);
207 if (d->canvas && d->canvas->canvasController() && d->canvas->canvasController()) {
208 return d->canvas->canvasController()->actionCollection()->action(name);
209 }
210 return 0;
211}

◆ activate

void KoToolBase::activate ( const QSet< KoShape * > & shapes)
virtualslot

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 in KisToolColorSampler, KoPencilTool, KoPathTool, KoZoomTool, KisToolPolylineBase, KisToolRectangleBase, KisToolSelectBase< __KisToolSelectEllipticalLocal >, KisToolSelectBase< __KisToolSelectOutlineLocal >, KisToolSelectBase< __KisToolSelectPolygonalLocal >, KisToolSelectBase< __KisToolSelectRectangularLocal >, KisToolLine, KarbonCalligraphyTool, SvgTextTool, and KisToolDyna.

Definition at line 78 of file KoToolBase.cpp.

79{
80 Q_UNUSED(shapes);
81
82 Q_D(KoToolBase);
83 d->isActivated = true;
84}

◆ activateTool

void KoToolBase::activateTool ( const QString & id)
signal

Emitted when this tool wants itself to be replaced by another tool.

Parameters
idthe identification of the desired tool
See also
toolId(), KoToolFactoryBase::id()

◆ canvas()

KoCanvasBase * KoToolBase::canvas ( ) const

Returns the canvas the tool is working on.

Definition at line 264 of file KoToolBase.cpp.

265{
266 Q_D(const KoToolBase);
267 return d->canvas;
268}

◆ canvasResourceChanged

void KoToolBase::canvasResourceChanged ( int key,
const QVariant & res )
virtualslot

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 in DefaultTool, KisToolCrop, and KisToolPaint.

Definition at line 92 of file KoToolBase.cpp.

93{
94 Q_UNUSED(key);
95 Q_UNUSED(res);
96}

◆ copy()

void KoToolBase::copy ( ) const
virtual

copies the tools selection to the clipboard. The default implementation is empty to aid tools that don't have any selection.

See also
selection()

Reimplemented in DefaultTool, and SvgTextTool.

Definition at line 364 of file KoToolBase.cpp.

365{
366}

◆ createOptionWidget()

◆ createOptionWidgets()

QList< QPointer< QWidget > > KoToolBase::createOptionWidgets ( )
protectedvirtual

Reimplemented in KoCreatePathTool, KoPencilTool, KoPathTool, KisToolRectangleBase, __KisToolPathLocalTool, __KisToolPencilLocalTool, DefaultTool, ToolReferenceImages, KarbonCalligraphyTool, __KisToolSelectPathLocalTool, and KisToolPathLocalTool.

Definition at line 218 of file KoToolBase.cpp.

219{
221 if (QWidget *widget = createOptionWidget()) {
222 if (widget->objectName().isEmpty()) {
223 widget->setObjectName(toolId());
224 }
225 ow.append(widget);
226 }
227 return ow;
228}
Q_INVOKABLE QString toolId() const
virtual QWidget * createOptionWidget()

References createOptionWidget(), and toolId().

◆ cursor()

QCursor KoToolBase::cursor ( ) const

return the last emitted cursor

Definition at line 248 of file KoToolBase.cpp.

249{
250 Q_D(const KoToolBase);
251 return d->currentCursor;
252}

◆ cursorChanged

void KoToolBase::cursorChanged ( const QCursor & cursor)
signal

Emitted by useCursor() when the cursor to display on the canvas is changed. The KoToolManager should connect to this signal to handle cursors further.

◆ customMoveEvent()

void KoToolBase::customMoveEvent ( KoPointerEvent * event)
virtual

Called when a custom device moved over the canvas. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this custom device move

Definition at line 181 of file KoToolBase.cpp.

182{
183 event->ignore();
184}

◆ customPressEvent()

void KoToolBase::customPressEvent ( KoPointerEvent * event)
virtual

Called when (one of) a custom device buttons is pressed. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this custom device press

Definition at line 171 of file KoToolBase.cpp.

172{
173 event->ignore();
174}

◆ customReleaseEvent()

void KoToolBase::customReleaseEvent ( KoPointerEvent * event)
virtual

Called when (one of) a custom device buttons is released. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this custom device release

Definition at line 176 of file KoToolBase.cpp.

177{
178 event->ignore();
179}

◆ cut()

void KoToolBase::cut ( )
virtual

Cut the tools selection and copy it to the clipboard. The default implementation calls copy() and then deleteSelection()

See also
copy()
deleteSelection()

Definition at line 258 of file KoToolBase.cpp.

259{
260 copy();
262}
virtual void deleteSelection()
virtual void copy() const

References copy(), and deleteSelection().

◆ deactivate

◆ decorationsRect()

QRectF KoToolBase::decorationsRect ( ) const
virtual

Reimplemented in KoCreatePathTool, KoPathTool, DefaultTool, SvgTextTool, and KisDynamicDelegatedTool< KisToolShape >.

Definition at line 409 of file KoToolBase.cpp.

410{
411 return QRectF();
412}

◆ decorationThickness()

int KoToolBase::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);

Returns
the minimum thickness for decoration lines in pixels.

Definition at line 297 of file KoToolBase.cpp.

298{
299 Q_D(const KoToolBase);
300 if (d->canvas
301 && d->canvas->resourceManager()
302 )
303 {
304 return d->canvas->resourceManager()->decorationThickness();
305 }
306 else {
307 return 1;
308 }
309}

◆ deleteSelection()

void KoToolBase::deleteSelection ( )
virtual

Delete the tools selection. The default implementation is empty to aid tools that don't have any selection.

See also
selection()

Reimplemented in KoPathTool, KisTool, DefaultTool, ToolReferenceImages, and SvgTextTool.

Definition at line 254 of file KoToolBase.cpp.

255{
256}

◆ deselect()

void KoToolBase::deselect ( )
virtual

deselect the tool should clear the selection if it has one.

Reimplemented in KoPathTool, DefaultTool, and SvgTextTool.

Definition at line 360 of file KoToolBase.cpp.

361{
362}

◆ documentResourceChanged

void KoToolBase::documentResourceChanged ( int key,
const QVariant & res )
virtualslot

This method is called whenever a property in the resource provider associated with the document this tool belongs to changes. An example is the handle radius

Definition at line 98 of file KoToolBase.cpp.

99{
100 Q_UNUSED(key);
101 Q_UNUSED(res);
102}

◆ dragLeaveEvent()

void KoToolBase::dragLeaveEvent ( QDragLeaveEvent * event)
virtual

Handle the dragLeaveEvent Basically just a notification that the drag is no long relevant The tool should Accept the event if it is meaningful; Default implementation does not.

Definition at line 374 of file KoToolBase.cpp.

375{
376 Q_UNUSED(event);
377}

◆ dragMoveEvent()

void KoToolBase::dragMoveEvent ( QDragMoveEvent * event,
const QPointF & point )
virtual

Handle the dragMoveEvent A tool typically has one or more shapes selected and dropping into should do something meaningful for this specific shape and tool combination. For example dropping text in a text tool. The tool should Accept the event if it is meaningful; Default implementation does not.

Definition at line 368 of file KoToolBase.cpp.

369{
370 Q_UNUSED(event);
371 Q_UNUSED(point);
372}

◆ dropEvent()

void KoToolBase::dropEvent ( QDropEvent * event,
const QPointF & point )
virtual

Handle the dropEvent A tool typically has one or more shapes selected and dropping into should do something meaningful for this specific shape and tool combination. For example dropping text in a text tool. The tool should Accept the event if it is meaningful; Default implementation does not.

Definition at line 379 of file KoToolBase.cpp.

380{
381 Q_UNUSED(event);
382 Q_UNUSED(point);
383}

◆ explicitUserStrokeEndRequest()

void KoToolBase::explicitUserStrokeEndRequest ( )
virtual

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.

Reimplemented in KoPathTool, DefaultTool, KisDynamicDelegatedTool< KisToolShape >, and KisToolLazyBrush.

Definition at line 130 of file KoToolBase.cpp.

131{
132}

◆ factory()

KoToolFactoryBase * KoToolBase::factory ( ) const

The factory holds properties common to all instances of the same tool type, such as the string identifying the class or the icon name.

Not all tool instances have a factory reference, for example the "delegated" inner implementations to which events are forwarded don't have one, as well as instances created by regression tests.

Every instance used by the tool manager has a factory reference and a tool identifier, but they're not available during construction.

Definition at line 236 of file KoToolBase.cpp.

237{
238 Q_D(const KoToolBase);
239 return d->factory;
240}

◆ focusInEvent()

void KoToolBase::focusInEvent ( QFocusEvent * event)
virtual

This passes on the focusInEven from the canvas widget, which can be used to activate animating decorations (like a cursor blink effect in the text tool).

Reimplemented in SvgTextTool.

Definition at line 161 of file KoToolBase.cpp.

162{
163 event->ignore();
164}

◆ focusOutEvent()

void KoToolBase::focusOutEvent ( QFocusEvent * event)
virtual

This passes on the focusInEven from the canvas widget, which can be used to deactivate animating decorations (like a cursor blink effect in the text tool).

Reimplemented in SvgTextTool.

Definition at line 166 of file KoToolBase.cpp.

167{
168 event->ignore();
169}

◆ grabSensitivity()

int KoToolBase::grabSensitivity ( ) const
protected

Convenience function to get the current grab sensitivity.

Definition at line 311 of file KoToolBase.cpp.

312{
313 Q_D(const KoToolBase);
314 if(d->canvas->shapeController()->resourceManager())
315 {
316 return d->canvas->shapeController()->resourceManager()->grabSensitivity();
317 } else {
318 return 3;
319 }
320}

◆ handleDocRadius()

qreal KoToolBase::handleDocRadius ( ) const
protected

Convenience function to get the current handle radius measured in document coordinates (points)

Definition at line 289 of file KoToolBase.cpp.

290{
291 Q_D(const KoToolBase);
292 const KoViewConverter * converter = d->canvas->viewConverter();
293 const QPointF doc = converter->viewToDocument(QPointF(handleRadius(), handleRadius()));
294 return qMax(doc.x(), doc.y());
295}
int handleRadius() const
Convenience function to get the current handle radius.
virtual QPointF viewToDocument(const QPointF &viewPoint) const

References handleRadius(), and KoViewConverter::viewToDocument().

◆ handleGrabRect()

QRectF KoToolBase::handleGrabRect ( const QPointF & position) const
protected

Returns a handle grab rect at the given position.

The position is expected to be in document coordinates. The grab sensitivity canvas resource is used for the dimension of the rectangle.

Returns
the handle rectangle in document coordinates

Definition at line 322 of file KoToolBase.cpp.

323{
324 Q_D(const KoToolBase);
325 const KoViewConverter * converter = d->canvas->viewConverter();
326 uint handleSize = 2*grabSensitivity();
327 QRectF r = converter->viewToDocument(QRectF(0, 0, handleSize, handleSize));
328 r.moveCenter(position);
329 return r;
330}
unsigned int uint
int grabSensitivity() const
Convenience function to get the current grab sensitivity.

References grabSensitivity(), and KoViewConverter::viewToDocument().

◆ handlePaintRect()

QRectF KoToolBase::handlePaintRect ( const QPointF & position) const
protected

Returns a handle paint rect at the given position.

The position is expected to be in document coordinates. The handle radius canvas resource is used for the dimension of the rectangle.

Returns
the handle rectangle in document coordinates

Definition at line 332 of file KoToolBase.cpp.

333{
334 Q_D(const KoToolBase);
335 const KoViewConverter * converter = d->canvas->viewConverter();
336 uint handleSize = 2*handleRadius();
337 QRectF r = converter->viewToDocument(QRectF(0, 0, handleSize, handleSize));
338 r.moveCenter(position);
339 return r;
340}

References handleRadius(), and KoViewConverter::viewToDocument().

◆ handleRadius()

int KoToolBase::handleRadius ( ) const
protected

Convenience function to get the current handle radius.

Definition at line 275 of file KoToolBase.cpp.

276{
277 Q_D(const KoToolBase);
278 if (d->canvas
279 && d->canvas->resourceManager()
280 )
281 {
282 return d->canvas->resourceManager()->handleRadius();
283 }
284 else {
285 return 3;
286 }
287}

◆ hasSelection()

bool KoToolBase::hasSelection ( )
virtual
Returns
true if the tool has selected data.

Reimplemented in ToolReferenceImages, and SvgTextTool.

Definition at line 385 of file KoToolBase.cpp.

386{
387 KoToolSelection *sel = selection();
388 return (sel && sel->hasSelection());
389}
virtual KoToolSelection * selection()
virtual bool hasSelection()
return true if the tool currently has something selected that can be copied or deleted.

References KoToolSelection::hasSelection(), and selection().

◆ inputMethodEvent()

void KoToolBase::inputMethodEvent ( QInputMethodEvent * event)
virtual

Text entry of complex text, like CJK, can be made more interactive if a tool implements this and the InputMethodQuery() methods. Reimplementing this only provides the user with a more responsive text experience, since the default implementation forwards the typed text as key pressed events.

Parameters
eventthe input method event.

Reimplemented in SvgTextTool.

Definition at line 152 of file KoToolBase.cpp.

153{
154 if (! event->commitString().isEmpty()) {
155 QKeyEvent ke(QEvent::KeyPress, -1, QFlags<Qt::KeyboardModifier>(), event->commitString());
156 keyPressEvent(&ke);
157 }
158 event->accept();
159}
virtual void keyPressEvent(QKeyEvent *event)

References keyPressEvent().

◆ inputMethodQuery()

QVariant KoToolBase::inputMethodQuery ( Qt::InputMethodQuery query) const
virtual

This method is used to query a set of properties of the tool to be able to support complex input method operations as support for surrounding text and reconversions. Default implementation returns simple defaults, for tools that want to provide a more responsive text entry experience for CJK languages it would be good to reimplement.

Parameters
queryspecifies which property is queried.
converterthe view converter for the current canvas.

Reimplemented in SvgTextTool.

Definition at line 134 of file KoToolBase.cpp.

135{
136 Q_D(const KoToolBase);
137 if (d->canvas->canvasWidget() == 0)
138 return QVariant();
139
140 switch (query) {
141 case Qt::ImEnabled:
142 return isInTextMode();
143 case Qt::ImCursorRectangle:
144 return QRect(d->canvas->canvasWidget()->width() / 2, 0, 1, d->canvas->canvasWidget()->height());
145 case Qt::ImFont:
146 return d->canvas->canvasWidget()->font();
147 default:
148 return QVariant();
149 }
150}
bool isInTextMode() const

References isInTextMode().

◆ isActivated()

bool KoToolBase::isActivated ( ) const
protected

Returns true if activate() has been called (more times than deactivate :) )

Definition at line 62 of file KoToolBase.cpp.

63{
64 Q_D(const KoToolBase);
65 return d->isActivated;
66}

◆ isInTextMode()

bool KoToolBase::isInTextMode ( ) const

This method can be reimplemented in a subclass.

Returns
returns true, if the tool is in text mode. that means, that there is any kind of textual input and all single key shortcuts should be eaten.

Definition at line 414 of file KoToolBase.cpp.

415{
416 Q_D(const KoToolBase);
417 return d->isInTextMode;
418}

◆ isOpacityPresetMode()

bool KoToolBase::isOpacityPresetMode ( ) const
Returns
true if the tool uses preset opacity, false if it uses tool.

Definition at line 453 of file KoToolBase.cpp.

454{
455 Q_D(const KoToolBase);
456 return d->isOpacityPresetMode;
457}

◆ keyPressEvent()

void KoToolBase::keyPressEvent ( QKeyEvent * event)
virtual

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 in KoPencilTool, KoInteractionTool, KoPathTool, KoZoomTool, KisToolRectangleBase, KisToolSelectBase< __KisToolSelectEllipticalLocal >, KisToolSelectBase< __KisToolSelectOutlineLocal >, KisToolSelectBase< __KisToolSelectPolygonalLocal >, KisToolSelectBase< __KisToolSelectRectangularLocal >, KisToolOutlineBase, KisAssistantTool, KisToolPan, DefaultTool, SvgTextTool, and KisDynamicDelegatedTool< KisToolShape >.

Definition at line 119 of file KoToolBase.cpp.

120{
121 e->ignore();
122}

◆ keyReleaseEvent()

void KoToolBase::keyReleaseEvent ( QKeyEvent * event)
virtual

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 in KoInteractionTool, KoPathTool, KoZoomTool, KisToolRectangleBase, KisToolSelectBase< __KisToolSelectEllipticalLocal >, KisToolSelectBase< __KisToolSelectOutlineLocal >, KisToolSelectBase< __KisToolSelectPolygonalLocal >, KisToolSelectBase< __KisToolSelectRectangularLocal >, KisToolOutlineBase, SvgTextTool, and KisDynamicDelegatedTool< KisToolShape >.

Definition at line 124 of file KoToolBase.cpp.

125{
126 e->ignore();
127}

◆ lastDeliveredPointerEvent()

KoPointerEvent * KoToolBase::lastDeliveredPointerEvent ( ) const
protected

Returns the last pointer event that was delivered to the canvas, the tool belongs to. This event might be used as an approximation for the event0 handlers not having their own events, like activate()/deactivate().

Definition at line 68 of file KoToolBase.cpp.

69{
70 Q_D(const KoToolBase);
71
72 if (!d->canvas) return 0;
73 if (!d->canvas->toolProxy()) return 0;
74
75 return d->canvas->toolProxy()->lastDeliveredPointerEvent();
76}

◆ maskSyntheticEvents()

bool KoToolBase::maskSyntheticEvents ( ) const
Returns
true if synthetic mouse events on the canvas should be eaten.

For example, the guides tool should allow click and drag with touch, while the same touch events should be rejected by the freehand tool.

These events are sent by the OS in Windows

Definition at line 441 of file KoToolBase.cpp.

442{
443 Q_D(const KoToolBase);
444 return d->maskSyntheticEvents;
445}

◆ mouseDoubleClickEvent()

void KoToolBase::mouseDoubleClickEvent ( KoPointerEvent * event)
virtual

Called when (one of) the mouse or stylus buttons is double clicked. Implementors should call event->ignore() if they do not actually use the event. Default implementation ignores this event.

Parameters
eventstate and reason of this mouse or stylus press

Reimplemented in ToolReferenceImages, KoCreatePathTool, KoPathTool, KoZoomTool, KisTool, DefaultTool, SvgTextTool, and KisDynamicDelegatedTool< KisToolShape >.

Definition at line 109 of file KoToolBase.cpp.

110{
111 event->ignore();
112}

◆ mouseMoveEvent()

◆ mousePressEvent()

virtual void KoToolBase::mousePressEvent ( KoPointerEvent * event)
pure virtual

Called when (one of) the mouse or stylus buttons is pressed. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus press

Implemented in KisToolTransform, KoCreatePathTool, KoPencilTool, KoInteractionTool, KoPathTool, KisTool, KisToolPaint, DefaultTool, KarbonCalligraphyTool, SvgTextTool, and KisDynamicDelegatedTool< KisToolShape >.

◆ mouseReleaseEvent()

virtual void KoToolBase::mouseReleaseEvent ( KoPointerEvent * event)
pure virtual

Called when (one of) the mouse or stylus buttons is released. Implementors should call event->ignore() if they do not actually use the event.

Parameters
eventstate and reason of this mouse or stylus release

Implemented in KisToolTransform, KoCreatePathTool, KoPencilTool, KoInteractionTool, KoPathTool, KoZoomTool, KisTool, KisToolPaint, DefaultTool, KarbonCalligraphyTool, SvgTextTool, and KisDynamicDelegatedTool< KisToolShape >.

◆ mouseTripleClickEvent()

void KoToolBase::mouseTripleClickEvent ( KoPointerEvent * event)
virtual

Called when (one of) the mouse or stylus buttons is triple clicked. Implementors should call event->ignore() if they do not actually use the event. Default implementation ignores this event.

Parameters
eventstate and reason of this mouse or stylus press

Reimplemented in KisTool, SvgTextTool, and KisDynamicDelegatedTool< KisToolShape >.

Definition at line 114 of file KoToolBase.cpp.

115{
116 event->ignore();
117}

◆ operator=()

KoToolBase & KoToolBase::operator= ( const KoToolBase & )
private

◆ optionWidgets()

QList< QPointer< QWidget > > KoToolBase::optionWidgets ( )

Return the option widgets for this tool. Create them if they do not exist yet. If the tool does not have an option widget, this method return an empty list. (After discussion with Thomas, who prefers the toolmanager to handle that case.)

See also
m_optionWidgets

Definition at line 193 of file KoToolBase.cpp.

194{
195 Q_D(KoToolBase);
196 if (!d->optionWidgetsCreated) {
197 KisScopedPerformanceLogger perfLog(QStringLiteral("KoToolBase::optionWidgets(%1)").arg(toolId()));
198 d->optionWidgets = createOptionWidgets();
199 d->optionWidgetsCreated = true;
200 }
201 return d->optionWidgets;
202}
virtual QList< QPointer< QWidget > > createOptionWidgets()

References createOptionWidgets(), and toolId().

◆ paint()

virtual void KoToolBase::paint ( QPainter & painter,
const KoViewConverter & converter )
pure virtual

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.

Implemented in KisToolPaint, KisToolPolylineBase, KisToolRectangleBase, KisToolOutlineBase, KisAssistantTool, KisToolColorSampler, KisToolLine, KisToolMeasure, KisToolMove, KisToolMultihand, SvgTextTool, KisToolBasicBrushBase, KisToolTransform, KoCreatePathTool, KoPencilTool, KoInteractionTool, KoPathTool, KisToolGradient, KisToolPan, __KisToolPencilLocalTool, DefaultTool, KarbonCalligraphyTool, KisToolCrop, KisDynamicDelegatedTool< KisToolShape >, KisToolKnife, and KisToolSmartPatch.

◆ paste()

bool KoToolBase::paste ( )
virtual

Paste the clipboard selection. A tool typically has one or more shapes selected and pasting should do something meaningful for this specific shape and tool combination. Inserting text in a text tool, for example.

Returns
will return true if pasting succeeded. False if nothing happened.

Reimplemented in DefaultTool, and SvgTextTool.

Definition at line 350 of file KoToolBase.cpp.

351{
352 return false;
353}

◆ popupActionsMenu()

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

Reimplemented in KoPathTool, KisToolSelectBase< __KisToolSelectEllipticalLocal >, KisToolSelectBase< __KisToolSelectOutlineLocal >, KisToolSelectBase< __KisToolSelectPolygonalLocal >, KisToolSelectBase< __KisToolSelectRectangularLocal >, DefaultTool, ToolReferenceImages, KisToolCrop, KisDynamicDelegatedTool< KisToolShape >, and KisToolTransform.

Definition at line 334 of file KoToolBase.h.

334{return nullptr;}

◆ popupWidget()

virtual KisPopupWidgetInterface * KoToolBase::popupWidget ( )
inlinevirtual

◆ repaintDecorations

void KoToolBase::repaintDecorations ( )
virtualslot

request a repaint of the decorations to be made. This triggers an update call on the canvas, but does not paint directly.

Reimplemented in KoPathTool.

Definition at line 396 of file KoToolBase.cpp.

397{
398 Q_D(KoToolBase);
399
400 QRectF dirtyRect = d->lastDecorationsRect;
401 d->lastDecorationsRect = decorationsRect();
402 dirtyRect |= d->lastDecorationsRect;
403
404 if (!dirtyRect.isEmpty()) {
405 canvas()->updateCanvas(dirtyRect);
406 }
407}
virtual void updateCanvas(const QRectF &rc)=0
virtual QRectF decorationsRect() const

References canvas(), decorationsRect(), and KoCanvasBase::updateCanvas().

◆ requestRedoDuringStroke

void KoToolBase::requestRedoDuringStroke ( )
virtualslot

Called when the user requested redo while the stroke is active. If your tool supports redo and maintains an intermediate state which can interfere with redo override this method to handle the state.

Definition at line 429 of file KoToolBase.cpp.

430{
431}

◆ requestStrokeCancellation

void KoToolBase::requestStrokeCancellation ( )
virtualslot

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 in KoPathTool, KisToolPolylineBase, KisToolLine, and SvgTextTool.

Definition at line 433 of file KoToolBase.cpp.

434{
435}

◆ requestStrokeEnd

void KoToolBase::requestStrokeEnd ( )
virtualslot

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 in KoPathTool, KisToolPolylineBase, KisToolLine, and SvgTextTool.

Definition at line 437 of file KoToolBase.cpp.

438{
439}

◆ requestUndoDuringStroke

void KoToolBase::requestUndoDuringStroke ( )
virtualslot

Called when the user requested undo while the stroke is active. If you tool supports undo of the part of its actions, override this method and do the needed work there.

NOTE: Default implementation forwards this request to requestStrokeCancellation() method, so that the stroke would be cancelled.

Default implementation just cancels the stroke

Reimplemented in KoPathTool.

Definition at line 420 of file KoToolBase.cpp.

421{
426}
virtual void requestStrokeCancellation()

References requestStrokeCancellation().

◆ selectAll()

bool KoToolBase::selectAll ( )
virtual

selectAll select all data the tool can select.

Returns
true if something happened, false if nothing happened.

Reimplemented in KoPathTool, DefaultTool, and SvgTextTool.

Definition at line 355 of file KoToolBase.cpp.

356{
357 return false;
358}

◆ selection()

KoToolSelection * KoToolBase::selection ( )
virtual

Returns the internal selection object of this tool. Each tool can have a selection which is private to that tool and the specified shape that it comes with. The default returns 0.

Reimplemented in KoPathTool, DefaultTool, and SvgTextTool.

Definition at line 391 of file KoToolBase.cpp.

392{
393 return 0;
394}

◆ selectionChanged

void KoToolBase::selectionChanged ( bool hasSelection)
signal

A tool can have a selection that is copy-able, this signal is emitted when that status changes.

Parameters
hasSelectionis true when the tool holds selected data.

◆ setAbstractResource()

void KoToolBase::setAbstractResource ( KoAbstractCanvasResourceInterfaceSP abstractResource)
protected

Definition at line 470 of file KoToolBase.cpp.

470 {
471 Q_D(KoToolBase);
472 d->toolCanvasResources.abstractResources[abstractResource->key()] = abstractResource;
473}

◆ setConverter()

void KoToolBase::setConverter ( KoDerivedResourceConverterSP converter)
protected

Definition at line 465 of file KoToolBase.cpp.

465 {
466 Q_D(KoToolBase);
467 d->toolCanvasResources.converters[converter->key()] = converter;
468}

◆ setFactory()

void KoToolBase::setFactory ( KoToolFactoryBase * factory)
private

Set the KoToolFactoryBase that created this tool.

Parameters
factorythe KoToolFactoryBase
See also
KoToolFactoryBase

Definition at line 230 of file KoToolBase.cpp.

231{
232 Q_D(KoToolBase);
233 d->factory = factory;
234}
KoToolFactoryBase * factory() const

References factory().

◆ setIsOpacityPresetMode()

void KoToolBase::setIsOpacityPresetMode ( bool value)
protected

Sets the opacity mode to either preset (true) or tool (false).

Definition at line 459 of file KoToolBase.cpp.

460{
461 Q_D(KoToolBase);
462 d->isOpacityPresetMode = value;
463}
float value(const T *src, size_t ch)

References value().

◆ setMaskSyntheticEvents()

void KoToolBase::setMaskSyntheticEvents ( bool value)
protected

Allows subclasses to specify whether synthetic mouse events should be accepted.

Definition at line 447 of file KoToolBase.cpp.

448{
449 Q_D(KoToolBase);
450 d->maskSyntheticEvents = value;
451}

References value().

◆ setStatusText

void KoToolBase::setStatusText ( const QString & statusText)
slot

This method just relays the given text via the tools statusTextChanged signal.

Parameters
statusTextthe new status text

Definition at line 270 of file KoToolBase.cpp.

271{
272 Q_EMIT statusTextChanged(statusText);
273}
void statusTextChanged(const QString &statusText)

References statusTextChanged().

◆ setTextMode()

void KoToolBase::setTextMode ( bool value)
protected

You should set the text mode to true in subclasses, if this tool is in text input mode, eg if the users are able to type. If you don't set it, then single key shortcuts will get the key event and not this tool.

Definition at line 342 of file KoToolBase.cpp.

343{
344 Q_D(KoToolBase);
345 d->isInTextMode = value;
346 qApp->inputMethod()->update(Qt::ImEnabled);
347 Q_EMIT textModeChanged(d->isInTextMode);
348}
void textModeChanged(bool inTextMode)

References textModeChanged(), and value().

◆ statusTextChanged

void KoToolBase::statusTextChanged ( const QString & statusText)
signal

Emitted when the tool wants to display a different status text

Parameters
statusTextthe new status text

◆ textModeChanged

void KoToolBase::textModeChanged ( bool inTextMode)
signal

Emitted when the tool's text mode has changed.

Parameters
inTextModewhether it is now in text mode.

◆ toolAbstractResources()

QHash< int, KoAbstractCanvasResourceInterfaceSP > KoToolBase::toolAbstractResources ( )
protected

Definition at line 475 of file KoToolBase.cpp.

476{
477 Q_D(KoToolBase);
478 return d->toolCanvasResources.abstractResources;
479}

◆ toolConverters()

QHash< int, KoDerivedResourceConverterSP > KoToolBase::toolConverters ( )
protected

Definition at line 481 of file KoToolBase.cpp.

482{
483 Q_D(KoToolBase);
484 return d->toolCanvasResources.converters;
485}

◆ toolId()

QString KoToolBase::toolId ( ) const

get the identifier code from the KoToolFactoryBase that created this tool.

Returns
the toolId.
See also
KoToolFactoryBase::id()

Definition at line 242 of file KoToolBase.cpp.

243{
244 Q_D(const KoToolBase);
245 return d->factory ? d->factory->id() : 0;
246}

◆ updateOptionsWidgetIcons

void KoToolBase::updateOptionsWidgetIcons ( )
slot

force the update of the icons on the cached options widget

Definition at line 487 of file KoToolBase.cpp.

488{
489 Q_D(KoToolBase);
490 if (d->optionWidgetsCreated) {
491 QObjectList objects;
492 Q_FOREACH (QPointer<QWidget> widget, d->optionWidgets) {
493 objects.append(widget);
494 }
495 while (!objects.isEmpty()) {
496 QObject* object = objects.takeFirst();
497 objects.append(object->children());
499 }
500 }
501}
void updateIconCommon(QObject *object)

References KisIconUtils::updateIconCommon().

◆ useCursor()

void KoToolBase::useCursor ( const QCursor & cursor)
protected

Classes inheriting from this one can call this method to signify which cursor the tool wants to display at this time. Logical place to call it is after an incoming event has been handled.

Parameters
cursorthe new cursor.

Definition at line 186 of file KoToolBase.cpp.

187{
188 Q_D(KoToolBase);
189 d->currentCursor = cursor;
190 Q_EMIT cursorChanged(d->currentCursor);
191}
QCursor cursor() const
return the last emitted cursor
void cursorChanged(const QCursor &cursor)

References cursor(), and cursorChanged().

◆ wantsAutoScroll()

bool KoToolBase::wantsAutoScroll ( ) const
virtual

Return if dragging (moving with the mouse down) to the edge of a canvas should scroll the canvas (default is true).

Returns
if this tool wants mouse events to cause scrolling of canvas.

Reimplemented in KisToolFreehand, KisToolFill, KisToolMove, KisToolPan, DefaultTool, KisToolEncloseAndFill, KisDynamicDelegatedTool< KisToolShape >, and KisToolTransform.

Definition at line 104 of file KoToolBase.cpp.

105{
106 return true;
107}

Friends And Related Symbol Documentation

◆ KoToolManager

friend class KoToolManager
friend

Definition at line 572 of file KoToolBase.h.

Member Data Documentation

◆ d_ptr

KoToolBasePrivate* KoToolBase::d_ptr
protected

Definition at line 567 of file KoToolBase.h.


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