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

Tool Invocation action of KisAbstractInputAction. More...

#include <kis_tool_invocation_action.h>

+ Inheritance diagram for KisToolInvocationAction:

Classes

class  Private
 

Public Types

enum  Shortcut {
  ActivateShortcut , ConfirmShortcut , CancelShortcut , LineToolShortcut ,
  EllipseToolShortcut , RectToolShortcut , MoveToolShortcut , FillToolShortcut ,
  GradientToolShortcut , MeasureToolShortcut , EllipseSelToolShortcut , RectSelToolShortcut ,
  ContigSelToolShortcut , FreehandSelToolShortcut , ActivateWithOtherColorShortcut
}
 

Public Member Functions

void activate (int shortcut) override
 
void begin (int shortcut, QEvent *event) override
 
bool canIgnoreModifiers () const override
 
void deactivate (int shortcut) override
 
void end (QEvent *event) override
 
KisInputActionGroup inputActionGroup (int shortcut) const override
 
void inputEvent (QEvent *event) override
 
bool isShortcutRequired (int shortcut) const override
 
 KisToolInvocationAction ()
 
int priority () const override
 
void processUnhandledEvent (QEvent *event)
 
bool supportsHiResInputEvents (int shortcut) const override
 
 ~KisToolInvocationAction () override
 
- Public Member Functions inherited from KisAbstractInputAction
virtual QString description () const
 
virtual QString id () const
 
virtual bool isAvailable () const
 
 KisAbstractInputAction (const QString &id)
 
virtual QString name () const
 
virtual QHash< QString, int > shortcutIndexes () const
 
virtual bool trySwitchShortcut (int oldShortcut, int newShortcut)
 
virtual ~KisAbstractInputAction ()
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Public Attributes inherited from KisAbstractInputAction
QString description
 
QString id
 
QHash< QString, int > indexes
 
QPointF lastCursorPosition
 
QString name
 
QPointF startCursorPosition
 
- Static Public Attributes inherited from KisAbstractInputAction
static KisInputManager * inputManager
 
- Protected Member Functions inherited from KisAbstractInputAction
virtual void cursorMoved (const QPointF &lastPos, const QPointF &pos)
 
virtual void cursorMovedAbsolute (const QPointF &startPos, const QPointF &pos)
 
QPoint eventPos (const QEvent *event)
 
QPointF eventPosF (const QEvent *event)
 
KisInputManager * inputManager () const
 
void setDescription (const QString &description)
 
void setName (const QString &name)
 
void setShortcutIndexes (const QHash< QString, int > &indexes)
 

Detailed Description

Tool Invocation action of KisAbstractInputAction.

The Tool Invocation action invokes the current tool, for example, using the brush tool, it will start painting.

Definition at line 18 of file kis_tool_invocation_action.h.

Member Enumeration Documentation

◆ Shortcut

Enumerator
ActivateShortcut 
ConfirmShortcut 
CancelShortcut 
LineToolShortcut 
EllipseToolShortcut 
RectToolShortcut 
MoveToolShortcut 
FillToolShortcut 
GradientToolShortcut 
MeasureToolShortcut 
EllipseSelToolShortcut 
RectSelToolShortcut 
ContigSelToolShortcut 
FreehandSelToolShortcut 
ActivateWithOtherColorShortcut 

Definition at line 21 of file kis_tool_invocation_action.h.

21 {
37 };

Constructor & Destructor Documentation

◆ KisToolInvocationAction()

KisToolInvocationAction::KisToolInvocationAction ( )
explicit

Definition at line 35 of file kis_tool_invocation_action.cpp.

36 : KisAbstractInputAction("Tool Invocation")
37 , d(new Private)
38{
39 setName(i18n("Tool Invocation"));
40 setDescription(i18n("The <i>Tool Invocation</i> action invokes the current tool, for example, using the brush tool, it will start painting."));
41
42 QHash<QString, int> indexes;
43 indexes.insert(i18n("Activate"), ActivateShortcut);
44 indexes.insert(i18n("Confirm"), ConfirmShortcut);
45 indexes.insert(i18n("Cancel"), CancelShortcut);
46 indexes.insert(i18n("Activate Line Tool"), LineToolShortcut);
47 indexes.insert(i18n("Activate Ellipse Tool"), EllipseToolShortcut);
48 indexes.insert(i18n("Activate Rectangle Tool"), RectToolShortcut);
49 indexes.insert(i18n("Activate Move Tool"), MoveToolShortcut);
50 indexes.insert(i18n("Activate Fill Tool"), FillToolShortcut);
51 indexes.insert(i18n("Activate Gradient Tool"), GradientToolShortcut);
52 indexes.insert(i18n("Activate Measure Tool"), MeasureToolShortcut);
53 indexes.insert(i18n("Activate Elliptical Selection Tool"), EllipseSelToolShortcut);
54 indexes.insert(i18n("Activate Rectangular Selection Tool"), RectSelToolShortcut);
55 indexes.insert(i18n("Activate Contiguous Selection Tool"), ContigSelToolShortcut);
56 indexes.insert(i18n("Activate Freehand Selection Tool"), FreehandSelToolShortcut);
57 indexes.insert(i18n("Activate with Other Color"), ActivateWithOtherColorShortcut);
58
60}
KisAbstractInputAction(const QString &id)
void setShortcutIndexes(const QHash< QString, int > &indexes)
void setName(const QString &name)
void setDescription(const QString &description)

References ActivateShortcut, ActivateWithOtherColorShortcut, CancelShortcut, ConfirmShortcut, ContigSelToolShortcut, EllipseSelToolShortcut, EllipseToolShortcut, FillToolShortcut, FreehandSelToolShortcut, GradientToolShortcut, KisAbstractInputAction::indexes, LineToolShortcut, MeasureToolShortcut, MoveToolShortcut, RectSelToolShortcut, RectToolShortcut, KisAbstractInputAction::setDescription(), KisAbstractInputAction::setName(), and KisAbstractInputAction::setShortcutIndexes().

◆ ~KisToolInvocationAction()

KisToolInvocationAction::~KisToolInvocationAction ( )
override

Definition at line 62 of file kis_tool_invocation_action.cpp.

63{
64 delete d;
65}

References d.

Member Function Documentation

◆ activate()

void KisToolInvocationAction::activate ( int shortcut)
overridevirtual

The method is called when the action is yet to be started, that is, e.g. the user has pressed all the modifiers for the action but hasn't started painting yet. This method is a right place to show the user what is going to happen, e.g. change the cursor.

Reimplemented from KisAbstractInputAction.

Definition at line 67 of file kis_tool_invocation_action.cpp.

68{
69 Q_UNUSED(shortcut);
70 if (!inputManager()) return;
71
72 QString temporaryToolId;
73 switch(shortcut) {
75 temporaryToolId = "KritaShape/KisToolLine";
76 break;
78 temporaryToolId = "KritaShape/KisToolEllipse";
79 break;
81 temporaryToolId = "KritaShape/KisToolRectangle";
82 break;
84 temporaryToolId = "KritaTransform/KisToolMove";
85 break;
87 temporaryToolId = "KritaFill/KisToolFill";
88 break;
90 temporaryToolId = "KritaFill/KisToolGradient";
91 break;
93 temporaryToolId = "KritaShape/KisToolMeasure";
94 break;
96 temporaryToolId = "KisToolSelectElliptical";
97 break;
99 temporaryToolId = "KisToolSelectRectangular";
100 break;
102 temporaryToolId = "KisToolSelectContiguous";
103 break;
105 temporaryToolId = "KisToolSelectOutline";
106 break;
107 }
108
109 if (!temporaryToolId.isEmpty()) {
110 inputManager()->canvas()->canvasController()->toolManager()->switchToolRequested(temporaryToolId);
111 }
112
114
116
117 if (d->isUsingOtherColor) {
118 inputManager()->canvas()->resourceManager()->setUsingOtherColor(true);
119 }
120
121 d->activatedToolProxy->activateToolAction(KisTool::Primary);
122}
static KisInputManager * inputManager
KisCanvas2 * canvas() const
QPointer< KisToolProxy > toolProxy() const
QPointer< KoCanvasResourceProvider > resourceManager
KoCanvasController * canvasController() const
QPointer< KoToolManager > toolManager
@ Primary
Definition kis_tool.h:118

References KisToolInvocationAction::Private::activatedToolProxy, ActivateWithOtherColorShortcut, KisInputManager::canvas(), KoCanvasBase::canvasController(), ContigSelToolShortcut, d, EllipseSelToolShortcut, EllipseToolShortcut, FillToolShortcut, FreehandSelToolShortcut, GradientToolShortcut, KisAbstractInputAction::inputManager, KisToolInvocationAction::Private::isUsingOtherColor, LineToolShortcut, MeasureToolShortcut, MoveToolShortcut, KisTool::Primary, RectSelToolShortcut, RectToolShortcut, KoCanvasBase::resourceManager, KoCanvasController::toolManager, and KisInputManager::toolProxy().

◆ begin()

