Krita Source Code Documentation
Loading...
Searching...
No Matches
KisInputManager::Private Class Reference

#include <kis_input_manager_p.h>

Classes

class  CanvasSwitcher
 
class  ProximityNotifier
 
class  TabletLatencyTracker
 

Public Types

typedef QList< PriorityPair > PriorityList
 
typedef QPair< int, QPointer< QObject > > PriorityPair
 

Public Member Functions

void addKeyShortcut (KisAbstractInputAction *action, int index, const QList< Qt::Key > &keys)
 
bool addNativeGestureShortcut (KisAbstractInputAction *action, int index, KisShortcutConfiguration::NativeGestureAction gesture)
 
void addStrokeShortcut (KisAbstractInputAction *action, int index, const QList< Qt::Key > &modifiers, Qt::MouseButtons buttons)
 
void addTouchShortcut (KisAbstractInputAction *action, int index, KisShortcutConfiguration::TouchGestureAction gesture, bool isTouchPainting=false)
 
void addWheelShortcut (KisAbstractInputAction *action, int index, const QList< Qt::Key > &modifiers, KisShortcutConfiguration::MouseWheelMovement wheelAction)
 
void fixShortcutMatcherModifiersState ()
 
void fixShortcutMatcherModifiersState (QVector< Qt::Key > newKeys, Qt::KeyboardModifiers modifiers)
 
bool handleCompressedTabletEvent (QEvent *event)
 
 Private (KisInputManager *qq)
 
bool processUnhandledEvent (QEvent *event)
 
void resetCompressor ()
 
void setMaskSyntheticEvents (bool value)
 
void setupActions ()
 

Public Attributes

QPoint accumulatedScrollDelta
 
QPointer< KisCanvas2 > canvas
 
CanvasSwitcher canvasSwitcher
 
QScopedPointer< QEvent > compressedMoveEvent
 
KisToolInvocationAction * defaultInputAction = 0
 
KisInputEventsEater eventEater
 
QObject * eventsReceiver = 0
 
bool forwardAllEventsToTool = false
 
KisShortcutMatcher matcher
 
KisSignalCompressor moveEventCompressor
 
bool popupWasActive = false
 
KisPopupWidgetInterface * popupWidget
 
PriorityList priorityEventFilter
 
int priorityEventFilterSeqNo
 
KisInputManager * q
 
bool shouldSynchronizeOnNextKeyPress = false
 
KisSharedPtr< TabletLatencyTracker > tabletLatencyTracker
 
bool testingAcceptCompressedTabletEvents = false
 
bool testingCompressBrushEvents = false
 
QPointer< KisToolProxy > toolProxy
 
bool useUnbalancedKeyPressEventWorkaround = false
 

Detailed Description

Definition at line 26 of file kis_input_manager_p.h.

Member Typedef Documentation

◆ PriorityList

◆ PriorityPair

typedef QPair<int, QPointer<QObject> > KisInputManager::Private::PriorityPair

Definition at line 58 of file kis_input_manager_p.h.

Constructor & Destructor Documentation

◆ Private()

KisInputManager::Private::Private ( KisInputManager * qq)

On Windows and Linux we have a proper fix for this bug patched into our local version of Qt. We don't have a fix for macOS

In Linux distributions Qt is not patched, so we should use workaround for them

Definition at line 38 of file kis_input_manager_p.cpp.

