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

#include <kis_shortcut_matcher.h>

+ Inheritance diagram for KisShortcutMatcher:

Classes

struct  IgnoreMultiFingerCancelWorkaround
 
struct  RecursionGuard
 
struct  RecursionNotifier
 

Public Member Functions

bool actionsSuppressed () const
 
bool actionsSuppressedIgnoreFocus () const
 
void addShortcut (KisNativeGestureShortcut *shortcut)
 
void addShortcut (KisSingleActionShortcut *shortcut)
 
void addShortcut (KisStrokeShortcut *shortcut)
 
void addShortcut (KisTouchpadScrollShortcut *shortcut)
 
void addShortcut (KisTouchShortcut *shortcut)
 
bool autoRepeatedKeyPressed (Qt::Key key)
 
bool buttonPressed (Qt::MouseButton button, QEvent *event)
 
bool buttonReleased (Qt::MouseButton button, QEvent *event)
 
void clearShortcuts ()
 
QVector< Qt::Key > debugPressedKeys () const
 
void enterEvent ()
 
void handlePolledKeys (const QVector< Qt::Key > &keys)
 
bool hasPolledKeys ()
 
bool hasRunningShortcut () const
 
bool hasTouchHoldShortcut () const
 
bool hasTouchpadScrollShortcuts () const
 
bool ignoreMultiFingerCancelWorkaroundEnalbed () const
 
bool KeyboardActionsSuppressed () const
 
bool keyPressed (Qt::Key key)
 
bool keyReleased (Qt::Key key)
 
 KisShortcutMatcher ()
 
void leaveEvent ()
 
void lostFocusEvent (const QPointF &localPos)
 
bool nativeGestureBeginEvent (QNativeGestureEvent *event)
 
bool nativeGestureEndEvent (QNativeGestureEvent *event)
 
bool nativeGestureEvent (QNativeGestureEvent *event)
 
bool pointerMoved (QEvent *event)
 
 Private ()
 
void reinitialize ()
 
void reinitializeButtons ()
 
bool sanityCheckModifiersCorrectness (Qt::KeyboardModifiers modifiers) const
 
void setIgnoreMultiFingerCancelWorkaroundEnalbed (bool value)
 
void setInputActionGroupsMaskCallback (std::function< KisInputActionGroupsMask()> func)
 
void setTouchHoldDelay (int value)
 
bool supportsHiResInputEvents ()
 
void suppressAllActions (bool value)
 
void suppressAllKeyboardActions (bool value)
 
void suppressConflictingKeyActions (const QVector< QKeySequence > &shortcuts)
 
void toolHasBeenActivated ()
 
bool touchBeginEvent (QTouchEvent *event)
 
void touchCancelEvent (QTouchEvent *event)
 
bool touchEndEvent (QTouchEvent *event)
 
int touchHoldDelay () const
 
bool touchpadScrollBeginEvent (QWheelEvent *event)
 
bool touchpadScrollEndEvent (QWheelEvent *event)
 
bool touchpadScrollEvent (QWheelEvent *event)
 
bool touchUpdateEvent (QTouchEvent *event)
 
bool wheelEvent (KisSingleActionShortcut::WheelAction wheelAction, QWheelEvent *event)
 
 ~KisShortcutMatcher ()
 
 ~Private ()
 

Public Attributes

std::function< KisInputActionGroupsMask()> actionGroupMask
 
QScopedPointer< QEvent > bestCandidateForTapTouchEvent
 
int brokenByRecursion = 0
 
QSet< Qt::MouseButton > buttons
 
QList< KisStrokeShortcut * > candidateShortcuts
 
bool cursorEntered
 
std::optional< IgnoreMultiFingerCancelWorkaround > ignoreMultiFingerCancelWorkaround
 
bool isTouchDragDetected {false}
 
bool isTouchHeld {false}
 
QSet< Qt::Key > keys
 
QScopedPointer< QTouchEvent > lastProcessedTouchEvent
 
int matchingIteration {0}
 
int maxTouchPoints {0}
 
KisNativeGestureShortcut * nativeGestureShortcut
 
QList< KisNativeGestureShortcut * > nativeGestureShortcuts
 
QSet< Qt::Key > polledKeys
 
KisStrokeShortcut * readyShortcut
 
int recursiveCounter = 0
 
KisStrokeShortcut * runningShortcut
 
QList< KisSingleActionShortcut * > singleActionShortcuts
 
QList< KisStrokeShortcut * > strokeShortcuts
 
bool suppressAllActions
 
bool suppressAllKeyboardActions
 
QSet< KisSingleActionShortcut * > suppressedSingleActionShortcuts
 
bool touchActionTracked {false}
 
int touchHoldDelayMs {400}
 
std::optional< KisTouchHoldEventsPostponer > touchHoldEventPostponer
 
KisTouchpadScrollShortcut * touchpadScrollShortcut
 
QList< KisTouchpadScrollShortcut * > touchpadScrollShortcuts
 
KisTouchShortcut * touchShortcut
 
QList< KisTouchShortcut * > touchShortcuts
 

Static Public Attributes

static constexpr qreal TOUCH_SLOP = 16
 
static constexpr int TOUCH_SLOP_SQUARED = 16 * 16
 

Private Types

enum class  TouchShortcutMode { Drag = 0 , Tap , Hold }
 

Private Member Functions

void forceDeactivateAllActions ()
 
void forceEndRunningShortcut (const QPointF &localPos)
 
KisTouchShortcut * matchTouchShortcut (QTouchEvent *event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode)
 
bool matchTouchShortcutBasedOnState (QTouchEvent *event, KisTouchShortcut *shortcut, Qt::TouchPointStates allowedStates, TouchShortcutMode mode)
 
void prepareReadyShortcuts ()
 
void reset ()
 
void reset (QString msg)
 
void setMaxTouchPointEvent (QTouchEvent *event)
 
void slotTouchHoldCompleted ()
 
bool touchUpdateEventImpl (QTouchEvent *event)
 
void tryActivateReadyShortcut ()
 
void tryCancelAllCurrentTouchActionsImpl ()
 
template<typename EventType , typename ShortcutType >
bool tryEndGestureBasedShortcutImpl (EventType *event, ShortcutType **resultShortcutPtr)
 
bool tryEndNativeGestureShortcut (QNativeGestureEvent *event)
 
bool tryEndRunningShortcut (Qt::MouseButton button, QEvent *event)
 
bool tryEndTouchpadScrollShortcut (QWheelEvent *event)
 
bool tryEndTouchShortcut (QTouchEvent *event)
 
bool tryFireTapTouchShortcut (QTouchEvent *event, Qt::TouchPointStates allowedStates)
 
template<typename EventType , typename ShortcutType >
bool tryRunGestureBasedShortcutImpl (EventType *event, ShortcutType **resultShortcutPtr, const QList< ShortcutType * > allTypedShortcuts)
 
bool tryRunNativeGestureShortcut (QNativeGestureEvent *event)
 
bool tryRunReadyShortcut (Qt::MouseButton button, QEvent *event)
 
template<typename T , typename U >
bool tryRunSingleActionShortcutImpl (T param, U *event, const QSet< Qt::Key > &keysState, bool keyboard=true)
 
bool tryRunTouchpadScrollShortcut (QWheelEvent *event)
 
bool tryRunTouchShortcut (QTouchEvent *event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode)
 
bool tryRunWheelShortcut (KisSingleActionShortcut::WheelAction wheelAction, QWheelEvent *event)
 
- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

Private *const m_d
 
- Private Attributes inherited from Private
KisCanvas2 * canvas
 
int displayedFrame
 
int intendedFrame
 

Friends

class KisInputManagerTest
 

Detailed Description

The class that manages connections between shortcuts and actions.

It processes input events and generates state transitions for the actions basing on the data, represented by the shortcuts.

The class works with two types of actions: long running (represented by KisStrokeShortcuts) and "atomic" (KisSingleActionShortcut). The former one involves some long interaction with the user by means of a mouse cursor or a tablet, the latter one simple action like "Zoom 100%" or "Reset Rotation".

The single action shortcuts are handled quite easily. The matcher listens to the events coming, manages two lists of the pressed keys and buttons and when their content corresponds to some single action shortcut it just runs this shortcut once.

The strategy for handling the stroke shortcuts is a bit more complex. Each such action may be in one of the three states:

Idle <-> Ready <-> Running

In "Idle" state the action is completely inactive and has no access to the user

When the action is in "Ready" state, it means that all the modifiers for the action are already pressed and we are only waiting for a user to press the mouse button and start a stroke. In this state the action can show the user its Cursor to notify the user what is going to happen next.

In the "Running" state, the action has full access to the user input and is considered to perform all the work it was created for.

To implement such state transitions for the actions, KisShortcutMatcher first forms a list of the actions which can be moved to a ready state (m_d->readyShortcuts), then chooses the one with the highest priority to be the only shortcut in the "Ready" state and activates it (m_d->readyShortcut). Then when the user presses the mouse button, the matcher looks through the list of ready shortcuts, chooses which will be running now, deactivates (if needed) currently activated action and starts the chosen one.

See also
KisSingleActionShortcut
KisStrokeShortcut

Definition at line 89 of file kis_shortcut_matcher.cpp.

Member Enumeration Documentation

◆ TouchShortcutMode

enum class KisShortcutMatcher::TouchShortcutMode
strongprivate
Enumerator
Drag 
Tap 
Hold 

Definition at line 320 of file kis_shortcut_matcher.h.

Constructor & Destructor Documentation

◆ ~Private()

KisShortcutMatcher::~Private ( )
inline

Definition at line 104 of file kis_shortcut_matcher.cpp.

105 {
106 qDeleteAll(singleActionShortcuts);
107 qDeleteAll(strokeShortcuts);
108 qDeleteAll(touchShortcuts);
109 }
QList< KisStrokeShortcut * > strokeShortcuts
QList< KisSingleActionShortcut * > singleActionShortcuts
QList< KisTouchShortcut * > touchShortcuts

◆ KisShortcutMatcher()

KisShortcutMatcher::KisShortcutMatcher ( )

Definition at line 218 of file kis_shortcut_matcher.cpp.

219 : m_d(new Private)
220{}

◆ ~KisShortcutMatcher()

KisShortcutMatcher::~KisShortcutMatcher ( )

Definition at line 222 of file kis_shortcut_matcher.cpp.

223{
224 delete m_d;
225}

References m_d.

Member Function Documentation

◆ actionsSuppressed()

bool KisShortcutMatcher::actionsSuppressed ( ) const
inline

Definition at line 200 of file kis_shortcut_matcher.cpp.

200 {
201#ifndef Q_OS_ANDROID
203#else
204 // when S-pen is not pointing the canvas, actions on canvas are disabled, till it points back to canvas.
205 return suppressAllActions;
206#endif
207 }

◆ actionsSuppressedIgnoreFocus()

bool KisShortcutMatcher::actionsSuppressedIgnoreFocus ( ) const
inline

Definition at line 209 of file kis_shortcut_matcher.cpp.

209 {
210 return suppressAllActions;
211 }

◆ addShortcut() [1/5]

void KisShortcutMatcher::addShortcut ( KisNativeGestureShortcut * shortcut)

Definition at line 257 of file kis_shortcut_matcher.cpp.

258{
259 m_d->nativeGestureShortcuts.append(shortcut);
260}

