Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix compilation on Android
Dmitry Kazakova95c5dd03543
diff --git a/libs/ui/input/kis_input_manager.cpp b/libs/ui/input/kis_input_manager.cppindex 567649cad1..829e09febd 100644--- a/libs/ui/input/kis_input_manager.cpp+++ b/libs/ui/input/kis_input_manager.cpp@@ -714,28 +714,12 @@ bool KisInputManager::eventFilterImpl(QEvent * event)}case QEvent::TouchCancel:{- // On some Android devices, such as Xiaomi Pads, the system always eats- // multitouch inputs with more than two fingers, even if the user- // disables all gestures related to them in their system settings or- // uses the game boost mode that is supposed to disable gestures. So we- // handle those inputs even when they are cancelled, if the user wants- // to use it for a system gesture, they can disable the Krita shortcut.-#ifdef Q_OS_ANDROID- bool ignoreCancel = d->lastPointCount > 2;-#else- bool ignoreCancel = false;-#endif-if (d->popupWasActive) {event->setAccepted(true);return true;}QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);- if (ignoreCancel) {- d->matcher.touchEndEvent(touchEvent);- } else {- d->matcher.touchCancelEvent(touchEvent);- }+ d->matcher.touchCancelEvent(touchEvent);retval = true;diff --git a/libs/ui/input/kis_input_manager_p.cpp b/libs/ui/input/kis_input_manager_p.cppindex cb77f9c34a..24be8e340e 100644--- a/libs/ui/input/kis_input_manager_p.cpp+++ b/libs/ui/input/kis_input_manager_p.cpp@@ -58,6 +58,11 @@ KisInputManager::Private::Private(KisInputManager *qq)return this->canvas ? this->canvas->inputActionGroupsMaskInterface()->inputActionGroupsMask() : AllActionGroup;});+#ifdef Q_OS_ANDROID+ // a workaround for Xiaomi tablets+ matcher.setIgnoreMultiFingerCancelWorkaroundEnalbed(true);+#endif+/*** On Windows and Linux we have a proper fix for this bug* patched into our local version of Qt. We don't have a fixdiff --git a/libs/ui/input/kis_shortcut_matcher.cpp b/libs/ui/input/kis_shortcut_matcher.cppindex b852ba4f92..d2327cf48a 100644--- a/libs/ui/input/kis_shortcut_matcher.cpp+++ b/libs/ui/input/kis_shortcut_matcher.cpp@@ -133,6 +133,19 @@ public:bool touchActionTracked {false};int touchHoldDelayMs {400};++ // A workaround for some Android systems, which force-cancel all the+ // actions with 3+ fingers. This workaround just converts the "cancel"+ // into "end" event, letting Krita handle these events as "tap" events.+ struct IgnoreMultiFingerCancelWorkaround {+ // NOTE: we cannot reuse maxTouchPoints for this workaround, because+ // maxTouchPoints is used at the lower stages of the touch processing+ // pipeline, **after** the touch events left the hold-postponer. And+ // we need this workaround to cancel the postponer itself.+ int lastRawTouchPointsCount = 0;+ };+ std::optional<IgnoreMultiFingerCancelWorkaround> ignoreMultiFingerCancelWorkaround;+std::function<KisInputActionGroupsMask()> actionGroupMask;bool suppressAllActions;bool suppressAllKeyboardActions;@@ -461,7 +474,10 @@ bool KisShortcutMatcher::touchBeginEvent( QTouchEvent* event )#endif// reset state- m_d->maxTouchPoints = event->touchPoints().size();+ m_d->maxTouchPoints = KisTouchShortcut::countTouchPoints(event, KisTouchShortcut::pressedOnlyTouchStates());+ if (m_d->ignoreMultiFingerCancelWorkaround) {+ m_d->ignoreMultiFingerCancelWorkaround->lastRawTouchPointsCount = m_d->maxTouchPoints;+ }m_d->matchingIteration = 1;m_d->isTouchDragDetected = false;m_d->isTouchHeld = false;@@ -497,6 +513,11 @@ bool KisShortcutMatcher::touchUpdateEvent(QTouchEvent *event)// consume and ignore it.if (!m_d->touchActionTracked) return false;+ if (m_d->ignoreMultiFingerCancelWorkaround) {+ m_d->ignoreMultiFingerCancelWorkaround->lastRawTouchPointsCount =+ KisTouchShortcut::countTouchPoints(event, KisTouchShortcut::pressedOnlyTouchStates());+ }+if (m_d->touchHoldEventPostponer) {m_d->touchHoldEventPostponer->pushThrough(event);if (m_d->touchHoldEventPostponer->state() == KisTouchHoldEventsPostponer::HoldCancelled) {@@ -738,8 +759,34 @@ void KisShortcutMatcher::touchCancelEvent(QTouchEvent *event){Q_UNUSED(event)+ // The design requirement of touch-cancel handling is the following:+ //+ // 1) If drag-action has already been started, it is finished normally+ // 2) If tap-action is pending, it is cancelled+ // 3) If hold-action is pending, it is cancelled+ // 4) If hold-action has already been started, it is ended normally++ // On some Android devices, such as Xiaomi Pads, the system always eats+ // multitouch inputs with more than two fingers, even if the user+ // disables all gestures related to them in their system settings or+ // uses the game boost mode that is supposed to disable gestures. So we+ // handle those inputs even when they are cancelled, if the user wants+ // to use it for a system gesture, they can disable the Krita shortcut.+ if (m_d->ignoreMultiFingerCancelWorkaround) {+ // NOTE: we cannot use the number of touch points from the actual+ // cancel event, since Qt sets touch points as empty for the cancel+ // event+ if (m_d->ignoreMultiFingerCancelWorkaround->lastRawTouchPointsCount >= 3) {+ DEBUG_ACTION("IgnoreMultiFingerCancelWorkaround: converting a cancelled action into a normally finished action")+ touchEndEvent(event);+ return;+ }+ }+Private::RecursionNotifier notifier(this);+ DEBUG_TOUCH_ACTION("enter", event);+// the touch action has been overridden by some tablet action,// consume and ignore it.if (!m_d->touchActionTracked) {@@ -1422,4 +1469,18 @@ int KisShortcutMatcher::touchHoldDelay() constvoid KisShortcutMatcher::setTouchHoldDelay(int value){m_d->touchHoldDelayMs = value;+}++void KisShortcutMatcher::setIgnoreMultiFingerCancelWorkaroundEnalbed(bool value)+{+ if (value) {+ m_d->ignoreMultiFingerCancelWorkaround = Private::IgnoreMultiFingerCancelWorkaround();+ } else {+ m_d->ignoreMultiFingerCancelWorkaround = std::nullopt;+ }+}++bool KisShortcutMatcher::ignoreMultiFingerCancelWorkaroundEnalbed() const+{+ return m_d->ignoreMultiFingerCancelWorkaround.has_value();}\ No newline at end of filediff --git a/libs/ui/input/kis_shortcut_matcher.h b/libs/ui/input/kis_shortcut_matcher.hindex 1ed4842740..3a464521db 100644--- a/libs/ui/input/kis_shortcut_matcher.h+++ b/libs/ui/input/kis_shortcut_matcher.h@@ -291,6 +291,18 @@ public:*/void setTouchHoldDelay(int 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.+ */+ void setIgnoreMultiFingerCancelWorkaroundEnalbed(bool value);++ /**+ * \see setIgnoreMultiFingerCancelWorkaroundEnalbed()+ */+ bool ignoreMultiFingerCancelWorkaroundEnalbed() const;+private:friend class KisInputManagerTest;diff --git a/libs/ui/tests/kis_input_manager_test.cpp b/libs/ui/tests/kis_input_manager_test.cppindex 2b0a48aeff..c000c83d00 100644--- a/libs/ui/tests/kis_input_manager_test.cpp+++ b/libs/ui/tests/kis_input_manager_test.cpp@@ -860,6 +860,7 @@ void KisInputManagerTest::testTouchMoves_data()QTest::addColumn<QPointF>("pointOffset");QTest::addColumn<bool>("enableTouchPainting");QTest::addColumn<bool>("enableHoldShortcuts");+ QTest::addColumn<bool>("cancelShortcut");QTest::addColumn<QList<int>>("triggeredTouchShortcuts");QTest::addColumn<QList<int>>("triggeredPaintShortcuts");QTest::addColumn<int>("actionEventsCount"); // `-1` to ignore this test@@ -872,6 +873,8 @@ void KisInputManagerTest::testTouchMoves_data()const bool touchPaintingOn = true;const bool touchPaintingOff = false;+ const bool cancelShortcutOn = true;+ const bool cancelShortcutOff = false;const int ignoreActionEventCount = -1;const int ignorePaintEventCount = -1;@@ -880,53 +883,53 @@ void KisInputManagerTest::testTouchMoves_data()const char *holdPrefix = enableHoldShortcuts ? "hold_enabled-" : "";- QTest::addRow("%sclean-1p-drag", holdPrefix) << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{15} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-2p-drag", holdPrefix) << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-3p-drag", holdPrefix) << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-1p-drag", holdPrefix) << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{15} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-2p-drag", holdPrefix) << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-3p-drag", holdPrefix) << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-1p-drag-paint", holdPrefix) << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOn << enableHoldShortcuts << QList<int>{} << QList<int>{30} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-2p-drag-paint", holdPrefix) << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOn << enableHoldShortcuts << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-3p-drag-paint", holdPrefix) << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOn << enableHoldShortcuts << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-1p-drag-paint", holdPrefix) << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{} << QList<int>{30} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-2p-drag-paint", holdPrefix) << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-3p-drag-paint", holdPrefix) << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// painting skips only the first two events- QTest::addRow("%sclean-1p-drag-paint-delayed-start", holdPrefix) << "touchCleanDrag" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOn << enableHoldShortcuts << QList<int>{} << QList<int>{30} << ignoreActionEventCount << 98;+ QTest::addRow("%sclean-1p-drag-paint-delayed-start", holdPrefix) << "touchCleanDrag" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{} << QList<int>{30} << ignoreActionEventCount << 98;// action has higher threshold, so it skips the first 17 events- QTest::addRow("%sclean-1p-drag-delayed-start", holdPrefix) << "touchCleanDrag" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOff << enableHoldShortcuts << QList<int>{15} << QList<int>{} << 83 << ignorePaintEventCount;+ QTest::addRow("%sclean-1p-drag-delayed-start", holdPrefix) << "touchCleanDrag" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{15} << QList<int>{} << 83 << ignorePaintEventCount;- QTest::addRow("%sclean-1p-tap", holdPrefix) << "touchCleanDrag" << 1 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{20} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-2p-tap", holdPrefix) << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-3p-tap", holdPrefix) << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-1p-tap", holdPrefix) << "touchCleanDrag" << 1 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{20} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-2p-tap", holdPrefix) << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-3p-tap", holdPrefix) << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// touch painting stroke has a lower drag threshold, so we should use smaller offset value for it- QTest::addRow("%sclean-1p-tap-paint", holdPrefix) << "touchCleanDrag" << 1 << 10 << smallTapOffset << touchPaintingOn << enableHoldShortcuts << QList<int>{} << QList<int>{31} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-2p-tap-paint", holdPrefix) << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOn << enableHoldShortcuts << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-3p-tap-paint", holdPrefix) << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOn << enableHoldShortcuts << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-1p-tap-paint", holdPrefix) << "touchCleanDrag" << 1 << 10 << smallTapOffset << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{} << QList<int>{31} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-2p-tap-paint", holdPrefix) << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-3p-tap-paint", holdPrefix) << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// 16px is the threshold for distinguishing taps and drags (touch-begin + 16 steps + touch-end)- QTest::addRow("%sclean-1p-tap-upper-bound", holdPrefix) << "touchCleanDrag" << 1 << 18 << QPointF(1, 0) << touchPaintingOff << enableHoldShortcuts << QList<int>{20} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sclean-1p-drag-lower-bound", holdPrefix) << "touchCleanDrag" << 1 << 19 << QPointF(1, 0) << touchPaintingOff << enableHoldShortcuts << QList<int>{15} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-1p-tap-upper-bound", holdPrefix) << "touchCleanDrag" << 1 << 18 << QPointF(1, 0) << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{20} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-1p-drag-lower-bound", holdPrefix) << "touchCleanDrag" << 1 << 19 << QPointF(1, 0) << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{15} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sdirty-start-2p-drag", holdPrefix) << "touchDragDirtyStart" << 2 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sdirty-start-3p-drag", holdPrefix) << "touchDragDirtyStart" << 3 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sdirty-start-2p-drag", holdPrefix) << "touchDragDirtyStart" << 2 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sdirty-start-3p-drag", holdPrefix) << "touchDragDirtyStart" << 3 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sdirty-end-2p-drag", holdPrefix) << "touchDragDirtyEnd" << 2 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sdirty-end-3p-drag", holdPrefix) << "touchDragDirtyEnd" << 3 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sdirty-end-2p-drag", holdPrefix) << "touchDragDirtyEnd" << 2 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sdirty-end-3p-drag", holdPrefix) << "touchDragDirtyEnd" << 3 << 100 << dirtyDragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sdirty-end-2p-tap", holdPrefix) << "touchDragDirtyEnd" << 2 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("%sdirty-end-3p-tap", holdPrefix) << "touchDragDirtyEnd" << 3 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sdirty-end-2p-tap", holdPrefix) << "touchDragDirtyEnd" << 2 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sdirty-end-3p-tap", holdPrefix) << "touchDragDirtyEnd" << 3 << 10 << tapOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// the current implementation is expected to switch to a "more-fingers-rich" shortcut immetiately- QTest::addRow("%sclean-2p-then-3p-drag", holdPrefix) << "touchDragTwoThenThree" << 2 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{16, 17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-2p-then-3p-drag", holdPrefix) << "touchDragTwoThenThree" << 2 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{16, 17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// the current implementation is expected to stay on the "finger-richest" shortcut and,// not to switch to a "finger-poorer" shortcut- QTest::addRow("%sclean-3p-then-2p-drag", holdPrefix) << "touchDragThreeThenTwo" << 3 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-3p-then-2p-drag", holdPrefix) << "touchDragThreeThenTwo" << 3 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// the 3-point gesture should be run twice during the same run- QTest::addRow("%sclean-3p-then-2p-then-3p-drag", holdPrefix) << "touchDragThreeThenTwoThenThree" << 3 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << QList<int>{17, 17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("%sclean-3p-then-2p-then-3p-drag", holdPrefix) << "touchDragThreeThenTwoThenThree" << 3 << 100 << dragOffset << touchPaintingOff << enableHoldShortcuts << cancelShortcutOff << QList<int>{17, 17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// the amount of paint events should **not** depend on whether we have hold enabled or not- QTest::addRow("%sclean-1p-drag-paint-very-short", holdPrefix) << "touchCleanDrag" << 1 << 15 << QPointF(1.0, 0) << touchPaintingOn << enableHoldShortcuts << QList<int>{} << QList<int>{30} << ignoreActionEventCount << 13;+ QTest::addRow("%sclean-1p-drag-paint-very-short", holdPrefix) << "touchCleanDrag" << 1 << 15 << QPointF(1.0, 0) << touchPaintingOn << enableHoldShortcuts << cancelShortcutOff << QList<int>{} << QList<int>{30} << ignoreActionEventCount << 13;// clang-format on}@@ -934,8 +937,36 @@ void KisInputManagerTest::testTouchMoves_data()// clang-format offconst bool holdShortcutsOn = true;+ const bool holdShortcutsOff = false;- QTest::addRow("hold-drag-1p") << "touchHoldFirstFourUpdateEventsFor50ms" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOn << holdShortcutsOn << QList<int>{40} << QList<int>{} << 97 << ignorePaintEventCount;+ QTest::addRow("hold-drag-1p") << "touchHoldFirstFourUpdateEventsFor50ms" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOn << holdShortcutsOn << cancelShortcutOff<< QList<int>{40} << QList<int>{} << 97 << ignorePaintEventCount;++ /// the cancellation test cases++ // normal ending shortcuts, i.e. the last event is "TouchEnd"+ QTest::addRow("normal_ending-clean-2p-drag-hold-off") << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOff << holdShortcutsOff << cancelShortcutOff << QList<int>{16} << QList<int>{} << 98 << ignorePaintEventCount;+ QTest::addRow("normal_ending-clean-2p-tap-hold-off") << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOff << holdShortcutsOff << cancelShortcutOff << QList<int>{21} << QList<int>{} << 2 << ignorePaintEventCount;+ QTest::addRow("normal_ending-clean-3p-tap-hold-off") << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOff << holdShortcutsOff << cancelShortcutOff <<QList<int>{22} << QList<int>{} << 2 << ignorePaintEventCount;+ // hold timeout was not reached, so the touch-paiting-tap shortcut is triggered instead+ QTest::addRow("normal_ending-hold-drag-1p-before-delay") << "touchHoldFirstFourUpdateEventsFor50ms" << 1 << 3 << QPointF(1.0, 0) << touchPaintingOn << holdShortcutsOn << cancelShortcutOff << QList<int>{} << QList<int>{31} << ignoreActionEventCount << 2;+ QTest::addRow("normal_ending-hold-drag-1p-after-delay") << "touchHoldFirstFourUpdateEventsFor50ms" << 1 << 6 << QPointF(1.0, 0) << touchPaintingOn << holdShortcutsOn << cancelShortcutOff <<QList<int>{40} << QList<int>{} << 3 << ignorePaintEventCount;++ // cancelled shortcuts+ // the drag shortcut is ended normally+ QTest::addRow("cancelled-clean-2p-drag-hold-off") << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOff << holdShortcutsOff << cancelShortcutOn << QList<int>{16} << QList<int>{} << 98 << ignorePaintEventCount;+ // tap shortcut is cancelled+ QTest::addRow("cancelled-clean-2p-tap-hold-off") << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOff << holdShortcutsOff << cancelShortcutOn <<QList<int>{} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ // hold shortcut didn't have time to start, so it is completely cancelled, no touch-painting stroke is started+ QTest::addRow("cancelled-hold-drag-1p-before-delay") << "touchHoldFirstFourUpdateEventsFor50ms" << 1 << 3 << QPointF(1.0, 0) << touchPaintingOn << holdShortcutsOn << cancelShortcutOn << QList<int>{} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ // hold shortcut has already started, so just end it gracefully+ QTest::addRow("cancelled-hold-drag-1p-after-delay") << "touchHoldFirstFourUpdateEventsFor50ms" << 1 << 6 << QPointF(1.0, 0) << touchPaintingOn << holdShortcutsOn << cancelShortcutOn << QList<int>{40} << QList<int>{} << 3 << ignorePaintEventCount;++ // 3+ finger shortcuts have a special workaround on Android, they should never be cancelled,+ // because some Xiaomi tablets deliver Cancel events for them even when three-finger shortcuts+ // are disabled in the system.++ // three-finger-tap shortcut is still present, even though it is cancelled+ QTest::addRow("cancelled-clean-3p-tap-hold-off") << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOff << holdShortcutsOff << cancelShortcutOn <<QList<int>{22} << QList<int>{} << 2 << ignorePaintEventCount;// clang-format on}@@ -948,6 +979,7 @@ void KisInputManagerTest::testTouchMoves()KisShortcutMatcher m;// the timeout should happen on the fourth event after the first (with a 30 ms margin)m.setTouchHoldDelay(170);+ m.setIgnoreMultiFingerCancelWorkaroundEnalbed(true);m.enterEvent();m.addShortcut(@@ -995,6 +1027,7 @@ void KisInputManagerTest::testTouchMoves()QFETCH(QPointF, pointOffset);QFETCH(bool, enableTouchPainting);QFETCH(bool, enableHoldShortcuts);+ QFETCH(bool, cancelShortcut);QFETCH(QList<int>, triggeredTouchShortcuts);QFETCH(QList<int>, triggeredPaintShortcuts);QFETCH(int, actionEventsCount);@@ -1046,12 +1079,17 @@ void KisInputManagerTest::testTouchMoves()#endifm.touchUpdateEvent(&e);} else if (eventIndex == eventsCount - 1) {+ QEvent::Type endingType = !cancelShortcut ? QEvent::TouchEnd : QEvent::TouchCancel;#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)- QTouchEvent e(QEvent::TouchEnd, &device, Qt::NoModifier, calcTouchPointStates(touchPoints), touchPoints);+ QTouchEvent e(endingType, &device, Qt::NoModifier, calcTouchPointStates(touchPoints), touchPoints);#else- QTouchEvent e(QEvent::TouchEnd, &device, Qt::NoModifier, touchPoints);+ QTouchEvent e(endingType, &device, Qt::NoModifier, touchPoints);#endif- m.touchEndEvent(&e);+ if (e.type() == QEvent::TouchEnd) {+ m.touchEndEvent(&e);+ } else {+ m.touchCancelEvent(&e);+ }} else {qFatal("invalid step value");}