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 41 of file KoToolBase.cpp.

42 : d_ptr(new KoToolBasePrivate(this, canvas))
43{
44 Q_D(KoToolBase);
45 d->connectSignals();
46}
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 55 of file KoToolBase.cpp.

56{
57 delete d_ptr;
58}

References d_ptr.

◆ KoToolBase() [2/4]

KoToolBase::KoToolBase ( KoToolBasePrivate & dd)
protected

Definition at line 48 of file KoToolBase.cpp.

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

◆ 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 202 of file KoToolBase.cpp.

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

◆ 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 77 of file KoToolBase.cpp.

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

◆ 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 262 of file KoToolBase.cpp.

263{
264 Q_D(const KoToolBase);
265 return d->canvas;
266}

◆ 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 91 of file KoToolBase.cpp.

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

◆ 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 362 of file KoToolBase.cpp.

363{
364}

◆ 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 216 of file KoToolBase.cpp.

217{
219 if (QWidget *widget = createOptionWidget()) {
220 if (widget->objectName().isEmpty()) {
221 widget->setObjectName(toolId());
222 }
223 ow.append(widget);
224 }
225 return ow;
226}
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 246 of file KoToolBase.cpp.

247{
248 Q_D(const KoToolBase);
249 return d->currentCursor;
250}

◆ 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 180 of file KoToolBase.cpp.

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

◆ 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 170 of file KoToolBase.cpp.

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

◆ 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 175 of file KoToolBase.cpp.

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

◆ 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 256 of file KoToolBase.cpp.

257{
258 copy();
260}
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 407 of file KoToolBase.cpp.

408{
409 return QRectF();
410}

◆ 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 295 of file KoToolBase.cpp.

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

◆ 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 252 of file KoToolBase.cpp.

253{
254}

◆ 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 358 of file KoToolBase.cpp.

359{
360}

◆ 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 97 of file KoToolBase.cpp.

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

◆ 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 372 of file KoToolBase.cpp.

373{
374 Q_UNUSED(event);
375}

◆ 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 366 of file KoToolBase.cpp.

367{
368 Q_UNUSED(event);
369 Q_UNUSED(point);
370}

◆ 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 377 of file KoToolBase.cpp.

378{
379 Q_UNUSED(event);
380 Q_UNUSED(point);
381}

◆ 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 129 of file KoToolBase.cpp.

130{
131}

◆ 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 234 of file KoToolBase.cpp.

235{
236 Q_D(const KoToolBase);
237 return d->factory;
238}

◆ 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 160 of file KoToolBase.cpp.

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

◆ 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 165 of file KoToolBase.cpp.

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

◆ grabSensitivity()

int KoToolBase::grabSensitivity ( ) const
protected

Convenience function to get the current grab sensitivity.

Definition at line 309 of file KoToolBase.cpp.

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

◆ handleDocRadius()

qreal KoToolBase::handleDocRadius ( ) const
protected

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

Definition at line 287 of file KoToolBase.cpp.

288{
289 Q_D(const KoToolBase);
290 const KoViewConverter * converter = d->canvas->viewConverter();
291 const QPointF doc = converter->viewToDocument(QPointF(handleRadius(), handleRadius()));
292 return qMax(doc.x(), doc.y());
293}
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 320 of file KoToolBase.cpp.

321{
322 Q_D(const KoToolBase);
323 const KoViewConverter * converter = d->canvas->viewConverter();
324 uint handleSize = 2*grabSensitivity();
325 QRectF r = converter->viewToDocument(QRectF(0, 0, handleSize, handleSize));
326 r.moveCenter(position);
327 return r;
328}
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 330 of file KoToolBase.cpp.

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

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

◆ handleRadius()

int KoToolBase::handleRadius ( ) const
protected

Convenience function to get the current handle radius.

Definition at line 273 of file KoToolBase.cpp.

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

◆ hasSelection()

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

Reimplemented in ToolReferenceImages, and SvgTextTool.

Definition at line 383 of file KoToolBase.cpp.

384{
385 KoToolSelection *sel = selection();
386 return (sel && sel->hasSelection());
387}
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 151 of file KoToolBase.cpp.

152{
153 if (! event->commitString().isEmpty()) {
154 QKeyEvent ke(QEvent::KeyPress, -1, QFlags<Qt::KeyboardModifier>(), event->commitString());
155 keyPressEvent(&ke);
156 }
157 event->accept();
158}
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 133 of file KoToolBase.cpp.

134{
135 Q_D(const KoToolBase);
136 if (d->canvas->canvasWidget() == 0)
137 return QVariant();
138
139 switch (query) {
140 case Qt::ImEnabled:
141 return isInTextMode();
142 case Qt::ImCursorRectangle:
143 return QRect(d->canvas->canvasWidget()->width() / 2, 0, 1, d->canvas->canvasWidget()->height());
144 case Qt::ImFont:
145 return d->canvas->canvasWidget()->font();
146 default:
147 return QVariant();
148 }
149}
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 61 of file KoToolBase.cpp.

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