References m_d.

◆ addShortcut() [2/5]

void KisShortcutMatcher::addShortcut ( KisSingleActionShortcut * shortcut)

Definition at line 242 of file kis_shortcut_matcher.cpp.

243{
244 m_d->singleActionShortcuts.append(shortcut);
245}

References m_d.

◆ addShortcut() [3/5]

void KisShortcutMatcher::addShortcut ( KisStrokeShortcut * shortcut)

Definition at line 247 of file kis_shortcut_matcher.cpp.

248{
249 m_d->strokeShortcuts.append(shortcut);
250}

References m_d.

◆ addShortcut() [4/5]

void KisShortcutMatcher::addShortcut ( KisTouchpadScrollShortcut * shortcut)

Definition at line 262 of file kis_shortcut_matcher.cpp.

263{
264 m_d->touchpadScrollShortcuts.append(shortcut);
265}

References m_d.

◆ addShortcut() [5/5]

void KisShortcutMatcher::addShortcut ( KisTouchShortcut * shortcut)

Definition at line 252 of file kis_shortcut_matcher.cpp.

253{
254 m_d->touchShortcuts.append(shortcut);
255}

References m_d.

◆ autoRepeatedKeyPressed()

bool KisShortcutMatcher::autoRepeatedKeyPressed ( Qt::Key key)

Handles a key press event that has been generated by the autorepeat.

Returns
whether the event has been handled successfully and should be eaten by the events filter

Definition at line 304 of file kis_shortcut_matcher.cpp.

305{
306 Private::RecursionNotifier notifier(this);
307
308
309 bool retval = false;
310
311 if (!m_d->keys.contains(key)) { DEBUG_ACTION("Peculiar, autorepeated key but can't remember it was pressed"); }
312
313 if (m_d->polledKeys.contains(key)) {
314 m_d->polledKeys.remove(key);
315 }
316
317 if (notifier.isInRecursion()) {
319 } else if (!hasRunningShortcut()) {
320 // Autorepeated key should not be included in the shortcut
321 QSet<Qt::Key> filteredKeys = m_d->keys;
322 filteredKeys.remove(key);
323 retval = tryRunSingleActionShortcutImpl(key, (QEvent*)0, filteredKeys);
324 }
325
326 return retval;
327}
bool tryRunSingleActionShortcutImpl(T param, U *event, const QSet< Qt::Key > &keysState, bool keyboard=true)
#define DEBUG_ACTION(action)
WGConfigNotifier * notifier()
Definition WGConfig.cpp:190

References DEBUG_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), m_d, and tryRunSingleActionShortcutImpl().

◆ buttonPressed()

bool KisShortcutMatcher::buttonPressed ( Qt::MouseButton button,
QEvent * event )

Handles button presses from a tablet or mouse.

Parameters
eventthe event that caused this call. Must be of type QTabletEvent or QMouseEvent.
Returns
whether the event has been handled successfully and should be eaten by the events filter

Definition at line 350 of file kis_shortcut_matcher.cpp.

351{
352 Private::RecursionNotifier notifier(this);
353 DEBUG_BUTTON_ACTION("entered", button);
354
355 // the tablet actions have the priority over any existing
356 // touch action, so we should cancel them first
358
359 bool retval = false;
360
361 if (m_d->buttons.contains(button)) { DEBUG_ACTION("Peculiar, button was already pressed."); }
362
363 if (!hasRunningShortcut() && !notifier.isInRecursion()) {
365 retval = tryRunReadyShortcut(button, event);
366 }
367
368 m_d->buttons.insert(button);
369
370 if (notifier.isInRecursion()) {
372 } else if (!hasRunningShortcut()) {
375 }
376
377 return retval;
378}
bool tryRunReadyShortcut(Qt::MouseButton button, QEvent *event)
#define DEBUG_BUTTON_ACTION(text, button)
QString button(const QWheelEvent &ev)

References button(), DEBUG_ACTION, DEBUG_BUTTON_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), tryActivateReadyShortcut(), tryCancelAllCurrentTouchActionsImpl(), and tryRunReadyShortcut().

◆ buttonReleased()

bool KisShortcutMatcher::buttonReleased ( Qt::MouseButton button,
QEvent * event )

Handles the mouse button release event

Parameters
eventthe event that caused this call. Must be of type QTabletEvent or QMouseEvent.
Returns
whether the event has been handled successfully and should be eaten by the events filter

Definition at line 380 of file kis_shortcut_matcher.cpp.

381{
382 Private::RecursionNotifier notifier(this);
383 DEBUG_BUTTON_ACTION("entered", button);
384
385 bool retval = false;
386
387 // here we check for the presence of the **stroke** shortcut only
388 if (m_d->runningShortcut) {
389 KIS_SAFE_ASSERT_RECOVER_NOOP(!notifier.isInRecursion());
390
391 retval = tryEndRunningShortcut(button, event);
392 DEBUG_BUTTON_ACTION("ended", button);
393 }
394
395 if (!m_d->buttons.contains(button)) reset("Peculiar, button released but we can't remember it was pressed");
396 else m_d->buttons.remove(button);
397
398 if (notifier.isInRecursion()) {
400 } else if (!hasRunningShortcut()) {
403 }
404
405 return retval;
406}
bool tryEndRunningShortcut(Qt::MouseButton button, QEvent *event)
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References button(), DEBUG_BUTTON_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), KIS_SAFE_ASSERT_RECOVER_NOOP, m_d, prepareReadyShortcuts(), reset(), tryActivateReadyShortcut(), and tryEndRunningShortcut().

◆ clearShortcuts()

void KisShortcutMatcher::clearShortcuts ( )

Remove all shortcuts that have been registered.

Definition at line 1102 of file kis_shortcut_matcher.cpp.

1103{
1104 reset("Clearing shortcuts");
1105
1106 qDeleteAll(m_d->singleActionShortcuts);
1107 m_d->singleActionShortcuts.clear();
1108 m_d->suppressedSingleActionShortcuts.clear();
1109
1110 qDeleteAll(m_d->strokeShortcuts);
1111 m_d->strokeShortcuts.clear();
1112
1113 qDeleteAll(m_d->touchShortcuts);
1114 m_d->touchShortcuts.clear();
1115
1116 qDeleteAll(m_d->nativeGestureShortcuts);
1117 m_d->nativeGestureShortcuts.clear();
1118
1119 qDeleteAll(m_d->touchpadScrollShortcuts);
1120 m_d->touchpadScrollShortcuts.clear();
1121
1122 m_d->candidateShortcuts.clear();
1123 m_d->runningShortcut = 0;
1124 m_d->readyShortcut = 0;
1125 m_d->touchShortcut = 0;
1126 m_d->nativeGestureShortcut = 0;
1127 m_d->touchpadScrollShortcut = 0;
1128}

References m_d, and reset().

◆ debugPressedKeys()

QVector< Qt::Key > KisShortcutMatcher::debugPressedKeys ( ) const

Return the internal state of the tracked modifiers.

Definition at line 1016 of file kis_shortcut_matcher.cpp.

1017{
1019 std::copy(m_d->keys.begin(), m_d->keys.end(), std::back_inserter(keys));
1020 return keys;
1021}

References keys, and m_d.

◆ enterEvent()

void KisShortcutMatcher::enterEvent ( )

Handle cursor's Enter event. We never eat it because it might be used by someone else

Definition at line 440 of file kis_shortcut_matcher.cpp.

441{
442 Private::RecursionNotifier notifier(this);
443
444 m_d->cursorEntered = true;
445
446 if (notifier.isInRecursion()) {
448 } else if (!hasRunningShortcut()) {
451 }
452}

References forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), and tryActivateReadyShortcut().

◆ forceDeactivateAllActions()

void KisShortcutMatcher::forceDeactivateAllActions ( )
private

Definition at line 1360 of file kis_shortcut_matcher.cpp.

1361{
1362 if (m_d->readyShortcut) {
1363 DEBUG_SHORTCUT("Forcefully deactivating action", m_d->readyShortcut);
1364 m_d->readyShortcut->action()->deactivate(m_d->readyShortcut->shortcutIndex());
1365 m_d->readyShortcut = 0;
1366 }
1367}
#define DEBUG_SHORTCUT(text, shortcut)

References DEBUG_SHORTCUT, and m_d.

◆ forceEndRunningShortcut()

void KisShortcutMatcher::forceEndRunningShortcut ( const QPointF & localPos)
private

Definition at line 1335 of file kis_shortcut_matcher.cpp.

1336{
1337 KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->runningShortcut);
1338 KIS_SAFE_ASSERT_RECOVER(!m_d->readyShortcut) {
1339 // it shouldn't have happened, running and ready shortcuts
1340 // at the same time should not be possible
1342 }
1343
1344 // first reset running shortcut to avoid infinite recursion via end()
1345 KisStrokeShortcut *runningShortcut = m_d->runningShortcut;
1346 m_d->runningShortcut = 0;
1347
1348 if (runningShortcut->action()) {
1349 DEBUG_ACTION("Forced ending running shortcut at event");
1351 int shortcutIndex = runningShortcut->shortcutIndex();
1352
1353 QMouseEvent event = runningShortcut->fakeEndEvent(localPos);
1354
1355 action->end(&event);
1356 action->deactivate(shortcutIndex);
1357 }
1358}
Abstract base class for input actions.
virtual void deactivate(int shortcut)
virtual void end(QEvent *event)
KisAbstractInputAction * action
KisStrokeShortcut * runningShortcut
QMouseEvent fakeEndEvent(const QPointF &localPos) const
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128

References KisAbstractShortcut::action, KisAbstractInputAction::deactivate(), DEBUG_ACTION, KisAbstractInputAction::end(), KisStrokeShortcut::fakeEndEvent(), forceDeactivateAllActions(), KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_RETURN, m_d, runningShortcut, and KisAbstractShortcut::shortcutIndex.

◆ handlePolledKeys()

void KisShortcutMatcher::handlePolledKeys ( const QVector< Qt::Key > & keys)

Resets the internal state of the matcher, tries to resync it to the state passed via argument and activates the prepared action if possible.

This synchronization happens when the user hovers Krita windows, without having keyboard focus set to it (therefore matcher cannot get key press and release events), and is also used for various other fixes.

Definition at line 976 of file kis_shortcut_matcher.cpp.

977{
978 Q_FOREACH (Qt::Key key, m_d->keys) {
979 if (!keys.contains(key)) {
980 keyReleased(key);
981 }
982 }
983
984 Q_FOREACH (Qt::Key key, keys) {
985 if (!m_d->keys.contains(key)) {
986 keyPressed(key);
987 m_d->polledKeys << key;
988 }
989 }
990
991 Private::RecursionNotifier notifier(this);
992
993 if (notifier.isInRecursion()) {
995 } else if (!hasRunningShortcut()) {
998 }
999
1000 DEBUG_ACTION("recoverySyncModifiers");
1001}
bool keyPressed(Qt::Key key)
bool keyReleased(Qt::Key key)

References DEBUG_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), keyPressed(), keyReleased(), keys, m_d, prepareReadyShortcuts(), and tryActivateReadyShortcut().

◆ hasPolledKeys()

bool KisShortcutMatcher::hasPolledKeys ( )

Check if polled keys are present, which signals that we need to call KisInputManager::Private::fixShortcutMatcherModifiersState.

Definition at line 1023 of file kis_shortcut_matcher.cpp.

1024{
1025 return !m_d->polledKeys.empty();
1026}

References m_d.

◆ hasRunningShortcut()

bool KisShortcutMatcher::hasRunningShortcut ( ) const

Definition at line 227 of file kis_shortcut_matcher.cpp.

228{
229 return m_d->runningShortcut || m_d->touchShortcut || m_d->nativeGestureShortcut || m_d->touchpadScrollShortcut;
230}

References m_d.

◆ hasTouchHoldShortcut()

bool KisShortcutMatcher::hasTouchHoldShortcut ( ) const

Definition at line 232 of file kis_shortcut_matcher.cpp.

233{
234 for (const KisTouchShortcut *shortcut : m_d->touchShortcuts) {
235 if (shortcut->isHoldType() && shortcut->isAvailable(m_d->actionGroupMask())) {
236 return true;
237 }
238 }
239 return false;
240}
The KisTouchShortcut class only handles touch gestures it does not handle tool invocation i....

References m_d.

◆ hasTouchpadScrollShortcuts()

bool KisShortcutMatcher::hasTouchpadScrollShortcuts ( ) const

Definition at line 875 of file kis_shortcut_matcher.cpp.

876{
877 return !m_d->touchpadScrollShortcuts.isEmpty();
878}

References m_d.

◆ ignoreMultiFingerCancelWorkaroundEnalbed()

bool KisShortcutMatcher::ignoreMultiFingerCancelWorkaroundEnalbed ( ) const
See also
setIgnoreMultiFingerCancelWorkaroundEnalbed()

Definition at line 1613 of file kis_shortcut_matcher.cpp.

1614{
1615 return m_d->ignoreMultiFingerCancelWorkaround.has_value();
1616}

References m_d.

◆ KeyboardActionsSuppressed()

bool KisShortcutMatcher::KeyboardActionsSuppressed ( ) const
inline

Definition at line 213 of file kis_shortcut_matcher.cpp.

213 {
215 }

◆ keyPressed()

bool KisShortcutMatcher::keyPressed ( Qt::Key key)

Handles a key press event. No autorepeat events should be passed to this method.

Returns
whether the event has been handled successfully and should be eaten by the events filter

Definition at line 279 of file kis_shortcut_matcher.cpp.

280{
281 Private::RecursionNotifier notifier(this);
282
283 bool retval = false;
284
285 if (m_d->keys.contains(key)) { DEBUG_ACTION("Peculiar, records show key was already pressed"); }
286
287 if (!hasRunningShortcut() && !notifier.isInRecursion()) {
288 retval = tryRunSingleActionShortcutImpl(key, (QEvent*)0, m_d->keys);
289 }
290
291 m_d->keys.insert(key);
292 DEBUG_KEY("Pressed");
293
294 if (notifier.isInRecursion()) {
296 } else if (!hasRunningShortcut()) {
299 }
300
301 return retval;
302}
#define DEBUG_KEY(text)

References DEBUG_ACTION, DEBUG_KEY, forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), tryActivateReadyShortcut(), and tryRunSingleActionShortcutImpl().

◆ keyReleased()

bool KisShortcutMatcher::keyReleased ( Qt::Key key)

Handles a key release event. No autorepeat events should be passed to this method.

Returns
whether the event has been handled successfully and should be eaten by the events filter

Definition at line 329 of file kis_shortcut_matcher.cpp.

330{
331 Private::RecursionNotifier notifier(this);
332
333 if (!m_d->keys.contains(key)) { DEBUG_ACTION("Peculiar, key released but can't remember it was pressed"); }
334 else m_d->keys.remove(key);
335
336 m_d->polledKeys.remove(key);
337
338 DEBUG_KEY("Released");
339
340 if (notifier.isInRecursion()) {
342 } else if (!hasRunningShortcut()) {
345 }
346
347 return false;
348}

References DEBUG_ACTION, DEBUG_KEY, forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), and tryActivateReadyShortcut().

◆ leaveEvent()

void KisShortcutMatcher::leaveEvent ( )

Handle cursor's Leave event. We never eat it because it might be used by someone else

Definition at line 454 of file kis_shortcut_matcher.cpp.

455{
456 Private::RecursionNotifier notifier(this);
457
458 m_d->cursorEntered = false;
459
460 if (notifier.isInRecursion()) {
462 } else if (!hasRunningShortcut()) {
465 }
466}

References forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), and tryActivateReadyShortcut().

◆ lostFocusEvent()

void KisShortcutMatcher::lostFocusEvent ( const QPointF & localPos)

Krita lost focus, it means that all the running actions should be ended forcefully.

TODO: it might be that we should also deactivate touch and native gestures on focus-out events. After testing on Windows it seems like it works fine without any explicit stopping the touch strokes. They just continue in the unfocused application (given that Krita does not get overlapped by another window)

Definition at line 1028 of file kis_shortcut_matcher.cpp.

1029{
1030 Private::RecursionNotifier notifier(this);
1031
1032 DEBUG_ACTION("lostFocusEvent");
1033
1034 if (m_d->runningShortcut) {
1035 forceEndRunningShortcut(localPos);
1036 }
1037
1039
1047}
void forceEndRunningShortcut(const QPointF &localPos)

References DEBUG_ACTION, forceDeactivateAllActions(), forceEndRunningShortcut(), and m_d.

◆ matchTouchShortcut()

KisTouchShortcut * KisShortcutMatcher::matchTouchShortcut ( QTouchEvent * event,
Qt::TouchPointStates allowedStates,
TouchShortcutMode mode )
private

Definition at line 1412 of file kis_shortcut_matcher.cpp.

1413{
1414 KisTouchShortcut *goodCandidate = nullptr;
1415 Q_FOREACH (KisTouchShortcut *shortcut, m_d->touchShortcuts) {
1416 if (shortcut->isAvailable(m_d->actionGroupMask())
1417 && matchTouchShortcutBasedOnState(event, shortcut, allowedStates, mode)
1418 && (!goodCandidate || shortcut->priority() > goodCandidate->priority())) {
1419
1420 goodCandidate = shortcut;
1421 }
1422 }
1423 return goodCandidate;
1424}
bool matchTouchShortcutBasedOnState(QTouchEvent *event, KisTouchShortcut *shortcut, Qt::TouchPointStates allowedStates, TouchShortcutMode mode)
bool isAvailable(KisInputActionGroupsMask mask) const override
int priority() const override

References KisTouchShortcut::isAvailable(), m_d, matchTouchShortcutBasedOnState(), and KisTouchShortcut::priority().

◆ matchTouchShortcutBasedOnState()

bool KisShortcutMatcher::matchTouchShortcutBasedOnState ( QTouchEvent * event,
KisTouchShortcut * shortcut,
Qt::TouchPointStates allowedStates,
TouchShortcutMode mode )
private

Definition at line 1426 of file kis_shortcut_matcher.cpp.

1427{
1428 switch (mode) {
1430 return shortcut->matchHoldType(event, allowedStates);
1431 break;
1433 return shortcut->matchDragType(event, allowedStates);
1434 break;
1436 return shortcut->matchTapType(event, allowedStates);
1437 break;
1438 }
1439
1440#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1441 return false;
1442#else
1443 Q_UNREACHABLE_RETURN(false);
1444#endif
1445}
bool matchTapType(const QTouchEvent *event, Qt::TouchPointStates allowedStates)
bool matchDragType(const QTouchEvent *event, Qt::TouchPointStates allowedStates)
bool matchHoldType(const QTouchEvent *event, Qt::TouchPointStates allowedStates)

References Drag, Hold, KisTouchShortcut::matchDragType(), KisTouchShortcut::matchHoldType(), KisTouchShortcut::matchTapType(), and Tap.

◆ nativeGestureBeginEvent()

bool KisShortcutMatcher::nativeGestureBeginEvent ( QNativeGestureEvent * event)

Definition at line 827 of file kis_shortcut_matcher.cpp.

828{
829 Q_UNUSED(event);
830
831 Private::RecursionNotifier notifier(this);
832
833 DEBUG_EVENT_ACTION("entered", event);
834
835 return !notifier.isInRecursion();
836}
#define DEBUG_EVENT_ACTION(text, event)

References DEBUG_EVENT_ACTION.

◆ nativeGestureEndEvent()

bool KisShortcutMatcher::nativeGestureEndEvent ( QNativeGestureEvent * event)

Definition at line 855 of file kis_shortcut_matcher.cpp.

856{
857 Private::RecursionNotifier notifier(this);
858
859 DEBUG_EVENT_ACTION("entered", event);
860
861 if (m_d->nativeGestureShortcut) {
863 }
864
865 if (notifier.isInRecursion()) {
867 } else if (!hasRunningShortcut()) {
870 }
871
872 return true;
873}
bool tryEndNativeGestureShortcut(QNativeGestureEvent *event)

References DEBUG_EVENT_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), tryActivateReadyShortcut(), and tryEndNativeGestureShortcut().

◆ nativeGestureEvent()

bool KisShortcutMatcher::nativeGestureEvent ( QNativeGestureEvent * event)

Definition at line 838 of file kis_shortcut_matcher.cpp.

839{
840 bool retval = false;
841
842 DEBUG_EVENT_ACTION("entered", event);
843
844 if (!hasRunningShortcut()) {
845 retval = tryRunNativeGestureShortcut( event );
846 }
847 else if (m_d->nativeGestureShortcut) {
848 m_d->nativeGestureShortcut->action()->inputEvent( event );
849 retval = true;
850 }
851
852 return retval;
853}
bool tryRunNativeGestureShortcut(QNativeGestureEvent *event)

References DEBUG_EVENT_ACTION, hasRunningShortcut(), m_d, and tryRunNativeGestureShortcut().

◆ pointerMoved()

bool KisShortcutMatcher::pointerMoved ( QEvent * event)

Handles tablet and mouse move events.

Parameters
eventthe event that caused this call
Returns
whether the event has been handled successfully and should be eaten by the events filter

Definition at line 421 of file kis_shortcut_matcher.cpp.

422{
423 Private::RecursionNotifier notifier(this);
424
425 if (notifier.isInRecursion()) {
426 return false;
427 }
428
429 bool retval = false;
430
431 if (m_d->runningShortcut) {
432 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(!m_d->touchShortcut && !m_d->nativeGestureShortcut, false);
433 m_d->runningShortcut->action()->inputEvent(event);
434 retval = true;
435 }
436
437 return retval;
438}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, and m_d.

◆ prepareReadyShortcuts()

void KisShortcutMatcher::prepareReadyShortcuts ( )
private

Definition at line 1172 of file kis_shortcut_matcher.cpp.

1173{
1174 m_d->candidateShortcuts.clear();
1175 if (m_d->actionsSuppressed()) return;
1176
1177 // Allow letting the modifiers to be matched so key_shift + middle mouse move can be matched, but key_v + mouse drag can not.
1178 bool containsOnlyModifiers = !m_d->keys.isEmpty();
1179 Q_FOREACH(const Qt::Key k, m_d->keys) {
1180 if (k != Qt::Key_Shift && k != Qt::Key_Control && k != Qt::Key_Alt && k != Qt::Key_Meta) {
1181 containsOnlyModifiers = false;
1182 break;
1183 }
1184 }
1185 if (m_d->KeyboardActionsSuppressed()
1186 && !containsOnlyModifiers && !m_d->keys.isEmpty()
1187 && m_d->buttons.isEmpty()) {
1188 return;
1189 }
1190
1191 Q_FOREACH (KisStrokeShortcut *s, m_d->strokeShortcuts) {
1192 if (s->matchReady(m_d->keys, m_d->buttons)) {
1193 m_d->candidateShortcuts.append(s);
1194 }
1195 }
1196}
bool matchReady(const QSet< Qt::Key > &modifiers, const QSet< Qt::MouseButton > &buttons)

