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++
draft: implement a different drag threshold for touch-painting
Dmitry Kazakov12323e9c3028
diff --git a/libs/ui/input/kis_input_manager_p.cpp b/libs/ui/input/kis_input_manager_p.cppindex a79d818868..a299a8616f 100644--- a/libs/ui/input/kis_input_manager_p.cpp+++ b/libs/ui/input/kis_input_manager_p.cpp@@ -563,6 +563,7 @@ void KisInputManager::Private::addTouchShortcut(KisAbstractInputAction* action,KisTouchShortcut *shortcut = new KisTouchShortcut(action, index, gesture);if (isTouchPainting) {shortcut->setIsTouchPainting(true);+ shortcut->setMinDragThreshold(1.5); // min threshold for touch painting is 1.5 px}dbgKrita << "TouchAction:" << action->name() << (isTouchPainting ? "touch-painting" : "");switch(gesture) {diff --git a/libs/ui/input/kis_shortcut_matcher.cpp b/libs/ui/input/kis_shortcut_matcher.cppindex 561bddc931..062966ca90 100644--- a/libs/ui/input/kis_shortcut_matcher.cpp+++ b/libs/ui/input/kis_shortcut_matcher.cpp@@ -10,7 +10,6 @@#include <QMouseEvent>#include <QTabletEvent>-#include <kis_algebra_2d.h>#include "kis_assert.h"#include "kis_abstract_input_action.h"#include "kis_stroke_shortcut.h"@@ -425,23 +424,28 @@ bool KisShortcutMatcher::touchUpdateEvent(QTouchEvent *event)bool retval = false;-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)- auto points = event->touchPoints();-#else- auto points = event->points();-#endif-// Check whether the touchpoints are relatively stationary or have// been moved for dragging. If the drag is detected, until the next// TouchBegin event, we'll be assuming the gesture to be of// dragging type.if (!m_d->isTouchDragDetected) {- for (auto it = points.begin(); it != points.end(); ++it) {- const QPointF delta = it->pos() - it->startPos();- if (KisAlgebra2D::normSquared(delta) > TOUCH_SLOP_SQUARED) {- m_d->isTouchDragDetected = true;- break;- }+ if (KisTouchShortcut::touchDragDistance(event, KisTouchShortcut::allTouchStates()) > TOUCH_SLOP) {+ m_d->isTouchDragDetected = true;+ }+ }++ // Different drag shortcuts can have different drag thresholds. E.g.+ // touch-painting shortcut will have much lower threshold value. The+ // shortcuts will calculate the distance themselves in+ // KisTouchShortcut::matchDragType, so we should just ask them to do that.+ const int numStillDraggedPoints =+ KisTouchShortcut::countTouchPoints(event, KisTouchShortcut::pressedOnlyTouchStates());+ if (!hasRunningShortcut() && numStillDraggedPoints >= m_d->maxTouchPoints) {+ m_d->maxTouchPoints = numStillDraggedPoints;+ DEBUG_TOUCH_ACTION("starting", event);+ if (tryRunTouchShortcut(event, KisTouchShortcut::pressedOnlyTouchStates(), TouchShortcutMode::Drag)) {+ m_d->isTouchDragDetected = true;+ return true;}}@@ -453,26 +457,22 @@ bool KisShortcutMatcher::touchUpdateEvent(QTouchEvent *event)m_d->matchingIteration++;setMaxTouchPointEvent(event);DEBUG_TOUCH_ACTION("return best", event)- return matchTouchShortcut((QTouchEvent *)m_d->bestCandidateForTapTouchEvent.data(), KisTouchShortcut::allTouchStates());+ return matchTouchShortcut((QTouchEvent *)m_d->bestCandidateForTapTouchEvent.data(),+ KisTouchShortcut::allTouchStates(),+ TouchShortcutMode::Tap);}if (m_d->isTouchDragDetected) {- const int numStillDraggedPoints =- KisTouchShortcut::countTouchPoints(event, KisTouchShortcut::pressedOnlyTouchStates());-- if (m_d->touchShortcut && !m_d->touchShortcut->matchDragType(event, KisTouchShortcut::pressedOnlyTouchStates())) {+ if (m_d->touchShortcut+ && !m_d->touchShortcut->matchDragType(event, KisTouchShortcut::pressedOnlyTouchStates())) {DEBUG_TOUCH_ACTION("ending", event)// we should end the event as an event with more touchpoints was receivedretval = tryEndTouchShortcut(event);- } else if (!hasRunningShortcut() && numStillDraggedPoints >= m_d->maxTouchPoints) {- m_d->maxTouchPoints = numStillDraggedPoints;- DEBUG_TOUCH_ACTION("starting", event);- retval = tryRunTouchShortcut(event, KisTouchShortcut::pressedOnlyTouchStates());} else if (m_d->touchShortcut) {m_d->touchShortcut->action()->inputEvent(event);retval = true;}- } else {+ } else { // !m_d->isTouchDragDetected// triggered if a new finger was added, which might result in shortcut not matching the action#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)const auto FlagReleased = Qt::TouchPointReleased;@@ -480,8 +480,7 @@ bool KisShortcutMatcher::touchUpdateEvent(QTouchEvent *event)const auto FlagReleased = QEventPoint::Released;#endifif (event->touchPointStates().testFlag(FlagReleased) && !hasRunningShortcut()) {- const int previousNumPoints =- KisTouchShortcut::countTouchPoints(event, KisTouchShortcut::allTouchStates());+ const int previousNumPoints = KisTouchShortcut::countTouchPoints(event, KisTouchShortcut::allTouchStates());// we should end the event as an event with more touchpoints was receivedif (previousNumPoints >= m_d->maxTouchPoints) {@@ -494,6 +493,7 @@ bool KisShortcutMatcher::touchUpdateEvent(QTouchEvent *event)}}}+ // TODO: update maxTouchPointsreturn retval;}@@ -580,7 +580,7 @@ bool KisShortcutMatcher::touchHoldBeginEvent(QTouchEvent *event)}m_d->isTouchHeld = true; // Must be set first, used in tryRunTouchShortcut.- if (tryRunTouchShortcut(event, KisTouchShortcut::pressedOnlyTouchStates())) {+ if (tryRunTouchShortcut(event, KisTouchShortcut::pressedOnlyTouchStates(), TouchShortcutMode::Hold)) {DEBUG_ACTION("touch shortcut found");return true;} else {@@ -1048,7 +1048,7 @@ void KisShortcutMatcher::setMaxTouchPointEvent(QTouchEvent *event)bool KisShortcutMatcher::tryFireTapTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates){- KisTouchShortcut *goodCandidate = matchTouchShortcut(event, allowedStates);+ KisTouchShortcut *goodCandidate = matchTouchShortcut(event, allowedStates, TouchShortcutMode::Tap);if (goodCandidate) {DEBUG_TOUCH_ACTION("starting", event)goodCandidate->action()->activate(goodCandidate->shortcutIndex());@@ -1061,12 +1061,12 @@ bool KisShortcutMatcher::tryFireTapTouchShortcut(QTouchEvent *event, Qt::TouchPoreturn goodCandidate;}-KisTouchShortcut *KisShortcutMatcher::matchTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates)+KisTouchShortcut *KisShortcutMatcher::matchTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode){KisTouchShortcut *goodCandidate = nullptr;Q_FOREACH (KisTouchShortcut *shortcut, m_d->touchShortcuts) {if (shortcut->isAvailable(m_d->actionGroupMask())- && matchTouchShortcutBasedOnState(event, shortcut, allowedStates)+ && matchTouchShortcutBasedOnState(event, shortcut, allowedStates, mode)&& (!goodCandidate || shortcut->priority() > goodCandidate->priority())) {goodCandidate = shortcut;@@ -1075,20 +1075,30 @@ KisTouchShortcut *KisShortcutMatcher::matchTouchShortcut(QTouchEvent *event, Qt:return goodCandidate;}-bool KisShortcutMatcher::matchTouchShortcutBasedOnState(QTouchEvent *event, KisTouchShortcut *shortcut, Qt::TouchPointStates allowedStates)+bool KisShortcutMatcher::matchTouchShortcutBasedOnState(QTouchEvent *event, KisTouchShortcut *shortcut, Qt::TouchPointStates allowedStates, TouchShortcutMode mode){- if (m_d->isTouchHeld) {+ switch (mode) {+ case TouchShortcutMode::Hold:return shortcut->matchHoldType(event, allowedStates);- } else if (m_d->isTouchDragDetected) {+ break;+ case TouchShortcutMode::Drag:return shortcut->matchDragType(event, allowedStates);- } else {+ break;+ case TouchShortcutMode::Tap:return shortcut->matchTapType(event, allowedStates);+ break;}++#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ return false;+#else+ Q_UNREACHABLE_RETURN(false);+#endif}-bool KisShortcutMatcher::tryRunTouchShortcut(QTouchEvent* event, Qt::TouchPointStates allowedStates)+bool KisShortcutMatcher::tryRunTouchShortcut(QTouchEvent* event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode){- KisTouchShortcut *goodCandidate = matchTouchShortcut(event, allowedStates);+ KisTouchShortcut *goodCandidate = matchTouchShortcut(event, allowedStates, mode);if (m_d->actionsSuppressed())return false;diff --git a/libs/ui/input/kis_shortcut_matcher.h b/libs/ui/input/kis_shortcut_matcher.hindex 1fa10182db..a742952cf3 100644--- a/libs/ui/input/kis_shortcut_matcher.h+++ b/libs/ui/input/kis_shortcut_matcher.h@@ -74,7 +74,8 @@ class KisNativeGestureShortcut;class KRITAUI_EXPORT KisShortcutMatcher{public:- static constexpr int TOUCH_SLOP_SQUARED = 16 * 16;+ static constexpr int TOUCH_SLOP_SQUARED = 16 * 16; // TODO: remove!+ static constexpr qreal TOUCH_SLOP = 16;KisShortcutMatcher();~KisShortcutMatcher();@@ -294,6 +295,12 @@ private:void reset();void reset(QString msg);+ enum class TouchShortcutMode {+ Drag = 0,+ Tap,+ Hold+ };+bool tryRunWheelShortcut(KisSingleActionShortcut::WheelAction wheelAction, QWheelEvent *event);template<typename T, typename U> bool tryRunSingleActionShortcutImpl(T param, U *event, const QSet<Qt::Key> &keysState, bool keyboard = true);@@ -307,9 +314,9 @@ private:void setMaxTouchPointEvent(QTouchEvent *event);bool tryFireTapTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates);- KisTouchShortcut *matchTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates);- bool matchTouchShortcutBasedOnState(QTouchEvent *event, KisTouchShortcut *shortcut, Qt::TouchPointStates allowedStates);- bool tryRunTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates);+ KisTouchShortcut *matchTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode);+ bool matchTouchShortcutBasedOnState(QTouchEvent *event, KisTouchShortcut *shortcut, Qt::TouchPointStates allowedStates, TouchShortcutMode mode);+ bool tryRunTouchShortcut(QTouchEvent *event, Qt::TouchPointStates allowedStates, TouchShortcutMode mode);bool tryEndTouchShortcut(QTouchEvent *event);bool tryRunNativeGestureShortcut(QNativeGestureEvent *event);diff --git a/libs/ui/input/kis_touch_shortcut.cpp b/libs/ui/input/kis_touch_shortcut.cppindex 1fd5942634..2957308daf 100644--- a/libs/ui/input/kis_touch_shortcut.cpp+++ b/libs/ui/input/kis_touch_shortcut.cpp@@ -7,6 +7,8 @@*/#include "kis_touch_shortcut.h"++#include <kis_algebra_2d.h>#include "kis_abstract_input_action.h"#include "kis_config.h"@@ -21,6 +23,7 @@ public:, type(type), disableOnTouchPainting(false), isTouchPainting(false)+ , minDragThreshold(16){ }int minTouchPoints;@@ -28,6 +31,7 @@ public:GestureAction type;bool disableOnTouchPainting;bool isTouchPainting;+ qreal minDragThreshold;};KisTouchShortcut::KisTouchShortcut(KisAbstractInputAction* action, int index, GestureAction type)@@ -42,6 +46,16 @@ KisTouchShortcut::~KisTouchShortcut()delete d;}+qreal KisTouchShortcut::minDragThreshold() const+{+ return d->minDragThreshold;+}++void KisTouchShortcut::setMinDragThreshold(qreal value)+{+ d->minDragThreshold = value;+}+int KisTouchShortcut::priority() const{return d->isTouchPainting ? std::numeric_limits<int>::max() : action()->priority();@@ -100,7 +114,8 @@ bool KisTouchShortcut::matchTapType(QTouchEvent *event, Qt::TouchPointStates allbool KisTouchShortcut::matchDragType(QTouchEvent *event, Qt::TouchPointStates allowedStates){- return matchTouchPoint(event, allowedStates)+ return touchDragDistance(event, allowedStates) > d->minDragThreshold &&+ matchTouchPoint(event, allowedStates)#ifndef Q_OS_MACOS&& (d->type >= KisShortcutConfiguration::OneFingerDrag && d->type <= KisShortcutConfiguration::FiveFingerDrag)#endif@@ -114,7 +129,7 @@ bool KisTouchShortcut::matchHoldType(QTouchEvent *event, Qt::TouchPointStates alint KisTouchShortcut::countTouchPoints(QTouchEvent *event, Qt::TouchPointStates allowedStates){- #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)auto points = event->touchPoints();using TouchPoint = QTouchEvent::TouchPoint;#else@@ -131,6 +146,27 @@ int KisTouchShortcut::countTouchPoints(QTouchEvent *event, Qt::TouchPointStatesreturn count;}+qreal KisTouchShortcut::touchDragDistance(QTouchEvent *event, Qt::TouchPointStates allowedStates)+{+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)+ auto points = event->touchPoints();+ using TouchPoint = QTouchEvent::TouchPoint;+#else+ auto points = event->points();+ using TouchPoint = QEventPoint;+#endif++ return std::sqrt(std::accumulate(points.begin(), points.end(), qreal(0),+ [&] (qreal maxOffsetSq, const TouchPoint &point) {+ auto state = static_cast<Qt::TouchPointState>(point.state());+ if (!allowedStates.testFlag(state)) {+ return maxOffsetSq;+ }++ return std::max(maxOffsetSq, KisAlgebra2D::normSquared(point.pos() - point.startPos()));+ }));+}+bool KisTouchShortcut::matchTouchPoint(QTouchEvent *event, Qt::TouchPointStates allowedStates){const int numStillActivePoints = countTouchPoints(event, allowedStates);diff --git a/libs/ui/input/kis_touch_shortcut.h b/libs/ui/input/kis_touch_shortcut.hindex 065fa03a6f..1f9b114749 100644--- a/libs/ui/input/kis_touch_shortcut.h+++ b/libs/ui/input/kis_touch_shortcut.h@@ -41,6 +41,9 @@ class KRITAUI_EXPORT KisTouchShortcut : public KisAbstractShortcutbool matchHoldType(QTouchEvent *event, Qt::TouchPointStates allowedStates);bool matchTouchPoint(QTouchEvent *event, Qt::TouchPointStates allowedStates);+ qreal minDragThreshold() const;+ void setMinDragThreshold(qreal value);+static inline Qt::TouchPointStates allTouchStates() {return Qt::TouchPointStationary | Qt::TouchPointPressed | Qt::TouchPointMoved | Qt::TouchPointReleased;}@@ -51,6 +54,8 @@ class KRITAUI_EXPORT KisTouchShortcut : public KisAbstractShortcutstatic int countTouchPoints(QTouchEvent *event, Qt::TouchPointStates allowedStates);+ static qreal touchDragDistance(QTouchEvent *event, Qt::TouchPointStates allowedStates);+private:class Private;Private * const d;diff --git a/libs/ui/tests/kis_input_manager_test.cpp b/libs/ui/tests/kis_input_manager_test.cppindex e65d02ec7b..f41ab26063 100644--- a/libs/ui/tests/kis_input_manager_test.cpp+++ b/libs/ui/tests/kis_input_manager_test.cpp@@ -111,6 +111,8 @@ struct TestingAction : public KisAbstractInputActionm_beginIndex = shortcut;m_begunIndexes.append(shortcut);m_beginNonNull = event;++ m_inputEventCount++;}void end(QEvent *event) override {KIS_ASSERT(m_state == Running);@@ -118,11 +120,16 @@ struct TestingAction : public KisAbstractInputActionm_endedIndexes.append(m_beginIndex);m_ended = true; m_endNonNull = event;++ m_inputEventCount++;}void inputEvent(QEvent* event) override {KIS_ASSERT(m_state == Running);- Q_UNUSED(event); m_gotInput = true;+ Q_UNUSED(event);+ m_gotInput = true;++ m_inputEventCount++;}void reset() {@@ -130,6 +137,7 @@ struct TestingAction : public KisAbstractInputActionm_begunIndexes.clear();m_ended = false;m_gotInput = false;+ m_inputEventCount = 0;m_beginNonNull = false;m_endNonNull = false;}@@ -154,7 +162,7 @@ struct TestingAction : public KisAbstractInputActionState m_stateBeforeRunning {Deactivated};QList<int> m_begunIndexes;QList<int> m_endedIndexes;-+ int m_inputEventCount = 0;};KisSingleActionShortcut* createKeyShortcut(KisAbstractInputAction *action,@@ -804,6 +812,8 @@ TouchSequenceGeneratorBase* createTouchSequenceGenerator(const QString sequenceN#endif}++void KisInputManagerTest::testTouchMoves_data(){QTest::addColumn<QString>("sequenceName");@@ -813,52 +823,63 @@ void KisInputManagerTest::testTouchMoves_data()QTest::addColumn<bool>("enableTouchPainting");QTest::addColumn<QList<int>>("triggeredTouchShortcuts");QTest::addColumn<QList<int>>("triggeredPaintShortcuts");+ QTest::addColumn<int>("actionEventsCount"); // `-1` to ignore this test+ QTest::addColumn<int>("paintEventsCount"); // `-1` to ignore this testconst QPointF dragOffset(10,10);const QPointF dirtyDragOffset(1,1);const QPointF tapOffset(0.5,0.5);+ const QPointF smallTapOffset(0.1,0.1);const bool touchPaintingOn = true;const bool touchPaintingOff = false;+ const int ignoreActionEventCount = -1;+ const int ignorePaintEventCount = -1;- QTest::addRow("clean-1p-drag") << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOff << QList<int>{15} << QList<int>{};- QTest::addRow("clean-2p-drag") << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOff << QList<int>{16} << QList<int>{};- QTest::addRow("clean-3p-drag") << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOff << QList<int>{17} << QList<int>{};+ QTest::addRow("clean-1p-drag") << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOff << QList<int>{15} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-2p-drag") << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOff << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-3p-drag") << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("clean-1p-drag-paint") << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOn << QList<int>{} << QList<int>{30};- QTest::addRow("clean-2p-drag-paint") << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOn << QList<int>{16} << QList<int>{};- QTest::addRow("clean-3p-drag-paint") << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOn << QList<int>{17} << QList<int>{};+ QTest::addRow("clean-1p-drag-paint") << "touchCleanDrag" << 1 << 100 << dragOffset << touchPaintingOn << QList<int>{} << QList<int>{30} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-2p-drag-paint") << "touchCleanDrag" << 2 << 100 << dragOffset << touchPaintingOn << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-3p-drag-paint") << "touchCleanDrag" << 3 << 100 << dragOffset << touchPaintingOn << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("clean-1p-tap") << "touchCleanDrag" << 1 << 10 << tapOffset << touchPaintingOff << QList<int>{20} << QList<int>{};- QTest::addRow("clean-2p-tap") << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOff << QList<int>{21} << QList<int>{};- QTest::addRow("clean-3p-tap") << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOff << QList<int>{22} << QList<int>{};+ // painting skips only the first two events+ QTest::addRow("clean-1p-drag-paint-delayed-start") << "touchCleanDrag" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOn << QList<int>{} << QList<int>{30} << ignoreActionEventCount << 98;+ // action has higher threshold, so it skips the first 17 events+ QTest::addRow("clean-1p-drag-delayed-start") << "touchCleanDrag" << 1 << 100 << QPointF(1.0, 0) << touchPaintingOff << QList<int>{15} << QList<int>{} << 83 << ignorePaintEventCount;- QTest::addRow("clean-1p-tap-paint") << "touchCleanDrag" << 1 << 10 << tapOffset << touchPaintingOn << QList<int>{} << QList<int>{31};- QTest::addRow("clean-2p-tap-paint") << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOn << QList<int>{21} << QList<int>{};- QTest::addRow("clean-3p-tap-paint") << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOn << QList<int>{22} << QList<int>{};+ QTest::addRow("clean-1p-tap") << "touchCleanDrag" << 1 << 10 << tapOffset << touchPaintingOff << QList<int>{20} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-2p-tap") << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOff << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-3p-tap") << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOff << 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("clean-1p-tap-paint") << "touchCleanDrag" << 1 << 10 << smallTapOffset << touchPaintingOn << QList<int>{} << QList<int>{31} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-2p-tap-paint") << "touchCleanDrag" << 2 << 10 << tapOffset << touchPaintingOn << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-3p-tap-paint") << "touchCleanDrag" << 3 << 10 << tapOffset << touchPaintingOn << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// 16px is the threshold for distinguishing taps and drags (touch-begin + 16 steps + touch-end)- QTest::addRow("clean-1p-tap-upper-bound") << "touchCleanDrag" << 1 << 18 << QPointF(1, 0) << touchPaintingOff << QList<int>{20} << QList<int>{};- QTest::addRow("clean-1p-drag-lower-bound") << "touchCleanDrag" << 1 << 19 << QPointF(1, 0) << touchPaintingOff << QList<int>{15} << QList<int>{};+ QTest::addRow("clean-1p-tap-upper-bound") << "touchCleanDrag" << 1 << 18 << QPointF(1, 0) << touchPaintingOff << QList<int>{20} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("clean-1p-drag-lower-bound") << "touchCleanDrag" << 1 << 19 << QPointF(1, 0) << touchPaintingOff << QList<int>{15} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("dirty-start-2p-drag") << "touchDragDirtyStart" << 2 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{16} << QList<int>{};- QTest::addRow("dirty-start-3p-drag") << "touchDragDirtyStart" << 3 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{17} << QList<int>{};+ QTest::addRow("dirty-start-2p-drag") << "touchDragDirtyStart" << 2 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("dirty-start-3p-drag") << "touchDragDirtyStart" << 3 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("dirty-end-2p-drag") << "touchDragDirtyEnd" << 2 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{16} << QList<int>{};- QTest::addRow("dirty-end-3p-drag") << "touchDragDirtyEnd" << 3 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{17} << QList<int>{};+ QTest::addRow("dirty-end-2p-drag") << "touchDragDirtyEnd" << 2 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{16} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("dirty-end-3p-drag") << "touchDragDirtyEnd" << 3 << 100 << dirtyDragOffset << touchPaintingOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;- QTest::addRow("dirty-end-2p-tap") << "touchDragDirtyEnd" << 2 << 10 << tapOffset << touchPaintingOff << QList<int>{21} << QList<int>{};- QTest::addRow("dirty-end-3p-tap") << "touchDragDirtyEnd" << 3 << 10 << tapOffset << touchPaintingOff << QList<int>{22} << QList<int>{};+ QTest::addRow("dirty-end-2p-tap") << "touchDragDirtyEnd" << 2 << 10 << tapOffset << touchPaintingOff << QList<int>{21} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;+ QTest::addRow("dirty-end-3p-tap") << "touchDragDirtyEnd" << 3 << 10 << tapOffset << touchPaintingOff << QList<int>{22} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// the current implementation is expected to switch to a "more-fingers-rich" shortcut immetiately- QTest::addRow("clean-2p-then-3p-drag") << "touchDragTwoThenThree" << 2 << 100 << dragOffset << touchPaintingOff << QList<int>{16, 17} << QList<int>{};+ QTest::addRow("clean-2p-then-3p-drag") << "touchDragTwoThenThree" << 2 << 100 << dragOffset << touchPaintingOff << 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("clean-3p-then-2p-drag") << "touchDragThreeThenTwo" << 3 << 100 << dragOffset << touchPaintingOff << QList<int>{17} << QList<int>{};+ QTest::addRow("clean-3p-then-2p-drag") << "touchDragThreeThenTwo" << 3 << 100 << dragOffset << touchPaintingOff << QList<int>{17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;// the 3-point gesture should be run twice during the same run- QTest::addRow("clean-3p-then-2p-then-3p-drag") << "touchDragThreeThenTwoThenThree" << 3 << 100 << dragOffset << touchPaintingOff << QList<int>{17, 17} << QList<int>{};+ QTest::addRow("clean-3p-then-2p-then-3p-drag") << "touchDragThreeThenTwoThenThree" << 3 << 100 << dragOffset << touchPaintingOff << QList<int>{17, 17} << QList<int>{} << ignoreActionEventCount << ignorePaintEventCount;}void KisInputManagerTest::testTouchMoves()@@ -898,6 +919,7 @@ void KisInputManagerTest::testTouchMoves()// Touch painting shortcutsauto *shortcutDrag = createTouchShortcut(paintAction.get(), 30, KisShortcutConfiguration::OneFingerDrag);shortcutDrag->setIsTouchPainting(true);+ shortcutDrag->setMinDragThreshold(1.5);m.addShortcut(shortcutDrag);auto *shortcutTap = createTouchShortcut(paintAction.get(), 31, KisShortcutConfiguration::OneFingerTap);@@ -912,6 +934,8 @@ void KisInputManagerTest::testTouchMoves()QFETCH(bool, enableTouchPainting);QFETCH(QList<int>, triggeredTouchShortcuts);QFETCH(QList<int>, triggeredPaintShortcuts);+ QFETCH(int, actionEventsCount);+ QFETCH(int, paintEventsCount);KisConfig(false).setTouchPainting(enableTouchPainting ? KisConfig::TOUCH_PAINTING_ENABLED: KisConfig::TOUCH_PAINTING_DISABLED);@@ -967,11 +991,18 @@ void KisInputManagerTest::testTouchMoves()QCOMPARE(a->m_begunIndexes, triggeredTouchShortcuts);QCOMPARE(a->m_endedIndexes, triggeredTouchShortcuts);QCOMPARE(a->m_ended, !a->m_begunIndexes.isEmpty());- //QCOMPARE(a->m_gotInput, true); // TODO!QCOMPARE(paintAction->m_begunIndexes, triggeredPaintShortcuts);QCOMPARE(paintAction->m_endedIndexes, triggeredPaintShortcuts);QCOMPARE(paintAction->m_ended, !paintAction->m_begunIndexes.isEmpty());++ if (actionEventsCount >= 0) {+ QCOMPARE(a->m_inputEventCount, actionEventsCount);+ }++ if (paintEventsCount >= 0) {+ QCOMPARE(paintAction->m_inputEventCount, paintEventsCount);+ }}#include "../input/wintab/kis_incremental_average.h"