void KisToolInvocationAction::begin ( int shortcut,
QEvent * event )
overridevirtual

Begin the action.

Parameters
shortcutThe index of the behaviour to trigger.
eventThe mouse event that has triggered this action. Is null for keyboard-activated actions.

All the tools now have a KisTool::requestStrokeEnd() method, so they should use this instead of direct filtering Enter key press. Until all the tools support it, we just duplicate the key event and the method call

Some tools would like to distinguish automated requestStrokeEnd() calls from explicit user actions. Just let them do it!

Please note that this call should happen after requestStrokeEnd(). Some of the tools will switch to another tool on this request, and this (next) tool does not expect to get requestStrokeEnd() right after switching in.

The tools now have a KisTool::requestStrokeCancellation() method, so just request it.

Reimplemented from KisAbstractInputAction.

Definition at line 161 of file kis_tool_invocation_action.cpp.

162{
163 if (shortcut != ConfirmShortcut && shortcut != CancelShortcut ) {
165 d->active =
166 d->runningToolProxy->forwardEvent(
168 }
169 else if (shortcut == ConfirmShortcut) {
170 QKeyEvent pressEvent(QEvent::KeyPress, Qt::Key_Return, QFlags<Qt::KeyboardModifier>());
171 inputManager()->toolProxy()->keyPressEvent(&pressEvent);
172 QKeyEvent releaseEvent(QEvent::KeyRelease, Qt::Key_Return, QFlags<Qt::KeyboardModifier>());
173 inputManager()->toolProxy()->keyReleaseEvent(&releaseEvent);
174
182
192 inputManager()->toolProxy()->explicitUserStrokeEndRequest();
193
194 } else if (shortcut == CancelShortcut) {
201 }
202}
KisImageWSP image() const
void requestStrokeCancellation()
void requestStrokeEnd()

References KisToolInvocationAction::Private::active, KisToolProxy::BEGIN, CancelShortcut, KisInputManager::canvas(), ConfirmShortcut, d, KisCanvas2::image(), KisAbstractInputAction::inputManager, KisTool::Primary, KisImage::requestStrokeCancellation(), KisImage::requestStrokeEnd(), KisToolInvocationAction::Private::runningToolProxy, and KisInputManager::toolProxy().

◆ canIgnoreModifiers()

bool KisToolInvocationAction::canIgnoreModifiers ( ) const
overridevirtual

Returns true if an action can run with any modifiers pressed (the shortcut's modifiers list must be empty for that). That is used for making one type of actions default one.

Reimplemented from KisAbstractInputAction.

Definition at line 156 of file kis_tool_invocation_action.cpp.

157{
158 return true;
159}

◆ deactivate()

void KisToolInvocationAction::deactivate ( int shortcut)
overridevirtual

The method is called when the action is not a candidate for the starting anymore. The action should revert everything that was done in activate() method.

See also
activate()

Activate call might have come before actual input manager or tool proxy was attached. So we may end up with null activatedToolProxy.

Reimplemented from KisAbstractInputAction.

Definition at line 124 of file kis_tool_invocation_action.cpp.

125{
126 Q_UNUSED(shortcut);
127 if (!inputManager()) return;
128
129 // Revert UsingOtherColor
130 if (d->isUsingOtherColor) {
131 inputManager()->canvas()->resourceManager()->setUsingOtherColor(false);
132 }
133
138 if (d->activatedToolProxy) {
139 d->activatedToolProxy->deactivateToolAction(KisTool::Primary);
140 d->activatedToolProxy.clear();
141 }
142
143 if (shortcut != ActivateShortcut && shortcut != ConfirmShortcut && shortcut != CancelShortcut && shortcut != ActivateWithOtherColorShortcut && !d->deactivating) {
144 // Switching tool will force deactivation and will re-enter
145 d->deactivating = true;
146 inputManager()->canvas()->canvasController()->toolManager()->switchBackRequested();
147 d->deactivating = false;
148 }
149}

References KisToolInvocationAction::Private::activatedToolProxy, ActivateShortcut, ActivateWithOtherColorShortcut, CancelShortcut, KisInputManager::canvas(), KoCanvasBase::canvasController(), ConfirmShortcut, d, KisToolInvocationAction::Private::deactivating, KisAbstractInputAction::inputManager, KisToolInvocationAction::Private::isUsingOtherColor, KisTool::Primary, KoCanvasBase::resourceManager, and KoCanvasController::toolManager.

◆ end()

void KisToolInvocationAction::end ( QEvent * event)
overridevirtual

End the action.

Parameters
eventThe mouse event that has finished this action. Is null for keyboard-activated actions.

Reimplemented from KisAbstractInputAction.

Definition at line 204 of file kis_tool_invocation_action.cpp.

205{
206 if (d->active) {
207 // It might happen that the action is still running, while the
208 // canvas has been removed, which kills the toolProxy.
210 if (d->runningToolProxy) {
212 forwardEvent(KisToolProxy::END, KisTool::Primary, event, event);
213 d->runningToolProxy.clear();
214 }
215 d->active = false;
216 }
217
219}
virtual void end(QEvent *event)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KisToolInvocationAction::Private::active, d, KisToolProxy::END, KisAbstractInputAction::end(), KIS_SAFE_ASSERT_RECOVER_NOOP, KisTool::Primary, and KisToolInvocationAction::Private::runningToolProxy.

◆ inputActionGroup()

KisInputActionGroup KisToolInvocationAction::inputActionGroup ( int shortcut) const
overridevirtual
Returns
the group of the action the specified shortcut belongs to

Reimplemented from KisAbstractInputAction.

Definition at line 256 of file kis_tool_invocation_action.cpp.

257{
258 Q_UNUSED(shortcut);
260}
@ ToolInvoactionActionGroup

References ToolInvoactionActionGroup.

◆ inputEvent()

void KisToolInvocationAction::inputEvent ( QEvent * event)
overridevirtual

Process an input event.

By default handles MouseMove events and passes the data to a convenience cursorMoved() method

Parameters
eventAn event to process.

Reimplemented from KisAbstractInputAction.

Definition at line 221 of file kis_tool_invocation_action.cpp.

222{
223 if (!d->active) return;
224 if (!d->runningToolProxy) return;
225
227 forwardEvent(KisToolProxy::CONTINUE, KisTool::Primary, event, event);
228}

References KisToolInvocationAction::Private::active, KisToolProxy::CONTINUE, d, KisTool::Primary, and KisToolInvocationAction::Private::runningToolProxy.

◆ isShortcutRequired()

bool KisToolInvocationAction::isShortcutRequired ( int shortcut) const
overridevirtual

Return true when the specified shortcut is required for basic user interaction. This is used by the configuration system to prevent basic actions like painting from being removed.

Parameters
shortcutThe shortcut index to check.
Returns
True if the shortcut is required, false if not.

Reimplemented from KisAbstractInputAction.

Definition at line 249 of file kis_tool_invocation_action.cpp.

250{
251 // These three shortcuts are pretty important for basic user interaction,
252 // so they should always exist.
253 return (shortcut == ActivateShortcut || shortcut == ConfirmShortcut || shortcut == CancelShortcut);
254}

References ActivateShortcut, CancelShortcut, and ConfirmShortcut.

◆ priority()

int KisToolInvocationAction::priority ( ) const
overridevirtual

The priority for this action.

Priority determines how "important" the action is and is used to resolve conflicts when multiple actions can be activated.

Reimplemented from KisAbstractInputAction.

Definition at line 151 of file kis_tool_invocation_action.cpp.

152{
153 return 0;
154}

◆ processUnhandledEvent()

void KisToolInvocationAction::processUnhandledEvent ( QEvent * event)

Definition at line 230 of file kis_tool_invocation_action.cpp.

231{
232 bool savedState = d->active;
233 KisToolProxy *savedToolProxy = d->runningToolProxy;
234 if (!d->runningToolProxy) {
236 }
237 d->active = true;
238 inputEvent(event);
239 d->active = savedState;
240 d->runningToolProxy = savedToolProxy;
241}
void inputEvent(QEvent *event) override

References KisToolInvocationAction::Private::active, d, inputEvent(), KisAbstractInputAction::inputManager, KisToolInvocationAction::Private::runningToolProxy, and KisInputManager::toolProxy().

◆ supportsHiResInputEvents()

bool KisToolInvocationAction::supportsHiResInputEvents ( int shortcut) const
overridevirtual

Returns true if the action can handle HiRes flow of move events which is generated by the tablet. If the function returns false, some of the events will be dropped or postponed. For most of the actions in Krita (except of real painting) it is perfectly acceptable, so 'false' is the default value.

Reimplemented from KisAbstractInputAction.

Definition at line 243 of file kis_tool_invocation_action.cpp.

244{
245 Q_UNUSED(shortcut);
246 return inputManager()->toolProxy()->primaryActionSupportsHiResEvents();
247}

References KisAbstractInputAction::inputManager, and KisInputManager::toolProxy().

Member Data Documentation

◆ d

Private* const KisToolInvocationAction::d
private

Definition at line 63 of file kis_tool_invocation_action.h.


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