References m_d, and KisStrokeShortcut::matchReady().

◆ Private()

KisShortcutMatcher::Private ( )
inline

Definition at line 92 of file kis_shortcut_matcher.cpp.

94 , readyShortcut(0)
95 , touchShortcut(0)
98 , actionGroupMask([] () { return AllActionGroup; })
99 , suppressAllActions(false)
101 , cursorEntered(false)
102 {}
@ AllActionGroup
KisTouchpadScrollShortcut * touchpadScrollShortcut
KisTouchShortcut * touchShortcut
KisStrokeShortcut * readyShortcut
std::function< KisInputActionGroupsMask()> actionGroupMask
KisNativeGestureShortcut * nativeGestureShortcut

References AllActionGroup.

◆ reinitialize()

void KisShortcutMatcher::reinitialize ( )

Resets the internal state of the matcher and activates the prepared action if possible.

This should be done when the window has lost the focus for some time, so that several events could be lost

Definition at line 946 of file kis_shortcut_matcher.cpp.

947{
948 Private::RecursionNotifier notifier(this);
949
950
951 reset("reinitialize");
952
953 if (notifier.isInRecursion()) {
955 } else if (!hasRunningShortcut()) {
958 }
959}

References forceDeactivateAllActions(), hasRunningShortcut(), prepareReadyShortcuts(), reset(), and tryActivateReadyShortcut().

◆ reinitializeButtons()

void KisShortcutMatcher::reinitializeButtons ( )

Resets the internal state of the buttons inside matcher and activates the prepared action if possible.

This should be done when the window has lost the focus for some time, so that several events could be lost

Definition at line 961 of file kis_shortcut_matcher.cpp.

962{
963 Private::RecursionNotifier notifier(this);
964
965 m_d->buttons.clear();
966 DEBUG_ACTION("reinitializing buttons");
967
968 if (notifier.isInRecursion()) {
970 } else if (!hasRunningShortcut()) {
973 }
974}

References DEBUG_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), and tryActivateReadyShortcut().

◆ reset() [1/2]

void KisShortcutMatcher::reset ( )
private

Definition at line 1063 of file kis_shortcut_matcher.cpp.

1064{
1065 m_d->keys.clear();
1066 m_d->buttons.clear();
1067 DEBUG_ACTION("reset!");
1068}

References DEBUG_ACTION, and m_d.

◆ reset() [2/2]

void KisShortcutMatcher::reset ( QString msg)
private

Definition at line 1071 of file kis_shortcut_matcher.cpp.

1072{
1073 m_d->keys.clear();
1074 m_d->buttons.clear();
1075 Q_UNUSED(msg);
1076 DEBUG_ACTION(msg);
1077}

References DEBUG_ACTION, and m_d.

◆ sanityCheckModifiersCorrectness()

bool KisShortcutMatcher::sanityCheckModifiersCorrectness ( Qt::KeyboardModifiers modifiers) const

Sanity check correctness of the internal state of the matcher by comparing it to the standard modifiers that we get with every input event. Right now this sanity check is used on Windows only.

Definition at line 1003 of file kis_shortcut_matcher.cpp.

1004{
1005 auto checkKey = [this, modifiers] (Qt::Key key, Qt::KeyboardModifier modifier) {
1006 return m_d->keys.contains(key) == bool(modifiers & modifier);
1007 };
1008
1009 return checkKey(Qt::Key_Shift, Qt::ShiftModifier) &&
1010 checkKey(Qt::Key_Control, Qt::ControlModifier) &&
1011 checkKey(Qt::Key_Alt, Qt::AltModifier) &&
1012 checkKey(Qt::Key_Meta, Qt::MetaModifier);
1013
1014}

References m_d.

◆ setIgnoreMultiFingerCancelWorkaroundEnalbed()

void KisShortcutMatcher::setIgnoreMultiFingerCancelWorkaroundEnalbed ( bool value)

Enabled a workaround that allows processing 3+ finger tap shortcuts, even when the system sends QEvent::TouchCancel for them. Need on some Android devices.

Definition at line 1604 of file kis_shortcut_matcher.cpp.

1605{
1606 if (value) {
1607 m_d->ignoreMultiFingerCancelWorkaround = Private::IgnoreMultiFingerCancelWorkaround();
1608 } else {
1609 m_d->ignoreMultiFingerCancelWorkaround = std::nullopt;
1610 }
1611}
float value(const T *src, size_t ch)

References m_d, and value().

◆ setInputActionGroupsMaskCallback()

void KisShortcutMatcher::setInputActionGroupsMaskCallback ( std::function< KisInputActionGroupsMask()> func)

Definition at line 1130 of file kis_shortcut_matcher.cpp.

1131{
1132 m_d->actionGroupMask = func;
1133}

References m_d.

◆ setMaxTouchPointEvent()

void KisShortcutMatcher::setMaxTouchPointEvent ( QTouchEvent * event)
private

Definition at line 1369 of file kis_shortcut_matcher.cpp.

1370{
1371 int previousNumTouchPoints = -1;
1372
1373 if (m_d->bestCandidateForTapTouchEvent) {
1374 QTouchEvent *bestTouchEvent = static_cast<QTouchEvent*>(m_d->bestCandidateForTapTouchEvent.data());
1375 previousNumTouchPoints = KisTouchShortcut::countTouchPoints(bestTouchEvent, KisTouchShortcut::pressedOnlyTouchStates());
1376 }
1377
1379
1380 if (newNumTouchPoints >= previousNumTouchPoints) {
1381#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
1382 KoPointerEvent::copyQtPointerEvent(event, m_d->bestCandidateForTapTouchEvent);
1383#else
1384 m_d->bestCandidateForTapTouchEvent.reset(event->clone());
1385#endif
1386 }
1387}
static Qt::TouchPointStates pressedOnlyTouchStates()
static int countTouchPoints(const QTouchEvent *event, Qt::TouchPointStates allowedStates)

References KisTouchShortcut::countTouchPoints(), m_d, and KisTouchShortcut::pressedOnlyTouchStates().

◆ setTouchHoldDelay()

void KisShortcutMatcher::setTouchHoldDelay ( int value)
Returns
the currently set delay for the touch-hold actions (milliseconds)

Definition at line 1599 of file kis_shortcut_matcher.cpp.

1600{
1601 m_d->touchHoldDelayMs = value;
1602}

References m_d, and value().

◆ slotTouchHoldCompleted()

void KisShortcutMatcher::slotTouchHoldCompleted ( )
private

Definition at line 559 of file kis_shortcut_matcher.cpp.

560{
561 KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->touchHoldEventPostponer);
563
564 // Can happen when multiple shortcut sources interact
565 KIS_SAFE_ASSERT_RECOVER_RETURN(!m_d->runningShortcut);
566
567 // take the very first begin event to start the action
568 QTouchEvent *event = m_d->touchHoldEventPostponer->postponedEvents().front();
569 KIS_SAFE_ASSERT_RECOVER_RETURN(event->type() == QEvent::TouchBegin);
570
571 m_d->isTouchHeld = true; // Must be set first, used in tryRunTouchShortcut.
572
573 DEBUG_TOUCH_ACTION("entered", event);
574
576 // noop, all is fine!
577 } else {
578 KIS_SAFE_ASSERT_RECOVER(0 && "should not happen")
579 {
580 // Shouldn't really happen, since KisInputManager checks whether a touch
581 // hold shortcut exists beforehand. We'll just handle this though.
582 m_d->isTouchHeld = false;
583 }
584 }
585
586 // remove the postponer to continue processing events in-place
587 m_d->touchHoldEventPostponer.reset();
588}
bool tryRunTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode)
@ HoldCompleted
the postponer is still accumulating the events
#define DEBUG_TOUCH_ACTION(text, event)

References DEBUG_TOUCH_ACTION, Hold, KisTouchHoldEventsPostponer::HoldCompleted, KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_RETURN, m_d, KisTouchShortcut::pressedOnlyTouchStates(), and tryRunTouchShortcut().

◆ supportsHiResInputEvents()

bool KisShortcutMatcher::supportsHiResInputEvents ( )

Returns true if the currently running shortcut supports processing hi resolution flow of events from the tablet device. In most of the cases (except of the painting itself) too many events make the execution of the action too slow, so the action can decide whether it needs it.

Definition at line 267 of file kis_shortcut_matcher.cpp.

268{
269 return (m_d->runningShortcut && m_d->runningShortcut->action()
270 && m_d->runningShortcut->action()->supportsHiResInputEvents(m_d->runningShortcut->shortcutIndex()))
271 || (m_d->touchShortcut && m_d->touchShortcut->action()
272 && m_d->touchShortcut->action()->supportsHiResInputEvents(m_d->touchShortcut->shortcutIndex()))
273 || (m_d->nativeGestureShortcut && m_d->nativeGestureShortcut->action()
274 && m_d->nativeGestureShortcut->action()->supportsHiResInputEvents(m_d->nativeGestureShortcut->shortcutIndex()))
275 || (m_d->touchpadScrollShortcut && m_d->touchpadScrollShortcut->action()
276 && m_d->touchpadScrollShortcut->action()->supportsHiResInputEvents(m_d->touchpadScrollShortcut->shortcutIndex()));
277}

References m_d.

◆ suppressAllActions()

void KisShortcutMatcher::suppressAllActions ( bool value)

Disables the start of any actions.

WARNING: the actions that has been started before this call will not be ended. They will be ended in their usual way, when the mouse button will be released.

◆ suppressAllKeyboardActions()

void KisShortcutMatcher::suppressAllKeyboardActions ( bool value)

Disable keyboard actions.

This will disable all actions that consist of only keyboard keys being pressed without mouse or stylus buttons being pressed.

This is turned on when the tool is in text mode.

◆ suppressConflictingKeyActions()

void KisShortcutMatcher::suppressConflictingKeyActions ( const QVector< QKeySequence > & shortcuts)

Disable one-time actions whose shortcuts conflict with the listed shortcuts

Definition at line 1084 of file kis_shortcut_matcher.cpp.

1085{
1086 m_d->suppressedSingleActionShortcuts.clear();
1087
1088 Q_FOREACH (KisSingleActionShortcut *s, m_d->singleActionShortcuts) {
1089 Q_FOREACH (const QKeySequence &seq, shortcuts) {
1090 if (s->conflictsWith(seq)) {
1091 m_d->suppressedSingleActionShortcuts.insert(s);
1092 }
1093 }
1094 }
1095}
bool conflictsWith(const QKeySequence &seq)

References KisSingleActionShortcut::conflictsWith(), and m_d.

◆ toolHasBeenActivated()

void KisShortcutMatcher::toolHasBeenActivated ( )

Is called when a new tool has been activated. The method activates any tool's action if possible with the currently active modifiers.

Definition at line 1049 of file kis_shortcut_matcher.cpp.

1050{
1051 Private::RecursionNotifier notifier(this);
1052
1053 DEBUG_ACTION("toolHasBeenActivated");
1054
1055 if (notifier.isInRecursion()) {
1057 } else if (!hasRunningShortcut()) {
1060 }
1061}

References DEBUG_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), prepareReadyShortcuts(), and tryActivateReadyShortcut().

◆ touchBeginEvent()

bool KisShortcutMatcher::touchBeginEvent ( QTouchEvent * event)

Definition at line 468 of file kis_shortcut_matcher.cpp.

469{
470 DEBUG_TOUCH_ACTION("entered", event)
471
472 Private::RecursionNotifier notifier(this);
473
474 if (hasRunningShortcut()) {
475 DEBUG_ACTION("touch action rejected by a running shortcut");
476
477 // touch has been triggered while some tablet action is in progress,
478 // just consume and ignore it
479 return !notifier.isInRecursion();
480 }
481
482#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
483 QScopedPointer<QEvent> tmp;
484 KoPointerEvent::copyQtPointerEvent(event, tmp);
485 m_d->lastProcessedTouchEvent.reset(static_cast<QTouchEvent*>(tmp.take()));
486#else
487 m_d->lastProcessedTouchEvent.reset(event->clone());
488#endif
489
490 // reset state
492 if (m_d->ignoreMultiFingerCancelWorkaround) {
493 m_d->ignoreMultiFingerCancelWorkaround->lastRawTouchPointsCount = m_d->maxTouchPoints;
494 }
495 m_d->matchingIteration = 1;
496 m_d->isTouchDragDetected = false;
497 m_d->isTouchHeld = false;
498 m_d->touchActionTracked = true;
499#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
500 KoPointerEvent::copyQtPointerEvent(event, m_d->bestCandidateForTapTouchEvent);
501#else
502 m_d->bestCandidateForTapTouchEvent.reset(event->clone());
503#endif
504
505 // TODO: also check if the first point actually qualifies
506 if (hasTouchHoldShortcut()) {
507 m_d->touchHoldEventPostponer.emplace(TOUCH_SLOP, m_d->touchHoldDelayMs);
508 QObject::connect(&m_d->touchHoldEventPostponer.value(),
510 &m_d->touchHoldEventPostponer.value(),
511 [this]() {
512 slotTouchHoldCompleted();
513 });
514 m_d->touchHoldEventPostponer->pushThrough(event);
515 if (m_d->touchHoldEventPostponer->state() == KisTouchHoldEventsPostponer::HoldCancelled) {
516 m_d->touchHoldEventPostponer.reset();
517 } else {
518 DEBUG_ACTION("thouch-hold timer is set up");
519 }
520 }
521
522 return !notifier.isInRecursion();
523}
static constexpr qreal TOUCH_SLOP
@ HoldCancelled
the hold action has been detected, the accumulated events should be dropped and the hold action shoul...

References KisTouchShortcut::countTouchPoints(), DEBUG_ACTION, DEBUG_TOUCH_ACTION, hasRunningShortcut(), hasTouchHoldShortcut(), KisTouchHoldEventsPostponer::HoldCancelled, m_d, KisTouchShortcut::pressedOnlyTouchStates(), KisTouchHoldEventsPostponer::sigHoldCompleted(), and TOUCH_SLOP.

◆ touchCancelEvent()

void KisShortcutMatcher::touchCancelEvent ( QTouchEvent * event)

We received TouchCancel event, it means this event sequence has ended right here i.e without a valid TouchEnd, so we should immediately stop all running actions.

Definition at line 773 of file kis_shortcut_matcher.cpp.

774{
775 Q_UNUSED(event)
776
777 // The design requirement of touch-cancel handling is the following:
778 //
779 // 1) If drag-action has already been started, it is finished normally
780 // 2) If tap-action is pending, it is cancelled
781 // 3) If hold-action is pending, it is cancelled
782 // 4) If hold-action has already been started, it is ended normally
783
784 // On some Android devices, such as Xiaomi Pads, the system always eats
785 // multitouch inputs with more than two fingers, even if the user
786 // disables all gestures related to them in their system settings or
787 // uses the game boost mode that is supposed to disable gestures. So we
788 // handle those inputs even when they are cancelled, if the user wants
789 // to use it for a system gesture, they can disable the Krita shortcut.
790 if (m_d->ignoreMultiFingerCancelWorkaround) {
791 // NOTE: we cannot use the number of touch points from the actual
792 // cancel event, since Qt sets touch points as empty for the cancel
793 // event
794 if (m_d->ignoreMultiFingerCancelWorkaround->lastRawTouchPointsCount >= 3) {
795 DEBUG_ACTION("IgnoreMultiFingerCancelWorkaround: converting a cancelled action into a normally finished action")
796 touchEndEvent(event);
797 return;
798 }
799 }
800
801 Private::RecursionNotifier notifier(this);
802
803 DEBUG_TOUCH_ACTION("enter", event);
804
805 // the touch action has been overridden by some tablet action,
806 // consume and ignore it.
807 if (!m_d->touchActionTracked) {
808 KIS_SAFE_ASSERT_RECOVER(!m_d->touchHoldEventPostponer.has_value()) {
809 m_d->touchHoldEventPostponer->cancelHoldWait();
810 m_d->touchHoldEventPostponer.reset();
811 }
812 return;
813 }
814
815 KIS_SAFE_ASSERT_RECOVER_NOOP(!m_d->runningShortcut || !m_d->touchShortcut);
816
818
819 if (notifier.isInRecursion()) {
821 } else if (!hasRunningShortcut()) {
824 }
825}
bool touchEndEvent(QTouchEvent *event)

References DEBUG_ACTION, DEBUG_TOUCH_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_NOOP, m_d, prepareReadyShortcuts(), touchEndEvent(), tryActivateReadyShortcut(), and tryCancelAllCurrentTouchActionsImpl().

◆ touchEndEvent()

bool KisShortcutMatcher::touchEndEvent ( QTouchEvent * event)

Definition at line 687 of file kis_shortcut_matcher.cpp.

688{
689 Private::RecursionNotifier notifier(this);
690
691 DEBUG_TOUCH_ACTION("enter", event);
692
693 // the touch action has been overridden by some tablet action,
694 // consume and ignore it.
695 if (!m_d->touchActionTracked) {
696 DEBUG_ACTION("touch was not tracked");
697 KIS_SAFE_ASSERT_RECOVER(!m_d->touchHoldEventPostponer.has_value()) {
698 m_d->touchHoldEventPostponer->cancelHoldWait();
699 m_d->touchHoldEventPostponer.reset();
700 }
701 return true;
702 }
703
704 // flush all the touch-hold postiponed events if they were present
705 if (m_d->touchHoldEventPostponer) {
706 DEBUG_ACTION("flushing all postponed hold events");
707
709 m_d->touchHoldEventPostponer->cancelHoldWait();
710 // process all the postponed **update** events,
711 // the very first begin event is only used in
712 // the hold-completion operation
713 Q_FOREACH (QTouchEvent *event, m_d->touchHoldEventPostponer->postponedEvents()) {
714 if (event->type() == QEvent::TouchUpdate) {
715 (void) touchUpdateEventImpl(event);
716 }
717 }
718 m_d->touchHoldEventPostponer.reset();
719 }
720
721 m_d->touchActionTracked = false;
722
723 bool retval = false;
724
725 if (!m_d->isTouchDragDetected && m_d->bestCandidateForTapTouchEvent && !hasRunningShortcut()) {
726 retval = tryFireTapTouchShortcut(static_cast<QTouchEvent *>(m_d->bestCandidateForTapTouchEvent.data()),
728 }
729
730 // we should try and end the shortcut too (it might be that there is none? (sketch))
731 retval |= tryEndTouchShortcut(event);
732
733 if (notifier.isInRecursion()) {
735 } else if (!hasRunningShortcut()) {
738 }
739
740 return retval;
741}
bool tryFireTapTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates)
bool touchUpdateEventImpl(QTouchEvent *event)
bool tryEndTouchShortcut(QTouchEvent *event)
static Qt::TouchPointStates allTouchStates()
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)

References KisTouchShortcut::allTouchStates(), DEBUG_ACTION, DEBUG_TOUCH_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_NOOP, m_d, prepareReadyShortcuts(), touchUpdateEventImpl(), tryActivateReadyShortcut(), tryEndTouchShortcut(), tryFireTapTouchShortcut(), void(), and KisTouchHoldEventsPostponer::WaitingForHold.

◆ touchHoldDelay()

int KisShortcutMatcher::touchHoldDelay ( ) const
Returns
the currently set delay for the touch-hold actions (milliseconds)

Definition at line 1594 of file kis_shortcut_matcher.cpp.

1595{
1596 return m_d->touchHoldDelayMs;
1597}

References m_d.

◆ touchpadScrollBeginEvent()

bool KisShortcutMatcher::touchpadScrollBeginEvent ( QWheelEvent * event)

Definition at line 880 of file kis_shortcut_matcher.cpp.

881{
882 Private::RecursionNotifier notifier(this);
883
884 if (notifier.isInRecursion()) return false;
885
886 DEBUG_EVENT_ACTION("entered", event);
887
888 if (!hasRunningShortcut()) {
890 }
891
892 if (m_d->touchpadScrollShortcut) {
893 m_d->touchpadScrollShortcut->action()->inputEvent(event);
894 }
895
896 return bool(m_d->touchpadScrollShortcut);
897}
bool tryRunTouchpadScrollShortcut(QWheelEvent *event)

References DEBUG_EVENT_ACTION, hasRunningShortcut(), m_d, and tryRunTouchpadScrollShortcut().

◆ touchpadScrollEndEvent()

bool KisShortcutMatcher::touchpadScrollEndEvent ( QWheelEvent * event)

Definition at line 914 of file kis_shortcut_matcher.cpp.

915{
916 Private::RecursionNotifier notifier(this);
917
918 if (notifier.isInRecursion()) return false;
919
920 DEBUG_EVENT_ACTION("entered", event);
921
922 bool retval = false;
923
924 if (m_d->touchpadScrollShortcut) {
925 retval = tryEndTouchpadScrollShortcut(event);
926 }
927
928 if (notifier.isInRecursion()) {
930 } else if (!hasRunningShortcut()) {
933 }
934
935 return retval;
936}
bool tryEndTouchpadScrollShortcut(QWheelEvent *event)

References DEBUG_EVENT_ACTION, forceDeactivateAllActions(), hasRunningShortcut(), m_d, prepareReadyShortcuts(), tryActivateReadyShortcut(), and tryEndTouchpadScrollShortcut().

◆ touchpadScrollEvent()

bool KisShortcutMatcher::touchpadScrollEvent ( QWheelEvent * event)

Definition at line 899 of file kis_shortcut_matcher.cpp.

900{
901 Private::RecursionNotifier notifier(this);
902
903 if (notifier.isInRecursion()) return false;
904
905 DEBUG_EVENT_ACTION("entered", event);
906
907 if (m_d->touchpadScrollShortcut) {
908 m_d->touchpadScrollShortcut->action()->inputEvent(event);
909 }
910
911 return bool(m_d->touchpadScrollShortcut);
912}

References DEBUG_EVENT_ACTION, and m_d.

◆ touchUpdateEvent()

bool KisShortcutMatcher::touchUpdateEvent ( QTouchEvent * event)

Definition at line 525 of file kis_shortcut_matcher.cpp.

526{
527 // the touch action has been overridden by some tablet action,
528 // consume and ignore it.
529 if (!m_d->touchActionTracked) return false;
530
531 if (m_d->ignoreMultiFingerCancelWorkaround) {
532 m_d->ignoreMultiFingerCancelWorkaround->lastRawTouchPointsCount =
534 }
535
536 if (m_d->touchHoldEventPostponer) {
537 m_d->touchHoldEventPostponer->pushThrough(event);
538 if (m_d->touchHoldEventPostponer->state() == KisTouchHoldEventsPostponer::HoldCancelled) {
539 // process all the postponed **update** events,
540 // the very first begin event is only used in
541 // the hold-completion operation
542 Q_FOREACH (QTouchEvent *event, m_d->touchHoldEventPostponer->postponedEvents()) {
543 if (event->type() == QEvent::TouchUpdate) {
544 (void) touchUpdateEventImpl(event);
545 }
546 }
547 m_d->touchHoldEventPostponer.reset();
548 } else {
549 // noop, we are waiting for hold
550 }
551 } else {
552 // TODO: don't enter for hold-drag events
553 return touchUpdateEventImpl(event);
554 }
555
556 return true;
557}

References KisTouchShortcut::countTouchPoints(), KisTouchHoldEventsPostponer::HoldCancelled, m_d, KisTouchShortcut::pressedOnlyTouchStates(), touchUpdateEventImpl(), and void().

◆ touchUpdateEventImpl()

bool KisShortcutMatcher::touchUpdateEventImpl ( QTouchEvent * event)
private

Definition at line 590 of file kis_shortcut_matcher.cpp.

591{
592 if (_41020().isDebugEnabled()) {
593 const int oldNumPressedPoints = KisTouchShortcut::countTouchPoints(m_d->lastProcessedTouchEvent.data(), KisTouchShortcut::pressedOnlyTouchStates());
595 if (oldNumPressedPoints != newNumPressedPoints) {
596 DEBUG_TOUCH_ACTION("touch point state changed", event)
597 }
598 }
599
600#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
601 QScopedPointer<QEvent> tmp;
602 KoPointerEvent::copyQtPointerEvent(event, tmp);
603 m_d->lastProcessedTouchEvent.reset(static_cast<QTouchEvent*>(tmp.take()));
604#else
605 m_d->lastProcessedTouchEvent.reset(event->clone());
606#endif
607
608 if (m_d->isTouchHeld) {
609 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_d->touchShortcut, false);
610 m_d->touchShortcut->action()->inputEvent(event);
611 return true;
612 }
613
614 bool retval = false;
615
616 // Check whether the touchpoints are relatively stationary or have
617 // been moved for dragging. If the drag is detected, until the next
618 // TouchBegin event, we'll be assuming the gesture to be of
619 // dragging type.
620 if (!m_d->isTouchDragDetected) {
622 m_d->isTouchDragDetected = true;
623 }
624 }
625
626 // Different drag shortcuts can have different drag thresholds. E.g.
627 // touch-painting shortcut will have much lower threshold value. The
628 // shortcuts will calculate the distance themselves in
629 // KisTouchShortcut::matchDragType, so we should just ask them to do that.
630 const int numStillDraggedPoints =
632 if (!hasRunningShortcut() && numStillDraggedPoints >= m_d->maxTouchPoints) {
633 m_d->maxTouchPoints = numStillDraggedPoints;
635 m_d->isTouchDragDetected = true;
636 return true;
637 }
638 }
639
640 // for a first few events we don't process the events right away. But analyze and keep track of the event with most
641 // touchpoints. This is done to prevent conditions where in three-finger-tap, two-finger-tap be preceded due to
642 // latency
643 const int numIterations = 10;
644 if (m_d->matchingIteration <= numIterations && !m_d->isTouchDragDetected) {
645 m_d->matchingIteration++;
647 return matchTouchShortcut((QTouchEvent *)m_d->bestCandidateForTapTouchEvent.data(),
650 }
651
652 if (m_d->isTouchDragDetected) {
653 if (m_d->touchShortcut
654 // TODO: use a different check without threshold! split into match() and matchBegin()
655 && !m_d->touchShortcut->matchDragType(event, KisTouchShortcut::pressedOnlyTouchStates())) {
656 // we should end the event as an event with more touchpoints was received
657 retval = tryEndTouchShortcut(event);
658 } else if (m_d->touchShortcut) {
659 m_d->touchShortcut->action()->inputEvent(event);
660 retval = true;
661 }
662 } else { // !m_d->isTouchDragDetected
663 // triggered if a new finger was added, which might result in shortcut not matching the action
664#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
665 const auto FlagReleased = Qt::TouchPointReleased;
666#else
667 const auto FlagReleased = QEventPoint::Released;
668#endif
669 if (event->touchPointStates().testFlag(FlagReleased) && !hasRunningShortcut()) {
670 const int previousNumPoints = KisTouchShortcut::countTouchPoints(event, KisTouchShortcut::allTouchStates());
671
672 // we should end the event as an event with more touchpoints was received
673 if (previousNumPoints >= m_d->maxTouchPoints) {
674 m_d->maxTouchPoints = previousNumPoints;
676 m_d->bestCandidateForTapTouchEvent.reset();
677 retval = true;
678 }
679 }
680 }
681 }
682 // TODO: update maxTouchPoints
683
684 return retval;
685}
KisTouchShortcut * matchTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode)
void setMaxTouchPointEvent(QTouchEvent *event)
static qreal touchDragDistance(const QTouchEvent *event, Qt::TouchPointStates allowedStates)
const KRITAGLOBAL_EXPORT QLoggingCategory & _41020()

References _41020(), KisTouchShortcut::allTouchStates(), KisTouchShortcut::countTouchPoints(), DEBUG_TOUCH_ACTION, Drag, hasRunningShortcut(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, matchTouchShortcut(), KisTouchShortcut::pressedOnlyTouchStates(), setMaxTouchPointEvent(), Tap, TOUCH_SLOP, KisTouchShortcut::touchDragDistance(), tryEndTouchShortcut(), tryFireTapTouchShortcut(), and tryRunTouchShortcut().

◆ tryActivateReadyShortcut()

void KisShortcutMatcher::tryActivateReadyShortcut ( )
private

It is important that we first activate the action, and only after that assign it to m_d->readyShortcut. It makes is possible to activate another tool in KisToolInvocationAction and survive the call to forceDeactivateAllActions() from lostFocusEvent(), which would enter infinite loop otherwise.

Definition at line 1249 of file kis_shortcut_matcher.cpp.

1250{
1251 KisStrokeShortcut *goodCandidate = 0;
1252
1253 Q_FOREACH (KisStrokeShortcut *s, m_d->candidateShortcuts) {
1254 if (!goodCandidate || s->priority() > goodCandidate->priority()) {
1255 goodCandidate = s;
1256 }
1257 }
1258
1259 if (goodCandidate) {
1260 if (m_d->readyShortcut && m_d->readyShortcut != goodCandidate) {
1261 if (goodCandidate->action() == m_d->readyShortcut->action() &&
1262 goodCandidate->action()->trySwitchShortcut(
1263 m_d->readyShortcut->shortcutIndex(), goodCandidate->shortcutIndex())) {
1264 DEBUG_SHORTCUT("Switched previous shortcut action", m_d->readyShortcut);
1265 m_d->readyShortcut = goodCandidate;
1266 } else {
1267 DEBUG_SHORTCUT("Deactivated previous shortcut action", m_d->readyShortcut);
1268 m_d->readyShortcut->action()->deactivate(m_d->readyShortcut->shortcutIndex());
1269 m_d->readyShortcut = 0;
1270 }
1271 }
1272
1273 if (!m_d->readyShortcut) {
1274 DEBUG_SHORTCUT("Preparing new ready action", goodCandidate);
1275
1283 goodCandidate->action()->activate(goodCandidate->shortcutIndex());
1284 m_d->readyShortcut = goodCandidate;
1285 }
1286 } else if (m_d->readyShortcut) {
1287 DEBUG_SHORTCUT("Deactivating action", m_d->readyShortcut);
1288 m_d->readyShortcut->action()->deactivate(m_d->readyShortcut->shortcutIndex());
1289 m_d->readyShortcut = 0;
1290 }
1291}
virtual void activate(int shortcut)
virtual bool trySwitchShortcut(int oldShortcut, int newShortcut)
int priority() const override

References KisAbstractShortcut::action, KisAbstractInputAction::activate(), DEBUG_SHORTCUT, m_d, KisStrokeShortcut::priority(), KisAbstractShortcut::shortcutIndex, and KisAbstractInputAction::trySwitchShortcut().

◆ tryCancelAllCurrentTouchActionsImpl()

void KisShortcutMatcher::tryCancelAllCurrentTouchActionsImpl ( )
private

Definition at line 743 of file kis_shortcut_matcher.cpp.

744{
745 // discard all the postponed touch-hold events
746 if (m_d->touchHoldEventPostponer) {
748 m_d->touchHoldEventPostponer->cancelHoldWait();
749 m_d->touchHoldEventPostponer.reset();
750 }
751
752 // end the touch action if present
753 if (m_d->touchShortcut) {
754 DEBUG_ACTION("force-cancel touch action")
755
757 m_d->touchShortcut = 0;
758
760
761 // on some platforms touch-cancel event may have **no**
762 // touch points, which would greatly confuse our KoPointerEvent
763 // class, so we should just generate a normal touch-end from the
764 // last known event
765 QTouchEvent touchEvent = generateFakeTouchEndEvent(m_d->lastProcessedTouchEvent.data());
766 touchShortcut->action()->end(&touchEvent);
767 touchShortcut->action()->deactivate(touchShortcut->shortcutIndex());
768 }
769
770 m_d->touchActionTracked = false;
771}
QScopedPointer< QTouchEvent > lastProcessedTouchEvent

References KisAbstractShortcut::action, KisAbstractInputAction::deactivate(), DEBUG_ACTION, KisAbstractInputAction::end(), KIS_SAFE_ASSERT_RECOVER_NOOP, KIS_SAFE_ASSERT_RECOVER_RETURN, m_d, KisAbstractShortcut::shortcutIndex, touchShortcut, and KisTouchHoldEventsPostponer::WaitingForHold.

◆ tryEndGestureBasedShortcutImpl()

template<typename EventType , typename ShortcutType >
bool KisShortcutMatcher::tryEndGestureBasedShortcutImpl ( EventType * event,
ShortcutType ** resultShortcutPtr )
private

Definition at line 1547 of file kis_shortcut_matcher.cpp.

1548{
1549 Private::RecursionNotifier notifier(this);
1550
1551 if (*resultShortcutPtr) {
1552 // first reset running shortcut to avoid infinite recursion via end()
1553 ShortcutType *runningShortcut = *resultShortcutPtr;
1554 *resultShortcutPtr = nullptr;
1555
1557
1558 runningShortcut->action()->end(event);
1560
1561 return true;
1562 }
1563
1564 if (notifier.isInRecursion()) {
1566 } else if (!hasRunningShortcut()) {
1569 }
1570
1571 return false;
1572}

References KisAbstractShortcut::action, KisAbstractInputAction::deactivate(), DEBUG_SHORTCUT, KisAbstractInputAction::end(), forceDeactivateAllActions(), hasRunningShortcut(), prepareReadyShortcuts(), runningShortcut, KisAbstractShortcut::shortcutIndex, and tryActivateReadyShortcut().

◆ tryEndNativeGestureShortcut()

bool KisShortcutMatcher::tryEndNativeGestureShortcut ( QNativeGestureEvent * event)
private

Definition at line 1579 of file kis_shortcut_matcher.cpp.

1580{
1581 return tryEndGestureBasedShortcutImpl(event, &m_d->nativeGestureShortcut);
1582}
bool tryEndGestureBasedShortcutImpl(EventType *event, ShortcutType **resultShortcutPtr)

References m_d, and tryEndGestureBasedShortcutImpl().

◆ tryEndRunningShortcut()

bool KisShortcutMatcher::tryEndRunningShortcut ( Qt::MouseButton button,
QEvent * event )
private

Definition at line 1293 of file kis_shortcut_matcher.cpp.

1294{
1295 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_d->runningShortcut, true);
1296 KIS_SAFE_ASSERT_RECOVER(!m_d->readyShortcut) {
1297 // it shouldn't have happened, running and ready shortcuts
1298 // at the same time should not be possible
1300 }
1301
1302 if (m_d->runningShortcut && m_d->runningShortcut->matchBegin(button)) {
1303
1304 // first reset running shortcut to avoid infinite recursion via end()
1305 KisStrokeShortcut *runningShortcut = m_d->runningShortcut;
1306 m_d->runningShortcut = 0;
1307
1308 if (runningShortcut->action()) {
1309 DEBUG_EVENT_ACTION("Ending running shortcut at event", event);
1311 int shortcutIndex = runningShortcut->shortcutIndex();
1312
1313 // Keep keyed stroke shortcuts in ready state between repeated
1314 // button strokes while their activation keys are still held.
1315 QSet<Qt::MouseButton> buttonsAfterRelease = m_d->buttons;
1316 buttonsAfterRelease.remove(button);
1317 const bool keepReadyShortcut =
1318 !m_d->keys.isEmpty() &&
1319 runningShortcut->isAvailable(m_d->actionGroupMask()) &&
1320 runningShortcut->matchReady(m_d->keys, buttonsAfterRelease);
1321
1322 action->end(event);
1323
1324 if (keepReadyShortcut) {
1325 m_d->readyShortcut = runningShortcut;
1326 } else {
1327 action->deactivate(shortcutIndex);
1328 }
1329 }
1330 }
1331
1332 return !m_d->runningShortcut;
1333}
virtual bool isAvailable(KisInputActionGroupsMask mask) const