39 : q(qq)
40 , moveEventCompressor(10 /* ms */,
44 , popupWidget(nullptr)
45 , canvasSwitcher(this, qq)
46{
47 KisConfig cfg(true);
48
49 moveEventCompressor.setDelay(cfg.tabletEventsDelay());
50 testingAcceptCompressedTabletEvents = cfg.testingAcceptCompressedTabletEvents();
51 testingCompressBrushEvents = cfg.testingCompressBrushEvents();
52
53 if (cfg.trackTabletEventLatency()) {
54 tabletLatencyTracker = new TabletLatencyTracker();
55 }
56
58 [this] () {
59 return this->canvas ? this->canvas->inputActionGroupsMaskInterface()->inputActionGroupsMask() : AllActionGroup;
60 });
61
62#ifdef Q_OS_ANDROID
63 // a workaround for Xiaomi tablets
65#endif
66
72#ifdef Q_OS_MACOS
74#endif
75
80#if defined Q_OS_LINUX && !KRITA_QT_HAS_UNBALANCED_KEY_PRESS_RELEASE_PATCH
82#endif
83
84 if (qEnvironmentVariableIsSet("KRITA_FIX_UNBALANCED_KEY_EVENTS")) {
85 useUnbalancedKeyPressEventWorkaround = qEnvironmentVariableIntValue("KRITA_FIX_UNBALANCED_KEY_EVENTS");
86 }
87}
@ AllActionGroup
KisSignalCompressor moveEventCompressor
QPointer< KisCanvas2 > canvas
KisSharedPtr< TabletLatencyTracker > tabletLatencyTracker
KisPopupWidgetInterface * popupWidget
void setInputActionGroupsMaskCallback(std::function< KisInputActionGroupsMask()> func)
void setIgnoreMultiFingerCancelWorkaroundEnalbed(bool value)
void setDelay(std::function< bool()> idleCallback, int idleDelay, int timeout)

References AllActionGroup, canvas, matcher, moveEventCompressor, KisSignalCompressor::setDelay(), KisShortcutMatcher::setIgnoreMultiFingerCancelWorkaroundEnalbed(), KisShortcutMatcher::setInputActionGroupsMaskCallback(), KisConfig::tabletEventsDelay(), tabletLatencyTracker, testingAcceptCompressedTabletEvents, KisConfig::testingAcceptCompressedTabletEvents(), testingCompressBrushEvents, KisConfig::testingCompressBrushEvents(), KisConfig::trackTabletEventLatency(), and useUnbalancedKeyPressEventWorkaround.

Member Function Documentation

◆ addKeyShortcut()

void KisInputManager::Private::addKeyShortcut ( KisAbstractInputAction * action,
int index,
const QList< Qt::Key > & keys )

Definition at line 339 of file kis_input_manager_p.cpp.

341{
342 if (keys.size() == 0) return;
343
344 KisSingleActionShortcut *keyShortcut =
345 new KisSingleActionShortcut(action, index);
346
347 //Note: Ordering is important here, Shift + V is different from V + Shift,
348 //which is the reason we use the last key here since most users will enter
349 //shortcuts as "Shift + V". Ideally this should not happen, but this is
350 //the way the shortcut matcher is currently implemented.
351 QList<Qt::Key> allKeys = keys;
352 Qt::Key key = allKeys.takeLast();
353 QSet<Qt::Key> modifiers = QSet<Qt::Key>(allKeys.begin(), allKeys.end());
354 keyShortcut->setKey(modifiers, key);
355 matcher.addShortcut(keyShortcut);
356}
void addShortcut(KisSingleActionShortcut *shortcut)
void setKey(const QSet< Qt::Key > &modifiers, Qt::Key key)

References KisShortcutMatcher::addShortcut(), matcher, and KisSingleActionShortcut::setKey().

◆ addNativeGestureShortcut()

bool KisInputManager::Private::addNativeGestureShortcut ( KisAbstractInputAction * action,
int index,
KisShortcutConfiguration::NativeGestureAction gesture )

Definition at line 430 of file kis_input_manager_p.cpp.

