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

#include <KoPointerEvent.h>

+ Inheritance diagram for KoPointerEvent:

Public Member Functions

void accept ()
 
Qt::MouseButton button () const
 return button pressed (see QMouseEvent::button());
 
Qt::MouseButtons buttons () const
 return buttons pressed (see QMouseEvent::buttons());
 
KoPointerEventWrapper deepCopyEvent () const
 
QPoint globalPos () const
 Return the position screen coordinates.
 
void ignore ()
 
bool isAccepted () const
 return if the event has been accepted.
 
bool isTabletEvent () const
 
bool isTouchEvent () const
 
 KoPointerEvent (const KoPointerEvent &rhs)
 
 KoPointerEvent (KoPointerEvent *event, const QPointF &point)
 
 KoPointerEvent (QMouseEvent *event, const QPointF &point)
 
 KoPointerEvent (QTabletEvent *event, const QPointF &point)
 
 KoPointerEvent (QTouchEvent *ev, const QPointF &pnt)
 
Qt::KeyboardModifiers modifiers () const
 
KoPointerEventoperator= (const KoPointerEvent &rhs)
 
QPoint pos () const
 return the position in widget coordinates
 
qreal pressure () const
 
template<typename Event >
 Private (Event *event)
 
qreal rotation () const
 return the rotation (or a default value)
 
bool spontaneous () const
 return if this event was spontaneous (see QMouseEvent::spontaneous())
 
qreal tangentialPressure () const
 
ulong time () const
 
int x () const
 
qreal xTilt () const
 
int y () const
 
qreal yTilt () const
 
int z () const
 
 ~KoPointerEvent ()
 

Static Public Member Functions

static std::optional< QPointF > fetchGlobalPositionFromPointerEvent (QEvent *event)
 
static bool tabletInputReceived ()
 

Public Attributes

boost::variant2::variant< QMouseEvent *, QTabletEvent *, QTouchEvent * > eventPtr
 
QPointF point
 The point in document coordinates.
 

Static Public Attributes

static bool s_tabletInputReceived
 

Private Attributes

const QScopedPointer< Privated
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Friends

class KisScratchPadEventFilter
 
class KisToolProxy
 
class KoToolProxy
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

KoPointerEvent is a synthetic event that can be built from a mouse, touch or tablet event. In addition to always providing tools with tablet pressure characteristics, KoPointerEvent has both the original (canvas based) position as well as the normalized position, that is, the position of the event in the document coordinates.

Definition at line 92 of file KoPointerEvent.cpp.

Constructor & Destructor Documentation

◆ KoPointerEvent() [1/5]

KoPointerEvent::KoPointerEvent ( QMouseEvent * event,
const QPointF & point )

Constructor.

Parameters
eventthe mouse event that is the base of this event.
pointthe zoomed point in the normal coordinate system.

Definition at line 107 of file KoPointerEvent.cpp.

108 : point(pnt),
109 d(new Private(ev))
110{
111}
const QScopedPointer< Private > d
QPointF point
The point in document coordinates.

◆ KoPointerEvent() [2/5]

KoPointerEvent::KoPointerEvent ( QTabletEvent * event,
const QPointF & point )

Constructor.

Parameters
eventthe tablet event that is the base of this event.
pointthe zoomed point in the normal coordinate system.

Definition at line 113 of file KoPointerEvent.cpp.

114 : point(pnt),
115 d(new Private(ev))
116{
117 if (!Private::s_tabletInputReceived) {
118 Private::s_tabletInputReceived = true;
120 }
121}
static KisConfigNotifier * instance()

References KisConfigNotifier::instance(), and KisConfigNotifier::notifyTouchPaintingChanged().

◆ KoPointerEvent() [3/5]

KoPointerEvent::KoPointerEvent ( QTouchEvent * ev,
const QPointF & pnt )

Definition at line 123 of file KoPointerEvent.cpp.

124 : point(pnt),
125 d(new Private(ev))
126{
127}

◆ KoPointerEvent() [4/5]

KoPointerEvent::KoPointerEvent ( KoPointerEvent * event,
const QPointF & point )

Definition at line 129 of file KoPointerEvent.cpp.

130 : point(point)
131 , d(new Private(*(event->d)))
132{
133}

◆ ~KoPointerEvent()

KoPointerEvent::~KoPointerEvent ( )

Definition at line 151 of file KoPointerEvent.cpp.

152{
153}

◆ KoPointerEvent() [5/5]

KoPointerEvent::KoPointerEvent ( const KoPointerEvent & rhs)

Copies the event object

The newly created object will still point to the original QMouseEvent, QTabletEvent or QTouchEvent, so it is not safe to store such object. If you want to store a KoPointerEvent object, use deepCopyEvent() instead.

Definition at line 135 of file KoPointerEvent.cpp.

136 : point(rhs.point)
137 , d(new Private(*(rhs.d)))
138{
139}

Member Function Documentation

◆ accept()

void KoPointerEvent::accept ( )

For classes that are handed this event, you can choose to accept (default) this event. Acceptance signifies that you have handled this event and found it useful, the effect of that will be that the event will not be handled to other event handlers.

Definition at line 443 of file KoPointerEvent.cpp.

444{
445 struct Visitor {
446 void operator() (QInputEvent *event) {
447 event->accept();
448 }
449 };
450
451 return visit(Visitor(), d->eventPtr);
452}

References d.

◆ button()

Qt::MouseButton KoPointerEvent::button ( ) const

return button pressed (see QMouseEvent::button());

Definition at line 202 of file KoPointerEvent.cpp.

203{
204 struct Visitor {
205 Qt::MouseButton operator() (const QMouseEvent *event) {
206 return event->button();
207 }
208 Qt::MouseButton operator() (const QTabletEvent *event) {
209 return event->button();
210 }
211 Qt::MouseButton operator() (const QTouchEvent *) {
212 return Qt::LeftButton;
213 }
214 };
215
216 return visit(Visitor(), d->eventPtr);
217}

References d.

◆ buttons()

Qt::MouseButtons KoPointerEvent::buttons ( ) const

return buttons pressed (see QMouseEvent::buttons());

Definition at line 219 of file KoPointerEvent.cpp.

220{
221 struct Visitor {
222 Qt::MouseButtons operator() (const QMouseEvent *event) {
223 return event->buttons();
224 }
225 Qt::MouseButtons operator() (const QTabletEvent *event) {
226 return event->buttons();
227 }
228 Qt::MouseButtons operator() (const QTouchEvent *) {
229 return Qt::LeftButton;
230 }
231 };
232
233 return visit(Visitor(), d->eventPtr);
234}

References d.

◆ deepCopyEvent()

KoPointerEventWrapper KoPointerEvent::deepCopyEvent ( ) const

Copies KoPointerEvent and its underlying Qt event.

Normal copy-constructor keeps the pointers to the original Qt event intact, therefore you cannot store this event for any time longer than the lifetime of the handler for this event.

Definition at line 177 of file KoPointerEvent.cpp.

178{
179#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
180 return visit(DeepCopyVisitor{point}, d->eventPtr);
181#else
182 struct Visitor {
183
184 QPointF point;
185
186 KoPointerEventWrapper operator() (const QMouseEvent *event) {
187 return KoPointerEventWrapper(event->clone(), point);
188 }
189 KoPointerEventWrapper operator() (const QTabletEvent *event) {
190 return KoPointerEventWrapper(event->clone(), point);
191 }
192 KoPointerEventWrapper operator() (const QTouchEvent *event) {
193 return KoPointerEventWrapper(event->clone(), point);
194 }
195 };
196 return visit(Visitor{point}, d->eventPtr);
197
198
199#endif
200}

References d, and point.

◆ fetchGlobalPositionFromPointerEvent()

std::optional< QPointF > KoPointerEvent::fetchGlobalPositionFromPointerEvent ( QEvent * event)
static

Definition at line 504 of file KoPointerEvent.cpp.

505{
506 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(event, std::nullopt);
507
508 if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
509 const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);
510#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
511 const QList<QEventPoint> &touchPoints = touchEvent->points();
512#else
513 const QList<QTouchEvent::TouchPoint> &touchPoints = touchEvent->touchPoints();
514#endif
515 if (touchPoints.isEmpty()) {
516 // Getting zero touch points can happen on Android when pressing
517 // on the screen with an entire palm. Punt to using the cursor
518 // position after all.
519 return std::nullopt;
520 } else {
521#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
522 return touchPoints.constFirst().globalPosition();
523#else
524 return touchPoints.constFirst().screenPos();
525#endif
526 }
527 } else if (event->type() == QEvent::TabletPress || event->type() == QEvent::TabletRelease) {
528 const QTabletEvent *tabletEvent = static_cast<const QTabletEvent *>(event);
529#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
530 return tabletEvent->globalPosition();
531#else
532 return tabletEvent->globalPos();
533#endif
534 } else if (event->type() == QEvent::MouseButtonPress ||
535 event->type() == QEvent::MouseButtonRelease ||
536 event->type() == QEvent::MouseMove) {
537 const QMouseEvent *mouseEvent = static_cast<const QMouseEvent *>(event);
538#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
539 return mouseEvent->globalPosition();
540#else
541 return mouseEvent->globalPos();
542#endif
543 }
544
545 return std::nullopt;
546}
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE.

◆ globalPos()

QPoint KoPointerEvent::globalPos ( ) const

Return the position screen coordinates.

Definition at line 236 of file KoPointerEvent.cpp.

237{
238#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
239 struct Visitor {
240 QPoint operator() (const QMouseEvent *event) {
241 return event->globalPos();
242 }
243 QPoint operator() (const QTabletEvent *event) {
244 return event->globalPos();
245 }
246 QPoint operator() (const QTouchEvent *event) {
247 return event->touchPoints().constFirst().screenPos().toPoint();
248 }
249#else
250 struct Visitor {
251 QPoint operator() (const QMouseEvent *event) {
252 return event->globalPosition().toPoint();
253 }
254 QPoint operator() (const QTabletEvent *event) {
255 return event->globalPosition().toPoint();
256 }
257 QPoint operator() (const QTouchEvent *event) {
258 return event->points().constFirst().globalPosition().toPoint();
259 }
260#endif
261
262 };
263
264 return visit(Visitor(), d->eventPtr);
265}

◆ ignore()

void KoPointerEvent::ignore ( )

For classes that are handed this event, you can choose to ignore this event. Ignoring this event means you have not handled it and want to allow other event handlers to try to handle it.

Definition at line 454 of file KoPointerEvent.cpp.

455{
456 struct Visitor {
457 void operator() (QInputEvent *event) {
458 event->ignore();
459 }
460 };
461
462 return visit(Visitor(), d->eventPtr);
463}

References d.

◆ isAccepted()

bool KoPointerEvent::isAccepted ( ) const

return if the event has been accepted.

Definition at line 465 of file KoPointerEvent.cpp.

466{
467 struct Visitor {
468 bool operator() (const QInputEvent *event) {
469 return event->isAccepted();
470 }
471 };
472
473 return visit(Visitor(), d->eventPtr);
474}

References d.

◆ isTabletEvent()

bool KoPointerEvent::isTabletEvent ( ) const

Returns if the event comes from a tablet

Definition at line 417 of file KoPointerEvent.cpp.

418{
419 return d->eventPtr.index() == 1;
420}

References d.

◆ isTouchEvent()

bool KoPointerEvent::isTouchEvent ( ) const

Returns if the event comes from a touch

Definition at line 422 of file KoPointerEvent.cpp.

423{
424 return d->eventPtr.index() == 2;
425}

References d.

◆ modifiers()

Qt::KeyboardModifiers KoPointerEvent::modifiers ( ) const

Returns the keyboard modifier flags that existed immediately before the event occurred. See also QApplication::keyboardModifiers().

Definition at line 432 of file KoPointerEvent.cpp.

433{
434 struct Visitor {
435 Qt::KeyboardModifiers operator() (const QInputEvent *event) {
436 return event->modifiers();
437 }
438 };
439
440 return visit(Visitor(), d->eventPtr);
441}

References d.

◆ operator=()

KoPointerEvent & KoPointerEvent::operator= ( const KoPointerEvent & rhs)

Copies the event object

See a comment in copy constructor for the difference between deep/shallow copies.

Definition at line 141 of file KoPointerEvent.cpp.

142{
143 if (&rhs != this) {
144 *d = *rhs.d;
145 point = rhs.point;
146 }
147
148 return *this;
149}

References d, and point.

◆ pos()

QPoint KoPointerEvent::pos ( ) const

return the position in widget coordinates

Definition at line 267 of file KoPointerEvent.cpp.

268{
269#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
270 struct Visitor {
271 QPoint operator() (const QMouseEvent *event) {
272 return event->pos();
273 }
274 QPoint operator() (const QTabletEvent *event) {
275 return event->pos();
276 }
277 QPoint operator() (const QTouchEvent *event) {
278 return event->touchPoints().at(0).pos().toPoint();
279 }
280 };
281#else
282 struct Visitor {
283 QPoint operator() (const QMouseEvent *event) {
284 return event->position().toPoint();
285 }
286 QPoint operator() (const QTabletEvent *event) {
287 return event->position().toPoint();
288 }
289 QPoint operator() (const QTouchEvent *event) {
290 return event->points().at(0).position().toPoint();
291 }
292 };
293#endif
294 return visit(Visitor(), d->eventPtr);
295}

References d.

◆ pressure()

qreal KoPointerEvent::pressure ( ) const

return the pressure (or a default value). The range is 0.0 - 1.0 and the default pressure (this is the pressure that will be given when you use something like the mouse) is 1.0

Definition at line 307 of file KoPointerEvent.cpp.

308{
309 struct Visitor {
310 qreal operator() (const QTabletEvent *event) {
311 return event->pressure();
312 }
313 qreal operator() (const QTouchEvent *event) {
314#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
315 return s_optionContainer->useTouchPressure ? event->touchPoints().at(0).pressure() : 1.0;
316#else
317 return s_optionContainer->useTouchPressure ? event->points().at(0).pressure() : 1.0;
318#endif
319 }
320 qreal operator() (...) {
321 return 1.0;
322 }
323 };
324
325 return visit(Visitor(), d->eventPtr);
326}

References d.

◆ Private()

template<typename Event >
KoPointerEvent::Private ( Event * event)
inline

Definition at line 96 of file KoPointerEvent.cpp.

97 : eventPtr(event)
98 {
99 }
boost::variant2::variant< QMouseEvent *, QTabletEvent *, QTouchEvent * > eventPtr

◆ rotation()

qreal KoPointerEvent::rotation ( ) const

return the rotation (or a default value)

Definition at line 328 of file KoPointerEvent.cpp.

329{
330 struct Visitor {
331 qreal operator() (const QTabletEvent *event) {
332 return event->rotation();
333 }
334 qreal operator() (const QTouchEvent *event) {
335#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
336 return event->touchPoints().at(0).rotation();
337#else
338 return event->points().at(0).rotation();
339#endif
340 }
341 qreal operator() (...) {
342 return 0.0;
343 }
344 };
345
346 return visit(Visitor(), d->eventPtr);
347}

References d.

◆ spontaneous()

bool KoPointerEvent::spontaneous ( ) const

return if this event was spontaneous (see QMouseEvent::spontaneous())

Definition at line 476 of file KoPointerEvent.cpp.

477{
478 struct Visitor {
479 bool operator() (const QInputEvent *event) {
480 return event->spontaneous();
481 }
482 };
483
484 return visit(Visitor(), d->eventPtr);
485}

References d.

◆ tabletInputReceived()

bool KoPointerEvent::tabletInputReceived ( )
static

Whether we ever had any tablet inputs this session

Definition at line 427 of file KoPointerEvent.cpp.

428{
429 return Private::s_tabletInputReceived;
430}

◆ tangentialPressure()

qreal KoPointerEvent::tangentialPressure ( ) const

return the tangential pressure (or a default value) This is typically given by a finger wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a neutral position. Current airbrushes can only move in the positive direction from the neutral position. If the device does not support tangential pressure, this value is always 0.0.

Definition at line 349 of file KoPointerEvent.cpp.

350{
351 struct Visitor {
352 qreal operator() (const QTabletEvent *event) {
353 return std::fmod((event->tangentialPressure() - (-1.0)) / (1.0 - (-1.0)), 2.0);
354 }
355 qreal operator() (...) {
356 return 0.0;
357 }
358 };
359
360 return visit(Visitor(), d->eventPtr);
361}

References d.

◆ time()

ulong KoPointerEvent::time ( ) const

Returns the time the event was registered.

Definition at line 406 of file KoPointerEvent.cpp.

407{
408 struct Visitor {
409 ulong operator() (const QInputEvent *event) {
410 return event->timestamp();
411 }
412 };
413
414 return visit(Visitor(), d->eventPtr);
415}

References d.

◆ x()

int KoPointerEvent::x ( ) const

Return the x position in widget coordinates.

See also
point

Definition at line 297 of file KoPointerEvent.cpp.

298{
299 return pos().x();
300}
QPoint pos() const
return the position in widget coordinates

References pos().

◆ xTilt()

qreal KoPointerEvent::xTilt ( ) const

Returns the angle between the device (a pen, for example) and the perpendicular in the direction of the x axis. Positive values are towards the tablet's physical right. The angle is in the range -60 to +60 degrees. The default value is 0.

Definition at line 363 of file KoPointerEvent.cpp.

364{
365 struct Visitor {
366 int operator() (const QTabletEvent *event) {
367 return event->xTilt();
368 }
369 int operator() (...) {
370 return 0;
371 }
372 };
373
374 return visit(Visitor(), d->eventPtr);
375}

References d.

◆ y()

int KoPointerEvent::y ( ) const

Return the y position in widget coordinates.

See also
point

Definition at line 302 of file KoPointerEvent.cpp.

303{
304 return pos().y();
305}

References pos().

◆ yTilt()

qreal KoPointerEvent::yTilt ( ) const

Returns the angle between the device (a pen, for example) and the perpendicular in the direction of the x axis. Positive values are towards the tablet's physical right. The angle is in the range -60 to +60 degrees. The default value is 0.

Definition at line 378 of file KoPointerEvent.cpp.

379{
380 struct Visitor {
381 int operator() (const QTabletEvent *event) {
382 return event->yTilt();
383 }
384 int operator() (...) {
385 return 0;
386 }
387 };
388
389 return visit(Visitor(), d->eventPtr);
390}

References d.

◆ z()

int KoPointerEvent::z ( ) const

Returns the z position of the device. Typically this is represented by a wheel on a 4D Mouse. If the device does not support a Z-axis, this value is always zero. This is not the same as pressure.

Definition at line 392 of file KoPointerEvent.cpp.

393{
394 struct Visitor {
395 int operator() (const QTabletEvent *event) {
396 return event->z();
397 }
398 int operator() (...) {
399 return 0;
400 }
401 };
402
403 return visit(Visitor(), d->eventPtr);
404}

References d.

Friends And Related Symbol Documentation

◆ KisScratchPadEventFilter

friend class KisScratchPadEventFilter
friend

Definition at line 215 of file KoPointerEvent.h.

◆ KisToolProxy

friend class KisToolProxy
friend

Definition at line 214 of file KoPointerEvent.h.

◆ KoToolProxy

friend class KoToolProxy
friend

Definition at line 213 of file KoPointerEvent.h.

Member Data Documentation

◆ d

const QScopedPointer<Private> KoPointerEvent::d
private

Definition at line 219 of file KoPointerEvent.h.

◆ eventPtr

boost::variant2::variant<QMouseEvent*, QTabletEvent*, QTouchEvent*> KoPointerEvent::eventPtr

Definition at line 101 of file KoPointerEvent.cpp.

◆ point

QPointF KoPointerEvent::point

The point in document coordinates.

Definition at line 186 of file KoPointerEvent.h.

◆ s_tabletInputReceived

bool KoPointerEvent::s_tabletInputReceived
static

Definition at line 102 of file KoPointerEvent.cpp.


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