References KisAbstractShortcut::action, button(), KisAbstractInputAction::deactivate(), DEBUG_EVENT_ACTION, KisAbstractInputAction::end(), forceDeactivateAllActions(), KisAbstractShortcut::isAvailable(), KIS_SAFE_ASSERT_RECOVER, KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, KisStrokeShortcut::matchReady(), runningShortcut, and KisAbstractShortcut::shortcutIndex.

◆ tryEndTouchpadScrollShortcut()

bool KisShortcutMatcher::tryEndTouchpadScrollShortcut ( QWheelEvent * event)
private

Definition at line 1589 of file kis_shortcut_matcher.cpp.

1590{
1591 return tryEndGestureBasedShortcutImpl(event, &m_d->touchpadScrollShortcut);
1592}

References m_d, and tryEndGestureBasedShortcutImpl().

◆ tryEndTouchShortcut()

bool KisShortcutMatcher::tryEndTouchShortcut ( QTouchEvent * event)
private

Definition at line 1486 of file kis_shortcut_matcher.cpp.

1487{
1488 if (m_d->touchShortcut) {
1489 // first reset running shortcut to avoid infinite recursion via end()
1490 KisTouchShortcut *touchShortcut = m_d->touchShortcut;
1491
1492 DEBUG_SHORTCUT("ending", touchShortcut)
1493 touchShortcut->action()->end(event);
1494 touchShortcut->action()->deactivate(m_d->touchShortcut->shortcutIndex());
1495
1496 m_d->touchShortcut = 0; // empty it out now that we are done with it
1497
1498 return true;
1499 }
1500
1501 return false;
1502}

References KisAbstractShortcut::action, KisAbstractInputAction::deactivate(), DEBUG_SHORTCUT, KisAbstractInputAction::end(), m_d, and touchShortcut.

◆ tryFireTapTouchShortcut()

bool KisShortcutMatcher::tryFireTapTouchShortcut ( QTouchEvent * event,
Qt::TouchPointStates allowedStates )
private

Touch actions don't usually send focus events, since they have no hover functionality, so they should be triggered unrelated to the current focus state.

Definition at line 1389 of file kis_shortcut_matcher.cpp.

1390{
1396 if (m_d->actionsSuppressedIgnoreFocus())
1397 return false;
1398
1399 KisTouchShortcut *goodCandidate = matchTouchShortcut(event, allowedStates, TouchShortcutMode::Tap);
1400 if (goodCandidate) {
1401 DEBUG_SHORTCUT("Starting new touch-tap action", goodCandidate);
1402 goodCandidate->action()->activate(goodCandidate->shortcutIndex());
1403 goodCandidate->action()->begin(goodCandidate->shortcutIndex(), event);
1404
1405 goodCandidate->action()->end(event);
1406 goodCandidate->action()->deactivate(goodCandidate->shortcutIndex());
1407 }
1408
1409 return goodCandidate;
1410}
virtual void begin(int shortcut, QEvent *event)

References KisAbstractShortcut::action, KisAbstractInputAction::activate(), KisAbstractInputAction::begin(), KisAbstractInputAction::deactivate(), DEBUG_SHORTCUT, KisAbstractInputAction::end(), m_d, matchTouchShortcut(), KisAbstractShortcut::shortcutIndex, and Tap.

◆ tryRunGestureBasedShortcutImpl()

template<typename EventType , typename ShortcutType >
bool KisShortcutMatcher::tryRunGestureBasedShortcutImpl ( EventType * event,
ShortcutType ** resultShortcutPtr,
const QList< ShortcutType * > allTypedShortcuts )
private

Definition at line 1505 of file kis_shortcut_matcher.cpp.

1506{
1507 ShortcutType *goodCandidate = 0;
1508
1509 if (m_d->actionsSuppressed())
1510 return false;
1511
1512 Q_FOREACH (ShortcutType* shortcut, allTypedShortcuts) {
1513 if (shortcut->match(event) && (!goodCandidate || shortcut->priority() > goodCandidate->priority())) {
1514 goodCandidate = shortcut;
1515 }
1516 }
1517
1518 if (goodCandidate) {
1519 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(!m_d->runningShortcut, false);
1520
1521 // Because we don't match keyboard or button based actions with touch system, we have to ensure that we first
1522 // deactivate an activated readyShortcut, to not throw other statemachines out of place.
1524
1525 *resultShortcutPtr = goodCandidate;
1526
1527 Private::RecursionGuard guard(this);
1528
1529 DEBUG_SHORTCUT("starting", goodCandidate)
1530
1531 goodCandidate->action()->activate(goodCandidate->shortcutIndex());
1532 goodCandidate->action()->begin(goodCandidate->shortcutIndex(), event);
1533
1534 // the tool might have opened some dialog, which could break our event loop
1535 if (guard.brokenByRecursion()) {
1536 goodCandidate->action()->end(event);
1537 *resultShortcutPtr = 0;
1538
1540 }
1541 }
1542
1543 return bool(*resultShortcutPtr);
1544}