431{
432 auto addNativeGesture = [&] (KisNativeGestureShortcut::Type type) {
433 KisNativeGestureShortcut *shortcut = new KisNativeGestureShortcut(action, index, type);
434 matcher.addShortcut(shortcut);
435 };
436
437 // Native gestures:
438 // Qt5 only implements QNativeGestureEvent for macOS
439 // Qt6 implements QNativeGestureEvent for macOS and Wayland
440 //
441 // Touchpad pixel scrolling:
442 // Qt5 only implements touchpad pixel scrolling for macOS
443 // Qt6 implements touchpad pixel scrolling for macOS and Wayland
444
445 switch (gesture) {
448 break;
451 break;
454 break;
455 default:
456 return false;
457 }
458
459 return true;
460}
@ TouchpadScroll
Two-dimensional pixel scrolling on a touchpad, supported on MacOS and Wayland only.
@ SmartZoomGesture
Smart zoom gesture, typically a double tap that is a boolean zoom/unzoom.
@ PinchGesture
Pinch gesture, a two finger gesture used for navigating the canvas.

References KisShortcutMatcher::addShortcut(), matcher, KisShortcutConfiguration::PinchGesture, KisNativeGestureShortcut::PinchNavigation, KisShortcutConfiguration::SmartZoomGesture, KisNativeGestureShortcut::SmartZoomNativeGesture, and KisShortcutConfiguration::TouchpadScroll.

◆ addStrokeShortcut()

void KisInputManager::Private::addStrokeShortcut ( KisAbstractInputAction * action,
int index,
const QList< Qt::Key > & modifiers,
Qt::MouseButtons buttons )

Definition at line 310 of file kis_input_manager_p.cpp.

313{
314 KisStrokeShortcut *strokeShortcut =
315 new KisStrokeShortcut(action, index);
316
317 QSet<Qt::MouseButton> buttonSet;
318 if(buttons & Qt::LeftButton) {
319 buttonSet << Qt::LeftButton;
320 }
321 if(buttons & Qt::RightButton) {
322 buttonSet << Qt::RightButton;
323 }
324 if(buttons & Qt::MiddleButton) {
325 buttonSet << Qt::MiddleButton;
326 }
327
328BOOST_PP_REPEAT_FROM_TO(1, 25, EXTRA_BUTTON, _)
329
330 if (!buttonSet.empty()) {
331 strokeShortcut->setButtons(QSet<Qt::Key>(modifiers.cbegin(), modifiers.cend()), buttonSet);
332 matcher.addShortcut(strokeShortcut);
333 }
334 else {
335 delete strokeShortcut;
336 }
337}
void setButtons(const QSet< Qt::Key > &modifiers, const QSet< Qt::MouseButton > &buttons)
#define EXTRA_BUTTON(z, n, _)
QString buttons(const T &ev)

References KisShortcutMatcher::addShortcut(), buttons(), EXTRA_BUTTON, matcher, and KisStrokeShortcut::setButtons().

◆ addTouchShortcut()

void KisInputManager::Private::addTouchShortcut ( KisAbstractInputAction * action,
int index,
KisShortcutConfiguration::TouchGestureAction gesture,
bool isTouchPainting = false )

Definition at line 390 of file kis_input_manager_p.cpp.

391{
392 KisTouchShortcut *shortcut = new KisTouchShortcut(action, index, gesture);
393 if (isTouchPainting) {
394 shortcut->setIsTouchPainting(true);
395 shortcut->setMinDragThreshold(1.5); // min threshold for touch painting is 1.5 px
396 }
397 dbgKrita << "TouchAction:" << action->name() << (isTouchPainting ? "touch-painting" : "");
398 switch(gesture) {
402 shortcut->setMinimumTouchPoints(1);
403 shortcut->setMaximumTouchPoints(1);
404 break;
407 shortcut->setMinimumTouchPoints(2);
408 shortcut->setMaximumTouchPoints(2);
409 break;
412 shortcut->setMinimumTouchPoints(3);
413 shortcut->setMaximumTouchPoints(3);
414 break;
417 shortcut->setMinimumTouchPoints(4);
418 shortcut->setMaximumTouchPoints(4);
419 break;
422 shortcut->setMinimumTouchPoints(5);
423 shortcut->setMaximumTouchPoints(5);
424 default:
425 break;
426 }
427 matcher.addShortcut(shortcut);
428}
The KisTouchShortcut class only handles touch gestures it does not handle tool invocation i....
void setIsTouchPainting(bool value)
void setMinDragThreshold(qreal value)
void setMaximumTouchPoints(int max)
void setMinimumTouchPoints(int min)
#define dbgKrita
Definition kis_debug.h:49

