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++
Make touch-hold delay configurable in KisShortcutMatcher
Dmitry Kazakov957a5efb95f5
diff --git a/libs/ui/input/kis_shortcut_matcher.cpp b/libs/ui/input/kis_shortcut_matcher.cppindex 26e6c770b9..5c5397f6b5 100644--- a/libs/ui/input/kis_shortcut_matcher.cpp+++ b/libs/ui/input/kis_shortcut_matcher.cpp@@ -127,6 +127,7 @@ public:QScopedPointer<QEvent> bestCandidateForTapTouchEvent;QScopedPointer<QTouchEvent> lastProcessedTouchEvent;bool touchActionTracked {false};+ int touchHoldDelayMs {400};std::function<KisInputActionGroupsMask()> actionGroupMask;bool suppressAllActions;@@ -465,9 +466,7 @@ bool KisShortcutMatcher::touchBeginEvent( QTouchEvent* event )// TODO: also check if the first point actually qualifiesif (hasTouchHoldShortcut()) {- //static constexpr int TOUCH_HOLD_DELAY_MS = 400;- static constexpr int TOUCH_HOLD_DELAY_MS = 180;- m_d->touchHoldEventPostponer.emplace(TOUCH_SLOP, TOUCH_HOLD_DELAY_MS);+ m_d->touchHoldEventPostponer.emplace(TOUCH_SLOP, m_d->touchHoldDelayMs);QObject::connect(&m_d->touchHoldEventPostponer.value(),&KisTouchHoldEventsPostponer::sigHoldCompleted,[this]() {@@ -1362,3 +1361,13 @@ bool KisShortcutMatcher::tryEndNativeGestureShortcut(QNativeGestureEvent* event)return false;}++int KisShortcutMatcher::touchHoldDelay() const+{+ return m_d->touchHoldDelayMs;+}++void KisShortcutMatcher::setTouchHoldDelay(int value)+{+ m_d->touchHoldDelayMs = value;+}\ No newline at end of filediff --git a/libs/ui/input/kis_shortcut_matcher.h b/libs/ui/input/kis_shortcut_matcher.hindex b3302c1251..1ed4842740 100644--- a/libs/ui/input/kis_shortcut_matcher.h+++ b/libs/ui/input/kis_shortcut_matcher.h@@ -281,6 +281,16 @@ public:void setInputActionGroupsMaskCallback(std::function<KisInputActionGroupsMask()> func);+ /**+ * \return the currently set delay for the touch-hold actions (milliseconds)+ */+ int touchHoldDelay() const;++ /**+ * \return the currently set delay for the touch-hold actions (milliseconds)+ */+ void setTouchHoldDelay(int value);+private:friend class KisInputManagerTest;diff --git a/libs/ui/tests/kis_input_manager_test.cpp b/libs/ui/tests/kis_input_manager_test.cppindex cd4b38416b..285adb4dbd 100644--- a/libs/ui/tests/kis_input_manager_test.cpp+++ b/libs/ui/tests/kis_input_manager_test.cpp@@ -946,6 +946,8 @@ void KisInputManagerTest::testTouchMoves()std::unique_ptr<TestingAction> a(new TestingAction("touch-action"));KisShortcutMatcher m;+ // the timeout should happen on the fourth event after the first (with a 30 ms margin)+ m.setTouchHoldDelay(170);m.enterEvent();m.addShortcut(@@ -1088,7 +1090,8 @@ void KisInputManagerTest::testTouchHoldPostponer_data()const int noComplete = -1;const QPointF dragOffset(1,0);- const int holdTimeout = 170 /* ms */; // the timeout should happen on the fourth event after the first (with a 30 ms margin)+ // the timeout should happen on the fourth event after the first (with a 30 ms margin)+ const int holdTimeout = 170 /* ms */;QTest::addRow("clean-1p-drag") << "touchCleanDrag" << 1 << 100 << dragOffset << holdTimeout << 21 << noComplete;QTest::addRow("clean-2p-drag") << "touchCleanDrag" << 2 << 100 << dragOffset << holdTimeout << 0 << noComplete;@@ -1194,42 +1197,40 @@ void KisInputManagerTest::testTouchOverriddenByTablet_data(){QTest::addColumn<QString>("sequenceName");QTest::addColumn<QPointF>("pointOffset");- QTest::addColumn<int>("holdTimeout");QTest::addColumn<int>("tabletStartEventIndex");QTest::addColumn<QList<int>>("triggeredShortcuts");const QPointF dragOffset(10,0);const QPointF holdOffset(1,0);const QPointF tapOffset(0,0);- const int holdTimeout = 170 /* ms */; // the timeout should happen on the fourth event after the first (with a 30 ms margin)const int tabletStartsBeforeTouch = -1;- QTest::addRow("clean-1p-drag-no-tablet") << "touchCleanDrag" << dragOffset << holdTimeout << 200 << QList<int>{15};- QTest::addRow("clean-1p-hold-no-tablet") << "touchHoldFirstFourUpdateEventsFor50ms" << holdOffset << holdTimeout << 200 << QList<int>{40};- QTest::addRow("clean-1p-tap-no-tablet") << "touchCleanDrag" << tapOffset << holdTimeout << 200 << QList<int>{20};- QTest::addRow("clean-1p-drag-slow-start-no-tablet") << "touchCleanDrag" << holdOffset << holdTimeout << 200 << QList<int>{15};+ QTest::addRow("clean-1p-drag-no-tablet") << "touchCleanDrag" << dragOffset << 200 << QList<int>{15};+ QTest::addRow("clean-1p-hold-no-tablet") << "touchHoldFirstFourUpdateEventsFor50ms" << holdOffset << 200 << QList<int>{40};+ QTest::addRow("clean-1p-tap-no-tablet") << "touchCleanDrag" << tapOffset << 200 << QList<int>{20};+ QTest::addRow("clean-1p-drag-slow-start-no-tablet") << "touchCleanDrag" << holdOffset << 200 << QList<int>{15};/// tablet action has been started while touch drag was running,/// the touch action is ended and a tablet action is started- QTest::addRow("clean-1p-drag") << "touchCleanDrag" << dragOffset << holdTimeout << 2 << QList<int>{15, 50};+ QTest::addRow("clean-1p-drag") << "touchCleanDrag" << dragOffset << 2 << QList<int>{15, 50};/// tablet action has been started while touch-hold was being waited for,/// the touch-hold action should never start until the next touch-begin- QTest::addRow("clean-1p-hold") << "touchHoldFirstFourUpdateEventsFor50ms" << holdOffset << holdTimeout << 2 << QList<int>{50};+ QTest::addRow("clean-1p-hold") << "touchHoldFirstFourUpdateEventsFor50ms" << holdOffset << 2 << QList<int>{50};/// tablet action has been started before the touch-drag hasn't reached the/// drash threshold, the touch-drag action should never start until/// the next touch-begin- QTest::addRow("clean-1p-drag-slow-start") << "touchCleanDrag" << holdOffset << holdTimeout << 2 << QList<int>{50};+ QTest::addRow("clean-1p-drag-slow-start") << "touchCleanDrag" << holdOffset << 2 << QList<int>{50};/// touch-drag is requested during a tablet stroke, nothig should happen- QTest::addRow("clean-1p-drag-over-tablet") << "touchCleanDrag" << dragOffset << holdTimeout << tabletStartsBeforeTouch << QList<int>{50};+ QTest::addRow("clean-1p-drag-over-tablet") << "touchCleanDrag" << dragOffset << tabletStartsBeforeTouch << QList<int>{50};/// touch-hold is requested during a tablet stroke, nothig should happen- QTest::addRow("clean-1p-hold-over-tablet") << "touchHoldFirstFourUpdateEventsFor50ms" << holdOffset << holdTimeout << tabletStartsBeforeTouch << QList<int>{50};+ QTest::addRow("clean-1p-hold-over-tablet") << "touchHoldFirstFourUpdateEventsFor50ms" << holdOffset << tabletStartsBeforeTouch << QList<int>{50};/// touch-tap is requested during the tablet stroke, nothig should happen- QTest::addRow("clean-1p-tap-over-tablet") << "touchCleanDrag" << tapOffset << holdTimeout << tabletStartsBeforeTouch << QList<int>{50};+ QTest::addRow("clean-1p-tap-over-tablet") << "touchCleanDrag" << tapOffset << tabletStartsBeforeTouch << QList<int>{50};}class TabletEventsGenerator@@ -1313,7 +1314,6 @@ void KisInputManagerTest::testTouchOverriddenByTablet(){QFETCH(QString, sequenceName);QFETCH(QPointF, pointOffset);- QFETCH(int, holdTimeout); // TODO: unused!QFETCH(int, tabletStartEventIndex);QFETCH(QList<int>, triggeredShortcuts);@@ -1323,6 +1323,8 @@ void KisInputManagerTest::testTouchOverriddenByTablet()std::unique_ptr<TestingAction> a(new TestingAction("touch-action"));KisShortcutMatcher m;+ // the timeout should happen on the fourth event after the first (with a 30 ms margin)+ m.setTouchHoldDelay(170);m.enterEvent();m.addShortcut(