References DEBUG_SHORTCUT, forceDeactivateAllActions(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, and m_d.

◆ tryRunNativeGestureShortcut()

bool KisShortcutMatcher::tryRunNativeGestureShortcut ( QNativeGestureEvent * event)
private

Definition at line 1574 of file kis_shortcut_matcher.cpp.

1575{
1576 return tryRunGestureBasedShortcutImpl(event, &m_d->nativeGestureShortcut, m_d->nativeGestureShortcuts);
1577}
bool tryRunGestureBasedShortcutImpl(EventType *event, ShortcutType **resultShortcutPtr, const QList< ShortcutType * > allTypedShortcuts)

References m_d, and tryRunGestureBasedShortcutImpl().

◆ tryRunReadyShortcut()

bool KisShortcutMatcher::tryRunReadyShortcut ( Qt::MouseButton button,
QEvent * event )
private

Definition at line 1198 of file kis_shortcut_matcher.cpp.

1199{
1200 KisStrokeShortcut *goodCandidate = 0;
1201
1202 Q_FOREACH (KisStrokeShortcut *s, m_d->candidateShortcuts) {
1203 if (s->isAvailable(m_d->actionGroupMask()) &&
1204 s->matchBegin(button) &&
1205 (!goodCandidate || s->priority() > goodCandidate->priority())) {
1206
1207 goodCandidate = s;
1208 }
1209 }
1210
1211 if (goodCandidate) {
1212 if (m_d->readyShortcut) {
1213 if (m_d->readyShortcut != goodCandidate) {
1214 if (goodCandidate->action() == m_d->readyShortcut->action() &&
1215 goodCandidate->action()->trySwitchShortcut(
1216 m_d->readyShortcut->shortcutIndex(), goodCandidate->shortcutIndex())) {
1217 m_d->readyShortcut = goodCandidate;
1218 } else {
1219 m_d->readyShortcut->action()->deactivate(m_d->readyShortcut->shortcutIndex());
1220 goodCandidate->action()->activate(goodCandidate->shortcutIndex());
1221 }
1222 }
1223 m_d->readyShortcut = 0;
1224 } else {
1225 DEBUG_EVENT_ACTION("Matched *new* shortcut for event", event);
1226 goodCandidate->action()->activate(goodCandidate->shortcutIndex());
1227 }
1228
1229 DEBUG_SHORTCUT("Starting new action", goodCandidate);
1230
1231 {
1232 m_d->runningShortcut = goodCandidate;
1233 Private::RecursionGuard guard(this);
1234 goodCandidate->action()->begin(goodCandidate->shortcutIndex(), event);
1235
1236 // the tool might have opened some dialog, which could break our event loop
1237 if (guard.brokenByRecursion()) {
1238 goodCandidate->action()->end(event);
1239 m_d->runningShortcut = 0;
1240
1242 }
1243 }
1244 }
1245
1246 return m_d->runningShortcut;
1247}
bool matchBegin(Qt::MouseButton button)

References KisAbstractShortcut::action, KisAbstractInputAction::activate(), KisAbstractInputAction::begin(), button(), DEBUG_EVENT_ACTION, DEBUG_SHORTCUT, KisAbstractInputAction::end(), forceDeactivateAllActions(), KisAbstractShortcut::isAvailable(), m_d, KisStrokeShortcut::matchBegin(), KisStrokeShortcut::priority(), KisAbstractShortcut::shortcutIndex, and KisAbstractInputAction::trySwitchShortcut().

◆ tryRunSingleActionShortcutImpl()

template<typename T , typename U >
bool KisShortcutMatcher::tryRunSingleActionShortcutImpl ( T param,
U * event,
const QSet< Qt::Key > & keysState,
bool keyboard = true )
private

Definition at line 1142 of file kis_shortcut_matcher.cpp.

1143{
1144 if (m_d->actionsSuppressedIgnoreFocus() || (keyboard && m_d->KeyboardActionsSuppressed())) {
1145 DEBUG_EVENT_ACTION("Event suppressed", event)
1146 return false;
1147 }
1148
1149 KisSingleActionShortcut *goodCandidate = 0;
1150
1151 Q_FOREACH (KisSingleActionShortcut *s, m_d->singleActionShortcuts) {
1152 if (!m_d->suppressedSingleActionShortcuts.contains(s) &&
1153 s->isAvailable(m_d->actionGroupMask()) &&
1154 s->match(keysState, param) &&
1155 (!goodCandidate || s->priority() > goodCandidate->priority())) {
1156
1157 goodCandidate = s;
1158 }
1159 }
1160
1161 if (goodCandidate) {
1162 DEBUG_EVENT_ACTION("Beginning action for event", event);
1163 goodCandidate->action()->begin(goodCandidate->shortcutIndex(), event);
1164 goodCandidate->action()->end(0);
1165 } else {
1166 DEBUG_EVENT_ACTION("Could not match a candidate for event", event)
1167 }
1168
1169 return goodCandidate;
1170}
bool match(const QSet< Qt::Key > &modifiers, Qt::Key key)

References KisAbstractShortcut::action, KisAbstractInputAction::begin(), DEBUG_EVENT_ACTION, KisAbstractInputAction::end(), KisAbstractShortcut::isAvailable(), m_d, KisSingleActionShortcut::match(), KisSingleActionShortcut::priority(), and KisAbstractShortcut::shortcutIndex.

◆ tryRunTouchpadScrollShortcut()

bool KisShortcutMatcher::tryRunTouchpadScrollShortcut ( QWheelEvent * event)
private

Definition at line 1584 of file kis_shortcut_matcher.cpp.

1585{
1586 return tryRunGestureBasedShortcutImpl(event, &m_d->touchpadScrollShortcut, m_d->touchpadScrollShortcuts);
1587}

References m_d, and tryRunGestureBasedShortcutImpl().

◆ tryRunTouchShortcut()

bool KisShortcutMatcher::tryRunTouchShortcut ( QTouchEvent * event,
Qt::TouchPointStates allowedStates,
TouchShortcutMode mode )
private

Touch actions don't usually send focus events, since they have no hover functionality, so they should be triggered unrelated to the current focus state.

Definition at line 1447 of file kis_shortcut_matcher.cpp.

1448{
1449 KisTouchShortcut *goodCandidate = matchTouchShortcut(event, allowedStates, mode);
1450
1456 if (m_d->actionsSuppressedIgnoreFocus())
1457 return false;
1458
1459 if (goodCandidate) {
1460 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(!m_d->runningShortcut, false);
1461
1462 // Because we don't match keyboard or button based actions with touch system, we have to ensure that we first
1463 // deactivate an activated readyShortcut, to not throw other statemachines out of place.
1465
1466 m_d->touchShortcut = goodCandidate;
1467
1468 Private::RecursionGuard guard(this);
1469 DEBUG_SHORTCUT("Running a new touch action", goodCandidate)
1470
1471 goodCandidate->action()->activate(goodCandidate->shortcutIndex());
1472 goodCandidate->action()->begin(goodCandidate->shortcutIndex(), event);
1473
1474 // the tool might have opened some dialog, which could break our event loop
1475 if (guard.brokenByRecursion()) {
1476 goodCandidate->action()->end(event);
1477 m_d->touchShortcut = 0;
1478
1480 }
1481 }
1482
1483 return m_d->touchShortcut;
1484}

References KisAbstractShortcut::action, KisAbstractInputAction::activate(), KisAbstractInputAction::begin(), DEBUG_SHORTCUT, KisAbstractInputAction::end(), forceDeactivateAllActions(), KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_d, matchTouchShortcut(), and KisAbstractShortcut::shortcutIndex.

◆ tryRunWheelShortcut()

bool KisShortcutMatcher::tryRunWheelShortcut ( KisSingleActionShortcut::WheelAction wheelAction,
QWheelEvent * event )
private

Definition at line 1135 of file kis_shortcut_matcher.cpp.

1136{
1137 return tryRunSingleActionShortcutImpl(wheelAction, event, m_d->keys, false);
1138}

References m_d, and tryRunSingleActionShortcutImpl().

◆ wheelEvent()

bool KisShortcutMatcher::wheelEvent ( KisSingleActionShortcut::WheelAction wheelAction,
QWheelEvent * event )

Handles the mouse wheel event

Returns
whether the event has been handled successfully and should be eaten by the events filter

Definition at line 408 of file kis_shortcut_matcher.cpp.

409{
410 Private::RecursionNotifier notifier(this);
411
412
413 if (hasRunningShortcut() || notifier.isInRecursion()) {
414 DEBUG_ACTION("Wheel event canceled.");
415 return false;
416 }
417
418 return tryRunWheelShortcut(wheelAction, event);
419}
bool tryRunWheelShortcut(KisSingleActionShortcut::WheelAction wheelAction, QWheelEvent *event)

References DEBUG_ACTION, hasRunningShortcut(), and tryRunWheelShortcut().

Friends And Related Symbol Documentation

◆ KisInputManagerTest

friend class KisInputManagerTest
friend

Definition at line 315 of file kis_shortcut_matcher.h.

Member Data Documentation

◆ actionGroupMask

std::function<KisInputActionGroupsMask()> KisShortcutMatcher::actionGroupMask

Definition at line 155 of file kis_shortcut_matcher.cpp.

◆ bestCandidateForTapTouchEvent

QScopedPointer<QEvent> KisShortcutMatcher::bestCandidateForTapTouchEvent

Definition at line 137 of file kis_shortcut_matcher.cpp.

◆ brokenByRecursion

int KisShortcutMatcher::brokenByRecursion = 0

Definition at line 161 of file kis_shortcut_matcher.cpp.

◆ buttons

QSet<Qt::MouseButton> KisShortcutMatcher::buttons

Definition at line 119 of file kis_shortcut_matcher.cpp.

◆ candidateShortcuts

QList<KisStrokeShortcut*> KisShortcutMatcher::candidateShortcuts

Definition at line 125 of file kis_shortcut_matcher.cpp.

◆ cursorEntered

bool KisShortcutMatcher::cursorEntered

Definition at line 158 of file kis_shortcut_matcher.cpp.

◆ ignoreMultiFingerCancelWorkaround

std::optional<IgnoreMultiFingerCancelWorkaround> KisShortcutMatcher::ignoreMultiFingerCancelWorkaround

Definition at line 153 of file kis_shortcut_matcher.cpp.

◆ isTouchDragDetected

bool KisShortcutMatcher::isTouchDragDetected {false}

Definition at line 135 of file kis_shortcut_matcher.cpp.

135{false};

◆ isTouchHeld

bool KisShortcutMatcher::isTouchHeld {false}

Definition at line 136 of file kis_shortcut_matcher.cpp.

136{false};

◆ keys

QSet<Qt::Key> KisShortcutMatcher::keys

Definition at line 118 of file kis_shortcut_matcher.cpp.

◆ lastProcessedTouchEvent

QScopedPointer<QTouchEvent> KisShortcutMatcher::lastProcessedTouchEvent

Definition at line 138 of file kis_shortcut_matcher.cpp.

◆ m_d

Private* const KisShortcutMatcher::m_d
private

Definition at line 361 of file kis_shortcut_matcher.h.

◆ matchingIteration

int KisShortcutMatcher::matchingIteration {0}

Definition at line 134 of file kis_shortcut_matcher.cpp.

134{0};

◆ maxTouchPoints

int KisShortcutMatcher::maxTouchPoints {0}

Definition at line 133 of file kis_shortcut_matcher.cpp.

133{0};

◆ nativeGestureShortcut

KisNativeGestureShortcut* KisShortcutMatcher::nativeGestureShortcut

Definition at line 128 of file kis_shortcut_matcher.cpp.

◆ nativeGestureShortcuts

QList<KisNativeGestureShortcut*> KisShortcutMatcher::nativeGestureShortcuts

Definition at line 115 of file kis_shortcut_matcher.cpp.

◆ polledKeys

QSet<Qt::Key> KisShortcutMatcher::polledKeys

Definition at line 121 of file kis_shortcut_matcher.cpp.

◆ readyShortcut

KisStrokeShortcut* KisShortcutMatcher::readyShortcut

Definition at line 124 of file kis_shortcut_matcher.cpp.

◆ recursiveCounter

int KisShortcutMatcher::recursiveCounter = 0

Definition at line 160 of file kis_shortcut_matcher.cpp.

◆ runningShortcut

KisStrokeShortcut* KisShortcutMatcher::runningShortcut

Definition at line 123 of file kis_shortcut_matcher.cpp.

◆ singleActionShortcuts

QList<KisSingleActionShortcut*> KisShortcutMatcher::singleActionShortcuts

Definition at line 111 of file kis_shortcut_matcher.cpp.

◆ strokeShortcuts

QList<KisStrokeShortcut*> KisShortcutMatcher::strokeShortcuts

Definition at line 113 of file kis_shortcut_matcher.cpp.

◆ suppressAllActions

void KisShortcutMatcher::suppressAllActions

Definition at line 156 of file kis_shortcut_matcher.cpp.

◆ suppressAllKeyboardActions

void KisShortcutMatcher::suppressAllKeyboardActions

Definition at line 157 of file kis_shortcut_matcher.cpp.

◆ suppressedSingleActionShortcuts

QSet<KisSingleActionShortcut*> KisShortcutMatcher::suppressedSingleActionShortcuts

Definition at line 112 of file kis_shortcut_matcher.cpp.

◆ TOUCH_SLOP

constexpr qreal KisShortcutMatcher::TOUCH_SLOP = 16
staticconstexpr

Definition at line 79 of file kis_shortcut_matcher.h.

◆ TOUCH_SLOP_SQUARED

constexpr int KisShortcutMatcher::TOUCH_SLOP_SQUARED = 16 * 16
staticconstexpr

Definition at line 78 of file kis_shortcut_matcher.h.

◆ touchActionTracked

bool KisShortcutMatcher::touchActionTracked {false}

Definition at line 139 of file kis_shortcut_matcher.cpp.

139{false};

◆ touchHoldDelayMs

int KisShortcutMatcher::touchHoldDelayMs {400}

Definition at line 140 of file kis_shortcut_matcher.cpp.

140{400};

◆ touchHoldEventPostponer

std::optional<KisTouchHoldEventsPostponer> KisShortcutMatcher::touchHoldEventPostponer

Definition at line 130 of file kis_shortcut_matcher.cpp.

◆ touchpadScrollShortcut

KisTouchpadScrollShortcut* KisShortcutMatcher::touchpadScrollShortcut

Definition at line 129 of file kis_shortcut_matcher.cpp.

◆ touchpadScrollShortcuts

QList<KisTouchpadScrollShortcut*> KisShortcutMatcher::touchpadScrollShortcuts

Definition at line 116 of file kis_shortcut_matcher.cpp.

◆ touchShortcut

KisTouchShortcut* KisShortcutMatcher::touchShortcut

Definition at line 127 of file kis_shortcut_matcher.cpp.

◆ touchShortcuts

QList<KisTouchShortcut*> KisShortcutMatcher::touchShortcuts

Definition at line 114 of file kis_shortcut_matcher.cpp.


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