References KisShortcutMatcher::addShortcut(), dbgKrita, KisShortcutConfiguration::FiveFingerDrag, KisShortcutConfiguration::FiveFingerTap, KisShortcutConfiguration::FourFingerDrag, KisShortcutConfiguration::FourFingerTap, matcher, KisAbstractInputAction::name, KisShortcutConfiguration::OneFingerDrag, KisShortcutConfiguration::OneFingerHold, KisShortcutConfiguration::OneFingerTap, KisTouchShortcut::setIsTouchPainting(), KisTouchShortcut::setMaximumTouchPoints(), KisTouchShortcut::setMinDragThreshold(), KisTouchShortcut::setMinimumTouchPoints(), KisShortcutConfiguration::ThreeFingerDrag, KisShortcutConfiguration::ThreeFingerTap, KisShortcutConfiguration::TwoFingerDrag, and KisShortcutConfiguration::TwoFingerTap.

◆ addWheelShortcut()

void KisInputManager::Private::addWheelShortcut ( KisAbstractInputAction * action,
int index,
const QList< Qt::Key > & modifiers,
KisShortcutConfiguration::MouseWheelMovement wheelAction )

Definition at line 358 of file kis_input_manager_p.cpp.

361{
362
363
364 auto addSingleActionShortcut = [&] (KisSingleActionShortcut::WheelAction a) {
365 std::unique_ptr<KisSingleActionShortcut> keyShortcut(
366 new KisSingleActionShortcut(action, index));
367 keyShortcut->setWheel(QSet<Qt::Key>(modifiers.begin(), modifiers.end()), a);
368 matcher.addShortcut(keyShortcut.release());
369 };
370
371 switch(wheelAction) {
373 addSingleActionShortcut(KisSingleActionShortcut::WheelUp);
374 break;
376 addSingleActionShortcut(KisSingleActionShortcut::WheelDown);
377 break;
379 addSingleActionShortcut(KisSingleActionShortcut::WheelLeft);
380 break;
382 addSingleActionShortcut(KisSingleActionShortcut::WheelRight);
383 break;
386 break;
387 }
388}
@ WheelDown
Downwards movement, toward the user.
@ WheelUp
Upwards movement, away from the user.
@ WheelReserved_0
Do not use! Previously was used for TouchpadScroll shortcut.
@ WheelDown
Mouse wheel moves down.
@ WheelRight
Mouse wheel moves right.
@ WheelLeft
Mouse wheel moves left.

References KisShortcutMatcher::addShortcut(), matcher, KisShortcutConfiguration::NoMovement, KisShortcutConfiguration::WheelDown, KisSingleActionShortcut::WheelDown, KisShortcutConfiguration::WheelLeft, KisSingleActionShortcut::WheelLeft, KisShortcutConfiguration::WheelReserved_0, KisShortcutConfiguration::WheelRight, KisSingleActionShortcut::WheelRight, KisShortcutConfiguration::WheelUp, and KisSingleActionShortcut::WheelUp.

◆ fixShortcutMatcherModifiersState() [1/2]

void KisInputManager::Private::fixShortcutMatcherModifiersState ( )

Definition at line 513 of file kis_input_manager_p.cpp.

514{
516
517 QVector<Qt::Key> newKeys;
518 Qt::KeyboardModifiers modifiers = mapper.queryStandardModifiers();
519 Q_FOREACH (Qt::Key key, mapper.queryExtendedModifiers()) {
520 QKeyEvent kevent(QEvent::ShortcutOverride, key, modifiers);
522 }
523
524 fixShortcutMatcherModifiersState(newKeys, modifiers);
525}
static Qt::Key workaroundShiftAltMetaHell(const QKeyEvent *keyEvent)

References fixShortcutMatcherModifiersState(), KisExtendedModifiersMapper::queryExtendedModifiers(), KisExtendedModifiersMapper::queryStandardModifiers(), and KisExtendedModifiersMapper::workaroundShiftAltMetaHell().

◆ fixShortcutMatcherModifiersState() [2/2]

void KisInputManager::Private::fixShortcutMatcherModifiersState ( QVector< Qt::Key > newKeys,
Qt::KeyboardModifiers modifiers )

This function may be called from slotConfigChanged() from the constructor of KisInputManager. It may theoretically happen that we haven't recieved any sensible events to set up the link to the input manager.

Definition at line 527 of file kis_input_manager_p.cpp.

528{
530
531 matcher.handlePolledKeys(newKeys);
532
533 for (auto it = danglingKeys.begin(); it != danglingKeys.end();) {
534 if (newKeys.contains(*it)) {
535 newKeys.removeOne(*it);
536 it = danglingKeys.erase(it);
537 } else {
538 ++it;
539 }
540 }
541
549
550 Q_FOREACH (Qt::Key key, danglingKeys) {
551 QKeyEvent kevent(QEvent::KeyRelease, key, modifiers);
552 processUnhandledEvent(&kevent);
553 }
554
555 Q_FOREACH (Qt::Key key, newKeys) {
556 // just replay the whole sequence
557 {
558 QKeyEvent kevent(QEvent::ShortcutOverride, key, modifiers);
559 processUnhandledEvent(&kevent);
560 }
561 {
562 QKeyEvent kevent(QEvent::KeyPress, key, modifiers);
563 processUnhandledEvent(&kevent);
564 }
565 }
566}
static void setInputManager(KisInputManager *manager)
bool processUnhandledEvent(QEvent *event)
QVector< Qt::Key > debugPressedKeys() const
void handlePolledKeys(const QVector< Qt::Key > &keys)

References KisShortcutMatcher::debugPressedKeys(), KisShortcutMatcher::handlePolledKeys(), matcher, processUnhandledEvent(), q, and KisAbstractInputAction::setInputManager().

◆ handleCompressedTabletEvent()

bool KisInputManager::Private::handleCompressedTabletEvent ( QEvent * event)

Definition at line 500 of file kis_input_manager_p.cpp.

501{
502 bool retval = false;
503
504 if (!matcher.pointerMoved(event) && toolProxy) {
505 toolProxy->forwardHoverEvent(event);
506 }
507 retval = true;
508 event->setAccepted(true);
509
510 return retval;
511}
QPointer< KisToolProxy > toolProxy
bool pointerMoved(QEvent *event)

References matcher, KisShortcutMatcher::pointerMoved(), and toolProxy.

◆ processUnhandledEvent()

bool KisInputManager::Private::processUnhandledEvent ( QEvent * event)

Definition at line 480 of file kis_input_manager_p.cpp.

481{
482 bool retval = false;
483
485 event->type() == QEvent::KeyPress ||
486 event->type() == QEvent::KeyRelease) {
487
489 retval = true;
490 }
491
492 return retval && !forwardAllEventsToTool;
493}
KisToolInvocationAction * defaultInputAction

References defaultInputAction, forwardAllEventsToTool, and KisToolInvocationAction::processUnhandledEvent().

◆ resetCompressor()

void KisInputManager::Private::resetCompressor ( )

◆ setMaskSyntheticEvents()

void KisInputManager::Private::setMaskSyntheticEvents ( bool value)

Definition at line 32 of file kis_input_manager_p.cpp.

33{
34 Q_UNUSED(value)
35 // TODO: remove
36}
float value(const T *src, size_t ch)

References value().

◆ setupActions()

void KisInputManager::Private::setupActions ( )

Definition at line 462 of file kis_input_manager_p.cpp.

