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

Abstract base class for input actions. More...

#include <kis_abstract_input_action.h>

+ Inheritance diagram for KisAbstractInputAction:

Public Member Functions

virtual void activate (int shortcut)
 
virtual void begin (int shortcut, QEvent *event)
 
virtual bool canIgnoreModifiers () const
 
virtual void deactivate (int shortcut)
 
virtual QString description () const
 
virtual void end (QEvent *event)
 
virtual QString id () const
 
virtual KisInputActionGroup inputActionGroup (int shortcut) const
 
virtual void inputEvent (QEvent *event)
 
virtual bool isAvailable () const
 
virtual bool isShortcutRequired (int shortcut) const
 
 KisAbstractInputAction (const QString &id)
 
virtual QString name () const
 
virtual int priority () const
 
virtual QHash< QString, int > shortcutIndexes () const
 
virtual bool supportsHiResInputEvents (int shortcut) const
 
virtual ~KisAbstractInputAction ()
 

Public Attributes

QString description
 
QString id
 
QHash< QString, int > indexes
 
QPointF lastCursorPosition
 
QString name
 
QPointF startCursorPosition
 

Static Public Attributes

static KisInputManagerinputManager
 

Protected Member Functions

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)
 
KisInputManagerinputManager () const
 
void setDescription (const QString &description)
 
void setName (const QString &name)
 
void setShortcutIndexes (const QHash< QString, int > &indexes)
 

Static Private Member Functions

static void setInputManager (KisInputManager *manager)
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Friends

class KisInputManager
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

Abstract base class for input actions.

Input actions represent actions to be performed when interacting with the canvas. They are managed by KisInputManager and activated when KisKeyShortcut or KisStrokeShortcut detects it matches a certain set of inputs.

The begin() method uses an index for the type of behaviour to activate. This index can be used to trigger behaviour when different events occur.

The events can be of two types: 1) Key events. The input manager calls begin() and end() sequentially with an index parameter to begin() representing the type of action that should be performed. The event parameter of both calls in null. 2) Stroke events. The input manager calls begin() and end() on the corresponding mouse down and up events. The event parameter will be of QMouseEvent type, representing the event happened. All the mouse move events between begin() and end() will be redirected to the inputEvent() method.

Definition at line 18 of file kis_abstract_input_action.cpp.

Constructor & Destructor Documentation

◆ KisAbstractInputAction()

KisAbstractInputAction::KisAbstractInputAction ( const QString & id)
explicit

Constructor.

Parameters
managerThe InputManager this action belongs to.

Definition at line 34 of file kis_abstract_input_action.cpp.

35 : d(new Private)
36{
37 d->id = id;
38 d->indexes.insert(i18n("Activate"), 0);
39}

References d, and id.

◆ ~KisAbstractInputAction()

KisAbstractInputAction::~KisAbstractInputAction ( )
virtual

Destructor.

Definition at line 41 of file kis_abstract_input_action.cpp.

42{
43 delete d;
44}

References d.

Member Function Documentation

◆ activate()

void KisAbstractInputAction::activate ( int shortcut)
virtual

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 in KisAlternateInvocationAction, KisChangePrimarySettingAction, KisGammaExposureAction, KisPanAction, KisRotateCanvasAction, KisSelectLayerAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 46 of file kis_abstract_input_action.cpp.

47{
48 Q_UNUSED(shortcut);
49}

◆ begin()

void KisAbstractInputAction::begin ( int shortcut,
QEvent * event )
virtual

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.

Reimplemented in KisAlternateInvocationAction, KisChangeFrameAction, KisChangePrimarySettingAction, KisPanAction, KisRotateCanvasAction, KisSelectLayerAction, KisToolInvocationAction, KisZoomAndRotateAction, KisTouchGestureAction, KisZoomAction, KisCanvasOnlyAction, and KisGammaExposureAction.

Definition at line 56 of file kis_abstract_input_action.cpp.

