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 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 91 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 106 of file KoPointerEvent.cpp.

107 : point(pnt),
108 d(new Private(ev))
109{
110}
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 112 of file KoPointerEvent.cpp.

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

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

◆ KoPointerEvent() [3/5]

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

Definition at line 122 of file KoPointerEvent.cpp.

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

◆ KoPointerEvent() [4/5]

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

Definition at line 128 of file KoPointerEvent.cpp.

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

◆ ~KoPointerEvent()

KoPointerEvent::~KoPointerEvent ( )

Definition at line 150 of file KoPointerEvent.cpp.

151{
152}

◆ 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 134 of file KoPointerEvent.cpp.

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

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 442 of file KoPointerEvent.cpp.

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

References d.

◆ button()

Qt::MouseButton KoPointerEvent::button ( ) const

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

Definition at line 201 of file KoPointerEvent.cpp.

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

References d.

◆ buttons()

Qt::MouseButtons KoPointerEvent::buttons ( ) const

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

Definition at line 218 of file KoPointerEvent.cpp.

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

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 176 of file KoPointerEvent.cpp.

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

References d, and point.

◆ globalPos()

QPoint KoPointerEvent::globalPos ( ) const

Return the position screen coordinates.

Definition at line 235 of file KoPointerEvent.cpp.

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

◆ 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 453 of file KoPointerEvent.cpp.

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

References d.

◆ isAccepted()

bool KoPointerEvent::isAccepted ( ) const

return if the event has been accepted.

Definition at line 464 of file KoPointerEvent.cpp.

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

References d.

◆ isTabletEvent()

bool KoPointerEvent::isTabletEvent ( ) const

Returns if the event comes from a tablet

Definition at line 416 of file KoPointerEvent.cpp.

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

References d.

◆ isTouchEvent()

bool KoPointerEvent::isTouchEvent ( ) const

Returns if the event comes from a touch

Definition at line 421 of file KoPointerEvent.cpp.

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

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 431 of file KoPointerEvent.cpp.

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

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 140 of file KoPointerEvent.cpp.

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

References d, and point.

◆ pos()

QPoint KoPointerEvent::pos ( ) const

return the position in widget coordinates

Definition at line 266 of file KoPointerEvent.cpp.

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

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 306 of file KoPointerEvent.cpp.

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

References d.

◆ Private()

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

Definition at line 95 of file KoPointerEvent.cpp.

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

◆ rotation()

qreal KoPointerEvent::rotation ( ) const

return the rotation (or a default value)

Definition at line 327 of file KoPointerEvent.cpp.

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

References d.

◆ spontaneous()

bool KoPointerEvent::spontaneous ( ) const

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

Definition at line 475 of file KoPointerEvent.cpp.

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

References d.

◆ tabletInputReceived()

bool KoPointerEvent::tabletInputReceived ( )
static

Whether we ever had any tablet inputs this session

Definition at line 426 of file KoPointerEvent.cpp.

427{
428 return Private::s_tabletInputReceived;
429}

◆ 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 348 of file KoPointerEvent.cpp.

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

References d.

◆ time()

ulong KoPointerEvent::time ( ) const

Returns the time the event was registered.

Definition at line 405 of file KoPointerEvent.cpp.

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

References d.

◆ x()

int KoPointerEvent::x ( ) const

Return the x position in widget coordinates.

See also
point

Definition at line 296 of file KoPointerEvent.cpp.

297{
298 return pos().x();
299}
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 362 of file KoPointerEvent.cpp.

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

References d.

◆ y()

int KoPointerEvent::y ( ) const

Return the y position in widget coordinates.

See also
point

Definition at line 301 of file KoPointerEvent.cpp.

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

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 377 of file KoPointerEvent.cpp.

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

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 391 of file KoPointerEvent.cpp.

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

References d.

Friends And Related Symbol Documentation

◆ KisScratchPadEventFilter

friend class KisScratchPadEventFilter
friend

Definition at line 212 of file KoPointerEvent.h.

◆ KisToolProxy

friend class KisToolProxy
friend

Definition at line 211 of file KoPointerEvent.h.

◆ KoToolProxy

friend class KoToolProxy
friend

Definition at line 210 of file KoPointerEvent.h.

Member Data Documentation

◆ d

const QScopedPointer<Private> KoPointerEvent::d
private

Definition at line 216 of file KoPointerEvent.h.

◆ eventPtr

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

Definition at line 100 of file KoPointerEvent.cpp.

◆ point

QPointF KoPointerEvent::point

The point in document coordinates.

Definition at line 185 of file KoPointerEvent.h.

◆ s_tabletInputReceived

bool KoPointerEvent::s_tabletInputReceived
static

Definition at line 101 of file KoPointerEvent.cpp.


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