463{
465 Q_FOREACH (KisAbstractInputAction *action, actions) {
466 KisToolInvocationAction *toolAction =
467 dynamic_cast<KisToolInvocationAction*>(action);
468
469 if(toolAction) {
470 defaultInputAction = toolAction;
471 }
472 }
473
474 connect(KisInputProfileManager::instance(), SIGNAL(currentProfileChanged()), q, SLOT(profileChanged()));
475 if(KisInputProfileManager::instance()->currentProfile()) {
476 q->profileChanged();
477 }
478}
Abstract base class for input actions.
QList< KisAbstractInputAction * > actions
static KisInputProfileManager * instance()
Tool Invocation action of KisAbstractInputAction.

References KisInputProfileManager::actions, defaultInputAction, KisInputProfileManager::instance(), KisInputManager::profileChanged(), and q.

Member Data Documentation

◆ accumulatedScrollDelta

QPoint KisInputManager::Private::accumulatedScrollDelta

Definition at line 104 of file kis_input_manager_p.h.

◆ canvas

QPointer<KisCanvas2> KisInputManager::Private::canvas

Definition at line 43 of file kis_input_manager_p.h.

◆ canvasSwitcher

CanvasSwitcher KisInputManager::Private::canvasSwitcher

Definition at line 100 of file kis_input_manager_p.h.

◆ compressedMoveEvent

QScopedPointer<QEvent> KisInputManager::Private::compressedMoveEvent

Definition at line 54 of file kis_input_manager_p.h.

◆ defaultInputAction

KisToolInvocationAction* KisInputManager::Private::defaultInputAction = 0

Definition at line 50 of file kis_input_manager_p.h.

◆ eventEater

KisInputEventsEater KisInputManager::Private::eventEater

Definition at line 102 of file kis_input_manager_p.h.

◆ eventsReceiver

QObject* KisInputManager::Private::eventsReceiver = 0

Definition at line 52 of file kis_input_manager_p.h.

◆ forwardAllEventsToTool

bool KisInputManager::Private::forwardAllEventsToTool = false

Definition at line 46 of file kis_input_manager_p.h.

◆ matcher

KisShortcutMatcher KisInputManager::Private::matcher

Definition at line 48 of file kis_input_manager_p.h.

◆ moveEventCompressor

KisSignalCompressor KisInputManager::Private::moveEventCompressor

Definition at line 53 of file kis_input_manager_p.h.

◆ popupWasActive

bool KisInputManager::Private::popupWasActive = false

Definition at line 63 of file kis_input_manager_p.h.

◆ popupWidget

KisPopupWidgetInterface* KisInputManager::Private::popupWidget

Definition at line 68 of file kis_input_manager_p.h.

◆ priorityEventFilter

PriorityList KisInputManager::Private::priorityEventFilter

Definition at line 60 of file kis_input_manager_p.h.

◆ priorityEventFilterSeqNo

int KisInputManager::Private::priorityEventFilterSeqNo

Definition at line 61 of file kis_input_manager_p.h.

◆ q

KisInputManager* KisInputManager::Private::q

Definition at line 41 of file kis_input_manager_p.h.

◆ shouldSynchronizeOnNextKeyPress

bool KisInputManager::Private::shouldSynchronizeOnNextKeyPress = false

Definition at line 66 of file kis_input_manager_p.h.

◆ tabletLatencyTracker

KisSharedPtr<TabletLatencyTracker> KisInputManager::Private::tabletLatencyTracker

Definition at line 112 of file kis_input_manager_p.h.

◆ testingAcceptCompressedTabletEvents

bool KisInputManager::Private::testingAcceptCompressedTabletEvents = false

Definition at line 55 of file kis_input_manager_p.h.

◆ testingCompressBrushEvents

bool KisInputManager::Private::testingCompressBrushEvents = false

Definition at line 56 of file kis_input_manager_p.h.

◆ toolProxy

QPointer<KisToolProxy> KisInputManager::Private::toolProxy

Definition at line 44 of file kis_input_manager_p.h.

◆ useUnbalancedKeyPressEventWorkaround

bool KisInputManager::Private::useUnbalancedKeyPressEventWorkaround = false

Definition at line 65 of file kis_input_manager_p.h.


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