57{
58 Q_UNUSED(shortcut);
59
60 if (event) {
61 d->lastCursorPosition = eventPosF(event);
62 d->startCursorPosition = d->lastCursorPosition;
63 }
64}
QPointF eventPosF(const QEvent *event)

References d, and eventPosF().

◆ canIgnoreModifiers()

bool KisAbstractInputAction::canIgnoreModifiers ( ) const
virtual

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 in KisToolInvocationAction.

Definition at line 125 of file kis_abstract_input_action.cpp.

126{
127 return false;
128}

◆ cursorMoved()

void KisAbstractInputAction::cursorMoved ( const QPointF & lastPos,
const QPointF & pos )
protectedvirtual

Convenience method for handling cursor movement for tablet, mouse and touch. The default implementation of inputEvent calls this function.

Definition at line 81 of file kis_abstract_input_action.cpp.

82{
83 Q_UNUSED(lastPos);
84 Q_UNUSED(pos);
85}

◆ cursorMovedAbsolute()

void KisAbstractInputAction::cursorMovedAbsolute ( const QPointF & startPos,
const QPointF & pos )
protectedvirtual

Reimplemented in KisGammaExposureAction, KisPanAction, KisZoomAndRotateAction, KisRotateCanvasAction, and KisZoomAction.

Definition at line 87 of file kis_abstract_input_action.cpp.

88{
89 Q_UNUSED(startPos);
90 Q_UNUSED(pos);
91}

◆ deactivate()

void KisAbstractInputAction::deactivate ( int shortcut)
virtual

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()

Reimplemented in KisAlternateInvocationAction, KisChangePrimarySettingAction, KisGammaExposureAction, KisPanAction, KisRotateCanvasAction, KisSelectLayerAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 51 of file kis_abstract_input_action.cpp.

52{
53 Q_UNUSED(shortcut);
54}

◆ description()

virtual QString KisAbstractInputAction::description ( ) const
virtual

A short description of this action.

◆ end()

void KisAbstractInputAction::end ( QEvent * event)
virtual

End the action.

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

Reimplemented in KisPopupWidgetAction, KisAlternateInvocationAction, KisChangePrimarySettingAction, KisPanAction, KisRotateCanvasAction, KisToolInvocationAction, and KisTouchGestureAction.

Definition at line 76 of file kis_abstract_input_action.cpp.

77{
78 Q_UNUSED(event);
79}

◆ eventPos()

QPoint KisAbstractInputAction::eventPos ( const QEvent * event)
protected

Convenience method to extract the position from a cursor movement event.

Parameters
eventA mouse or tablet event.

Native gesture event has an issue in Qt on MacOS, its event->position() method returns an incorrect value (not in the widget's coordinates). So we should manually map it from global.

Definition at line 166 of file kis_abstract_input_action.cpp.

167{
168 if(!event) {
169 return QPoint();
170 }
171
172 switch (event->type()) {
173 case QEvent::MouseMove:
174 case QEvent::MouseButtonPress:
175 case QEvent::MouseButtonDblClick:
176 case QEvent::MouseButtonRelease:
177 return static_cast<const QMouseEvent*>(event)->pos();
178
179 case QEvent::TabletMove:
180 case QEvent::TabletPress:
181 case QEvent::TabletRelease:
182 return static_cast<const QTabletEvent*>(event)->pos();
183
184 case QEvent::TouchBegin:
185 case QEvent::TouchUpdate:
186 case QEvent::TouchEnd:
187 return static_cast<const QTouchEvent *>(event)->touchPoints().at(0).pos().toPoint();
188
189 case QEvent::Wheel:
190 return static_cast<const QWheelEvent*>(event)->position().toPoint();
191
192 case QEvent::NativeGesture: {
193 KisCanvas2 *canvas = d->inputManager->canvas();
195
202#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
203 return canvas->canvasWidget()->mapFromGlobal(QPointF(static_cast<const QNativeGestureEvent*>(event)->globalPos())).toPoint();
204#else
205 return canvas->canvasWidget()->mapFromGlobal(static_cast<const QNativeGestureEvent*>(event)->globalPos());
206#endif
207 }
208
209 default:
210 warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type();
211 return QPoint();
212 }
213}
KisAbstractCanvasWidget * canvasWidget
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define warnInput
Definition kis_debug.h:99
KisCanvas2 * canvas

References Private::canvas, KisCanvas2::canvasWidget, d, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, and warnInput.

◆ eventPosF()

QPointF KisAbstractInputAction::eventPosF ( const QEvent * event)
protected

Convenience method to extract the floating point position from a cursor movement event.

Parameters
eventA mouse or tablet event.

Native gesture event has an issue in Qt on MacOS, its event->position() method returns an incorrect value (not in the widget's coordinates). So we should manually map it from global.

Definition at line 215 of file kis_abstract_input_action.cpp.

215 {
216
217 switch (event->type()) {
218 case QEvent::MouseMove:
219 case QEvent::MouseButtonPress:
220 case QEvent::MouseButtonDblClick:
221 case QEvent::MouseButtonRelease:
222 return static_cast<const QMouseEvent*>(event)->localPos();
223
224 case QEvent::TabletMove:
225 case QEvent::TabletPress:
226 case QEvent::TabletRelease:
227 return static_cast<const QTabletEvent*>(event)->posF();
228
229 case QEvent::TouchBegin:
230 case QEvent::TouchUpdate:
231 case QEvent::TouchEnd:
232 return static_cast<const QTouchEvent *>(event)->touchPoints().at(0).pos();
233
234 case QEvent::Wheel:
235 return static_cast<const QWheelEvent*>(event)->position();
236
237 case QEvent::NativeGesture: {
238 KisCanvas2 *canvas = d->inputManager->canvas();
240
247#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
248 return canvas->canvasWidget()->mapFromGlobal(QPointF(static_cast<const QNativeGestureEvent*>(event)->globalPos()));
249#else
250 return canvas->canvasWidget()->mapFromGlobal(static_cast<const QNativeGestureEvent*>(event)->globalPos());
251#endif
252 }
253 default:
254 warnInput << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type();
255 return QPointF();
256 }
257}

References Private::canvas, KisCanvas2::canvasWidget, d, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, and warnInput.

◆ id()

virtual QString KisAbstractInputAction::id ( ) const
virtual

The id of this action.

◆ inputActionGroup()

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

Reimplemented in KisPanAction, KisRotateCanvasAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 99 of file kis_abstract_input_action.cpp.

100{
101 Q_UNUSED(shortcut);
103}
@ ModifyingActionGroup

References ModifyingActionGroup.

◆ inputEvent()

void KisAbstractInputAction::inputEvent ( QEvent * event)
virtual

Process an input event.

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

Parameters
eventAn event to process.

Reimplemented in KisAlternateInvocationAction, KisChangePrimarySettingAction, KisPanAction, KisRotateCanvasAction, KisSelectLayerAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 66 of file kis_abstract_input_action.cpp.

67{
68 if (event) {
69 QPointF newPosition = eventPosF(event);
70 cursorMoved(d->lastCursorPosition, newPosition);
71 cursorMovedAbsolute(d->startCursorPosition, newPosition);
72 d->lastCursorPosition = newPosition;
73 }
74}
virtual void cursorMoved(const QPointF &lastPos, const QPointF &pos)
virtual void cursorMovedAbsolute(const QPointF &startPos, const QPointF &pos)

References cursorMoved(), cursorMovedAbsolute(), d, and eventPosF().

◆ inputManager()

KisInputManager * KisAbstractInputAction::inputManager ( ) const
protected

The input manager this action belongs to.

◆ isAvailable()

bool KisAbstractInputAction::isAvailable ( ) const
virtual

Some of the actions are available in particular situations only. E.g. switch frame action is available iff an animated layer is selected. If isAvailable() returns true then the action will not be triggered by the shortcut matcher.

Reimplemented in KisChangeFrameAction.

Definition at line 259 of file kis_abstract_input_action.cpp.

260{
261 return true;
262}

◆ isShortcutRequired()

bool KisAbstractInputAction::isShortcutRequired ( int shortcut) const
virtual

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 in KisGammaExposureAction, KisPanAction, KisToolInvocationAction, and KisZoomAction.

Definition at line 160 of file kis_abstract_input_action.cpp.

161{
162 Q_UNUSED(shortcut);
163 return false;
164}

◆ name()

virtual QString KisAbstractInputAction::name ( ) const
virtual

The translated name of this action.

◆ priority()

int KisAbstractInputAction::priority ( ) const
virtual

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 in KisAlternateInvocationAction, KisChangePrimarySettingAction, KisGammaExposureAction, KisPanAction, KisRotateCanvasAction, KisSelectLayerAction, KisToolInvocationAction, KisZoomAction, KisZoomAndRotateAction, KisCanvasOnlyAction, KisPopupWidgetAction, and KisTouchGestureAction.

Definition at line 120 of file kis_abstract_input_action.cpp.

121{
122 return 0;
123}

◆ setDescription()

void KisAbstractInputAction::setDescription ( const QString & description)
protected

Set the description of this action.

Parameters
descriptionThe new description.

Definition at line 145 of file kis_abstract_input_action.cpp.

146{
147 d->description = description;
148}

References d, and description.

◆ setInputManager()

void KisAbstractInputAction::setInputManager ( KisInputManager * manager)
staticprivate

Definition at line 155 of file kis_abstract_input_action.cpp.

156{
157 Private::inputManager = manager;
158}

◆ setName()

void KisAbstractInputAction::setName ( const QString & name)
protected

Set the name of this action.

Parameters
nameThe new name.

Definition at line 140 of file kis_abstract_input_action.cpp.

141{
142 d->name = name;
143}

References d, and name.

◆ setShortcutIndexes()

void KisAbstractInputAction::setShortcutIndexes ( const QHash< QString, int > & indexes)
protected

Set the available indexes of shortcut behaviours.

Parameters
indexesThe new indexes.

Definition at line 150 of file kis_abstract_input_action.cpp.

151{
152 d->indexes = indexes;
153}

References d, and indexes.

◆ shortcutIndexes()

QHash< QString, int > KisAbstractInputAction::shortcutIndexes ( ) const
virtual

The indexes of shortcut behaviours available.

Definition at line 130 of file kis_abstract_input_action.cpp.

131{
132 return d->indexes;
133}

References d.

◆ supportsHiResInputEvents()

bool KisAbstractInputAction::supportsHiResInputEvents ( int shortcut) const
virtual

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 in KisAlternateInvocationAction, KisChangePrimarySettingAction, KisPanAction, KisRotateCanvasAction, KisToolInvocationAction, and KisZoomAction.

Definition at line 93 of file kis_abstract_input_action.cpp.

94{
95 Q_UNUSED(shortcut);
96 return false;
97}

Friends And Related Symbol Documentation

◆ KisInputManager

friend class KisInputManager
friend

Definition at line 213 of file kis_abstract_input_action.h.

Member Data Documentation

◆ d

Private* const KisAbstractInputAction::d
private

Definition at line 217 of file kis_abstract_input_action.h.

◆ description

QString KisAbstractInputAction::description

Definition at line 23 of file kis_abstract_input_action.cpp.

◆ id

QString KisAbstractInputAction::id

Definition at line 21 of file kis_abstract_input_action.cpp.

◆ indexes

QHash<QString, int> KisAbstractInputAction::indexes

Definition at line 24 of file kis_abstract_input_action.cpp.

◆ inputManager

KisInputManager * KisAbstractInputAction::inputManager
static

Definition at line 29 of file kis_abstract_input_action.cpp.

◆ lastCursorPosition

QPointF KisAbstractInputAction::lastCursorPosition

Definition at line 26 of file kis_abstract_input_action.cpp.

◆ name

QString KisAbstractInputAction::name

Definition at line 22 of file kis_abstract_input_action.cpp.

◆ startCursorPosition

QPointF KisAbstractInputAction::startCursorPosition

Definition at line 27 of file kis_abstract_input_action.cpp.


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