◆ 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 412 of file KoToolBase.cpp.

413{
414 Q_D(const KoToolBase);
415 return d->isInTextMode;
416}

◆ isOpacityPresetMode()

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

Definition at line 451 of file KoToolBase.cpp.

452{
453 Q_D(const KoToolBase);
454 return d->isOpacityPresetMode;
455}

◆ 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 118 of file KoToolBase.cpp.

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

◆ 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 123 of file KoToolBase.cpp.

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

◆ 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 67 of file KoToolBase.cpp.

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

◆ 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 439 of file KoToolBase.cpp.

440{
441 Q_D(const KoToolBase);
442 return d->maskSyntheticEvents;
443}

◆ 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 108 of file KoToolBase.cpp.

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

◆ 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 113 of file KoToolBase.cpp.

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

◆ 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 192 of file KoToolBase.cpp.

193{
194 Q_D(KoToolBase);
195 if (!d->optionWidgetsCreated) {
196 d->optionWidgets = createOptionWidgets();
197 d->optionWidgetsCreated = true;
198 }
199 return d->optionWidgets;
200}
virtual QList< QPointer< QWidget > > createOptionWidgets()

References createOptionWidgets().

◆ 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 >, 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 348 of file KoToolBase.cpp.

349{
350 return false;
351}

◆ 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 394 of file KoToolBase.cpp.

395{
396 Q_D(KoToolBase);
397
398 QRectF dirtyRect = d->lastDecorationsRect;
399 d->lastDecorationsRect = decorationsRect();
400 dirtyRect |= d->lastDecorationsRect;
401
402 if (!dirtyRect.isEmpty()) {
403 canvas()->updateCanvas(dirtyRect);
404 }
405}
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 427 of file KoToolBase.cpp.

428{
429}

◆ 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 431 of file KoToolBase.cpp.

432{
433}

◆ 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 435 of file KoToolBase.cpp.

436{
437}

◆ 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 418 of file KoToolBase.cpp.

419{
424}
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 353 of file KoToolBase.cpp.

354{
355 return false;
356}

◆ 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 389 of file KoToolBase.cpp.

390{
391 return 0;
392}

◆ 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 468 of file KoToolBase.cpp.

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

◆ setConverter()

void KoToolBase::setConverter ( KoDerivedResourceConverterSP converter)
protected

Definition at line 463 of file KoToolBase.cpp.

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

◆ setFactory()

void KoToolBase::setFactory ( KoToolFactoryBase * factory)
private

Set the KoToolFactoryBase that created this tool.

Parameters
factorythe KoToolFactoryBase
See also
KoToolFactoryBase

Definition at line 228 of file KoToolBase.cpp.

229{
230 Q_D(KoToolBase);
231 d->factory = factory;
232}
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 457 of file KoToolBase.cpp.

458{
459 Q_D(KoToolBase);
460 d->isOpacityPresetMode = value;
461}
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 445 of file KoToolBase.cpp.

446{
447 Q_D(KoToolBase);
448 d->maskSyntheticEvents = value;
449}

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 268 of file KoToolBase.cpp.

269{
270 Q_EMIT statusTextChanged(statusText);
271}
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 340 of file KoToolBase.cpp.

341{
342 Q_D(KoToolBase);
343 d->isInTextMode = value;
344 qApp->inputMethod()->update(Qt::ImEnabled);
345 Q_EMIT textModeChanged(d->isInTextMode);
346}
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 473 of file KoToolBase.cpp.

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

◆ toolConverters()

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

Definition at line 479 of file KoToolBase.cpp.

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

◆ 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 240 of file KoToolBase.cpp.

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

◆ updateOptionsWidgetIcons

void KoToolBase::updateOptionsWidgetIcons ( )
slot

force the update of the icons on the cached options widget

Definition at line 485 of file KoToolBase.cpp.

486{
487 Q_D(KoToolBase);
488 if (d->optionWidgetsCreated) {
489 QObjectList objects;
490 Q_FOREACH (QPointer<QWidget> widget, d->optionWidgets) {
491 objects.append(widget);
492 }
493 while (!objects.isEmpty()) {
494 QObject* object = objects.takeFirst();
495 objects.append(object->children());
497 }
498 }
499}
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 185 of file KoToolBase.cpp.

186{
187 Q_D(KoToolBase);
188 d->currentCursor = cursor;
189 Q_EMIT cursorChanged(d->currentCursor);
190}
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 103 of file KoToolBase.cpp.

104{
105 return true;
106}

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: