Krita Source Code Documentation
Loading...
Searching...
No Matches
KisToolProxy Class Reference

#include <kis_tool_proxy.h>

+ Inheritance diagram for KisToolProxy:

Public Types

enum  ActionState { BEGIN , CONTINUE , END }
 

Signals

void toolPrimaryActionActivated (bool activated)
 
- Signals inherited from KoToolProxy
void selectionChanged (bool hasSelection)
 
void toolChanged (const QString &toolId)
 

Public Member Functions

void activateToolAction (KisTool::ToolAction action)
 
bool alternateActionSupportsHiResEvents (KisTool::AlternateAction action) const
 
void deactivateToolAction (KisTool::ToolAction action)
 
bool forwardEvent (ActionState state, KisTool::ToolAction action, QEvent *event, QEvent *originalEvent)
 
void forwardHoverEvent (QEvent *event)
 
void initializeImage (KisImageSP image)
 
 KisToolProxy (KoCanvasBase *canvas, QObject *parent=0)
 
bool primaryActionSupportsHiResEvents () const
 
void setActiveTool (KoToolBase *tool) override
 Set the new active tool.
 
bool supportsPaintingAssistants () const
 
- Public Member Functions inherited from KoToolProxy
void copy () const
 Forwarded to the current KoToolBase.
 
void cut ()
 Forwarded to the current KoToolBase.
 
void deleteSelection ()
 Forwarded to the current KoToolBase.
 
void deselect ()
 Forwarded to the current KoToolBase.
 
void dragLeaveEvent (QDragLeaveEvent *event)
 Forwarded to the current KoToolBase.
 
void dragMoveEvent (QDragMoveEvent *event, const QPointF &point)
 Forwarded to the current KoToolBase.
 
void dropEvent (QDropEvent *event, const QPointF &point)
 Forwarded to the current KoToolBase.
 
void explicitUserStrokeEndRequest ()
 Forwarded to the current KoToolBase.
 
void focusInEvent (QFocusEvent *event)
 Forwarded to the current KoToolBase.
 
void focusOutEvent (QFocusEvent *event)
 Forwarded to the current KoToolBase.
 
bool hasSelection () const
 returns true if the current tool holds a selection
 
void inputMethodEvent (QInputMethodEvent *event)
 Forwarded to the current KoToolBase.
 
QVariant inputMethodQuery (Qt::InputMethodQuery query) const
 Forwarded to the current KoToolBase.
 
void keyPressEvent (QKeyEvent *event)
 Forwarded to the current KoToolBase.
 
void keyReleaseEvent (QKeyEvent *event)
 Forwarded to the current KoToolBase.
 
 KoToolProxy (KoCanvasBase *canvas, QObject *parent=0)
 
KoPointerEventlastDeliveredPointerEvent () const
 
void mouseDoubleClickEvent (KoPointerEvent *event)
 
void mouseDoubleClickEvent (QMouseEvent *event, const QPointF &point)
 Forwarded to the current KoToolBase.
 
void mouseMoveEvent (KoPointerEvent *event)
 
void mouseMoveEvent (QMouseEvent *event, const QPointF &point)
 Forwarded to the current KoToolBase.
 
void mousePressEvent (KoPointerEvent *event)
 
void mousePressEvent (QMouseEvent *event, const QPointF &point)
 Forwarded to the current KoToolBase.
 
void mouseReleaseEvent (KoPointerEvent *event)
 
void mouseReleaseEvent (QMouseEvent *event, const QPointF &point)
 Forwarded to the current KoToolBase.
 
void paint (QPainter &painter, const KoViewConverter &converter)
 Forwarded to the current KoToolBase.
 
bool paste ()
 Forwarded to the current KoToolBase.
 
QMenu * popupActionsMenu ()
 Forwarded to the current KoToolBase.
 
KisPopupWidgetInterfacepopupWidget ()
 Forwarded to the current KoToolBase.
 
KoToolProxyPrivatepriv ()
 
void processEvent (QEvent *) const
 
void repaintDecorations ()
 Forwarded to the current KoToolBase.
 
bool selectAll ()
 Forwarded to the current KoToolBase.
 
void tabletEvent (QTabletEvent *event, const QPointF &point)
 Forwarded to the current KoToolBase.
 
QVector< QKeySequence > toolPriorityShortcuts () const
 
void touchEvent (QTouchEvent *event, const QPointF &point)
 
 ~KoToolProxy () override
 

Protected Member Functions

QPointF documentToWidget (const QPointF &documentPoint) const override
 
QPointF widgetToDocument (const QPointF &widgetPoint) const override
 
- Protected Member Functions inherited from KoToolProxy
KoCanvasBasecanvas () const
 

Private Member Functions

KoPointerEvent convertEventToPointerEvent (QEvent *event, const QPointF &docPoint, bool *result)
 
void forwardToTool (ActionState state, KisTool::ToolAction action, QEvent *event, const QPointF &docPoint)
 
QPointF tabletToDocument (const QPointF &globalPos)
 

Private Attributes

bool m_isActionActivated
 
KisTool::ToolAction m_lastAction
 

Additional Inherited Members

- Protected Slots inherited from KoToolProxy
void requestRedoDuringStroke ()
 Forwarded to the current KoToolBase.
 
void requestStrokeCancellation ()
 Forwarded to the current KoToolBase.
 
void requestStrokeEnd ()
 Forwarded to the current KoToolBase.
 
void requestUndoDuringStroke ()
 Forwarded to the current KoToolBase.
 

Detailed Description

Definition at line 15 of file kis_tool_proxy.h.

Member Enumeration Documentation

◆ ActionState

Enumerator
BEGIN 

Beginning an action

CONTINUE 

Continuing an action

END 

Ending an action

Definition at line 19 of file kis_tool_proxy.h.

Constructor & Destructor Documentation

◆ KisToolProxy()

KisToolProxy::KisToolProxy ( KoCanvasBase * canvas,
QObject * parent = 0 )

Definition at line 14 of file kis_tool_proxy.cpp.

15 : KoToolProxy(canvas, parent),
18{
19}
KisTool::ToolAction m_lastAction
bool m_isActionActivated
KoCanvasBase * canvas() const
KoToolProxy(KoCanvasBase *canvas, QObject *parent=0)
@ Primary
Definition kis_tool.h:118

Member Function Documentation

◆ activateToolAction()

void KisToolProxy::activateToolAction ( KisTool::ToolAction action)

Definition at line 235 of file kis_tool_proxy.cpp.

236{
237 KisTool *activeTool = dynamic_cast<KisTool*>(const_cast<KisToolProxy*>(this)->priv()->activeTool);
238
239 if (activeTool) {
240 if (action == KisTool::Primary) {
241 activeTool->activatePrimaryAction();
242 } else {
244 }
245 }
246
247 m_isActionActivated = true;
248 m_lastAction = action;
249}
KoToolBase * activeTool
KoToolProxyPrivate * priv()
virtual void activatePrimaryAction()
Definition kis_tool.cc:421
virtual void activateAlternateAction(AlternateAction action)
Definition kis_tool.cc:456
static AlternateAction actionToAlternateAction(ToolAction action)
Definition kis_tool.cc:416

References KisTool::actionToAlternateAction(), KisTool::activateAlternateAction(), KisTool::activatePrimaryAction(), KoToolProxyPrivate::activeTool, m_isActionActivated, m_lastAction, KisTool::Primary, and KoToolProxy::priv().

◆ alternateActionSupportsHiResEvents()

bool KisToolProxy::alternateActionSupportsHiResEvents ( KisTool::AlternateAction action) const

Definition at line 216 of file kis_tool_proxy.cpp.

217{
218 KisTool *activeTool = dynamic_cast<KisTool*>(const_cast<KisToolProxy*>(this)->priv()->activeTool);
219 return activeTool && activeTool->alternateActionSupportsHiResEvents(action);
220}
virtual bool alternateActionSupportsHiResEvents(AlternateAction action) const
Definition kis_tool.cc:489

References KoToolProxyPrivate::activeTool, KisTool::alternateActionSupportsHiResEvents(), and KoToolProxy::priv().

◆ convertEventToPointerEvent()

KoPointerEvent KisToolProxy::convertEventToPointerEvent ( QEvent * event,
const QPointF & docPoint,
bool * result )
private

Definition at line 51 of file kis_tool_proxy.cpp.

52{
53 switch (event->type()) {
54 case QEvent::TabletPress:
55 case QEvent::TabletRelease:
56 case QEvent::TabletMove:
57 {
58 *result = true;
59 QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
60 KoPointerEvent ev(tabletEvent, docPoint);
61 return ev;
62 }
63 case QEvent::MouseButtonPress:
64 case QEvent::MouseButtonDblClick:
65 case QEvent::MouseButtonRelease:
66 case QEvent::MouseMove:
67 {
68 *result = true;
69 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
70 return KoPointerEvent(mouseEvent, docPoint);
71 }
72 case QEvent::TouchBegin:
73 case QEvent::TouchUpdate:
74 case QEvent::TouchEnd:
75 case QEvent::TouchCancel:
76 {
77 *result = true;
78 QTouchEvent *touchEvent = static_cast<QTouchEvent *> (event);
79 return KoPointerEvent(touchEvent, docPoint);
80 }
81 default:
82 ;
83 }
84
85 *result = false;
86 QMouseEvent fakeEvent(QEvent::MouseMove, QPoint(),
87 Qt::NoButton, Qt::NoButton,
88 Qt::NoModifier);
89
90 return KoPointerEvent(&fakeEvent, QPointF());
91}
void tabletEvent(QTabletEvent *event, const QPointF &point)
Forwarded to the current KoToolBase.
void touchEvent(QTouchEvent *event, const QPointF &point)

References KoToolProxy::tabletEvent(), and KoToolProxy::touchEvent().

◆ deactivateToolAction()

void KisToolProxy::deactivateToolAction ( KisTool::ToolAction action)

Definition at line 251 of file kis_tool_proxy.cpp.

252{
253 KisTool *activeTool = dynamic_cast<KisTool*>(const_cast<KisToolProxy*>(this)->priv()->activeTool);
254
255 if (activeTool) {
256 if (action == KisTool::Primary) {
257 activeTool->deactivatePrimaryAction();
258 } else {
260 }
261 }
262
263 m_isActionActivated = false;
264 m_lastAction = action;
265}
virtual void deactivateAlternateAction(AlternateAction action)
Definition kis_tool.cc:461
virtual void deactivatePrimaryAction()
Definition kis_tool.cc:426

References KisTool::actionToAlternateAction(), KoToolProxyPrivate::activeTool, KisTool::deactivateAlternateAction(), KisTool::deactivatePrimaryAction(), m_isActionActivated, m_lastAction, KisTool::Primary, and KoToolProxy::priv().

◆ documentToWidget()

QPointF KisToolProxy::documentToWidget ( const QPointF & documentPoint) const
overrideprotectedvirtual

Implements KoToolProxy.

Definition at line 43 of file kis_tool_proxy.cpp.

44{
45 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
46 Q_ASSERT(kritaCanvas);
47
48 return kritaCanvas->coordinatesConverter()->documentToWidget(documentPoint);
49}
KisCoordinatesConverter * coordinatesConverter
_Private::Traits< T >::Result documentToWidget(const T &obj) const

References KoToolProxy::canvas(), KisCanvas2::coordinatesConverter, and KisCoordinatesConverter::documentToWidget().

◆ forwardEvent()

bool KisToolProxy::forwardEvent ( ActionState state,
KisTool::ToolAction action,
QEvent * event,
QEvent * originalEvent )

Forwards the event to the active tool and returns true if the event was not ignored. That is by default the event is considered accepted, but the tool can explicitly ignore it.

Parameters
statebeginning, continuing, or ending the action.
actionalternate tool action requested.
eventthe event being sent to the tool by the AbstractInputAction.
originalEventthe original event received by the AbstractInputAction.

Definition at line 118 of file kis_tool_proxy.cpp.

119{
120 bool retval = true;
121
122 QTabletEvent *tabletEvent = dynamic_cast<QTabletEvent*>(event);
123 QMouseEvent *mouseEvent = dynamic_cast<QMouseEvent*>(event);
124 QTouchEvent *touchEvent = dynamic_cast<QTouchEvent *> (event);
125
126 if (tabletEvent) {
127 QPointF docPoint = widgetToDocument(tabletEvent->posF());
128 tabletEvent->accept();
129 this->tabletEvent(tabletEvent, docPoint);
130 forwardToTool(state, action, tabletEvent, docPoint);
131 retval = tabletEvent->isAccepted();
132 }
133 else if (mouseEvent) {
134 QPointF docPoint = widgetToDocument(mouseEvent->localPos());
135 mouseEvent->accept();
136 if (mouseEvent->type() == QEvent::MouseButtonPress) {
137 mousePressEvent(mouseEvent, docPoint);
138 } else if (mouseEvent->type() == QEvent::MouseButtonDblClick) {
139 mouseDoubleClickEvent(mouseEvent, docPoint);
140 } else if (mouseEvent->type() == QEvent::MouseButtonRelease) {
141 mouseReleaseEvent(mouseEvent, docPoint);
142 } else if (mouseEvent->type() == QEvent::MouseMove) {
143 mouseMoveEvent(mouseEvent, docPoint);
144 }
145 forwardToTool(state, action, originalEvent, docPoint);
146 retval = mouseEvent->isAccepted();
147 }
148 else if (touchEvent) {
149 QPointF docPoint = widgetToDocument(touchEvent->touchPoints().at(0).pos());
150 touchEvent->accept();
151 this->touchEvent(touchEvent, docPoint);
152 forwardToTool(state, action, touchEvent, docPoint);
153 retval = touchEvent->isAccepted();
154 }
155 else if (event && event->type() == QEvent::KeyPress) {
156 QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
157 keyPressEvent(kevent);
158 }
159 else if (event && event->type() == QEvent::KeyRelease) {
160 QKeyEvent* kevent = static_cast<QKeyEvent*>(event);
161 keyReleaseEvent(kevent);
162 }
163
164 return retval;
165}
void forwardToTool(ActionState state, KisTool::ToolAction action, QEvent *event, const QPointF &docPoint)
QPointF widgetToDocument(const QPointF &widgetPoint) const override
void mouseMoveEvent(QMouseEvent *event, const QPointF &point)
Forwarded to the current KoToolBase.
void mousePressEvent(QMouseEvent *event, const QPointF &point)
Forwarded to the current KoToolBase.
void mouseDoubleClickEvent(QMouseEvent *event, const QPointF &point)
Forwarded to the current KoToolBase.
void keyReleaseEvent(QKeyEvent *event)
Forwarded to the current KoToolBase.
void keyPressEvent(QKeyEvent *event)
Forwarded to the current KoToolBase.
void mouseReleaseEvent(QMouseEvent *event, const QPointF &point)
Forwarded to the current KoToolBase.

References forwardToTool(), KoToolProxy::keyPressEvent(), KoToolProxy::keyReleaseEvent(), KoToolProxy::mouseDoubleClickEvent(), KoToolProxy::mouseMoveEvent(), KoToolProxy::mousePressEvent(), KoToolProxy::mouseReleaseEvent(), KoToolProxy::tabletEvent(), KoToolProxy::touchEvent(), and widgetToDocument().

◆ forwardHoverEvent()

void KisToolProxy::forwardHoverEvent ( QEvent * event)

Definition at line 93 of file kis_tool_proxy.cpp.

94{
95 switch (event->type()) {
96 case QEvent::TabletMove: {
97 QTabletEvent *tabletEvent = static_cast<QTabletEvent*>(event);
98 QPointF docPoint = widgetToDocument(tabletEvent->posF());
99 this->tabletEvent(tabletEvent, docPoint);
100 return;
101 }
102
103 case QEvent::MouseMove: {
104 QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
105 QPointF docPoint = widgetToDocument(mouseEvent->localPos());
106 mouseMoveEvent(mouseEvent, docPoint);
107 return;
108 }
109
110 default: {
111 qWarning() << "forwardHoverEvent encountered unknown event type:"
112 << event->type();
113 return;
114 }
115 }
116}

References KoToolProxy::mouseMoveEvent(), KoToolProxy::tabletEvent(), and widgetToDocument().

◆ forwardToTool()

void KisToolProxy::forwardToTool ( ActionState state,
KisTool::ToolAction action,
QEvent * event,
const QPointF & docPoint )
private

Definition at line 167 of file kis_tool_proxy.cpp.

168{
169 bool eventValid = false;
170 KoPointerEvent ev = convertEventToPointerEvent(event, docPoint, &eventValid);
171 KisTool *activeTool = dynamic_cast<KisTool*>(priv()->activeTool);
172
173 if (!eventValid || !activeTool) return;
174
175 switch (state) {
176 case BEGIN:
177 if (action == KisTool::Primary) {
178 if (event->type() == QEvent::MouseButtonDblClick) {
179 activeTool->beginPrimaryDoubleClickAction(&ev);
180 } else {
181 activeTool->beginPrimaryAction(&ev);
182 }
183 } else {
184 if (event->type() == QEvent::MouseButtonDblClick) {
186 } else {
188 }
189 }
190 Q_EMIT toolPrimaryActionActivated(true);
191 break;
192 case CONTINUE:
193 if (action == KisTool::Primary) {
194 activeTool->continuePrimaryAction(&ev);
195 } else {
197 }
198 break;
199 case END:
200 if (action == KisTool::Primary) {
201 activeTool->endPrimaryAction(&ev);
202 } else {
204 }
205 Q_EMIT toolPrimaryActionActivated(false);
206 break;
207 }
208}
void toolPrimaryActionActivated(bool activated)
KoPointerEvent convertEventToPointerEvent(QEvent *event, const QPointF &docPoint, bool *result)
virtual void beginPrimaryAction(KoPointerEvent *event)
Definition kis_tool.cc:431
virtual void continueAlternateAction(KoPointerEvent *event, AlternateAction action)
Definition kis_tool.cc:477
virtual void endAlternateAction(KoPointerEvent *event, AlternateAction action)
Definition kis_tool.cc:483
virtual void endPrimaryAction(KoPointerEvent *event)
Definition kis_tool.cc:446
virtual void continuePrimaryAction(KoPointerEvent *event)
Definition kis_tool.cc:441
virtual void beginAlternateDoubleClickAction(KoPointerEvent *event, AlternateAction action)
Definition kis_tool.cc:472
virtual void beginAlternateAction(KoPointerEvent *event, AlternateAction action)
Definition kis_tool.cc:466
virtual void beginPrimaryDoubleClickAction(KoPointerEvent *event)
Definition kis_tool.cc:436

References KisTool::actionToAlternateAction(), KoToolProxyPrivate::activeTool, BEGIN, KisTool::beginAlternateAction(), KisTool::beginAlternateDoubleClickAction(), KisTool::beginPrimaryAction(), KisTool::beginPrimaryDoubleClickAction(), CONTINUE, KisTool::continueAlternateAction(), KisTool::continuePrimaryAction(), convertEventToPointerEvent(), END, KisTool::endAlternateAction(), KisTool::endPrimaryAction(), KisTool::Primary, KoToolProxy::priv(), and toolPrimaryActionActivated().

◆ initializeImage()

void KisToolProxy::initializeImage ( KisImageSP image)

Definition at line 21 of file kis_tool_proxy.cpp.

22{
23 connect(image, SIGNAL(sigUndoDuringStrokeRequested()), SLOT(requestUndoDuringStroke()), Qt::UniqueConnection);
24 connect(image, SIGNAL(sigRedoDuringStrokeRequested()), SLOT(requestRedoDuringStroke()), Qt::UniqueConnection);
25 connect(image, SIGNAL(sigStrokeCancellationRequested()), SLOT(requestStrokeCancellation()), Qt::UniqueConnection);
26 connect(image, SIGNAL(sigStrokeEndRequested()), SLOT(requestStrokeEnd()), Qt::UniqueConnection);
27}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void requestUndoDuringStroke()
Forwarded to the current KoToolBase.
void requestRedoDuringStroke()
Forwarded to the current KoToolBase.
void requestStrokeEnd()
Forwarded to the current KoToolBase.
void requestStrokeCancellation()
Forwarded to the current KoToolBase.

References connect(), KoToolProxy::requestRedoDuringStroke(), KoToolProxy::requestStrokeCancellation(), KoToolProxy::requestStrokeEnd(), and KoToolProxy::requestUndoDuringStroke().

◆ primaryActionSupportsHiResEvents()

bool KisToolProxy::primaryActionSupportsHiResEvents ( ) const

Definition at line 210 of file kis_tool_proxy.cpp.

211{
212 KisTool *activeTool = dynamic_cast<KisTool*>(const_cast<KisToolProxy*>(this)->priv()->activeTool);
213 return activeTool && activeTool->primaryActionSupportsHiResEvents();
214}
virtual bool primaryActionSupportsHiResEvents() const
Definition kis_tool.cc:451

References KoToolProxyPrivate::activeTool, KisTool::primaryActionSupportsHiResEvents(), and KoToolProxy::priv().

◆ setActiveTool()

void KisToolProxy::setActiveTool ( KoToolBase * tool)
overridevirtual

Set the new active tool.

Reimplemented from KoToolProxy.

Definition at line 222 of file kis_tool_proxy.cpp.

223{
224 if (!tool) return;
225
230 } else {
232 }
233}
void deactivateToolAction(KisTool::ToolAction action)
void activateToolAction(KisTool::ToolAction action)
virtual void setActiveTool(KoToolBase *tool)
Set the new active tool.

References activateToolAction(), deactivateToolAction(), m_isActionActivated, m_lastAction, and KoToolProxy::setActiveTool().

◆ supportsPaintingAssistants()

bool KisToolProxy::supportsPaintingAssistants ( ) const

Definition at line 267 of file kis_tool_proxy.cpp.

268{
269 KisTool *activeTool = dynamic_cast<KisTool*>(const_cast<KisToolProxy*>(this)->priv()->activeTool);
270 return activeTool && activeTool->supportsPaintingAssistants();
271}
virtual bool supportsPaintingAssistants() const
Definition kis_tool.cc:495

References KoToolProxyPrivate::activeTool, KoToolProxy::priv(), and KisTool::supportsPaintingAssistants().

◆ tabletToDocument()

QPointF KisToolProxy::tabletToDocument ( const QPointF & globalPos)
private

Definition at line 29 of file kis_tool_proxy.cpp.

30{
31 const QPointF pos = globalPos - QPointF(canvas()->canvasWidget()->mapToGlobal(QPoint(0, 0)));
32 return widgetToDocument(pos);
33}

References KoToolProxy::canvas(), and widgetToDocument().

◆ toolPrimaryActionActivated

void KisToolProxy::toolPrimaryActionActivated ( bool activated)
signal

◆ widgetToDocument()

QPointF KisToolProxy::widgetToDocument ( const QPointF & widgetPoint) const
overrideprotectedvirtual

Implements KoToolProxy.

Definition at line 35 of file kis_tool_proxy.cpp.

36{
37 KisCanvas2 *kritaCanvas = dynamic_cast<KisCanvas2*>(canvas());
38 Q_ASSERT(kritaCanvas);
39
40 return kritaCanvas->coordinatesConverter()->widgetToDocument(widgetPoint);
41}
_Private::Traits< T >::Result widgetToDocument(const T &obj) const

References KoToolProxy::canvas(), KisCanvas2::coordinatesConverter, and KisCoordinatesConverter::widgetToDocument().

Member Data Documentation

◆ m_isActionActivated

bool KisToolProxy::m_isActionActivated
private

Definition at line 63 of file kis_tool_proxy.h.

◆ m_lastAction

KisTool::ToolAction KisToolProxy::m_lastAction
private

Definition at line 64 of file kis_tool_proxy.h.


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