Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Implement one-finger touch and hold gesture

Carsten Hartenfels5a9fb49998fd
diff --git a/libs/ui/input/kis_input_manager.cpp b/libs/ui/input/kis_input_manager.cpp
index a3795e9931..3279e24ae6 100644
--- a/libs/ui/input/kis_input_manager.cpp
+++ b/libs/ui/input/kis_input_manager.cpp
@@ -134,6 +134,16 @@ void KisInputManager::slotConfigChanged()
#endif
}
+void KisInputManager::slotTouchHoldTriggered()
+{
+ d->cancelTouchHoldTimer();
+ d->clearBufferedTouchEvents();
+ KIS_SAFE_ASSERT_RECOVER_RETURN(d->originatingTouchBeginEvent);
+ if (d->matcher.touchHoldBeginEvent(static_cast<QTouchEvent *>(d->originatingTouchBeginEvent.data()))) {
+ d->touchHasBlockedPressEvents = true;
+ }
+}
+
void KisInputManager::toggleTabletLogger()
{
@@ -708,14 +718,29 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
if (startTouch(retval)) {
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
KisAbstractInputAction::setInputManager(this);
- d->previousPos = touchEvent->touchPoints().at(0).pos();
+ d->startingPos = touchEvent->touchPoints().at(0).pos();
+ d->previousPos = d->startingPos;
// we don't want to lose this event
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
KoPointerEvent::copyQtPointerEvent(touchEvent, d->originatingTouchBeginEvent);
#else
d->originatingTouchBeginEvent.reset(touchEvent->clone());
#endif
- retval = d->matcher.touchBeginEvent(touchEvent);
+
+ // In the face of a touch and hold shortcut being present, we need
+ // to disambiguate whether this is a touch being held or the user
+ // is doing something else. For that purpose, we start buffering
+ // received touch events until we can actually make a decision.
+ d->clearBufferedTouchEvents();
+ if (d->matcher.hasTouchHoldShortcut() && touchEvent->touchPoints().length() == 1) {
+ d->bufferTouchEvent(touchEvent);
+ d->restartTouchHoldTimer();
+ retval = true;
+ } else {
+ d->cancelTouchHoldTimer();
+ retval = handleTouchBegin(touchEvent);
+ }
+
KIS_SAFE_ASSERT_RECOVER(!d->touchStrokeStarted) {
d->touchStrokeStarted = false;
}
@@ -744,35 +769,15 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
if (count < 2 && touchEvent->touchPoints().length() > count) {
d->touchHasBlockedPressEvents = false;
+ d->cancelTouchHoldTimer();
retval = d->matcher.touchEndEvent(touchEvent);
} else {
#endif
- QPointF currentPos = touchEvent->touchPoints().at(0).pos();
- if (d->touchStrokeStarted || (!KisConfig(true).disableTouchOnCanvas()
- && !d->touchHasBlockedPressEvents
- && touchEvent->touchPoints().count() == 1
- && touchEvent->touchPointStates() != Qt::TouchPointStationary
- && (qAbs(currentPos.x() - d->previousPos.x()) > 1 // stop wobbliness which Qt sends us
- || qAbs(currentPos.y() - d->previousPos.y()) > 1)))
- {
- d->previousPos = currentPos;
- if (!d->touchStrokeStarted) {
- // we start it here not in TouchBegin, because Qt::TouchPointStationary doesn't work with hpdi devices.
- retval = d->matcher.buttonPressed(Qt::LeftButton, d->originatingTouchBeginEvent.data());
- d->touchStrokeStarted = retval;
- } else {
- // if it is a full-fledged stroke, then ignore (currentPos.x - previousPos.x)
- retval = compressMoveEventCommon(touchEvent);
- d->blockMouseEvents();
- }
+ // Touch hold shortcuts need to buffer events, see TouchBegin.
+ if (touchHoldBufferUpdate(touchEvent)) {
+ retval = true; // Event was buffered.
} else {
- KisAbstractInputAction::setInputManager(this);
- if (d->touchHasBlockedPressEvents) {
- retval = compressMoveEventCommon(touchEvent);
- } else {
- retval = d->matcher.touchUpdateEvent(touchEvent);
- d->touchHasBlockedPressEvents = retval;
- }
+ retval = handleTouchUpdate(touchEvent);
}
#ifdef Q_OS_MACOS
}
@@ -787,15 +792,20 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
case QEvent::TouchEnd:
{
+ d->cancelTouchHoldTimer();
+ d->flushBufferedTouchEvents();
+
if (d->popupWasActive) {
event->setAccepted(true);
return true;
}
d->debugEvent<QTouchEvent, false>(event);
QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
+
retval = d->matcher.touchEndEvent(touchEvent);
if (d->touchStrokeStarted) {
retval = d->matcher.buttonReleased(Qt::LeftButton, touchEvent);
+ d->startingPos = {0, 0};
d->previousPos = {0, 0};
d->touchStrokeStarted = false; // stroke ended
} else if (!KisConfig(true).disableTouchOnCanvas() && !d->touchHasBlockedPressEvents
@@ -820,6 +830,9 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
}
case QEvent::TouchCancel:
{
+ d->cancelTouchHoldTimer();
+ d->clearBufferedTouchEvents();
+
if (d->popupWasActive) {
event->setAccepted(true);
return true;
@@ -830,6 +843,7 @@ bool KisInputManager::eventFilterImpl(QEvent * event)
QTouchEvent *touchEvent = static_cast<QTouchEvent*>(event);
d->matcher.touchCancelEvent(touchEvent, d->previousPos);
// reset state
+ d->startingPos = {0, 0};
d->previousPos = {0, 0};
d->touchStrokeStarted = false;
retval = true;
@@ -892,6 +906,57 @@ void KisInputManager::endTouch()
d->touchHasBlockedPressEvents = false;
}
+bool KisInputManager::touchHoldBufferUpdate(QTouchEvent *touchEvent)
+{
+ if (d->isPendingTouchHold()) {
+ if (touchEvent->touchPoints().length() == 1 && d->isWithinTouchHoldSlopRange(touchEvent->touchPoints().at(0).pos())) {
+ d->bufferTouchEvent(touchEvent);
+ return true;
+ } else {
+ d->cancelTouchHoldTimer();
+ d->flushBufferedTouchEvents();
+ }
+ }
+ return false;
+}
+
+bool KisInputManager::handleTouchBegin(QTouchEvent *touchEvent)
+{
+ return d->matcher.touchBeginEvent(touchEvent);
+}
+
+bool KisInputManager::handleTouchUpdate(QTouchEvent *touchEvent)
+{
+ QPointF currentPos = touchEvent->touchPoints().at(0).pos();
+ if (d->touchStrokeStarted
+ || (!KisConfig(true).disableTouchOnCanvas() && !d->touchHasBlockedPressEvents
+ && touchEvent->touchPoints().count() == 1 && touchEvent->touchPointStates() != Qt::TouchPointStationary
+ && (qAbs(currentPos.x() - d->previousPos.x()) > 1 // stop wobbliness which Qt sends us
+ || qAbs(currentPos.y() - d->previousPos.y()) > 1))) {
+ d->previousPos = currentPos;
+ if (!d->touchStrokeStarted) {
+ // we start it here not in TouchBegin, because Qt::TouchPointStationary doesn't work with hpdi devices.
+ bool retval = d->matcher.buttonPressed(Qt::LeftButton, d->originatingTouchBeginEvent.data());
+ d->touchStrokeStarted = retval;
+ return retval;
+ } else {
+ // if it is a full-fledged stroke, then ignore (currentPos.x - previousPos.x)
+ bool retval = compressMoveEventCommon(touchEvent);
+ d->blockMouseEvents();
+ return retval;
+ }
+ } else {
+ KisAbstractInputAction::setInputManager(this);
+ if (d->touchHasBlockedPressEvents) {
+ return compressMoveEventCommon(touchEvent);
+ } else {
+ bool retval = d->matcher.touchUpdateEvent(touchEvent);
+ d->touchHasBlockedPressEvents = retval;
+ return retval;
+ }
+ }
+}
+
void KisInputManager::slotCompressedMoveEvent()
{
if (d->compressedMoveEvent) {
diff --git a/libs/ui/input/kis_input_manager.h b/libs/ui/input/kis_input_manager.h
index 38de484526..89990cace5 100644
--- a/libs/ui/input/kis_input_manager.h
+++ b/libs/ui/input/kis_input_manager.h
@@ -102,10 +102,16 @@ private Q_SLOTS:
void slotCompressedMoveEvent();
void deregisterPopupWidget();
void slotConfigChanged();
+ void slotTouchHoldTriggered();
private:
bool startTouch(bool &retval);
void endTouch();
+ bool touchHoldBufferUpdate(QTouchEvent *touchEvent);
+
+ // Handlers for events that may have been buffered for a touch hold.
+ bool handleTouchBegin(QTouchEvent *touchEvent);
+ bool handleTouchUpdate(QTouchEvent *touchEvent);
bool eventFilterImpl(QEvent * event);
template <class Event>
diff --git a/libs/ui/input/kis_input_manager_p.cpp b/libs/ui/input/kis_input_manager_p.cpp
index e56461d070..d26ad285fc 100644
--- a/libs/ui/input/kis_input_manager_p.cpp
+++ b/libs/ui/input/kis_input_manager_p.cpp
@@ -9,6 +9,7 @@
#include <QMap>
#include <QApplication>
#include <QScopedPointer>
+#include <QTimer>
#include <QtGlobal>
#include <boost/preprocessor/repeat_from_to.hpp>
@@ -201,6 +202,7 @@ KisInputManager::Private::Private(KisInputManager *qq)
KisSignalCompressor::ADDITIVE_INTERVAL)
, priorityEventFilterSeqNo(0)
, popupWidget(nullptr)
+ , touchHoldTimer(new QTimer(qq))
, canvasSwitcher(this, qq)
{
KisConfig cfg(true);
@@ -238,6 +240,11 @@ KisInputManager::Private::Private(KisInputManager *qq)
if (qEnvironmentVariableIsSet("KRITA_FIX_UNBALANCED_KEY_EVENTS")) {
useUnbalancedKeyPressEventWorkaround = qEnvironmentVariableIntValue("KRITA_FIX_UNBALANCED_KEY_EVENTS");
}
+
+ touchHoldTimer->setTimerType(Qt::CoarseTimer);
+ touchHoldTimer->setSingleShot(true);
+ touchHoldTimer->setInterval(TOUCH_HOLD_DELAY_MS);
+ connect(touchHoldTimer, &QTimer::timeout, qq, &KisInputManager::slotTouchHoldTriggered);
}
static const int InputWidgetsThreshold = 2000;
@@ -558,8 +565,12 @@ void KisInputManager::Private::addTouchShortcut(KisAbstractInputAction* action,
case KisShortcutConfiguration::OneFingerTap:
case KisShortcutConfiguration::OneFingerDrag:
// Touch painting takes precedence over one-finger touch shortcuts, so
- // disable this type of shortcut when touch painting is active.
+ // disable this type of shortcut when touch painting is active. Except
+ // touch hold shortcuts, since touching and holding in one spot does
+ // nothing otherwise and is therefore unambiguous.
shortcut->setDisableOnTouchPainting(true);
+ Q_FALLTHROUGH();
+ case KisShortcutConfiguration::OneFingerHold:
shortcut->setMinimumTouchPoints(1);
shortcut->setMaximumTouchPoints(1);
break;
@@ -711,6 +722,66 @@ void KisInputManager::Private::stopBlockingTouch()
eventEater.stopBlockingTouch();
}
+void KisInputManager::Private::restartTouchHoldTimer()
+{
+ touchHoldTimer->start();
+}
+
+void KisInputManager::Private::cancelTouchHoldTimer()
+{
+ touchHoldTimer->stop();
+}
+
+bool KisInputManager::Private::isPendingTouchHold() const
+{
+ return touchHoldTimer->isActive();
+}
+
+bool KisInputManager::Private::isWithinTouchHoldSlopRange(const QPointF &currentPos) const
+{
+ QPointF d = startingPos - currentPos;
+ qreal distanceSquared = (d.x() * d.x()) + (d.y() * d.y());
+ return distanceSquared <= KisShortcutMatcher::TOUCH_SLOP_SQUARED;
+}
+
+void KisInputManager::Private::bufferTouchEvent(QTouchEvent *touchEvent)
+{
+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
+ QScopedPointer<QEvent> dst;
+ KoPointerEvent::copyQtPointerEvent(touchEvent, dst);
+ bufferedTouchEvents.append(static_cast<QTouchEvent *>(dst.take()));
+#else
+ bufferedTouchEvents.append(touchEvent->clone());
+#endif
+}
+
+void KisInputManager::Private::flushBufferedTouchEvents()
+{
+ for (QTouchEvent *touchEvent : bufferedTouchEvents) {
+ switch (touchEvent->type()) {
+ case QEvent::TouchBegin:
+ q->handleTouchBegin(touchEvent);
+ break;
+ case QEvent::TouchUpdate:
+ q->handleTouchUpdate(touchEvent);
+ break;
+ default:
+ qWarning("Unhandled buffered touch event type %d", int(touchEvent->type()));
+ break;
+ }
+ delete touchEvent;
+ }
+ bufferedTouchEvents.clear();
+}
+
+void KisInputManager::Private::clearBufferedTouchEvents()
+{
+ for (QTouchEvent *event : bufferedTouchEvents) {
+ delete event;
+ }
+ bufferedTouchEvents.clear();
+}
+
bool KisInputManager::Private::handleCompressedTabletEvent(QEvent *event)
{
bool retval = false;
diff --git a/libs/ui/input/kis_input_manager_p.h b/libs/ui/input/kis_input_manager_p.h
index 4d015516f5..f788624dad 100644
--- a/libs/ui/input/kis_input_manager_p.h
+++ b/libs/ui/input/kis_input_manager_p.h
@@ -29,6 +29,8 @@ class KisToolInvocationAction;
class KisInputManager::Private
{
public:
+ static constexpr int TOUCH_HOLD_DELAY_MS = 400;
+
Private(KisInputManager *qq);
void addStrokeShortcut(KisAbstractInputAction* action, int index, const QList< Qt::Key >& modifiers, Qt::MouseButtons buttons);
void addKeyShortcut(KisAbstractInputAction* action, int index,const QList<Qt::Key> &keys);
@@ -69,13 +71,17 @@ public:
bool touchStrokeStarted = false;
bool popupWasActive = false;
+ QPointF startingPos;
QPointF previousPos;
QScopedPointer<QEvent> originatingTouchBeginEvent;
bool useUnbalancedKeyPressEventWorkaround = false;
bool shouldSynchronizeOnNextKeyPress = false;
- KisPopupWidgetInterface* popupWidget;
+ KisPopupWidgetInterface *popupWidget;
+
+ QTimer *touchHoldTimer;
+ QVector<QTouchEvent *> bufferedTouchEvents;
void blockMouseEvents();
void allowMouseEvents();
@@ -84,6 +90,13 @@ public:
void resetCompressor();
void startBlockingTouch();
void stopBlockingTouch();
+ void restartTouchHoldTimer();
+ void cancelTouchHoldTimer();
+ bool isPendingTouchHold() const;
+ bool isWithinTouchHoldSlopRange(const QPointF &currentPos) const;
+ void bufferTouchEvent(QTouchEvent *event);
+ void flushBufferedTouchEvents();
+ void clearBufferedTouchEvents();
template <class Event, bool useBlocking>
void debugEvent(QEvent *event)
diff --git a/libs/ui/input/kis_shortcut_configuration.cpp b/libs/ui/input/kis_shortcut_configuration.cpp
index cee5774af0..4ba0936106 100644
--- a/libs/ui/input/kis_shortcut_configuration.cpp
+++ b/libs/ui/input/kis_shortcut_configuration.cpp
@@ -501,6 +501,8 @@ QString KisShortcutConfiguration::gestureToText(GestureAction action)
return i18n("Four Finger Drag");
case FiveFingerDrag:
return i18n("Five Finger Drag");
+ case OneFingerHold:
+ return i18n("One Finger Hold");
#endif
default:
return i18n("No Gesture");
diff --git a/libs/ui/input/kis_shortcut_configuration.h b/libs/ui/input/kis_shortcut_configuration.h
index 5c16a85eb7..a2d49747df 100644
--- a/libs/ui/input/kis_shortcut_configuration.h
+++ b/libs/ui/input/kis_shortcut_configuration.h
@@ -72,6 +72,7 @@ public:
ThreeFingerDrag,
FourFingerDrag,
FiveFingerDrag,
+ OneFingerHold,
#endif
MaxGesture,
};
diff --git a/libs/ui/input/kis_shortcut_matcher.cpp b/libs/ui/input/kis_shortcut_matcher.cpp
index 4136449bc9..17f776cfbf 100644
--- a/libs/ui/input/kis_shortcut_matcher.cpp
+++ b/libs/ui/input/kis_shortcut_matcher.cpp
@@ -86,6 +86,7 @@ public:
int maxTouchPoints{0};
int matchingIteration{0};
bool isTouchDragDetected {false};
+ bool isTouchHeld {false};
QScopedPointer<QEvent> bestCandidateTouchEvent;
std::function<KisInputActionGroupsMask()> actionGroupMask;
@@ -165,6 +166,16 @@ bool KisShortcutMatcher::hasRunningShortcut() const
return m_d->runningShortcut || m_d->touchShortcut || m_d->nativeGestureShortcut;
}
+bool KisShortcutMatcher::hasTouchHoldShortcut() const
+{
+ for (const KisTouchShortcut *shortcut : m_d->touchShortcuts) {
+ if (shortcut->isHoldType() && shortcut->isAvailable(m_d->actionGroupMask())) {
+ return true;
+ }
+ }
+ return false;
+}
+
void KisShortcutMatcher::addShortcut(KisSingleActionShortcut *shortcut)
{
m_d->singleActionShortcuts.append(shortcut);
@@ -391,6 +402,7 @@ bool KisShortcutMatcher::touchBeginEvent( QTouchEvent* event )
m_d->maxTouchPoints = event->touchPoints().size();
m_d->matchingIteration = 1;
m_d->isTouchDragDetected = false;
+ m_d->isTouchHeld = false;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
KoPointerEvent::copyQtPointerEvent(event, m_d->bestCandidateTouchEvent);
#else
@@ -404,10 +416,15 @@ bool KisShortcutMatcher::touchUpdateEvent(QTouchEvent *event)
{
DEBUG_TOUCH_ACTION("entered", event)
+ if (m_d->isTouchHeld) {
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_d->touchShortcut, false);
+ m_d->touchShortcut->action()->inputEvent(event);
+ return true;
+ }
+
bool retval = false;
const int touchPointCount = event->touchPoints().size();
- const int touchSlopSquared = 16 * 16;
// check whether the touchpoints are relatively stationary or have been moved for dragging.
for (int i = 0; i < event->touchPoints().size() && !m_d->isTouchDragDetected; ++i) {
const QTouchEvent::TouchPoint &touchPoint = event->touchPoints().at(i);
@@ -415,7 +432,7 @@ bool KisShortcutMatcher::touchUpdateEvent(QTouchEvent *event)
const qreal deltaSquared = delta.x() * delta.x() + delta.y() * delta.y();
// if the drag is detected, until the next TouchBegin even, we'll be assuming the gesture to be of dragging
// type.
- m_d->isTouchDragDetected = deltaSquared > touchSlopSquared;
+ m_d->isTouchDragDetected = deltaSquared > TOUCH_SLOP_SQUARED;
}
// for a first few events we don't process the events right away. But analyze and keep track of the event with most
@@ -477,6 +494,7 @@ bool KisShortcutMatcher::touchEndEvent(QTouchEvent *event)
Private::RecursionNotifier notifier(this);
m_d->maxTouchPoints = 0;
+ m_d->isTouchHeld = false;
if (!m_d->isTouchDragDetected && m_d->bestCandidateTouchEvent && !hasRunningShortcut()) {
fireReadyTouchShortcut(static_cast<QTouchEvent *>(m_d->bestCandidateTouchEvent.data()));
@@ -501,6 +519,7 @@ void KisShortcutMatcher::touchCancelEvent(QTouchEvent *event, const QPointF &loc
Private::RecursionNotifier notifier(this);
m_d->maxTouchPoints = 0;
+ m_d->isTouchHeld = false;
KIS_SAFE_ASSERT_RECOVER_NOOP(!m_d->runningShortcut || !m_d->touchShortcut);
@@ -538,6 +557,28 @@ void KisShortcutMatcher::touchCancelEvent(QTouchEvent *event, const QPointF &loc
}
}
+bool KisShortcutMatcher::touchHoldBeginEvent(QTouchEvent *event)
+{
+ DEBUG_TOUCH_ACTION("hold", event)
+
+ // Can happen when multiple shortcut sources interact.
+ if (m_d->runningShortcut) {
+ return false;
+ }
+
+ m_d->isTouchHeld = true; // Must be set first, used in tryRunTouchShortcut.
+ if (tryRunTouchShortcut(event)) {
+ DEBUG_ACTION("touch shortcut found");
+ return true;
+ } else {
+ // Shouldn't really happen, since KisInputManager checks whether a touch
+ // hold shortcut exists beforehand. We'll just handle this though.
+ DEBUG_ACTION("touch shortcut not found");
+ m_d->isTouchHeld = false;
+ return touchBeginEvent(event);
+ }
+}
+
bool KisShortcutMatcher::nativeGestureBeginEvent(QNativeGestureEvent *event)
{
Q_UNUSED(event);
@@ -999,11 +1040,8 @@ KisTouchShortcut *KisShortcutMatcher::matchTouchShortcut(QTouchEvent *event)
{
KisTouchShortcut *goodCandidate = nullptr;
Q_FOREACH (KisTouchShortcut *shortcut, m_d->touchShortcuts) {
- // if the type of the action is drag, check if we match with drag type and if the type is tap, check if we match
- // with tap type.
if (shortcut->isAvailable(m_d->actionGroupMask())
- && ((shortcut->matchDragType(event) && m_d->isTouchDragDetected)
- || (shortcut->matchTapType(event) && !m_d->isTouchDragDetected))
+ && matchTouchShortcutBasedOnState(event, shortcut)
&& (!goodCandidate || shortcut->priority() > goodCandidate->priority())) {
goodCandidate = shortcut;
@@ -1012,6 +1050,17 @@ KisTouchShortcut *KisShortcutMatcher::matchTouchShortcut(QTouchEvent *event)
return goodCandidate;
}
+bool KisShortcutMatcher::matchTouchShortcutBasedOnState(QTouchEvent *event, KisTouchShortcut *shortcut)
+{
+ if (m_d->isTouchHeld) {
+ return shortcut->matchHoldType(event);
+ } else if (m_d->isTouchDragDetected) {
+ return shortcut->matchDragType(event);
+ } else {
+ return shortcut->matchTapType(event);
+ }
+}
+
bool KisShortcutMatcher::tryRunTouchShortcut( QTouchEvent* event )
{
KisTouchShortcut *goodCandidate = matchTouchShortcut(event);
diff --git a/libs/ui/input/kis_shortcut_matcher.h b/libs/ui/input/kis_shortcut_matcher.h
index ac9988ce53..e84d905172 100644
--- a/libs/ui/input/kis_shortcut_matcher.h
+++ b/libs/ui/input/kis_shortcut_matcher.h
@@ -74,10 +74,13 @@ class KisNativeGestureShortcut;
class KRITAUI_EXPORT KisShortcutMatcher
{
public:
+ static constexpr int TOUCH_SLOP_SQUARED = 16 * 16;
+
KisShortcutMatcher();
~KisShortcutMatcher();
bool hasRunningShortcut() const;
+ bool hasTouchHoldShortcut() const;
void addShortcut(KisSingleActionShortcut *shortcut);
void addShortcut(KisStrokeShortcut *shortcut);
@@ -183,6 +186,13 @@ public:
*/
void touchCancelEvent(QTouchEvent *event, const QPointF &localPos);
+ /**
+ * Effectively a long-press touch event, generated by KisInputManager
+ * when the user touches and holds a spot with one finger. Replaces
+ * touchBeginEvent, but other events keep streaming in as normal.
+ */
+ bool touchHoldBeginEvent(QTouchEvent *event);
+
bool nativeGestureBeginEvent(QNativeGestureEvent *event);
bool nativeGestureEvent(QNativeGestureEvent *event);
bool nativeGestureEndEvent(QNativeGestureEvent *event);
@@ -297,6 +307,7 @@ private:
void setMaxTouchPointEvent(QTouchEvent *event);
void fireReadyTouchShortcut(QTouchEvent *event);
KisTouchShortcut *matchTouchShortcut(QTouchEvent *event);
+ bool matchTouchShortcutBasedOnState(QTouchEvent *event, KisTouchShortcut *shortcut);
bool tryRunTouchShortcut(QTouchEvent *event);
bool tryEndTouchShortcut(QTouchEvent *event);
diff --git a/libs/ui/input/kis_touch_shortcut.cpp b/libs/ui/input/kis_touch_shortcut.cpp
index 1dc2861a9e..b2879b4538 100644
--- a/libs/ui/input/kis_touch_shortcut.cpp
+++ b/libs/ui/input/kis_touch_shortcut.cpp
@@ -45,6 +45,15 @@ int KisTouchShortcut::priority() const
return action()->priority();
}
+bool KisTouchShortcut::isHoldType() const
+{
+#ifdef Q_OS_MACOS
+ return false; // No equivalent gestures on macOS.
+#else
+ return d->type == KisShortcutConfiguration::OneFingerHold;
+#endif
+}
+
void KisTouchShortcut::setMinimumTouchPoints(int min)
{
d->minTouchPoints = min;
@@ -78,6 +87,11 @@ bool KisTouchShortcut::matchDragType(QTouchEvent *event)
;
}
+bool KisTouchShortcut::matchHoldType(QTouchEvent *event)
+{
+ return isHoldType() && matchTouchPoint(event);
+}
+
bool KisTouchShortcut::matchTouchPoint(QTouchEvent *event)
{
return (!d->disableOnTouchPainting || KisConfig(true).disableTouchOnCanvas())
diff --git a/libs/ui/input/kis_touch_shortcut.h b/libs/ui/input/kis_touch_shortcut.h
index 1e989dbfcb..d31c94a6c3 100644
--- a/libs/ui/input/kis_touch_shortcut.h
+++ b/libs/ui/input/kis_touch_shortcut.h
@@ -27,6 +27,7 @@ class KisTouchShortcut : public KisAbstractShortcut
~KisTouchShortcut() override;
int priority() const override;
+ bool isHoldType() const;
void setMinimumTouchPoints( int min );
void setMaximumTouchPoints( int max );
@@ -34,6 +35,7 @@ class KisTouchShortcut : public KisAbstractShortcut
bool matchTapType(QTouchEvent *event);
bool matchDragType(QTouchEvent *event);
+ bool matchHoldType(QTouchEvent *event);
bool matchTouchPoint(QTouchEvent *event);
private: