Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTouchShortcut Class Reference

The KisTouchShortcut class only handles touch gestures it does not handle tool invocation i.e painting (which is being handled in KisShortcutMatcher). More...

#include <kis_touch_shortcut.h>

+ Inheritance diagram for KisTouchShortcut:

Classes

class  Private
 

Public Member Functions

bool isAvailable (KisInputActionGroupsMask mask) const override
 
bool isHoldType () const
 
 KisTouchShortcut (KisAbstractInputAction *action, int index, TouchGestureAction type)
 
bool matchDragType (const QTouchEvent *event, Qt::TouchPointStates allowedStates)
 
bool matchHoldType (const QTouchEvent *event, Qt::TouchPointStates allowedStates)
 
bool matchTapType (const QTouchEvent *event, Qt::TouchPointStates allowedStates)
 
bool matchTouchPoint (const QTouchEvent *event, Qt::TouchPointStates allowedStates)
 
qreal minDragThreshold () const
 
int priority () const override
 
void setIsTouchPainting (bool value)
 
void setMaximumTouchPoints (int max)
 
void setMinDragThreshold (qreal value)
 
void setMinimumTouchPoints (int min)
 
 ~KisTouchShortcut () override
 
- Public Member Functions inherited from KisAbstractShortcut
KisAbstractInputAction * action () const
 
 KisAbstractShortcut (KisAbstractInputAction *action, int index)
 
void setAction (KisAbstractInputAction *action)
 
int shortcutIndex () const
 
virtual ~KisAbstractShortcut ()
 

Static Public Member Functions

static Qt::TouchPointStates allTouchStates ()
 
static int countTouchPoints (const QTouchEvent *event, Qt::TouchPointStates allowedStates)
 
static Qt::TouchPointStates pressedOnlyTouchStates ()
 
static qreal touchDragDistance (const QTouchEvent *event, Qt::TouchPointStates allowedStates)
 

Private Types

using TouchGestureAction = KisShortcutConfiguration::TouchGestureAction
 

Private Attributes

Private *const d
 

Additional Inherited Members

- Public Attributes inherited from KisAbstractShortcut
KisAbstractInputAction * action
 
int shortcutIndex
 
- Protected Member Functions inherited from KisAbstractShortcut
bool compareKeys (const QSet< Qt::Key > &keys1, const QSet< Qt::Key > &keys2)
 

Detailed Description

The KisTouchShortcut class only handles touch gestures it does not handle tool invocation i.e painting (which is being handled in KisShortcutMatcher).

Definition at line 21 of file kis_touch_shortcut.h.

Member Typedef Documentation

◆ TouchGestureAction

Constructor & Destructor Documentation

◆ KisTouchShortcut()

KisTouchShortcut::KisTouchShortcut ( KisAbstractInputAction * action,
int index,
TouchGestureAction type )

Definition at line 35 of file kis_touch_shortcut.cpp.

37 , d(new Private(type))
38{
39
40}
KisAbstractInputAction * action
KisAbstractShortcut(KisAbstractInputAction *action, int index)

◆ ~KisTouchShortcut()

KisTouchShortcut::~KisTouchShortcut ( )
override

Definition at line 42 of file kis_touch_shortcut.cpp.

43{
44 delete d;
45}

References d.

Member Function Documentation

◆ allTouchStates()

static Qt::TouchPointStates KisTouchShortcut::allTouchStates ( )
inlinestatic

Definition at line 46 of file kis_touch_shortcut.h.

46 {
47 return Qt::TouchPointStationary | Qt::TouchPointPressed | Qt::TouchPointMoved | Qt::TouchPointReleased;
48 }

◆ countTouchPoints()

int KisTouchShortcut::countTouchPoints ( const QTouchEvent * event,
Qt::TouchPointStates allowedStates )
static

Definition at line 109 of file kis_touch_shortcut.cpp.

110{
111#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
112 auto points = event->touchPoints();
113 using TouchPoint = QTouchEvent::TouchPoint;
114#else
115 auto points = event->points();
116 using TouchPoint = QEventPoint;
117#endif
118
119 const int count =
120 std::count_if(points.begin(), points.end(), [=] (const TouchPoint &point) {
121 auto state = static_cast<Qt::TouchPointState>(point.state());
122 return allowedStates.testFlag(state);
123 });
124
125 return count;
126}

◆ isAvailable()

bool KisTouchShortcut::isAvailable ( KisInputActionGroupsMask mask) const
overridevirtual

Returns true if the shortcut is enabled at the moment

Reimplemented from KisAbstractShortcut.

Definition at line 82 of file kis_touch_shortcut.cpp.

83{
84 if (d->isTouchPainting && KisConfig(true).disableTouchOnCanvas()) {
85 return false;
86 }
87
89}
virtual bool isAvailable(KisInputActionGroupsMask mask) const

References d, KisAbstractShortcut::isAvailable(), and KisTouchShortcut::Private::isTouchPainting.

◆ isHoldType()

bool KisTouchShortcut::isHoldType ( ) const

◆ matchDragType()

bool KisTouchShortcut::matchDragType ( const QTouchEvent * event,
Qt::TouchPointStates allowedStates )

◆ matchHoldType()

bool KisTouchShortcut::matchHoldType ( const QTouchEvent * event,
Qt::TouchPointStates allowedStates )

Definition at line 104 of file kis_touch_shortcut.cpp.

105{
106 return isHoldType() && matchTouchPoint(event, allowedStates);
107}

References isHoldType(), and matchTouchPoint().

◆ matchTapType()

bool KisTouchShortcut::matchTapType ( const QTouchEvent * event,
Qt::TouchPointStates allowedStates )

◆ matchTouchPoint()

bool KisTouchShortcut::matchTouchPoint ( const QTouchEvent * event,
Qt::TouchPointStates allowedStates )

Definition at line 149 of file kis_touch_shortcut.cpp.

150{
151 const int numStillActivePoints = countTouchPoints(event, allowedStates);
152
153 return numStillActivePoints >= d->minTouchPoints && numStillActivePoints <= d->maxTouchPoints;
154}
static int countTouchPoints(const QTouchEvent *event, Qt::TouchPointStates allowedStates)

References countTouchPoints(), d, KisTouchShortcut::Private::maxTouchPoints, and KisTouchShortcut::Private::minTouchPoints.

◆ minDragThreshold()

qreal KisTouchShortcut::minDragThreshold ( ) const

Definition at line 47 of file kis_touch_shortcut.cpp.

48{
49 return d->minDragThreshold;
50}

References d, and KisTouchShortcut::Private::minDragThreshold.

◆ pressedOnlyTouchStates()

static Qt::TouchPointStates KisTouchShortcut::pressedOnlyTouchStates ( )
inlinestatic

Definition at line 50 of file kis_touch_shortcut.h.

50 {
51 return Qt::TouchPointStationary | Qt::TouchPointPressed | Qt::TouchPointMoved;
52 }

◆ priority()

int KisTouchShortcut::priority ( ) const
overridevirtual

The priority of the shortcut. The shortcut with the greatest value will be chosen for execution

Implements KisAbstractShortcut.

Definition at line 57 of file kis_touch_shortcut.cpp.

58{
59 return d->isTouchPainting ? std::numeric_limits<int>::max() : action()->priority();
60}
int priority() const override

References KisAbstractShortcut::action, d, KisTouchShortcut::Private::isTouchPainting, and KisAbstractInputAction::priority().

◆ setIsTouchPainting()

void KisTouchShortcut::setIsTouchPainting ( bool value)

Definition at line 77 of file kis_touch_shortcut.cpp.

78{
80}
float value(const T *src, size_t ch)

References d, KisTouchShortcut::Private::isTouchPainting, and value().

◆ setMaximumTouchPoints()

void KisTouchShortcut::setMaximumTouchPoints ( int max)

Definition at line 72 of file kis_touch_shortcut.cpp.

73{
75}
constexpr std::enable_if< sizeof...(values)==0, size_t >::type max()

References d, and KisTouchShortcut::Private::maxTouchPoints.

◆ setMinDragThreshold()

void KisTouchShortcut::setMinDragThreshold ( qreal value)

Definition at line 52 of file kis_touch_shortcut.cpp.

53{
55}

References d, KisTouchShortcut::Private::minDragThreshold, and value().

◆ setMinimumTouchPoints()

void KisTouchShortcut::setMinimumTouchPoints ( int min)

Definition at line 67 of file kis_touch_shortcut.cpp.

68{
70}
T min(T a, T b, T c)

References d, and KisTouchShortcut::Private::minTouchPoints.

◆ touchDragDistance()

qreal KisTouchShortcut::touchDragDistance ( const QTouchEvent * event,
Qt::TouchPointStates allowedStates )
static

Definition at line 128 of file kis_touch_shortcut.cpp.

129{
130#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
131 auto points = event->touchPoints();
132 using TouchPoint = QTouchEvent::TouchPoint;
133#else
134 auto points = event->points();
135 using TouchPoint = QEventPoint;
136#endif
137
138 return std::sqrt(std::accumulate(points.begin(), points.end(), qreal(0),
139 [&] (qreal maxOffsetSq, const TouchPoint &point) {
140 auto state = static_cast<Qt::TouchPointState>(point.state());
141 if (!allowedStates.testFlag(state)) {
142 return maxOffsetSq;
143 }
144
145 return std::max(maxOffsetSq, KisAlgebra2D::normSquared(point.pos() - point.startPos()));
146 }));
147}
qreal normSquared(const T &a)

References KisAlgebra2D::normSquared().

Member Data Documentation

◆ d

Private* const KisTouchShortcut::d
private

Definition at line 60 of file kis_touch_shortcut.h.


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