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 bool trySwitchShortcut (int oldShortcut, int newShortcut)
 
virtual ~KisAbstractInputAction ()
 

Public Attributes

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

Static Public Attributes

static KisInputManager * inputManager
 

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)
 
KisInputManager * inputManager () 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
KisCanvas2 * canvas
 
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 19 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 35 of file kis_abstract_input_action.cpp.

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

References d, and id.

◆ ~KisAbstractInputAction()

KisAbstractInputAction::~KisAbstractInputAction ( )
virtual

Destructor.

Definition at line 42 of file kis_abstract_input_action.cpp.

43{
44 delete d;
45}

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, KisTemporaryStraightRulerAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 47 of file kis_abstract_input_action.cpp.

48{
49 Q_UNUSED(shortcut);
50}

◆ 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, KisTemporaryStraightRulerAction, KisToolInvocationAction, KisZoomAndRotateAction, KisTouchGestureAction, KisZoomAction, KisCanvasOnlyAction, and KisGammaExposureAction.

Definition at line 64 of file kis_abstract_input_action.cpp.

65{
66 Q_UNUSED(shortcut);
67
68 if (event) {
69 d->lastCursorPosition = eventPosF(event);
70 d->startCursorPosition = d->lastCursorPosition;
71 }
72}
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 133 of file kis_abstract_input_action.cpp.

134{
135 return false;
136}

◆ 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 89 of file kis_abstract_input_action.cpp.

90{
91 Q_UNUSED(lastPos);
92 Q_UNUSED(pos);
93}

◆ cursorMovedAbsolute()

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

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

Definition at line 95 of file kis_abstract_input_action.cpp.

96{
97 Q_UNUSED(startPos);
98 Q_UNUSED(pos);
99}

◆ 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, KisTemporaryStraightRulerAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 52 of file kis_abstract_input_action.cpp.

53{
54 Q_UNUSED(shortcut);
55}

◆ 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, KisTemporaryStraightRulerAction, KisToolInvocationAction, KisZoomAction, KisZoomAndRotateAction, and KisTouchGestureAction.

Definition at line 84 of file kis_abstract_input_action.cpp.

85{
86 Q_UNUSED(event);
87}

◆ 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 174 of file kis_abstract_input_action.cpp.

175{
176 if(!event) {
177 return QPoint();
178 }
179
180 switch (event->type()) {
181 case QEvent::MouseMove:
182 case QEvent::MouseButtonPress:
183 case QEvent::MouseButtonDblClick:
184 case QEvent::MouseButtonRelease:
185 return static_cast<const QMouseEvent*>(event)->pos();
186
187 case QEvent::TabletMove:
188 case QEvent::TabletPress:
189 case QEvent::TabletRelease:
190 return static_cast<const QTabletEvent*>(event)->pos();
191
192 case QEvent::TouchBegin:
193 case QEvent::TouchUpdate:
194 case QEvent::TouchEnd:
195 return static_cast<const QTouchEvent *>(event)->touchPoints().at(0).pos().toPoint();
196
197 case QEvent::Wheel:
198 return static_cast<const QWheelEvent*>(event)->position().toPoint();
199
200 case QEvent::NativeGesture: {
201 KisCanvas2 *canvas = d->inputManager->canvas();
203
210#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
211 return canvas->canvasWidget()->mapFromGlobal(QPointF(static_cast<const QNativeGestureEvent*>(event)->globalPos())).toPoint();
212#else
213 return canvas->canvasWidget()->mapFromGlobal(static_cast<const QNativeGestureEvent*>(event)->globalPos());
214#endif
215 }
216
217 default:
218 warnUI << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type();
219 return QPoint();
220 }
221}
KisAbstractCanvasWidget * canvasWidget
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define warnUI
Definition kis_debug.h:101
KisCanvas2 * canvas

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

◆ 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 223 of file kis_abstract_input_action.cpp.

223 {
224
225 if(!event) {
226 return QPoint();
227 }
228
229 switch (event->type()) {
230 case QEvent::MouseMove:
231 case QEvent::MouseButtonPress:
232 case QEvent::MouseButtonDblClick:
233 case QEvent::MouseButtonRelease:
234 return static_cast<const QMouseEvent*>(event)->localPos();
235
236 case QEvent::TabletMove:
237 case QEvent::TabletPress:
238 case QEvent::TabletRelease:
239 return static_cast<const QTabletEvent*>(event)->posF();
240
241 case QEvent::TouchBegin:
242 case QEvent::TouchUpdate:
243 case QEvent::TouchEnd:
244 return static_cast<const QTouchEvent *>(event)->touchPoints().at(0).pos();
245
246 case QEvent::Wheel:
247 return static_cast<const QWheelEvent*>(event)->position();
248
249 case QEvent::NativeGesture: {
250 KisCanvas2 *canvas = d->inputManager->canvas();
252
259#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
260 return canvas->canvasWidget()->mapFromGlobal(QPointF(static_cast<const QNativeGestureEvent*>(event)->globalPos()));
261#else
262 return canvas->canvasWidget()->mapFromGlobal(static_cast<const QNativeGestureEvent*>(event)->globalPos());
263#endif
264 }
265 default:
266 warnUI << "KisAbstractInputAction" << d->name << "tried to process event data from an unhandled event type" << event->type();
267 return QPointF();
268 }
269}

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

◆ 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, KisTemporaryStraightRulerAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 107 of file kis_abstract_input_action.cpp.

108{
109 Q_UNUSED(shortcut);
111}
@ 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, KisTemporaryStraightRulerAction, KisToolInvocationAction, KisZoomAction, and KisZoomAndRotateAction.

Definition at line 74 of file kis_abstract_input_action.cpp.

75{
76 if (event) {
77 QPointF newPosition = eventPosF(event);
78 cursorMoved(d->lastCursorPosition, newPosition);
79 cursorMovedAbsolute(d->startCursorPosition, newPosition);
80 d->lastCursorPosition = newPosition;
81 }
82}
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, and KisTemporaryStraightRulerAction.

Definition at line 271 of file kis_abstract_input_action.cpp.

272{
273 return true;
274}

◆ 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 168 of file kis_abstract_input_action.cpp.

169{
170 Q_UNUSED(shortcut);
171 return false;
172}

◆ 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, KisTemporaryStraightRulerAction, KisToolInvocationAction, KisZoomAction, KisZoomAndRotateAction, KisCanvasOnlyAction, KisPopupWidgetAction, and KisTouchGestureAction.

Definition at line 128 of file kis_abstract_input_action.cpp.

129{
130 return 0;
131}

◆ setDescription()

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

Set the description of this action.

Parameters
descriptionThe new description.

Definition at line 153 of file kis_abstract_input_action.cpp.

154{
155 d->description = description;
156}

References d, and description.

◆ setInputManager()

void KisAbstractInputAction::setInputManager ( KisInputManager * manager)
staticprivate

Definition at line 163 of file kis_abstract_input_action.cpp.

164{
165 Private::inputManager = manager;
166}

◆ setName()

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

Set the name of this action.

Parameters
nameThe new name.

Definition at line 148 of file kis_abstract_input_action.cpp.

149{
150 d->name = name;
151}

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 158 of file kis_abstract_input_action.cpp.

159{
160 d->indexes = indexes;
161}

References d, and indexes.

◆ shortcutIndexes()

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

The indexes of shortcut behaviours available.

Definition at line 138 of file kis_abstract_input_action.cpp.

139{
140 return d->indexes;
141}

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, KisTemporaryStraightRulerAction, KisToolInvocationAction, and KisZoomAction.

Definition at line 101 of file kis_abstract_input_action.cpp.

102{
103 Q_UNUSED(shortcut);
104 return false;
105}

◆ trySwitchShortcut()

bool KisAbstractInputAction::trySwitchShortcut ( int oldShortcut,
int newShortcut )
virtual

Switch the active shortcut mode without deactivating the action.

Called when modifier keys change while the action is active. Override this to update action state in-place without resetting ongoing interaction.

Returns
true if the switch was handled and the action remains active; false to fall back to standard deactivate() / activate().

Reimplemented in KisTemporaryStraightRulerAction.

Definition at line 57 of file kis_abstract_input_action.cpp.

58{
59 Q_UNUSED(oldShortcut);
60 Q_UNUSED(newShortcut);
61 return false;
62}

Friends And Related Symbol Documentation

◆ KisInputManager

friend class KisInputManager
friend

Definition at line 225 of file kis_abstract_input_action.h.

Member Data Documentation

◆ d

Private* const KisAbstractInputAction::d
private

Definition at line 229 of file kis_abstract_input_action.h.

◆ description

QString KisAbstractInputAction::description

Definition at line 24 of file kis_abstract_input_action.cpp.

◆ id

QString KisAbstractInputAction::id

Definition at line 22 of file kis_abstract_input_action.cpp.

◆ indexes

QHash<QString, int> KisAbstractInputAction::indexes

Definition at line 25 of file kis_abstract_input_action.cpp.

◆ inputManager

KisInputManager * KisAbstractInputAction::inputManager
static

Definition at line 30 of file kis_abstract_input_action.cpp.

◆ lastCursorPosition

QPointF KisAbstractInputAction::lastCursorPosition

Definition at line 27 of file kis_abstract_input_action.cpp.

◆ name

QString KisAbstractInputAction::name

Definition at line 23 of file kis_abstract_input_action.cpp.

◆ startCursorPosition

QPointF KisAbstractInputAction::startCursorPosition

Definition at line 28 of file kis_abstract_input_action.cpp.


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