1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qevent.h"
41#include "qcursor.h"
42#include "private/qguiapplication_p.h"
43#include "private/qinputdevice_p.h"
44#include "private/qpointingdevice_p.h"
45#include "qpa/qplatformintegration.h"
46#include "private/qevent_p.h"
47#include "qfile.h"
48#include "qhashfunctions.h"
49#include "qmetaobject.h"
50#include "qmimedata.h"
51#include "qevent_p.h"
52#include "qmath.h"
53#include "qloggingcategory.h"
54
55#if QT_CONFIG(draganddrop)
56#include <qpa/qplatformdrag.h>
57#include <private/qdnd_p.h>
58#endif
59
60#include <private/qdebug_p.h>
61
62QT_BEGIN_NAMESPACE
63
64Q_LOGGING_CATEGORY(lcPointerGrab, "qt.pointer.grab")
65Q_LOGGING_CATEGORY(lcPointerVel, "qt.pointer.velocity")
66Q_LOGGING_CATEGORY(lcEPDetach, "qt.pointer.eventpoint.detach")
67
68/*!
69 \class QEnterEvent
70 \ingroup events
71 \inmodule QtGui
72
73 \brief The QEnterEvent class contains parameters that describe an enter event.
74
75 Enter events occur when the mouse cursor enters a window or a widget.
76
77 \since 5.0
78*/
79
80/*!
81 Constructs an enter event object originating from \a device.
82
83 The points \a localPos, \a scenePos and \a globalPos specify the
84 mouse cursor's position relative to the receiving widget or item,
85 window, and screen or desktop, respectively.
86*/
87QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, const QPointingDevice *device)
88 : QSinglePointEvent(QEvent::Enter, device, localPos, scenePos, globalPos)
89{
90}
91
92/*!
93 \internal
94*/
95QEnterEvent::~QEnterEvent()
96{
97}
98
99/*!
100 \fn QPoint QEnterEvent::globalPos() const
101
102 Returns the global position of the mouse cursor \e{at the time of the event}.
103*/
104/*!
105 \fn int QEnterEvent::globalX() const
106
107 Returns the global position on the X-axis of the mouse cursor \e{at the time of the event}.
108*/
109/*!
110 \fn int QEnterEvent::globalY() const
111
112 Returns the global position on the Y-axis of the mouse cursor \e{at the time of the event}.
113*/
114/*!
115 \fn QPointF QEnterEvent::localPos() const
116
117 Returns the mouse cursor's position relative to the receiving widget.
118*/
119/*!
120 \fn QPoint QEnterEvent::pos() const
121
122 Returns the position of the mouse cursor relative to the receiving widget.
123*/
124/*!
125 \fn QPointF QEnterEvent::screenPos() const
126
127 Returns the position of the mouse cursor relative to the receiving screen.
128*/
129/*!
130 \fn QPointF QEnterEvent::windowPos() const
131
132 Returns the position of the mouse cursor relative to the receiving window.
133*/
134/*!
135 \fn int QEnterEvent::x() const
136
137 Returns the x position of the mouse cursor relative to the receiving widget.
138*/
139/*!
140 \fn int QEnterEvent::y() const
141
142 Returns the y position of the mouse cursor relative to the receiving widget.
143*/
144
145/*!
146 \class QInputEvent
147 \ingroup events
148 \inmodule QtGui
149
150 \brief The QInputEvent class is the base class for events that
151 describe user input.
152*/
153
154/*!
155 \internal
156*/
157QInputEvent::QInputEvent(Type type, const QInputDevice *dev, Qt::KeyboardModifiers modifiers)
158 : QEvent(type, QEvent::InputEventTag{}), m_dev(dev), m_modState(modifiers)
159{}
160
161/*!
162 \internal
163*/
164QInputEvent::QInputEvent(QEvent::Type type, QEvent::PointerEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers)
165 : QEvent(type, QEvent::PointerEventTag{}), m_dev(dev), m_modState(modifiers)
166{}
167
168/*!
169 \internal
170*/
171QInputEvent::~QInputEvent()
172{
173}
174
175/*!
176 \fn QInputDevice *QInputEvent::device() const
177 \since 6.0
178
179 Returns the source device that generated the original event.
180
181 In case of a synthesized event, for example a mouse event that was
182 generated from a touch event, \c device() continues to return the touchscreen
183 device, so that you can tell that it did not come from an actual mouse.
184 Thus \c {mouseEvent.source()->type() != QInputDevice::DeviceType::Mouse}
185 is one possible replacement for the Qt 5 expression
186 \c {mouseEvent.source() == Qt::MouseEventSynthesizedByQt}.
187
188 \sa QPointerEvent::pointingDevice()
189*/
190
191/*!
192 \fn QInputDevice::DeviceType QInputEvent::deviceType() const
193
194 Returns the type of device that generated the event.
195*/
196
197/*!
198 \fn Qt::KeyboardModifiers QInputEvent::modifiers() const
199
200 Returns the keyboard modifier flags that existed immediately
201 before the event occurred.
202
203 \sa QGuiApplication::keyboardModifiers()
204*/
205
206/*! \fn void QInputEvent::setModifiers(Qt::KeyboardModifiers modifiers)
207
208 \internal
209
210 Sets the keyboard modifiers flags for this event.
211*/
212
213/*!
214 \fn ulong QInputEvent::timestamp() const
215
216 Returns the window system's timestamp for this event.
217 It will normally be in milliseconds since some arbitrary point
218 in time, such as the time when the system was started.
219*/
220
221/*! \fn void QInputEvent::setTimestamp(ulong atimestamp)
222
223 \internal
224
225 Sets the timestamp for this event.
226*/
227
228/*!
229 \internal
230 Constructs an invalid event point with the given \a id and the \a device
231 from which it originated.
232
233 This acts as a default constructor in usages like QMap<int, QEventPoint>,
234 as in qgraphicsscene_p.h.
235*/
236QEventPoint::QEventPoint(int id, const QPointingDevice *device)
237 : d(new QEventPointPrivate(id, device)) {}
238
239/*!
240 Constructs an event point with the given \a pointId, \a state,
241 \a scenePosition and \a globalPosition.
242*/
243QEventPoint::QEventPoint(int pointId, State state, const QPointF &scenePosition, const QPointF &globalPosition)
244 : d(new QEventPointPrivate(pointId, state, scenePosition, globalPosition)) {}
245
246/*!
247 Constructs an event point by making a shallow copy of \a other.
248*/
249QEventPoint::QEventPoint(const QEventPoint &other)
250 : d(other.d)
251{
252 if (d)
253 d->refCount++;
254}
255
256/*!
257 Assigns \a other to this event point and returns a reference to this
258 event point.
259*/
260QEventPoint &QEventPoint::operator=(const QEventPoint &other)
261{
262 if (other.d)
263 other.d->refCount++;
264 if (d && !(--d->refCount))
265 delete d;
266 d = other.d;
267 return *this;
268}
269
270/*!
271 \fn QEventPoint::QEventPoint(QEventPoint &&other) noexcept
272
273 Constructs an event point by moving \a other.
274*/
275
276/*!
277 \fn QEventPoint &QEventPoint::operator=(QEventPoint &&other) noexcept
278
279 Move-assigns \a other to this event point instance.
280*/
281
282/*!
283 Returns \c true if this event point is equal to \a other, otherwise
284 return \c false.
285*/
286bool QEventPoint::operator==(const QEventPoint &other) const noexcept
287{
288 if (d == other.d)
289 return true;
290 if (!d || !other.d)
291 return false;
292 return *d == *other.d;
293}
294
295/*!
296 \fn bool QEventPoint::operator!=(const QEventPoint &other) const noexcept
297
298 Returns \c true if this event point is not equal to \a other, otherwise
299 return \c false.
300*/
301
302/*!
303 Destroys the event point.
304*/
305QEventPoint::~QEventPoint()
306{
307 if (d && !(--d->refCount))
308 delete d;
309}
310
311QPointF QEventPoint::position() const
312{ return d->pos; }
313
314QPointF QEventPoint::pressPosition() const
315{ return d->globalPressPos - d->globalPos + d->pos; }
316
317QPointF QEventPoint::grabPosition() const
318{ return d->globalGrabPos - d->globalPos + d->pos; }
319
320QPointF QEventPoint::lastPosition() const
321{ return d->globalLastPos - d->globalPos + d->pos; }
322
323QPointF QEventPoint::scenePosition() const
324{ return d->scenePos; }
325
326QPointF QEventPoint::scenePressPosition() const
327{ return d->globalPressPos - d->globalPos + d->scenePos; }
328
329QPointF QEventPoint::sceneGrabPosition() const
330{ return d->globalGrabPos - d->globalPos + d->scenePos; }
331
332QPointF QEventPoint::sceneLastPosition() const
333{ return d->globalLastPos - d->globalPos + d->scenePos; }
334
335QPointF QEventPoint::globalPosition() const
336{ return d->globalPos; }
337
338QPointF QEventPoint::globalPressPosition() const
339{ return d->globalPressPos; }
340
341QPointF QEventPoint::globalGrabPosition() const
342{ return d->globalGrabPos; }
343
344QPointF QEventPoint::globalLastPosition() const
345{ return d->globalLastPos; }
346
347QVector2D QEventPoint::velocity() const
348{ return d->velocity; }
349
350QEventPoint::State QEventPoint::state() const
351{ return d->state; }
352
353const QPointingDevice *QEventPoint::device() const
354{ return d->device; }
355
356int QEventPoint::id() const
357{ return d->pointId; }
358
359QPointingDeviceUniqueId QEventPoint::uniqueId() const
360{ return d->uniqueId; }
361
362ulong QEventPoint::timestamp() const
363{ return d->timestamp; }
364
365ulong QEventPoint::pressTimestamp() const
366{ return d->pressTimestamp; }
367
368qreal QEventPoint::timeHeld() const
369{ return (d->timestamp - d->pressTimestamp) / qreal(1000); }
370
371qreal QEventPoint::pressure() const
372{ return d->pressure; }
373
374qreal QEventPoint::rotation() const
375{ return d->rotation; }
376
377QSizeF QEventPoint::ellipseDiameters() const
378{ return d->ellipseDiameters; }
379
380bool QEventPoint::isAccepted() const
381{ return d->accept; }
382
383/*!
384 Returns the time from the previous QPointerEvent that contained this point.
385
386 \sa globalLastPosition()
387*/
388ulong QEventPoint::lastTimestamp() const
389{ return d->lastTimestamp; }
390
391/*!
392 Sets the accepted state of the point to \a accepted.
393
394 In widget-based applications, this function is not used so far, because
395 it's only meaningful for a widget to accept or reject a complete QInputEvent.
396
397 In Qt Quick however, it's normal for an Item or Event Handler to accept
398 only the individual points in a QTouchEvent that are actually participating
399 in a gesture, while other points can be delivered to other items or
400 handlers. For the sake of consistency, that applies to any QPointerEvent;
401 and delivery is done only when all points in a QPointerEvent have been
402 accepted.
403
404 \sa QEvent::setAccepted()
405*/
406void QEventPoint::setAccepted(bool accepted)
407{
408 d->accept = accepted;
409}
410
411/*!
412 \obsolete
413 Deprecated since Qt 6.0. Use globalPosition() instead.
414
415 Returns the normalized position of this point.
416
417 The coordinates are normalized to QInputDevice::availableVirtualGeometry(),
418 i.e. (0, 0) is the top-left corner and (1, 1) is the bottom-right corner.
419
420 \sa startNormalizedPos(), lastNormalizedPos(), pos()
421*/
422QPointF QEventPoint::normalizedPos() const
423{
424 auto geom = d->device->availableVirtualGeometry();
425 if (geom.isNull())
426 return QPointF();
427 return (globalPosition() - geom.topLeft()) / geom.width();
428}
429
430/*!
431 \obsolete
432 Deprecated since Qt 6.0. Use globalPressPosition() instead.
433
434 Returns the normalized press position of this point.
435*/
436QPointF QEventPoint::startNormalizedPos() const
437{
438 auto geom = d->device->availableVirtualGeometry();
439 if (geom.isNull())
440 return QPointF();
441 return (globalPressPosition() - geom.topLeft()) / geom.width();
442}
443
444/*!
445 \obsolete
446 Deprecated since Qt 6.0. Use globalLastPosition() instead.
447
448 Returns the normalized position of this point from the previous press or
449 move event.
450
451 The coordinates are normalized to QInputDevice::availableVirtualGeometry(),
452 i.e. (0, 0) is the top-left corner and (1, 1) is the bottom-right corner.
453
454 \sa normalizedPos(), startNormalizedPos()
455*/
456QPointF QEventPoint::lastNormalizedPos() const
457{
458 auto geom = d->device->availableVirtualGeometry();
459 if (geom.isNull())
460 return QPointF();
461 return (globalLastPosition() - geom.topLeft()) / geom.width();
462}
463
464
465/*! \internal
466 This class is explicitly shared, which means if you construct an event and
467 then the point(s) that it holds are modified before the event is delivered,
468 the event will be seen to hold the modified points. The workaround is that
469 any code which modifies an eventpoint that could already be included in an
470 event, or code that wants to save an eventpoint for later, has
471 responsibility to detach before calling any setters, so as to hold and
472 modify an independent copy. (The independent copy can then be used in a
473 subsequent event.) If detaching is unnecessary, because refCount shows that
474 there is only one QEventPoint referring to the QEventPointPrivate instance,
475 this function does nothing.
476*/
477void QMutableEventPoint::detach()
478{
479 if (d->refCount == 1)
480 return; // no need: there is only one QEventPoint using it
481 qCDebug(lcEPDetach) << "detaching: refCount" << d->refCount << this;
482 auto old = d;
483 d = new QEventPointPrivate(*d);
484 d->refCount = 1;
485 --old->refCount;
486}
487
488/*! \internal
489 Update current state from the given \a other point, assuming that this
490 instance contains state from the previous event and \a other contains new
491 values that came in from a device.
492
493 That is: global position and other valuators will be updated, but
494 the following properties will not be updated:
495
496 \list
497 \li other properties that are not likely to be set after a fresh touchpoint
498 has been received from a device
499 \li properties that should be persistent between events (such as grabbers)
500 \endlist
501*/
502void QMutableEventPoint::updateFrom(const QEventPoint &other)
503{
504 detach();
505 setPressure(other.pressure());
506
507 switch (other.state()) {
508 case QEventPoint::State::Pressed:
509 setGlobalPressPosition(other.globalPosition());
510 setGlobalLastPosition(other.globalPosition());
511 if (pressure() < 0)
512 setPressure(1);
513 break;
514
515 case QEventPoint::State::Released:
516 if (globalPosition() != other.globalPosition())
517 setGlobalLastPosition(globalPosition());
518 setPressure(0);
519 break;
520
521 default: // update or stationary
522 if (globalPosition() != other.globalPosition())
523 setGlobalLastPosition(globalPosition());
524 if (pressure() < 0)
525 setPressure(1);
526 break;
527 }
528
529 setState(other.state());
530 setPosition(other.position());
531 setScenePosition(other.scenePosition());
532 setGlobalPosition(other.globalPosition());
533 setEllipseDiameters(other.ellipseDiameters());
534 setRotation(other.rotation());
535 setVelocity(other.velocity());
536}
537
538/*! \internal
539 Set the timestamp from the event that updated this point's positions,
540 and calculate a new value for velocity().
541
542 The velocity calculation is done here because none of the QPointerEvent
543 subclass constructors take the timestamp directly, and because
544 QGuiApplication traditionally constructs an event first and then sets its
545 timestamp (see for example QGuiApplicationPrivate::processMouseEvent()).
546
547 This function looks up the corresponding instance in QPointingDevicePrivate::activePoints,
548 and assumes that its timestamp() still holds the previous time when this point
549 was updated, its velocity() holds this point's last-known velocity, and
550 its globalPosition() and globalLastPosition() hold this point's current
551 and previous positions, respectively. We assume timestamps are in milliseconds.
552
553 The velocity calculation is skipped if the platform has promised to
554 provide velocities already by setting the QInputDevice::Velocity capability.
555*/
556void QMutableEventPoint::setTimestamp(const ulong t)
557{
558 // On mouse press, if the mouse has moved from its last-known location,
559 // QGuiApplicationPrivate::processMouseEvent() sends first a mouse move and
560 // then a press. Both events will get the same timestamp. So we need to set
561 // the press timestamp and position even when the timestamp isn't advancing,
562 // but skip setting lastTimestamp and velocity because those need a time delta.
563 if (state() == QEventPoint::State::Pressed) {
564 d->pressTimestamp = t;
565 d->globalPressPos = d->globalPos;
566 }
567 if (d->timestamp == t)
568 return;
569 detach();
570 if (device()) {
571 // get the persistent instance out of QPointingDevicePrivate::activePoints
572 // (which sometimes might be the same as this instance)
573 QEventPointPrivate *pd = QPointingDevicePrivate::get(
574 const_cast<QPointingDevice *>(d->device))->pointById(id())->eventPoint.d;
575 if (t > pd->timestamp) {
576 pd->lastTimestamp = pd->timestamp;
577 pd->timestamp = t;
578 if (state() == QEventPoint::State::Pressed)
579 pd->pressTimestamp = t;
580 if (pd->lastTimestamp > 0 && !device()->capabilities().testFlag(QInputDevice::Capability::Velocity)) {
581 // calculate instantaneous velocity according to time and distance moved since the previous point
582 QVector2D newVelocity = QVector2D(pd->globalPos - pd->globalLastPos) / (t - pd->lastTimestamp) * 1000;
583 // VERY simple kalman filter: does a weighted average
584 // where the older velocities get less and less significant
585 static const float KalmanGain = 0.7f;
586 pd->velocity = newVelocity * KalmanGain + pd->velocity * (1.0f - KalmanGain);
587 qCDebug(lcPointerVel) << "velocity" << newVelocity << "filtered" << pd->velocity <<
588 "based on movement" << pd->globalLastPos << "->" << pd->globalPos <<
589 "over time" << pd->lastTimestamp << "->" << pd->timestamp;
590 }
591 if (d != pd) {
592 d->lastTimestamp = pd->lastTimestamp;
593 d->velocity = pd->velocity;
594 }
595 }
596 }
597 d->timestamp = t;
598}
599
600/*! \internal
601 void QMutableEventPoint::setPosition(const QPointF &pos)
602 Sets the localized position.
603 Often events need to be localized before delivery to specific widgets or
604 items. This can be done directly, or in a copy (for which we have a copy
605 constructor), depending on whether the original point needs to be retained.
606 Usually it's calculated by mapping scenePosition() to the target anyway.
607*/
608
609/*!
610 \class QPointerEvent
611 \since 6.0
612 \inmodule QtGui
613
614 \brief A base class for pointer events.
615*/
616
617/*!
618 \fn qsizetype QPointerEvent::pointCount() const
619
620 Returns the number of points in this pointer event.
621*/
622
623/*!
624 \fn QEventPoint &QPointerEvent::point(qsizetype i)
625
626 Returns a QEventPoint reference for the point at index \a i.
627*/
628
629/*!
630 \fn QPointingDevice::PointerType QPointerEvent::pointerType() const
631
632 Returns the type of point that generated the event.
633*/
634
635/*!
636 \internal
637*/
638QPointerEvent::QPointerEvent(QEvent::Type type, const QPointingDevice *dev,
639 Qt::KeyboardModifiers modifiers, const QList<QEventPoint> &points)
640 : QInputEvent(type, QEvent::PointerEventTag{}, dev, modifiers), m_points(points)
641{
642}
643
644QPointerEvent::~QPointerEvent()
645{
646}
647
648/*!
649 Returns the point whose \l {QEventPoint::id()}{id} matches the given \a id,
650 or \c nullptr if no such point is found.
651*/
652QEventPoint *QPointerEvent::pointById(int id)
653{
654 for (auto &p : m_points) {
655 if (p.id() == id)
656 return &p;
657 }
658 return nullptr;
659}
660
661/*!
662 Returns \c true if every point in points() has an exclusiveGrabber().
663*/
664bool QPointerEvent::allPointsGrabbed() const
665{
666 for (const auto &p : points()) {
667 if (exclusiveGrabber(p) && passiveGrabbers(p).isEmpty())
668 return false;
669 }
670 return true;
671}
672
673/*!
674 Returns \c true if isPointAccepted() is \c true for every point in
675 points(); otherwise \c false.
676*/
677bool QPointerEvent::allPointsAccepted() const
678{
679 for (const auto &p : points()) {
680 if (!p.isAccepted())
681 return false;
682 }
683 return true;
684}
685
686/*!
687 \reimp
688*/
689void QPointerEvent::setAccepted(bool accepted)
690{
691 QEvent::setAccepted(accepted);
692 for (auto &p : m_points)
693 p.setAccepted(accepted);
694}
695
696/*!
697 Returns the source device from which this event originates.
698
699 This is the same as QInputEvent::device() but typecast for convenience.
700*/
701const QPointingDevice *QPointerEvent::pointingDevice() const
702{
703 return static_cast<const QPointingDevice *>(m_dev);
704}
705
706/*! \internal
707 Sets the timestamp for this event and its points().
708*/
709void QPointerEvent::setTimestamp(ulong timestamp)
710{
711 QInputEvent::setTimestamp(timestamp);
712 for (auto &p : m_points)
713 QMutableEventPoint::from(p).setTimestamp(timestamp);
714}
715
716/*!
717 Returns the object which has been set to receive all future update events
718 and the release event containing the given \a point.
719
720 It's mainly for use in Qt Quick at this time.
721*/
722QObject *QPointerEvent::exclusiveGrabber(const QEventPoint &point) const
723{
724 Q_ASSERT(pointingDevice());
725 auto persistentPoint = QPointingDevicePrivate::get(pointingDevice())->queryPointById(point.id());
726 if (Q_UNLIKELY(!persistentPoint)) {
727 qWarning() << "point is not in activePoints" << point;
728 return nullptr;
729 }
730 return persistentPoint->exclusiveGrabber;
731}
732
733/*!
734 Informs the delivery logic that the given \a exclusiveGrabber is to
735 receive all future update events and the release event containing
736 the given \a point, and that delivery to other items can be skipped.
737
738 It's mainly for use in Qt Quick at this time.
739*/
740void QPointerEvent::setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber)
741{
742 Q_ASSERT(pointingDevice());
743 auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
744 devPriv->setExclusiveGrabber(this, point, exclusiveGrabber);
745}
746
747/*!
748 Returns the list of objects that have been requested to receive all
749 future update events and the release event containing the given \a point.
750
751 It's mainly for use in Qt Quick at this time.
752
753 \sa QPointerEvent::addPassiveGrabber()
754*/
755QList<QPointer<QObject> > QPointerEvent::passiveGrabbers(const QEventPoint &point) const
756{
757 Q_ASSERT(pointingDevice());
758 auto persistentPoint = QPointingDevicePrivate::get(pointingDevice())->queryPointById(point.id());
759 if (Q_UNLIKELY(!persistentPoint)) {
760 qWarning() << "point is not in activePoints" << point;
761 return {};
762 }
763 return persistentPoint->passiveGrabbers;
764}
765
766/*!
767 Informs the delivery logic that the given \a grabber is to receive all
768 future update events and the release event containing the given \a point,
769 regardless where else those events may be delivered.
770
771 It's mainly for use in Qt Quick at this time.
772
773 Returns \c false if \a grabber was already added, \c true otherwise.
774*/
775bool QPointerEvent::addPassiveGrabber(const QEventPoint &point, QObject *grabber)
776{
777 Q_ASSERT(pointingDevice());
778 auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
779 return devPriv->addPassiveGrabber(this, point, grabber);
780}
781
782/*!
783 Removes the passive \a grabber from the given \a point if it was previously added.
784 Returns \c true if it had been a passive grabber before, \c false if not.
785
786 It's mainly for use in Qt Quick at this time.
787
788 \sa QPointerEvent::addPassiveGrabber()
789*/
790bool QPointerEvent::removePassiveGrabber(const QEventPoint &point, QObject *grabber)
791{
792 Q_ASSERT(pointingDevice());
793 auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
794 return devPriv->removePassiveGrabber(this, point, grabber);
795}
796
797/*!
798 Removes all passive grabbers from the given \a point.
799
800 It's mainly for use in Qt Quick at this time.
801
802 \sa QPointerEvent::addPassiveGrabber()
803*/
804void QPointerEvent::clearPassiveGrabbers(const QEventPoint &point)
805{
806 Q_ASSERT(pointingDevice());
807 auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
808 devPriv->clearPassiveGrabbers(this, point);
809}
810
811/*!
812 \class QSinglePointEvent
813 \since 6.0
814 \inmodule QtGui
815
816 \brief A base class for pointer events containing a single point, such as
817 mouse events.
818*/
819
820/*! \fn Qt::MouseButton QSinglePointEvent::button() const
821
822 Returns the button that caused the event.
823
824 The returned value is always Qt::NoButton for mouse move events, as
825 well as \l TabletMove, \l TabletEnterProximity, and
826 \l TabletLeaveProximity events.
827
828 \sa buttons()
829*/
830
831/*! \fn Qt::MouseButtons QSinglePointEvent::buttons() const
832
833 Returns the button state when the event was generated.
834
835 The button state is a combination of Qt::LeftButton, Qt::RightButton,
836 and Qt::MidButton using the OR operator.
837
838 For mouse move or \l TabletMove events, this is all buttons that are
839 pressed down.
840
841 For mouse press, double click, or \l TabletPress events, this includes
842 the button that caused the event.
843
844 For mouse release or \l TabletRelease events, this excludes the button
845 that caused the event.
846
847 \sa button()
848*/
849
850/*! \fn QPointF QSinglePointEvent::position() const
851
852 Returns the position of the point in this event, relative to the widget or
853 item that received the event.
854
855 If you move your widgets around in response to mouse events, use
856 globalPosition() instead.
857
858 \sa globalPosition()
859*/
860
861/*! \fn QPointF QSinglePointEvent::scenePosition() const
862
863 Returns the position of the point in this event, relative to the window or
864 scene.
865
866 \sa QEventPoint::scenePosition()
867*/
868
869/*! \fn QPointF QSinglePointEvent::globalPosition() const
870
871 Returns the position of the point in this event on the screen or virtual
872 desktop.
873
874 \note The global position of a mouse pointer is recorded \e{at the time
875 of the event}. This is important on asynchronous window systems
876 such as X11; whenever you move your widgets around in response to
877 mouse events, globalPosition() can differ a lot from the current
878 cursor position returned by QCursor::pos().
879
880 \sa position()
881*/
882
883/*!
884 \internal
885*/
886QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos,
887 const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
888 : QPointerEvent(type, dev, modifiers),
889 m_button(button),
890 m_mouseState(buttons),
891 m_source(Qt::MouseEventNotSynthesized),
892 m_doubleClick(false),
893 m_reserved(0)
894{
895 bool isPress = (button != Qt::NoButton && (button | buttons) == buttons);
896 bool isWheel = (type == QEvent::Type::Wheel);
897 auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
898 auto epd = devPriv->pointById(0);
899 QMutableEventPoint &mut = QMutableEventPoint::from(epd->eventPoint);
900 Q_ASSERT(mut.device() == dev);
901 // mut is now a reference to a non-detached instance that lives in QPointingDevicePrivate::activePoints.
902 // Update persistent info in that instance.
903 if (isPress || isWheel)
904 mut.setGlobalLastPosition(globalPos);
905 else
906 mut.setGlobalLastPosition(mut.globalPosition());
907 mut.setGlobalPosition(globalPos);
908 if (isWheel && mut.state() != QEventPoint::State::Updated)
909 mut.setGlobalPressPosition(globalPos);
910 if (type == MouseButtonDblClick)
911 mut.setState(QEventPoint::State::Stationary);
912 else if (button == Qt::NoButton || isWheel)
913 mut.setState(QEventPoint::State::Updated);
914 else if (isPress)
915 mut.setState(QEventPoint::State::Pressed);
916 else
917 mut.setState(QEventPoint::State::Released);
918 mut.setScenePosition(scenePos);
919 // Now detach, and update the detached instance with ephemeral state.
920 mut.detach();
921 mut.setPosition(localPos);
922 m_points.append(mut);
923}
924
925/*! \internal
926 Constructs a single-point event with the given \a point, which must be an instance
927 (or copy of one) that already exists in QPointingDevicePrivate::activePoints.
928 Unlike the other constructor, it does not modify the given \a point in any way.
929 This is useful when synthesizing a QMouseEvent from one point taken from a QTouchEvent, for example.
930
931 \sa QMutableSinglePointEvent()
932*/
933QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *dev, const QEventPoint &point,
934 Qt::MouseButton button, Qt::MouseButtons buttons,
935 Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source)
936 : QPointerEvent(type, dev, modifiers),
937 m_button(button),
938 m_mouseState(buttons),
939 m_source(source),
940 m_doubleClick(false),
941 m_reserved(0)
942{
943 m_points << point;
944}
945
946/*!
947 Returns \c true if this event represents a \l {button()}{button} being pressed.
948*/
949bool QSinglePointEvent::isBeginEvent() const
950{
951 // A double-click event does not begin a sequence: it comes after a press event,
952 // and while it tells which button caused the double-click, it doesn't represent
953 // a change of button state. So it's an update event.
954 return m_button != Qt::NoButton && m_mouseState.testFlag(m_button)
955 && type() != QEvent::MouseButtonDblClick;
956}
957
958/*!
959 Returns \c true if this event does not include a change in \l {buttons()}{button state}.
960*/
961bool QSinglePointEvent::isUpdateEvent() const
962{
963 // A double-click event is an update event even though it tells which button
964 // caused the double-click, because a MouseButtonPress event was sent right before it.
965 return m_button == Qt::NoButton || type() == QEvent::MouseButtonDblClick;
966}
967
968/*!
969 Returns \c true if this event represents a \l {button()}{button} being released.
970*/
971bool QSinglePointEvent::isEndEvent() const
972{
973 return m_button != Qt::NoButton && !m_mouseState.testFlag(m_button);
974}
975
976/*!
977 \property QSinglePointEvent::exclusivePointGrabber
978 \brief the object that will receive future updates
979
980 The exclusive grabber is an object that has chosen to receive all future
981 update events and the release event containing the same point that this
982 event carries.
983
984 Setting the exclusivePointGrabber property is a convenience equivalent to:
985 \code
986 setExclusiveGrabber(points().first(), exclusiveGrabber);
987 \endcode
988*/
989
990
991/*!
992 \class QMouseEvent
993 \ingroup events
994 \inmodule QtGui
995
996 \brief The QMouseEvent class contains parameters that describe a mouse event.
997
998 Mouse events occur when a mouse button is pressed or released
999 inside a widget, or when the mouse cursor is moved.
1000
1001 Mouse move events will occur only when a mouse button is pressed
1002 down, unless mouse tracking has been enabled with
1003 QWidget::setMouseTracking().
1004
1005 Qt automatically grabs the mouse when a mouse button is pressed
1006 inside a widget; the widget will continue to receive mouse events
1007 until the last mouse button is released.
1008
1009 A mouse event contains a special accept flag that indicates
1010 whether the receiver wants the event. You should call ignore() if
1011 the mouse event is not handled by your widget. A mouse event is
1012 propagated up the parent widget chain until a widget accepts it
1013 with accept(), or an event filter consumes it.
1014
1015 \note If a mouse event is propagated to a \l{QWidget}{widget} for
1016 which Qt::WA_NoMousePropagation has been set, that mouse event
1017 will not be propagated further up the parent widget chain.
1018
1019 The state of the keyboard modifier keys can be found by calling the
1020 \l{QInputEvent::modifiers()}{modifiers()} function, inherited from
1021 QInputEvent.
1022
1023 The position() function gives the cursor position
1024 relative to the widget or item that receives the mouse event.
1025 If you move the widget as a result of the mouse event, use the
1026 global position returned by globalPosition() to avoid a shaking motion.
1027
1028 The QWidget::setEnabled() function can be used to enable or
1029 disable mouse and keyboard events for a widget.
1030
1031 Reimplement the QWidget event handlers, QWidget::mousePressEvent(),
1032 QWidget::mouseReleaseEvent(), QWidget::mouseDoubleClickEvent(),
1033 and QWidget::mouseMoveEvent() to receive mouse events in your own
1034 widgets.
1035
1036 \sa QWidget::setMouseTracking(), QWidget::grabMouse(),
1037 QCursor::pos()
1038*/
1039
1040/*!
1041 Constructs a mouse event object originating from \a device.
1042
1043 The \a type parameter must be one of QEvent::MouseButtonPress,
1044 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
1045 or QEvent::MouseMove.
1046
1047 The \a localPos is the mouse cursor's position relative to the
1048 receiving widget or item. The window position is set to the same value
1049 as \a localPos.
1050 The \a button that caused the event is given as a value from
1051 the Qt::MouseButton enum. If the event \a type is
1052 \l MouseMove, the appropriate button for this event is Qt::NoButton.
1053 The mouse and keyboard states at the time of the event are specified by
1054 \a buttons and \a modifiers.
1055
1056 The globalPosition() is initialized to QCursor::pos(), which may not
1057 be appropriate. Use the other constructor to specify the global
1058 position explicitly.
1059*/
1060QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
1061 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
1062 : QSinglePointEvent(type, device, localPos, localPos,
1063#ifdef QT_NO_CURSOR
1064 localPos,
1065#else
1066 QCursor::pos(),
1067#endif
1068 button, buttons, modifiers)
1069{
1070}
1071
1072/*!
1073 Constructs a mouse event object originating from \a device.
1074
1075 The \a type parameter must be QEvent::MouseButtonPress,
1076 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
1077 or QEvent::MouseMove.
1078
1079 The \a localPos is the mouse cursor's position relative to the
1080 receiving widget or item. The cursor's position in screen coordinates is
1081 specified by \a globalPos. The window position is set to the same value
1082 as \a localPos. The \a button that caused the event is
1083 given as a value from the \l Qt::MouseButton enum. If the event \a
1084 type is \l MouseMove, the appropriate button for this event is
1085 Qt::NoButton. \a buttons is the state of all buttons at the
1086 time of the event, \a modifiers the state of all keyboard
1087 modifiers.
1088
1089*/
1090QMouseEvent::QMouseEvent(Type type, const QPointF &localPos, const QPointF &globalPos,
1091 Qt::MouseButton button, Qt::MouseButtons buttons,
1092 Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
1093 : QMouseEvent(type, localPos, localPos, globalPos, button, buttons, modifiers, device)
1094{
1095}
1096
1097/*!
1098 Constructs a mouse event object.
1099
1100 The \a type parameter must be QEvent::MouseButtonPress,
1101 QEvent::MouseButtonRelease, QEvent::MouseButtonDblClick,
1102 or QEvent::MouseMove.
1103
1104 The points \a localPos, \a scenePos and \a globalPos specify the
1105 mouse cursor's position relative to the receiving widget or item,
1106 window, and screen or desktop, respectively.
1107
1108 The \a button that caused the event is given as a value from the
1109 \l Qt::MouseButton enum. If the event \a type is \l MouseMove,
1110 the appropriate button for this event is Qt::NoButton. \a buttons
1111 is the state of all buttons at the time of the event, \a modifiers
1112 is the state of all keyboard modifiers.
1113*/
1114QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos,
1115 const QPointF &scenePos, const QPointF &globalPos,
1116 Qt::MouseButton button, Qt::MouseButtons buttons,
1117 Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
1118 : QSinglePointEvent(type, device, localPos, scenePos, globalPos, button, buttons, modifiers)
1119{
1120}
1121
1122QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPointF &windowPos,
1123 const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons,
1124 Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source,
1125 const QPointingDevice *device)
1126 : QSinglePointEvent(type, device, localPos, windowPos, globalPos, button, buttons, modifiers)
1127{
1128 m_source = source;
1129}
1130
1131/*!
1132 \internal
1133*/
1134QMouseEvent::~QMouseEvent()
1135{
1136}
1137
1138/*!
1139 \since 5.3
1140 \deprecated in 6.0: use pointingDevice()
1141
1142 Returns information about the mouse event source.
1143
1144 The mouse event source can be used to distinguish between genuine
1145 and artificial mouse events. The latter are events that are
1146 synthesized from touch events by the operating system or Qt itself.
1147 This enum tells you from where it was synthesized; but often
1148 it's more useful to know from which device it was synthesized,
1149 so try to use pointingDevice() instead.
1150
1151 \note Many platforms provide no such information. On such platforms
1152 \l Qt::MouseEventNotSynthesized is returned always.
1153
1154 \sa Qt::MouseEventSource
1155 \sa QGraphicsSceneMouseEvent::source()
1156*/
1157Qt::MouseEventSource QMouseEvent::source() const
1158{
1159 return Qt::MouseEventSource(m_source);
1160}
1161
1162/*!
1163 \since 5.3
1164
1165 Returns the mouse event flags.
1166
1167 The mouse event flags provide additional information about a mouse event.
1168
1169 \sa Qt::MouseEventFlag
1170 \sa QGraphicsSceneMouseEvent::flags()
1171*/
1172Qt::MouseEventFlags QMouseEvent::flags() const
1173{
1174 return (m_doubleClick ? Qt::MouseEventCreatedDoubleClick : Qt::NoMouseEventFlag);
1175}
1176
1177/*!
1178 \fn QPointF QMouseEvent::localPos() const
1179
1180 \since 5.0
1181
1182 Returns the position of the mouse cursor as a QPointF, relative to the
1183 widget or item that received the event.
1184
1185 If you move the widget as a result of the mouse event, use the
1186 screen position returned by screenPos() to avoid a shaking
1187 motion.
1188
1189 \sa x(), y(), windowPos(), screenPos()
1190*/
1191
1192/*!
1193 \fn void QMouseEvent::setLocalPos(const QPointF &localPosition)
1194
1195 \since 5.8
1196
1197 \internal
1198
1199 Sets the local position in the mouse event to \a localPosition. This allows to re-use one event
1200 when sending it to a series of receivers that expect the local pos in their
1201 respective local coordinates.
1202*/
1203
1204/*!
1205 \fn QPointF QMouseEvent::windowPos() const
1206
1207 \since 5.0
1208
1209 Returns the position of the mouse cursor as a QPointF, relative to the
1210 window that received the event.
1211
1212 If you move the widget as a result of the mouse event, use the
1213 global position returned by globalPos() to avoid a shaking
1214 motion.
1215
1216 \sa x(), y(), pos(), localPos(), screenPos()
1217*/
1218
1219/*!
1220 \fn QPointF QMouseEvent::screenPos() const
1221
1222 \since 5.0
1223
1224 Returns the position of the mouse cursor as a QPointF, relative to the
1225 screen that received the event.
1226
1227 \sa x(), y(), pos(), localPos(), windowPos()
1228*/
1229
1230/*!
1231 \fn QPoint QMouseEvent::pos() const
1232
1233 Returns the position of the mouse cursor, relative to the widget
1234 that received the event.
1235
1236 If you move the widget as a result of the mouse event, use the
1237 global position returned by globalPos() to avoid a shaking
1238 motion.
1239
1240 \sa x(), y(), globalPos()
1241*/
1242
1243/*!
1244 \fn QPoint QMouseEvent::globalPos() const
1245
1246 Returns the global position of the mouse cursor \e{at the time
1247 of the event}. This is important on asynchronous window systems
1248 like X11. Whenever you move your widgets around in response to
1249 mouse events, globalPos() may differ a lot from the current
1250 pointer position QCursor::pos(), and from
1251 QWidget::mapToGlobal(pos()).
1252
1253 \sa globalX(), globalY()
1254*/
1255
1256/*!
1257 \fn int QMouseEvent::x() const
1258
1259 Returns the x position of the mouse cursor, relative to the
1260 widget that received the event.
1261
1262 \sa y(), pos()
1263*/
1264
1265/*!
1266 \fn int QMouseEvent::y() const
1267
1268 Returns the y position of the mouse cursor, relative to the
1269 widget that received the event.
1270
1271 \sa x(), pos()
1272*/
1273
1274/*!
1275 \fn int QMouseEvent::globalX() const
1276
1277 Returns the global x position of the mouse cursor at the time of
1278 the event.
1279
1280 \sa globalY(), globalPos()
1281*/
1282
1283/*!
1284 \fn int QMouseEvent::globalY() const
1285
1286 Returns the global y position of the mouse cursor at the time of
1287 the event.
1288
1289 \sa globalX(), globalPos()
1290*/
1291
1292/*!
1293 \class QHoverEvent
1294 \ingroup events
1295 \inmodule QtGui
1296
1297 \brief The QHoverEvent class contains parameters that describe a mouse event.
1298
1299 Mouse events occur when a mouse cursor is moved into, out of, or within a
1300 widget, and if the widget has the Qt::WA_Hover attribute.
1301
1302 The function pos() gives the current cursor position, while oldPos() gives
1303 the old mouse position.
1304
1305 There are a few similarities between the events QEvent::HoverEnter
1306 and QEvent::HoverLeave, and the events QEvent::Enter and QEvent::Leave.
1307 However, they are slightly different because we do an update() in the event
1308 handler of HoverEnter and HoverLeave.
1309
1310 QEvent::HoverMove is also slightly different from QEvent::MouseMove. Let us
1311 consider a top-level window A containing a child B which in turn contains a
1312 child C (all with mouse tracking enabled):
1313
1314 \image hoverevents.png
1315
1316 Now, if you move the cursor from the top to the bottom in the middle of A,
1317 you will get the following QEvent::MouseMove events:
1318
1319 \list 1
1320 \li A::MouseMove
1321 \li B::MouseMove
1322 \li C::MouseMove
1323 \endlist
1324
1325 You will get the same events for QEvent::HoverMove, except that the event
1326 always propagates to the top-level regardless whether the event is accepted
1327 or not. It will only stop propagating with the Qt::WA_NoMousePropagation
1328 attribute.
1329
1330 In this case the events will occur in the following way:
1331
1332 \list 1
1333 \li A::HoverMove
1334 \li A::HoverMove, B::HoverMove
1335 \li A::HoverMove, B::HoverMove, C::HoverMove
1336 \endlist
1337
1338*/
1339
1340/*!
1341 \fn QPoint QHoverEvent::pos() const
1342
1343 Returns the position of the mouse cursor, relative to the widget
1344 that received the event.
1345
1346 On QEvent::HoverLeave events, this position will always be
1347 QPoint(-1, -1).
1348
1349 \sa oldPos()
1350*/
1351
1352/*!
1353 \fn QPoint QHoverEvent::oldPos() const
1354
1355 Returns the previous position of the mouse cursor, relative to the widget
1356 that received the event. If there is no previous position, oldPos() will
1357 return the same position as pos().
1358
1359 On QEvent::HoverEnter events, this position will always be
1360 QPoint(-1, -1).
1361
1362 \sa pos()
1363*/
1364
1365/*!
1366 \fn const QPointF &QHoverEvent::posF() const
1367
1368 Returns the position of the mouse cursor, relative to the widget
1369 that received the event.
1370
1371 On QEvent::HoverLeave events, this position will always be
1372 QPointF(-1, -1).
1373
1374 \sa oldPosF()
1375*/
1376
1377/*!
1378 \fn const QPointF &QHoverEvent::oldPosF() const
1379
1380 Returns the previous position of the mouse cursor, relative to the widget
1381 that received the event. If there is no previous position, oldPosF() will
1382 return the same position as posF().
1383
1384 On QEvent::HoverEnter events, this position will always be
1385 QPointF(-1, -1).
1386
1387 \sa posF()
1388*/
1389
1390/*!
1391 Constructs a hover event object originating from \a device.
1392
1393 The \a type parameter must be QEvent::HoverEnter,
1394 QEvent::HoverLeave, or QEvent::HoverMove.
1395
1396 The \a pos is the current mouse cursor's position relative to the
1397 receiving widget, while \a oldPos is its previous such position.
1398 \a modifiers hold the state of all keyboard modifiers at the time
1399 of the event.
1400*/
1401QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos,
1402 Qt::KeyboardModifiers modifiers, const QPointingDevice *device)
1403 : QSinglePointEvent(type, device, pos, pos, pos, Qt::NoButton, Qt::NoButton, modifiers), m_oldPos(oldPos)
1404{
1405}
1406
1407/*!
1408 \internal
1409*/
1410QHoverEvent::~QHoverEvent()
1411{
1412}
1413
1414#if QT_CONFIG(wheelevent)
1415/*!
1416 \class QWheelEvent
1417 \brief The QWheelEvent class contains parameters that describe a wheel event.
1418 \inmodule QtGui
1419
1420 \ingroup events
1421
1422 Wheel events are sent to the widget under the mouse cursor, but
1423 if that widget does not handle the event they are sent to the
1424 focus widget. Wheel events are generated for both mouse wheels
1425 and trackpad scroll gestures. There are two ways to read the
1426 wheel event delta: angleDelta() returns the deltas in wheel
1427 degrees. These values are always provided. pixelDelta() returns
1428 the deltas in screen pixels, and is available on platforms that
1429 have high-resolution trackpads, such as \macos. If that is the
1430 case, device()->type() will return QInputDevice::DeviceType::Touchpad.
1431
1432 The functions position() and globalPosition() return the mouse cursor's
1433 location at the time of the event.
1434
1435 A wheel event contains a special accept flag that indicates
1436 whether the receiver wants the event. You should call ignore() if
1437 you do not handle the wheel event; this ensures that it will be
1438 sent to the parent widget.
1439
1440 The QWidget::setEnabled() function can be used to enable or
1441 disable mouse and keyboard events for a widget.
1442
1443 The event handler QWidget::wheelEvent() receives wheel events.
1444
1445 \sa QMouseEvent, QWidget::grabMouse()
1446*/
1447
1448/*!
1449 \enum QWheelEvent::anonymous
1450 \internal
1451
1452 \value DefaultDeltasPerStep Defaqult deltas per step
1453*/
1454
1455/*!
1456 \fn Qt::MouseEventSource QWheelEvent::source() const
1457 \since 5.5
1458 \deprecated in 6.0: use pointingDevice()
1459
1460 Returns information about the wheel event source.
1461
1462 The source can be used to distinguish between events that come from a mouse
1463 with a physical wheel and events that are generated by some other means,
1464 such as a flick gesture on a touchpad.
1465 This enum tells you from where it was synthesized; but often
1466 it's more useful to know from which device it was synthesized,
1467 so try to use pointingDevice() instead.
1468
1469 \note Many platforms provide no such information. On such platforms
1470 \l Qt::MouseEventNotSynthesized is returned always.
1471
1472 \sa Qt::MouseEventSource
1473*/
1474
1475/*!
1476 \fn bool QWheelEvent::inverted() const
1477 \since 5.7
1478
1479 Returns whether the delta values delivered with the event are inverted.
1480
1481 Normally, a vertical wheel will produce a QWheelEvent with positive delta
1482 values if the top of the wheel is rotating away from the hand operating it.
1483 Similarly, a horizontal wheel movement will produce a QWheelEvent with
1484 positive delta values if the top of the wheel is moved to the left.
1485
1486 However, on some platforms this is configurable, so that the same
1487 operations described above will produce negative delta values (but with the
1488 same magnitude). With the inverted property a wheel event consumer can
1489 choose to always follow the direction of the wheel, regardless of the
1490 system settings, but only for specific widgets. (One such use case could be
1491 that the user is rotating the wheel in the same direction as a visual
1492 Tumbler rotates. Another usecase is to make a slider handle follow the
1493 direction of movement of fingers on a touchpad regardless of system
1494 configuration.)
1495
1496 \note Many platforms provide no such information. On such platforms
1497 \l inverted always returns false.
1498*/
1499
1500/*!
1501 Constructs a wheel event object.
1502
1503 \since 5.12
1504 The \a pos provides the location of the mouse cursor
1505 within the window. The position in global coordinates is specified
1506 by \a globalPos.
1507
1508 \a pixelDelta contains the scrolling distance in pixels on screen, while
1509 \a angleDelta contains the wheel rotation angle. \a pixelDelta is
1510 optional and can be null.
1511
1512 The mouse and keyboard states at the time of the event are specified by
1513 \a buttons and \a modifiers.
1514
1515 The scrolling phase of the event is specified by \a phase, and the
1516 \a source indicates whether this is a genuine or artificial (synthesized)
1517 event.
1518
1519 If the system is configured to invert the delta values delivered with the
1520 event (such as natural scrolling of the touchpad on macOS), \a inverted
1521 should be \c true. Otherwise, \a inverted is \c false
1522
1523 The device from which the wheel event originated is specified by \a device.
1524
1525 \sa position(), globalPosition(), angleDelta(), pixelDelta(), phase(), inverted(), device()
1526*/
1527QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
1528 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
1529 bool inverted, Qt::MouseEventSource source, const QPointingDevice *device)
1530 : QSinglePointEvent(Wheel, device, pos, pos, globalPos, Qt::NoButton, buttons, modifiers),
1531 m_phase(phase), m_invertedScrolling(inverted), m_pixelDelta(pixelDelta), m_angleDelta(angleDelta)
1532{
1533 m_source = source;
1534}
1535
1536/*!
1537 \internal
1538*/
1539QWheelEvent::~QWheelEvent()
1540{
1541}
1542
1543/*!
1544 Returns \c true if this event's phase() is Qt::ScrollBegin.
1545*/
1546bool QWheelEvent::isBeginEvent() const
1547{
1548 return m_phase == Qt::ScrollBegin;
1549}
1550
1551/*!
1552 Returns \c true if this event's phase() is Qt::ScrollUpdate or Qt::ScrollMomentum.
1553*/
1554bool QWheelEvent::isUpdateEvent() const
1555{
1556 return m_phase == Qt::ScrollUpdate || m_phase == Qt::ScrollMomentum;
1557}
1558
1559/*!
1560 Returns \c true if this event's phase() is Qt::ScrollEnd.
1561*/
1562bool QWheelEvent::isEndEvent() const
1563{
1564 return m_phase == Qt::ScrollEnd;
1565}
1566
1567#endif // QT_CONFIG(wheelevent)
1568
1569/*!
1570 \fn QPoint QWheelEvent::pixelDelta() const
1571
1572 Returns the scrolling distance in pixels on screen. This value is
1573 provided on platforms that support high-resolution pixel-based
1574 delta values, such as \macos. The value should be used directly
1575 to scroll content on screen.
1576
1577 Example:
1578
1579 \snippet code/src_gui_kernel_qevent.cpp 0
1580
1581 \note On platforms that support scrolling \l{phase()}{phases}, the delta may be null when:
1582 \list
1583 \li scrolling is about to begin, but the distance did not yet change (Qt::ScrollBegin),
1584 \li or scrolling has ended and the distance did not change anymore (Qt::ScrollEnd).
1585 \endlist
1586 \note On X11 this value is driver specific and unreliable, use angleDelta() instead
1587*/
1588
1589/*!
1590 \fn QPoint QWheelEvent::angleDelta() const
1591
1592 Returns the relative amount that the wheel was rotated, in eighths of a
1593 degree. A positive value indicates that the wheel was rotated forwards away
1594 from the user; a negative value indicates that the wheel was rotated
1595 backwards toward the user. \c angleDelta().y() provides the angle through
1596 which the common vertical mouse wheel was rotated since the previous event.
1597 \c angleDelta().x() provides the angle through which the horizontal mouse
1598 wheel was rotated, if the mouse has a horizontal wheel; otherwise it stays
1599 at zero. Some mice allow the user to tilt the wheel to perform horizontal
1600 scrolling, and some touchpads support a horizontal scrolling gesture; that
1601 will also appear in \c angleDelta().x().
1602
1603 Most mouse types work in steps of 15 degrees, in which case the
1604 delta value is a multiple of 120; i.e., 120 units * 1/8 = 15 degrees.
1605
1606 However, some mice have finer-resolution wheels and send delta values
1607 that are less than 120 units (less than 15 degrees). To support this
1608 possibility, you can either cumulatively add the delta values from events
1609 until the value of 120 is reached, then scroll the widget, or you can
1610 partially scroll the widget in response to each wheel event. But to
1611 provide a more native feel, you should prefer \l pixelDelta() on platforms
1612 where it's available.
1613
1614 Example:
1615
1616 \snippet code/src_gui_kernel_qevent.cpp 0
1617
1618 \note On platforms that support scrolling \l{phase()}{phases}, the delta may be null when:
1619 \list
1620 \li scrolling is about to begin, but the distance did not yet change (Qt::ScrollBegin),
1621 \li or scrolling has ended and the distance did not change anymore (Qt::ScrollEnd).
1622 \endlist
1623
1624 \sa pixelDelta()
1625*/
1626
1627/*!
1628 \fn Qt::ScrollPhase QWheelEvent::phase() const
1629 \since 5.2
1630
1631 Returns the scrolling phase of this wheel event.
1632
1633 \note The Qt::ScrollBegin and Qt::ScrollEnd phases are currently
1634 supported only on \macos.
1635*/
1636
1637
1638/*!
1639 \class QKeyEvent
1640 \brief The QKeyEvent class describes a key event.
1641
1642 \ingroup events
1643 \inmodule QtGui
1644
1645 Key events are sent to the widget with keyboard input focus
1646 when keys are pressed or released.
1647
1648 A key event contains a special accept flag that indicates whether
1649 the receiver will handle the key event. This flag is set by default
1650 for QEvent::KeyPress and QEvent::KeyRelease, so there is no need to
1651 call accept() when acting on a key event. For QEvent::ShortcutOverride
1652 the receiver needs to explicitly accept the event to trigger the override.
1653 Calling ignore() on a key event will propagate it to the parent widget.
1654 The event is propagated up the parent widget chain until a widget
1655 accepts it or an event filter consumes it.
1656
1657 The QWidget::setEnabled() function can be used to enable or disable
1658 mouse and keyboard events for a widget.
1659
1660 The event handlers QWidget::keyPressEvent(), QWidget::keyReleaseEvent(),
1661 QGraphicsItem::keyPressEvent() and QGraphicsItem::keyReleaseEvent()
1662 receive key events.
1663
1664 \sa QFocusEvent, QWidget::grabKeyboard()
1665*/
1666
1667/*!
1668 Constructs a key event object.
1669
1670 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
1671 or QEvent::ShortcutOverride.
1672
1673 Int \a key is the code for the Qt::Key that the event loop should listen
1674 for. If \a key is 0, the event is not a result of a known key; for
1675 example, it may be the result of a compose sequence or keyboard macro.
1676 The \a modifiers holds the keyboard modifiers, and the given \a text
1677 is the Unicode text that the key generated. If \a autorep is true,
1678 isAutoRepeat() will be true. \a count is the number of keys involved
1679 in the event.
1680*/
1681QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
1682 bool autorep, ushort count)
1683 : QInputEvent(type, QInputDevice::primaryKeyboard(), modifiers), m_text(text), m_key(key),
1684 m_scanCode(0), m_virtualKey(0), m_modifiers(0),
1685 m_count(count), m_autoRepeat(autorep)
1686{
1687 if (type == QEvent::ShortcutOverride)
1688 ignore();
1689}
1690
1691/*!
1692 Constructs a key event object.
1693
1694 The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
1695 or QEvent::ShortcutOverride.
1696
1697 Int \a key is the code for the Qt::Key that the event loop should listen
1698 for. If \a key is 0, the event is not a result of a known key; for
1699 example, it may be the result of a compose sequence or keyboard macro.
1700 The \a modifiers holds the keyboard modifiers, and the given \a text
1701 is the Unicode text that the key generated. If \a autorep is true,
1702 isAutoRepeat() will be true. \a count is the number of keys involved
1703 in the event.
1704
1705 In addition to the normal key event data, also contains \a nativeScanCode,
1706 \a nativeVirtualKey and \a nativeModifiers. This extra data is used by the
1707 shortcut system, to determine which shortcuts to trigger.
1708*/
1709QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
1710 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
1711 const QString &text, bool autorep, ushort count, const QInputDevice *device)
1712 : QInputEvent(type, device, modifiers), m_text(text), m_key(key),
1713 m_scanCode(nativeScanCode), m_virtualKey(nativeVirtualKey), m_modifiers(nativeModifiers),
1714 m_count(count), m_autoRepeat(autorep)
1715{
1716 if (type == QEvent::ShortcutOverride)
1717 ignore();
1718}
1719
1720
1721/*!
1722 \internal
1723*/
1724QKeyEvent::~QKeyEvent()
1725{
1726}
1727
1728/*!
1729 \fn quint32 QKeyEvent::nativeScanCode() const
1730 \since 4.2
1731
1732 Returns the native scan code of the key event. If the key event
1733 does not contain this data 0 is returned.
1734
1735 Note: The native scan code may be 0, even if the key event contains
1736 extended information.
1737*/
1738
1739/*!
1740 \fn quint32 QKeyEvent::nativeVirtualKey() const
1741 \since 4.2
1742
1743 Returns the native virtual key, or key sym of the key event.
1744 If the key event does not contain this data 0 is returned.
1745
1746 Note: The native virtual key may be 0, even if the key event contains extended information.
1747*/
1748
1749/*!
1750 \fn quint32 QKeyEvent::nativeModifiers() const
1751 \since 4.2
1752
1753 Returns the native modifiers of a key event.
1754 If the key event does not contain this data 0 is returned.
1755
1756 Note: The native modifiers may be 0, even if the key event contains extended information.
1757*/
1758
1759/*!
1760 \fn int QKeyEvent::key() const
1761
1762 Returns the code of the key that was pressed or released.
1763
1764 See \l Qt::Key for the list of keyboard codes. These codes are
1765 independent of the underlying window system. Note that this
1766 function does not distinguish between capital and non-capital
1767 letters, use the text() function (returning the Unicode text the
1768 key generated) for this purpose.
1769
1770 A value of either 0 or Qt::Key_unknown means that the event is not
1771 the result of a known key; for example, it may be the result of
1772 a compose sequence, a keyboard macro, or due to key event
1773 compression.
1774
1775 \sa Qt::WA_KeyCompression
1776*/
1777
1778/*!
1779 \fn QString QKeyEvent::text() const
1780
1781 Returns the Unicode text that this key generated.
1782
1783 Return values when modifier keys such as
1784 Shift, Control, Alt, and Meta are pressed
1785 differ among platforms and could return an empty string.
1786
1787 \note \l key() will always return a valid value,
1788 independent of modifier keys.
1789
1790 \sa Qt::WA_KeyCompression
1791*/
1792
1793/*!
1794 Returns the keyboard modifier flags that existed immediately
1795 after the event occurred.
1796
1797 \warning This function cannot always be trusted. The user can
1798 confuse it by pressing both \uicontrol{Shift} keys simultaneously and
1799 releasing one of them, for example.
1800
1801 \sa QGuiApplication::keyboardModifiers()
1802*/
1803
1804Qt::KeyboardModifiers QKeyEvent::modifiers() const
1805{
1806 if (key() == Qt::Key_Shift)
1807 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ShiftModifier);
1808 if (key() == Qt::Key_Control)
1809 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::ControlModifier);
1810 if (key() == Qt::Key_Alt)
1811 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::AltModifier);
1812 if (key() == Qt::Key_Meta)
1813 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::MetaModifier);
1814 if (key() == Qt::Key_AltGr)
1815 return Qt::KeyboardModifiers(QInputEvent::modifiers()^Qt::GroupSwitchModifier);
1816 return QInputEvent::modifiers();
1817}
1818
1819/*!
1820 \fn QKeyCombination QKeyEvent::keyCombination() const
1821
1822 Returns a QKeyCombination object containing both the key() and
1823 the modifiers() carried by this event.
1824
1825 \since 6.0
1826*/
1827
1828#if QT_CONFIG(shortcut)
1829/*!
1830 \fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
1831 \since 4.2
1832
1833 Returns \c true if the key event matches the given standard \a key;
1834 otherwise returns \c false.
1835*/
1836bool QKeyEvent::matches(QKeySequence::StandardKey matchKey) const
1837{
1838 //The keypad and group switch modifier should not make a difference
1839 uint searchkey = (modifiers() | key()) & ~(Qt::KeypadModifier | Qt::GroupSwitchModifier);
1840
1841 const QList<QKeySequence> bindings = QKeySequence::keyBindings(matchKey);
1842 return bindings.contains(QKeySequence(searchkey));
1843}
1844#endif // QT_CONFIG(shortcut)
1845
1846
1847/*!
1848 \fn bool QKeyEvent::isAutoRepeat() const
1849
1850 Returns \c true if this event comes from an auto-repeating key;
1851 returns \c false if it comes from an initial key press.
1852
1853 Note that if the event is a multiple-key compressed event that is
1854 partly due to auto-repeat, this function could return either true
1855 or false indeterminately.
1856*/
1857
1858/*!
1859 \fn int QKeyEvent::count() const
1860
1861 Returns the number of keys involved in this event. If text()
1862 is not empty, this is simply the length of the string.
1863
1864 \sa Qt::WA_KeyCompression
1865*/
1866
1867/*!
1868 \class QFocusEvent
1869 \brief The QFocusEvent class contains event parameters for widget focus
1870 events.
1871 \inmodule QtGui
1872
1873 \ingroup events
1874
1875 Focus events are sent to widgets when the keyboard input focus
1876 changes. Focus events occur due to mouse actions, key presses
1877 (such as \uicontrol{Tab} or \uicontrol{Backtab}), the window system, popup
1878 menus, keyboard shortcuts, or other application-specific reasons.
1879 The reason for a particular focus event is returned by reason()
1880 in the appropriate event handler.
1881
1882 The event handlers QWidget::focusInEvent(),
1883 QWidget::focusOutEvent(), QGraphicsItem::focusInEvent and
1884 QGraphicsItem::focusOutEvent() receive focus events.
1885
1886 \sa QWidget::setFocus(), QWidget::setFocusPolicy(), {Keyboard Focus in Widgets}
1887*/
1888
1889/*!
1890 Constructs a focus event object.
1891
1892 The \a type parameter must be either QEvent::FocusIn or
1893 QEvent::FocusOut. The \a reason describes the cause of the change
1894 in focus.
1895*/
1896QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason)
1897 : QEvent(type), m_reason(reason)
1898{}
1899
1900/*!
1901 \internal
1902*/
1903QFocusEvent::~QFocusEvent()
1904{
1905}
1906
1907/*!
1908 Returns the reason for this focus event.
1909 */
1910Qt::FocusReason QFocusEvent::reason() const
1911{
1912 return m_reason;
1913}
1914
1915/*!
1916 \fn bool QFocusEvent::gotFocus() const
1917
1918 Returns \c true if type() is QEvent::FocusIn; otherwise returns
1919 false.
1920*/
1921
1922/*!
1923 \fn bool QFocusEvent::lostFocus() const
1924
1925 Returns \c true if type() is QEvent::FocusOut; otherwise returns
1926 false.
1927*/
1928
1929
1930/*!
1931 \class QPaintEvent
1932 \brief The QPaintEvent class contains event parameters for paint events.
1933 \inmodule QtGui
1934
1935 \ingroup events
1936
1937 Paint events are sent to widgets that need to update themselves,
1938 for instance when part of a widget is exposed because a covering
1939 widget was moved.
1940
1941 The event contains a region() that needs to be updated, and a
1942 rect() that is the bounding rectangle of that region. Both are
1943 provided because many widgets cannot make much use of region(),
1944 and rect() can be much faster than region().boundingRect().
1945
1946 \section1 Automatic Clipping
1947
1948 Painting is clipped to region() during the processing of a paint
1949 event. This clipping is performed by Qt's paint system and is
1950 independent of any clipping that may be applied to a QPainter used to
1951 draw on the paint device.
1952
1953 As a result, the value returned by QPainter::clipRegion() on
1954 a newly-constructed QPainter will not reflect the clip region that is
1955 used by the paint system.
1956
1957 \sa QPainter, QWidget::update(), QWidget::repaint(),
1958 QWidget::paintEvent()
1959*/
1960
1961/*!
1962 Constructs a paint event object with the region that needs to
1963 be updated. The region is specified by \a paintRegion.
1964*/
1965QPaintEvent::QPaintEvent(const QRegion& paintRegion)
1966 : QEvent(Paint), m_rect(paintRegion.boundingRect()), m_region(paintRegion), m_erased(false)
1967{}
1968
1969/*!
1970 Constructs a paint event object with the rectangle that needs
1971 to be updated. The region is specified by \a paintRect.
1972*/
1973QPaintEvent::QPaintEvent(const QRect &paintRect)
1974 : QEvent(Paint), m_rect(paintRect),m_region(paintRect), m_erased(false)
1975{}
1976
1977
1978/*!
1979 \internal
1980*/
1981QPaintEvent::~QPaintEvent()
1982{
1983}
1984
1985/*!
1986 \fn const QRect &QPaintEvent::rect() const
1987
1988 Returns the rectangle that needs to be updated.
1989
1990 \sa region(), QPainter::setClipRect()
1991*/
1992
1993/*!
1994 \fn const QRegion &QPaintEvent::region() const
1995
1996 Returns the region that needs to be updated.
1997
1998 \sa rect(), QPainter::setClipRegion()
1999*/
2000
2001
2002/*!
2003 \class QMoveEvent
2004 \brief The QMoveEvent class contains event parameters for move events.
2005 \inmodule QtGui
2006
2007 \ingroup events
2008
2009 Move events are sent to widgets that have been moved to a new
2010 position relative to their parent.
2011
2012 The event handler QWidget::moveEvent() receives move events.
2013
2014 \sa QWidget::move(), QWidget::setGeometry()
2015*/
2016
2017/*!
2018 Constructs a move event with the new and old widget positions,
2019 \a pos and \a oldPos respectively.
2020*/
2021QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos)
2022 : QEvent(Move), m_pos(pos), m_oldPos(oldPos)
2023{}
2024
2025/*!
2026 \internal
2027*/
2028QMoveEvent::~QMoveEvent()
2029{
2030}
2031
2032/*!
2033 \fn const QPoint &QMoveEvent::pos() const
2034
2035 Returns the new position of the widget. This excludes the window
2036 frame for top level widgets.
2037*/
2038
2039/*!
2040 \fn const QPoint &QMoveEvent::oldPos() const
2041
2042 Returns the old position of the widget.
2043*/
2044
2045/*!
2046 \class QExposeEvent
2047 \since 5.0
2048 \brief The QExposeEvent class contains event parameters for expose events.
2049 \inmodule QtGui
2050
2051 \ingroup events
2052
2053 Expose events are sent to windows when they move between the un-exposed and
2054 exposed states.
2055
2056 An exposed window is potentially visible to the user. If the window is moved
2057 off screen, is made totally obscured by another window, is minimized, or
2058 similar, an expose event is sent to the window, and isExposed() might
2059 change to false.
2060
2061 Expose events should not be used to paint. Handle QPaintEvent
2062 instead.
2063
2064 The event handler QWindow::exposeEvent() receives expose events.
2065*/
2066
2067/*!
2068 Constructs an expose event for the given \a exposeRegion which must be
2069 in local coordinates.
2070*/
2071QExposeEvent::QExposeEvent(const QRegion &exposeRegion)
2072 : QEvent(Expose)
2073 , m_region(exposeRegion)
2074{
2075}
2076
2077/*!
2078 \internal
2079*/
2080QExposeEvent::~QExposeEvent()
2081{
2082}
2083
2084/*!
2085 \class QPlatformSurfaceEvent
2086 \since 5.5
2087 \brief The QPlatformSurfaceEvent class is used to notify about native platform surface events.
2088 \inmodule QtGui
2089
2090 \ingroup events
2091
2092 Platform window events are synchronously sent to windows and offscreen surfaces when their
2093 underlying native surfaces are created or are about to be destroyed.
2094
2095 Applications can respond to these events to know when the underlying platform
2096 surface exists.
2097*/
2098
2099/*!
2100 \enum QPlatformSurfaceEvent::SurfaceEventType
2101
2102 This enum describes the type of platform surface event. The possible types are:
2103
2104 \value SurfaceCreated The underlying native surface has been created
2105 \value SurfaceAboutToBeDestroyed The underlying native surface will be destroyed immediately after this event
2106
2107 The \c SurfaceAboutToBeDestroyed event type is useful as a means of stopping rendering to
2108 a platform window before it is destroyed.
2109*/
2110
2111/*!
2112 \fn QPlatformSurfaceEvent::SurfaceEventType QPlatformSurfaceEvent::surfaceEventType() const
2113
2114 Returns the specific type of platform surface event.
2115*/
2116
2117/*!
2118 Constructs a platform surface event for the given \a surfaceEventType.
2119*/
2120QPlatformSurfaceEvent::QPlatformSurfaceEvent(SurfaceEventType surfaceEventType)
2121 : QEvent(PlatformSurface)
2122 , m_surfaceEventType(surfaceEventType)
2123{
2124}
2125
2126/*!
2127 \internal
2128*/
2129QPlatformSurfaceEvent::~QPlatformSurfaceEvent()
2130{
2131}
2132
2133/*!
2134 \fn const QRegion &QExposeEvent::region() const
2135
2136 Returns the window area that has been exposed. The region is given in local coordinates.
2137*/
2138
2139/*!
2140 \class QResizeEvent
2141 \brief The QResizeEvent class contains event parameters for resize events.
2142 \inmodule QtGui
2143
2144 \ingroup events
2145
2146 Resize events are sent to widgets that have been resized.
2147
2148 The event handler QWidget::resizeEvent() receives resize events.
2149
2150 \sa QWidget::resize(), QWidget::setGeometry()
2151*/
2152
2153/*!
2154 Constructs a resize event with the new and old widget sizes, \a
2155 size and \a oldSize respectively.
2156*/
2157QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
2158 : QEvent(Resize), m_size(size), m_oldSize(oldSize)
2159{}
2160
2161/*!
2162 \internal
2163*/
2164QResizeEvent::~QResizeEvent()
2165{
2166}
2167
2168/*!
2169 \fn const QSize &QResizeEvent::size() const
2170
2171 Returns the new size of the widget. This is the same as
2172 QWidget::size().
2173*/
2174
2175/*!
2176 \fn const QSize &QResizeEvent::oldSize() const
2177
2178 Returns the old size of the widget.
2179*/
2180
2181
2182/*!
2183 \class QCloseEvent
2184 \brief The QCloseEvent class contains parameters that describe a close event.
2185
2186 \ingroup events
2187 \inmodule QtGui
2188
2189 Close events are sent to widgets that the user wants to close,
2190 usually by choosing "Close" from the window menu, or by clicking
2191 the \uicontrol{X} title bar button. They are also sent when you call
2192 QWidget::close() to close a widget programmatically.
2193
2194 Close events contain a flag that indicates whether the receiver
2195 wants the widget to be closed or not. When a widget accepts the
2196 close event, it is hidden (and destroyed if it was created with
2197 the Qt::WA_DeleteOnClose flag). If it refuses to accept the close
2198 event nothing happens. (Under X11 it is possible that the window
2199 manager will forcibly close the window; but at the time of writing
2200 we are not aware of any window manager that does this.)
2201
2202 The event handler QWidget::closeEvent() receives close events. The
2203 default implementation of this event handler accepts the close
2204 event. If you do not want your widget to be hidden, or want some
2205 special handling, you should reimplement the event handler and
2206 ignore() the event.
2207
2208 The \l{mainwindows/application#close event handler}{closeEvent() in the
2209 Application example} shows a close event handler that
2210 asks whether to save a document before closing.
2211
2212 If you want the widget to be deleted when it is closed, create it
2213 with the Qt::WA_DeleteOnClose flag. This is very useful for
2214 independent top-level windows in a multi-window application.
2215
2216 \l{QObject}s emits the \l{QObject::destroyed()}{destroyed()}
2217 signal when they are deleted.
2218
2219 If the last top-level window is closed, the
2220 QGuiApplication::lastWindowClosed() signal is emitted.
2221
2222 The isAccepted() function returns \c true if the event's receiver has
2223 agreed to close the widget; call accept() to agree to close the
2224 widget and call ignore() if the receiver of this event does not
2225 want the widget to be closed.
2226
2227 \sa QWidget::close(), QWidget::hide(), QObject::destroyed(),
2228 QCoreApplication::exec(), QCoreApplication::quit(),
2229 QGuiApplication::lastWindowClosed()
2230*/
2231
2232/*!
2233 Constructs a close event object.
2234
2235 \sa accept()
2236*/
2237QCloseEvent::QCloseEvent()
2238 : QEvent(Close)
2239{}
2240
2241/*! \internal
2242*/
2243QCloseEvent::~QCloseEvent()
2244{
2245}
2246
2247/*!
2248 \class QIconDragEvent
2249 \brief The QIconDragEvent class indicates that a main icon drag has begun.
2250 \inmodule QtGui
2251
2252 \ingroup events
2253
2254 Icon drag events are sent to widgets when the main icon of a window
2255 has been dragged away. On \macos, this happens when the proxy
2256 icon of a window is dragged off the title bar.
2257
2258 It is normal to begin using drag and drop in response to this
2259 event.
2260
2261 \sa {Drag and Drop}, QMimeData, QDrag
2262*/
2263
2264/*!
2265 Constructs an icon drag event object with the accept flag set to
2266 false.
2267
2268 \sa accept()
2269*/
2270QIconDragEvent::QIconDragEvent()
2271 : QEvent(IconDrag)
2272{ ignore(); }
2273
2274/*! \internal */
2275QIconDragEvent::~QIconDragEvent()
2276{
2277}
2278
2279/*!
2280 \class QContextMenuEvent
2281 \brief The QContextMenuEvent class contains parameters that describe a context menu event.
2282 \inmodule QtGui
2283
2284 \ingroup events
2285
2286 Context menu events are sent to widgets when a user performs
2287 an action associated with opening a context menu.
2288 The actions required to open context menus vary between platforms;
2289 for example, on Windows, pressing the menu button or clicking the
2290 right mouse button will cause this event to be sent.
2291
2292 When this event occurs it is customary to show a QMenu with a
2293 context menu, if this is relevant to the context.
2294
2295 Context menu events contain a special accept flag that indicates
2296 whether the receiver accepted the event. If the event handler does
2297 not accept the event then, if possible, whatever triggered the event will be
2298 handled as a regular input event.
2299*/
2300
2301#ifndef QT_NO_CONTEXTMENU
2302/*!
2303 Constructs a context menu event object with the accept parameter
2304 flag set to false.
2305
2306 The \a reason parameter must be QContextMenuEvent::Mouse or
2307 QContextMenuEvent::Keyboard.
2308
2309 The \a pos parameter specifies the mouse position relative to the
2310 receiving widget. \a globalPos is the mouse position in absolute
2311 coordinates.
2312*/
2313QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos)
2314 : QContextMenuEvent(reason, pos, globalPos, Qt::NoModifier)
2315{}
2316
2317/*!
2318 Constructs a context menu event object with the accept parameter
2319 flag set to false.
2320
2321 The \a reason parameter must be QContextMenuEvent::Mouse or
2322 QContextMenuEvent::Keyboard.
2323
2324 The \a pos parameter specifies the mouse position relative to the
2325 receiving widget. \a globalPos is the mouse position in absolute
2326 coordinates. The \a modifiers holds the keyboard modifiers.
2327*/
2328QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
2329 Qt::KeyboardModifiers modifiers)
2330 : QInputEvent(ContextMenu, QPointingDevice::primaryPointingDevice(), modifiers), m_pos(pos), m_globalPos(globalPos), m_reason(reason)
2331{}
2332
2333
2334/*! \internal */
2335QContextMenuEvent::~QContextMenuEvent()
2336{
2337}
2338/*!
2339 Constructs a context menu event object with the accept parameter
2340 flag set to false.
2341
2342 The \a reason parameter must be QContextMenuEvent::Mouse or
2343 QContextMenuEvent::Keyboard.
2344
2345 The \a pos parameter specifies the mouse position relative to the
2346 receiving widget.
2347
2348 The globalPos() is initialized to QCursor::pos(), which may not be
2349 appropriate. Use the other constructor to specify the global
2350 position explicitly.
2351*/
2352QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
2353 : QInputEvent(ContextMenu, QInputDevice::primaryKeyboard()), m_pos(pos), m_reason(reason)
2354{
2355#ifndef QT_NO_CURSOR
2356 m_globalPos = QCursor::pos();
2357#endif
2358}
2359
2360/*!
2361 \fn const QPoint &QContextMenuEvent::pos() const
2362
2363 Returns the position of the mouse pointer relative to the widget
2364 that received the event.
2365
2366 \sa x(), y(), globalPos()
2367*/
2368
2369/*!
2370 \fn int QContextMenuEvent::x() const
2371
2372 Returns the x position of the mouse pointer, relative to the
2373 widget that received the event.
2374
2375 \sa y(), pos()
2376*/
2377
2378/*!
2379 \fn int QContextMenuEvent::y() const
2380
2381 Returns the y position of the mouse pointer, relative to the
2382 widget that received the event.
2383
2384 \sa x(), pos()
2385*/
2386
2387/*!
2388 \fn const QPoint &QContextMenuEvent::globalPos() const
2389
2390 Returns the global position of the mouse pointer at the time of
2391 the event.
2392
2393 \sa x(), y(), pos()
2394*/
2395
2396/*!
2397 \fn int QContextMenuEvent::globalX() const
2398
2399 Returns the global x position of the mouse pointer at the time of
2400 the event.
2401
2402 \sa globalY(), globalPos()
2403*/
2404
2405/*!
2406 \fn int QContextMenuEvent::globalY() const
2407
2408 Returns the global y position of the mouse pointer at the time of
2409 the event.
2410
2411 \sa globalX(), globalPos()
2412*/
2413#endif // QT_NO_CONTEXTMENU
2414
2415/*!
2416 \enum QContextMenuEvent::Reason
2417
2418 This enum describes the reason why the event was sent.
2419
2420 \value Mouse The mouse caused the event to be sent. Normally this
2421 means the right mouse button was clicked, but this is platform
2422 dependent.
2423
2424 \value Keyboard The keyboard caused this event to be sent. On
2425 Windows, this means the menu button was pressed.
2426
2427 \value Other The event was sent by some other means (i.e. not by
2428 the mouse or keyboard).
2429*/
2430
2431
2432/*!
2433 \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
2434
2435 Returns the reason for this context event.
2436*/
2437
2438
2439/*!
2440 \class QInputMethodEvent
2441 \brief The QInputMethodEvent class provides parameters for input method events.
2442 \inmodule QtGui
2443
2444 \ingroup events
2445
2446 Input method events are sent to widgets when an input method is
2447 used to enter text into a widget. Input methods are widely used
2448 to enter text for languages with non-Latin alphabets.
2449
2450 Note that when creating custom text editing widgets, the
2451 Qt::WA_InputMethodEnabled window attribute must be set explicitly
2452 (using the QWidget::setAttribute() function) in order to receive
2453 input method events.
2454
2455 The events are of interest to authors of keyboard entry widgets
2456 who want to be able to correctly handle languages with complex
2457 character input. Text input in such languages is usually a three
2458 step process:
2459
2460 \list 1
2461 \li \b{Starting to Compose}
2462
2463 When the user presses the first key on a keyboard, an input
2464 context is created. This input context will contain a string
2465 of the typed characters.
2466
2467 \li \b{Composing}
2468
2469 With every new key pressed, the input method will try to create a
2470 matching string for the text typed so far called preedit
2471 string. While the input context is active, the user can only move
2472 the cursor inside the string belonging to this input context.
2473
2474 \li \b{Completing}
2475
2476 At some point, the user will activate a user interface component
2477 (perhaps using a particular key) where they can choose from a
2478 number of strings matching the text they have typed so far. The
2479 user can either confirm their choice cancel the input; in either
2480 case the input context will be closed.
2481 \endlist
2482
2483 QInputMethodEvent models these three stages, and transfers the
2484 information needed to correctly render the intermediate result. A
2485 QInputMethodEvent has two main parameters: preeditString() and
2486 commitString(). The preeditString() parameter gives the currently
2487 active preedit string. The commitString() parameter gives a text
2488 that should get added to (or replace parts of) the text of the
2489 editor widget. It usually is a result of the input operations and
2490 has to be inserted to the widgets text directly before the preedit
2491 string.
2492
2493 If the commitString() should replace parts of the of the text in
2494 the editor, replacementLength() will contain the number of
2495 characters to be replaced. replacementStart() contains the position
2496 at which characters are to be replaced relative from the start of
2497 the preedit string.
2498
2499 A number of attributes control the visual appearance of the
2500 preedit string (the visual appearance of text outside the preedit
2501 string is controlled by the widget only). The AttributeType enum
2502 describes the different attributes that can be set.
2503
2504 A class implementing QWidget::inputMethodEvent() or
2505 QGraphicsItem::inputMethodEvent() should at least understand and
2506 honor the \l TextFormat and \l Cursor attributes.
2507
2508 Since input methods need to be able to query certain properties
2509 from the widget or graphics item, subclasses must also implement
2510 QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
2511 respectively.
2512
2513 When receiving an input method event, the text widget has to performs the
2514 following steps:
2515
2516 \list 1
2517 \li If the widget has selected text, the selected text should get
2518 removed.
2519
2520 \li Remove the text starting at replacementStart() with length
2521 replacementLength() and replace it by the commitString(). If
2522 replacementLength() is 0, replacementStart() gives the insertion
2523 position for the commitString().
2524
2525 When doing replacement the area of the preedit
2526 string is ignored, thus a replacement starting at -1 with a length
2527 of 2 will remove the last character before the preedit string and
2528 the first character afterwards, and insert the commit string
2529 directly before the preedit string.
2530
2531 If the widget implements undo/redo, this operation gets added to
2532 the undo stack.
2533
2534 \li If there is no current preedit string, insert the
2535 preeditString() at the current cursor position; otherwise replace
2536 the previous preeditString with the one received from this event.
2537
2538 If the widget implements undo/redo, the preeditString() should not
2539 influence the undo/redo stack in any way.
2540
2541 The widget should examine the list of attributes to apply to the
2542 preedit string. It has to understand at least the TextFormat and
2543 Cursor attributes and render them as specified.
2544 \endlist
2545
2546 \sa QInputMethod
2547*/
2548
2549/*!
2550 \enum QInputMethodEvent::AttributeType
2551
2552 \value TextFormat
2553 A QTextCharFormat for the part of the preedit string specified by
2554 start and length. value contains a QVariant of type QTextFormat
2555 specifying rendering of this part of the preedit string. There
2556 should be at most one format for every part of the preedit
2557 string. If several are specified for any character in the string the
2558 behaviour is undefined. A conforming implementation has to at least
2559 honor the backgroundColor, textColor and fontUnderline properties
2560 of the format.
2561
2562 \value Cursor If set, a cursor should be shown inside the preedit
2563 string at position start. The length variable determines whether
2564 the cursor is visible or not. If the length is 0 the cursor is
2565 invisible. If value is a QVariant of type QColor this color will
2566 be used for rendering the cursor, otherwise the color of the
2567 surrounding text will be used. There should be at most one Cursor
2568 attribute per event. If several are specified the behaviour is
2569 undefined.
2570
2571 \value Language
2572 The variant contains a QLocale object specifying the language of a
2573 certain part of the preedit string. There should be at most one
2574 language set for every part of the preedit string. If several are
2575 specified for any character in the string the behavior is undefined.
2576
2577 \value Ruby
2578 The ruby text for a part of the preedit string. There should be at
2579 most one ruby text set for every part of the preedit string. If
2580 several are specified for any character in the string the behaviour
2581 is undefined.
2582
2583 \value Selection
2584 If set, the edit cursor should be moved to the specified position
2585 in the editor text contents. In contrast with \c Cursor, this
2586 attribute does not work on the preedit text, but on the surrounding
2587 text. The cursor will be moved after the commit string has been
2588 committed, and the preedit string will be located at the new edit
2589 position.
2590 The start position specifies the new position and the length
2591 variable can be used to set a selection starting from that point.
2592 The value is unused.
2593
2594 \sa Attribute
2595*/
2596
2597/*!
2598 \class QInputMethodEvent::Attribute
2599 \inmodule QtGui
2600 \brief The QInputMethodEvent::Attribute class stores an input method attribute.
2601*/
2602
2603/*!
2604 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
2605
2606 Constructs an input method attribute. \a type specifies the type
2607 of attribute, \a start and \a length the position of the
2608 attribute, and \a value the value of the attribute.
2609*/
2610
2611/*!
2612 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length)
2613 \overload
2614 \since 5.7
2615
2616 Constructs an input method attribute with no value. \a type
2617 specifies the type of attribute, and \a start and \a length
2618 the position of the attribute.
2619*/
2620
2621/*!
2622 Constructs an event of type QEvent::InputMethod. The
2623 attributes(), preeditString(), commitString(), replacementStart(),
2624 and replacementLength() are initialized to default values.
2625
2626 \sa setCommitString()
2627*/
2628QInputMethodEvent::QInputMethodEvent()
2629 : QEvent(QEvent::InputMethod), m_replacementStart(0), m_replacementLength(0)
2630{
2631}
2632
2633/*!
2634 Constructs an event of type QEvent::InputMethod. The
2635 preedit text is set to \a preeditText, the attributes to
2636 \a attributes.
2637
2638 The commitString(), replacementStart(), and replacementLength()
2639 values can be set using setCommitString().
2640
2641 \sa preeditString(), attributes()
2642*/
2643QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
2644 : QEvent(QEvent::InputMethod), m_preedit(preeditText), m_attributes(attributes),
2645 m_replacementStart(0), m_replacementLength(0)
2646{
2647}
2648
2649/*!
2650 Constructs a copy of \a other.
2651*/
2652QInputMethodEvent::QInputMethodEvent(const QInputMethodEvent &other)
2653 : QEvent(QEvent::InputMethod), m_preedit(other.m_preedit), m_attributes(other.m_attributes),
2654 m_commit(other.m_commit), m_replacementStart(other.m_replacementStart), m_replacementLength(other.m_replacementLength)
2655{
2656}
2657
2658QInputMethodEvent::~QInputMethodEvent()
2659{
2660}
2661
2662/*!
2663 Sets the commit string to \a commitString.
2664
2665 The commit string is the text that should get added to (or
2666 replace parts of) the text of the editor widget. It usually is a
2667 result of the input operations and has to be inserted to the
2668 widgets text directly before the preedit string.
2669
2670 If the commit string should replace parts of the of the text in
2671 the editor, \a replaceLength specifies the number of
2672 characters to be replaced. \a replaceFrom specifies the position
2673 at which characters are to be replaced relative from the start of
2674 the preedit string.
2675
2676 \sa commitString(), replacementStart(), replacementLength()
2677*/
2678void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
2679{
2680 m_commit = commitString;
2681 m_replacementStart = replaceFrom;
2682 m_replacementLength = replaceLength;
2683}
2684
2685/*!
2686 \fn const QList<Attribute> &QInputMethodEvent::attributes() const
2687
2688 Returns the list of attributes passed to the QInputMethodEvent
2689 constructor. The attributes control the visual appearance of the
2690 preedit string (the visual appearance of text outside the preedit
2691 string is controlled by the widget only).
2692
2693 \sa preeditString(), Attribute
2694*/
2695
2696/*!
2697 \fn const QString &QInputMethodEvent::preeditString() const
2698
2699 Returns the preedit text, i.e. the text before the user started
2700 editing it.
2701
2702 \sa commitString(), attributes()
2703*/
2704
2705/*!
2706 \fn const QString &QInputMethodEvent::commitString() const
2707
2708 Returns the text that should get added to (or replace parts of)
2709 the text of the editor widget. It usually is a result of the
2710 input operations and has to be inserted to the widgets text
2711 directly before the preedit string.
2712
2713 \sa setCommitString(), preeditString(), replacementStart(), replacementLength()
2714*/
2715
2716/*!
2717 \fn int QInputMethodEvent::replacementStart() const
2718
2719 Returns the position at which characters are to be replaced relative
2720 from the start of the preedit string.
2721
2722 \sa replacementLength(), setCommitString()
2723*/
2724
2725/*!
2726 \fn int QInputMethodEvent::replacementLength() const
2727
2728 Returns the number of characters to be replaced in the preedit
2729 string.
2730
2731 \sa replacementStart(), setCommitString()
2732*/
2733
2734/*!
2735 \class QInputMethodQueryEvent
2736 \since 5.0
2737 \inmodule QtGui
2738
2739 \brief The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
2740
2741 It is used by the
2742 input method to query a set of properties of the object to be
2743 able to support complex input method operations as support for
2744 surrounding text and reconversions.
2745
2746 queries() specifies which properties are queried.
2747
2748 The object should call setValue() on the event to fill in the requested
2749 data before calling accept().
2750*/
2751
2752/*!
2753 \fn Qt::InputMethodQueries QInputMethodQueryEvent::queries() const
2754
2755 Returns the properties queried by the event.
2756 */
2757
2758/*!
2759 Constructs a query event for properties given by \a queries.
2760 */
2761QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries)
2762 : QEvent(InputMethodQuery),
2763 m_queries(queries)
2764{
2765}
2766
2767/*!
2768 \internal
2769 */
2770QInputMethodQueryEvent::~QInputMethodQueryEvent()
2771{
2772}
2773
2774/*!
2775 Sets property \a query to \a value.
2776 */
2777void QInputMethodQueryEvent::setValue(Qt::InputMethodQuery query, const QVariant &value)
2778{
2779 for (int i = 0; i < m_values.size(); ++i) {
2780 if (m_values.at(i).query == query) {
2781 m_values[i].value = value;
2782 return;
2783 }
2784 }
2785 QueryPair pair = { query, value };
2786 m_values.append(pair);
2787}
2788
2789/*!
2790 Returns value of the property \a query.
2791 */
2792QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
2793{
2794 for (int i = 0; i < m_values.size(); ++i)
2795 if (m_values.at(i).query == query)
2796 return m_values.at(i).value;
2797 return QVariant();
2798}
2799
2800#if QT_CONFIG(tabletevent)
2801
2802/*!
2803 \class QTabletEvent
2804 \brief The QTabletEvent class contains parameters that describe a Tablet event.
2805 \inmodule QtGui
2806
2807 \ingroup events
2808
2809 \e{Tablet events} are generated from tablet peripherals such as Wacom
2810 tablets and various other brands, and electromagnetic stylus devices
2811 included with some types of tablet computers. (It is not the same as
2812 \l QTouchEvent which a touchscreen generates, even when a passive stylus is
2813 used on a touchscreen.)
2814
2815 Tablet events are similar to mouse events; for example, the \l x(), \l y(),
2816 \l pos(), \l globalX(), \l globalY(), and \l globalPos() accessors provide
2817 the cursor position, and you can see which \l buttons() are pressed
2818 (pressing the stylus tip against the tablet surface is equivalent to a left
2819 mouse button). But tablet events also pass through some extra information
2820 that the tablet device driver provides; for example, you might want to do
2821 subpixel rendering with higher resolution coordinates (\l globalPosF()),
2822 adjust color brightness based on the \l pressure() of the tool against the
2823 tablet surface, use different brushes depending on the type of tool in use
2824 (\l deviceType()), modulate the brush shape in some way according to the
2825 X-axis and Y-axis tilt of the tool with respect to the tablet surface
2826 (\l xTilt() and \l yTilt()), and use a virtual eraser instead of a brush if
2827 the user switches to the other end of a double-ended stylus
2828 (\l pointerType()).
2829
2830 Every event contains an accept flag that indicates whether the receiver
2831 wants the event. You should call QTabletEvent::accept() if you handle the
2832 tablet event; otherwise it will be sent to the parent widget. The exception
2833 are TabletEnterProximity and TabletLeaveProximity events: these are only
2834 sent to QApplication and do not check whether or not they are accepted.
2835
2836 The QWidget::setEnabled() function can be used to enable or disable
2837 mouse, tablet and keyboard events for a widget.
2838
2839 The event handler QWidget::tabletEvent() receives TabletPress,
2840 TabletRelease and TabletMove events. Qt will first send a
2841 tablet event, then if it is not accepted by any widget, it will send a
2842 mouse event. This allows users of applications that are not designed for
2843 tablets to use a tablet like a mouse. However high-resolution drawing
2844 applications should handle the tablet events, because they can occur at a
2845 higher frequency, which is a benefit for smooth and accurate drawing.
2846 If the tablet events are rejected, the synthetic mouse events may be
2847 compressed for efficiency.
2848
2849 Note that pressing the stylus button while the stylus hovers over the
2850 tablet will generate a button press on some types of tablets, while on
2851 other types it will be necessary to press the stylus against the tablet
2852 surface in order to register the simultaneous stylus button press.
2853
2854 \section1 Notes for X11 Users
2855
2856 If the tablet is configured in xorg.conf to use the Wacom driver, there
2857 will be separate XInput "devices" for the stylus, eraser, and (optionally)
2858 cursor and touchpad. Qt recognizes these by their names. Otherwise, if the
2859 tablet is configured to use the evdev driver, there will be only one device
2860 and applications may not be able to distinguish the stylus from the eraser.
2861
2862 \section1 Notes for Windows Users
2863
2864 Tablet support currently requires the WACOM windows driver providing the DLL
2865 \c{wintab32.dll} to be installed. It is contained in older packages,
2866 for example \c{pentablet_5.3.5-3.exe}.
2867
2868*/
2869
2870/*!
2871 Construct a tablet event of the given \a type.
2872
2873 The \a pos parameter indicates where the event occurred in the widget;
2874 \a globalPos is the corresponding position in absolute coordinates.
2875
2876 \a pressure gives the pressure exerted on the device \a dev.
2877
2878 \a xTilt and \a yTilt give the device's degree of tilt from the
2879 x and y axes respectively.
2880
2881 \a keyState specifies which keyboard modifiers are pressed (e.g.,
2882 \uicontrol{Ctrl}).
2883
2884 The \a z parameter gives the Z coordinate of the device on the tablet;
2885 this is usually given by a wheel on a 4D mouse. If the device does not
2886 support a Z-axis (i.e. \l QPointingDevice::capabilities() does not include
2887 \c ZPosition), pass \c 0 here.
2888
2889 The \a tangentialPressure parameter gives the tangential pressure
2890 thumbwheel value from an airbrush. If the device does not support
2891 tangential pressure (i.e. \l QPointingDevice::capabilities() does not
2892 include \c TangentialPressure), pass \c 0 here.
2893
2894 \a rotation gives the device's rotation in degrees.
2895 4D mice, the Wacom Art Pen, and the Apple Pencil support rotation.
2896 If the device does not support rotation (i.e. \l QPointingDevice::capabilities()
2897 does not include \c Rotation), pass \c 0 here.
2898
2899 The \a button that caused the event is given as a value from the
2900 \l Qt::MouseButton enum. If the event \a type is not \l TabletPress or
2901 \l TabletRelease, the appropriate button for this event is \l Qt::NoButton.
2902
2903 \a buttons is the state of all buttons at the time of the event.
2904
2905 \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(),
2906 tangentialPressure(), z()
2907*/
2908QTabletEvent::QTabletEvent(Type type, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
2909 qreal pressure, int xTilt, int yTilt,
2910 qreal tangentialPressure, qreal rotation, int z,
2911 Qt::KeyboardModifiers keyState,
2912 Qt::MouseButton button, Qt::MouseButtons buttons)
2913 : QSinglePointEvent(type, dev, pos, pos, globalPos, button, buttons, keyState),
2914 m_xTilt(xTilt),
2915 m_yTilt(yTilt),
2916 m_z(z),
2917 m_tangential(tangentialPressure)
2918{
2919 QMutableEventPoint &mut = QMutableEventPoint::from(point(0));
2920 mut.setPressure(pressure);
2921 mut.setRotation(rotation);
2922}
2923
2924/*!
2925 \internal
2926*/
2927QTabletEvent::~QTabletEvent()
2928{
2929}
2930
2931/*!
2932 \fn qreal QTabletEvent::tangentialPressure() const
2933
2934 Returns the tangential pressure for the device. This is typically given by a finger
2935 wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
2936 neutral position. Current airbrushes can only move in the positive
2937 direction from the neutrual position. If the device does not support
2938 tangential pressure, this value is always 0.0.
2939
2940 \sa pressure()
2941*/
2942
2943/*!
2944 \fn qreal QTabletEvent::rotation() const
2945
2946 Returns the rotation of the current tool in degrees, where zero means the
2947 tip of the stylus is pointing towards the top of the tablet, a positive
2948 value means it's turned to the right, and a negative value means it's
2949 turned to the left. This can be given by a 4D Mouse or a rotation-capable
2950 stylus (such as the Wacom Art Pen or the Apple Pencil). If the device does
2951 not support rotation, this value is always 0.0.
2952*/
2953
2954/*!
2955 \fn qreal QTabletEvent::pressure() const
2956
2957 Returns the pressure for the device. 0.0 indicates that the stylus is not
2958 on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
2959
2960 \sa tangentialPressure()
2961*/
2962
2963/*!
2964 \fn int QTabletEvent::xTilt() const
2965
2966 Returns the angle between the device (a pen, for example) and the
2967 perpendicular in the direction of the x axis.
2968 Positive values are towards the tablet's physical right. The angle
2969 is in the range -60 to +60 degrees.
2970
2971 \image qtabletevent-tilt.png
2972
2973 \sa yTilt()
2974*/
2975
2976/*!
2977 \fn int QTabletEvent::yTilt() const
2978
2979 Returns the angle between the device (a pen, for example) and the
2980 perpendicular in the direction of the y axis.
2981 Positive values are towards the bottom of the tablet. The angle is
2982 within the range -60 to +60 degrees.
2983
2984 \sa xTilt()
2985*/
2986
2987/*!
2988 \fn QPoint QTabletEvent::pos() const
2989
2990 Returns the position of the device, relative to the widget that
2991 received the event.
2992
2993 If you move widgets around in response to mouse events, use
2994 globalPos() instead of this function.
2995
2996 \sa x(), y(), globalPos()
2997*/
2998
2999/*!
3000 \fn int QTabletEvent::x() const
3001
3002 Returns the x position of the device, relative to the widget that
3003 received the event.
3004
3005 \sa y(), pos()
3006*/
3007
3008/*!
3009 \fn int QTabletEvent::y() const
3010
3011 Returns the y position of the device, relative to the widget that
3012 received the event.
3013
3014 \sa x(), pos()
3015*/
3016
3017/*!
3018 \fn int QTabletEvent::z() const
3019
3020 Returns the z position of the device. Typically this is represented by a
3021 wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
3022 always zero. This is \b not the same as pressure.
3023
3024 \sa pressure()
3025*/
3026
3027/*!
3028 \fn QPoint QTabletEvent::globalPos() const
3029
3030 Returns the global position of the device \e{at the time of the
3031 event}. This is important on asynchronous windows systems like X11;
3032 whenever you move your widgets around in response to mouse events,
3033 globalPos() can differ significantly from the current position
3034 QCursor::pos().
3035
3036 \sa globalX(), globalY()
3037*/
3038
3039/*!
3040 \fn int QTabletEvent::globalX() const
3041
3042 Returns the global x position of the mouse pointer at the time of
3043 the event.
3044
3045 \sa globalY(), globalPos()
3046*/
3047
3048/*!
3049 \fn int QTabletEvent::globalY() const
3050
3051 Returns the global y position of the tablet device at the time of
3052 the event.
3053
3054 \sa globalX(), globalPos()
3055*/
3056
3057/*!
3058 \fn qint64 QTabletEvent::uniqueId() const
3059
3060 Returns a unique ID for the current device, making it possible
3061 to differentiate between multiple devices being used at the same
3062 time on the tablet.
3063
3064 Support of this feature is dependent on the tablet.
3065
3066 Values for the same device may vary from OS to OS.
3067
3068 Later versions of the Wacom driver for Linux will now report
3069 the ID information. If you have a tablet that supports unique ID
3070 and are not getting the information on Linux, consider upgrading
3071 your driver.
3072
3073 As of Qt 4.2, the unique ID is the same regardless of the orientation
3074 of the pen. Earlier versions would report a different value when using
3075 the eraser-end versus the pen-end of the stylus on some OS's.
3076
3077 \sa pointerType()
3078*/
3079
3080/*!
3081 \fn const QPointF &QTabletEvent::posF() const
3082
3083 Returns the position of the device, relative to the widget that
3084 received the event.
3085
3086 If you move widgets around in response to mouse events, use
3087 globalPosF() instead of this function.
3088
3089 \sa globalPosF()
3090*/
3091
3092/*!
3093 \fn const QPointF &QTabletEvent::globalPosF() const
3094
3095 Returns the global position of the device \e{at the time of the
3096 event}. This is important on asynchronous windows systems like X11;
3097 whenever you move your widgets around in response to mouse events,
3098 globalPosF() can differ significantly from the current position
3099 QCursor::pos().
3100
3101 \sa posF()
3102*/
3103
3104#endif // QT_CONFIG(tabletevent)
3105
3106#ifndef QT_NO_GESTURES
3107/*!
3108 \class QNativeGestureEvent
3109 \since 5.2
3110 \brief The QNativeGestureEvent class contains parameters that describe a gesture event.
3111 \inmodule QtGui
3112 \ingroup events
3113
3114 Native gesture events are generated by the operating system, typically by
3115 interpreting touch events. Gesture events are high-level events such
3116 as zoom or rotate.
3117
3118 \table
3119 \header
3120 \li Event Type
3121 \li Description
3122 \li Touch sequence
3123 \row
3124 \li Qt::ZoomNativeGesture
3125 \li Magnification delta in percent.
3126 \li \macos: Two-finger pinch.
3127 \row
3128 \li Qt::SmartZoomNativeGesture
3129 \li Boolean magnification state.
3130 \li \macos: Two-finger douple tap (trackpad) / One-finger douple tap (magic mouse).
3131 \row
3132 \li Qt::RotateNativeGesture
3133 \li Rotation delta in degrees.
3134 \li \macos: Two-finger rotate.
3135 \endtable
3136
3137
3138 In addition, BeginNativeGesture and EndNativeGesture are sent before and after
3139 gesture event streams:
3140
3141 BeginNativeGesture
3142 ZoomNativeGesture
3143 ZoomNativeGesture
3144 ZoomNativeGesture
3145 EndNativeGesture
3146
3147 \sa Qt::NativeGestureType, QGestureEvent
3148*/
3149
3150/*!
3151 Constructs a native gesture event of type \a type originating from \a device.
3152
3153 The points \a localPos, \a scenePos and \a globalPos specify the
3154 gesture position relative to the receiving widget or item,
3155 window, and screen or desktop, respectively.
3156
3157 \a realValue is the \macos event parameter, \a sequenceId and \a intValue are the Windows event parameters.
3158 \since 5.10
3159*/
3160QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device, const QPointF &localPos, const QPointF &scenePos,
3161 const QPointF &globalPos, qreal realValue, ulong sequenceId, quint64 intValue)
3162 : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton, Qt::NoButton, Qt::NoModifier),
3163 m_gestureType(type), m_realValue(realValue), m_sequenceId(sequenceId),
3164 m_intValue(intValue)
3165{
3166}
3167
3168QNativeGestureEvent::~QNativeGestureEvent()
3169 = default;
3170
3171/*!
3172 \fn QNativeGestureEvent::gestureType() const
3173 \since 5.2
3174
3175 Returns the gesture type.
3176*/
3177
3178/*!
3179 \fn QNativeGestureEvent::value() const
3180 \since 5.2
3181
3182 Returns the gesture value. The value should be interpreted based on the
3183 gesture type. For example, a Zoom gesture provides a scale factor while a Rotate
3184 gesture provides a rotation delta.
3185
3186 \sa QNativeGestureEvent, gestureType()
3187*/
3188
3189/*!
3190 \fn QPoint QNativeGestureEvent::globalPos() const
3191 \since 5.2
3192
3193 Returns the position of the gesture as a QPointF in screen coordinates
3194*/
3195
3196/*!
3197 \fn QPoint QNativeGestureEvent::pos() const
3198 \since 5.2
3199
3200 Returns the position of the mouse cursor, relative to the widget
3201 or item that received the event.
3202*/
3203
3204/*!
3205 \fn QPointF QNativeGestureEvent::localPos() const
3206 \since 5.2
3207
3208 Returns the position of the gesture as a QPointF, relative to the
3209 widget or item that received the event.
3210*/
3211
3212/*!
3213 \fn QPointF QNativeGestureEvent::screenPos() const
3214 \since 5.2
3215
3216 Returns the position of the gesture as a QPointF in screen coordinates.
3217*/
3218
3219/*!
3220 \fn QPointF QNativeGestureEvent::windowPos() const
3221 \since 5.2
3222
3223 Returns the position of the gesture as a QPointF, relative to the
3224 window that received the event.
3225*/
3226#endif // QT_NO_GESTURES
3227
3228#if QT_CONFIG(draganddrop)
3229/*!
3230 Creates a QDragMoveEvent of the required \a type indicating
3231 that the mouse is at position \a pos given within a widget.
3232
3233 The mouse and keyboard states are specified by \a buttons and
3234 \a modifiers, and the \a actions describe the types of drag
3235 and drop operation that are possible.
3236 The drag data is passed as MIME-encoded information in \a data.
3237
3238 \warning Do not attempt to create a QDragMoveEvent yourself.
3239 These objects rely on Qt's internal state.
3240*/
3241QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
3242 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
3243 : QDropEvent(pos, actions, data, buttons, modifiers, type)
3244 , m_rect(pos, QSize(1, 1))
3245{}
3246
3247/*!
3248 Destroys the event.
3249*/
3250QDragMoveEvent::~QDragMoveEvent()
3251{
3252}
3253
3254/*!
3255 \fn void QDragMoveEvent::accept(const QRect &rectangle)
3256
3257 The same as accept(), but also notifies that future moves will
3258 also be acceptable if they remain within the \a rectangle
3259 given on the widget. This can improve performance, but may
3260 also be ignored by the underlying system.
3261
3262 If the rectangle is empty, drag move events will be sent
3263 continuously. This is useful if the source is scrolling in a
3264 timer event.
3265*/
3266
3267/*!
3268 \fn void QDragMoveEvent::accept()
3269
3270 \overload
3271
3272 Calls QDropEvent::accept().
3273*/
3274
3275/*!
3276 \fn void QDragMoveEvent::ignore()
3277
3278 \overload
3279
3280 Calls QDropEvent::ignore().
3281*/
3282
3283/*!
3284 \fn void QDragMoveEvent::ignore(const QRect &rectangle)
3285
3286 The opposite of the accept(const QRect&) function.
3287 Moves within the \a rectangle are not acceptable, and will be
3288 ignored.
3289*/
3290
3291/*!
3292 \fn QRect QDragMoveEvent::answerRect() const
3293
3294 Returns the rectangle in the widget where the drop will occur if accepted.
3295 You can use this information to restrict drops to certain places on the
3296 widget.
3297*/
3298
3299
3300/*!
3301 \class QDropEvent
3302 \ingroup events
3303 \ingroup draganddrop
3304 \inmodule QtGui
3305
3306 \brief The QDropEvent class provides an event which is sent when a
3307 drag and drop action is completed.
3308
3309 When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
3310 receive this event if it has accepted the most recent QDragEnterEvent or
3311 QDragMoveEvent sent to it.
3312
3313 The drop event contains a proposed action, available from proposedAction(), for
3314 the widget to either accept or ignore. If the action can be handled by the
3315 widget, you should call the acceptProposedAction() function. Since the
3316 proposed action can be a combination of \l Qt::DropAction values, it may be
3317 useful to either select one of these values as a default action or ask
3318 the user to select their preferred action.
3319
3320 If the proposed drop action is not suitable, perhaps because your custom
3321 widget does not support that action, you can replace it with any of the
3322 \l{possibleActions()}{possible drop actions} by calling setDropAction()
3323 with your preferred action. If you set a value that is not present in the
3324 bitwise OR combination of values returned by possibleActions(), the default
3325 copy action will be used. Once a replacement drop action has been set, call
3326 accept() instead of acceptProposedAction() to complete the drop operation.
3327
3328 The mimeData() function provides the data dropped on the widget in a QMimeData
3329 object. This contains information about the MIME type of the data in addition to
3330 the data itself.
3331
3332 \sa QMimeData, QDrag, {Drag and Drop}
3333*/
3334
3335/*!
3336 \fn const QMimeData *QDropEvent::mimeData() const
3337
3338 Returns the data that was dropped on the widget and its associated MIME
3339 type information.
3340*/
3341
3342// ### pos is in which coordinate system?
3343/*!
3344 Constructs a drop event of a certain \a type corresponding to a
3345 drop at the point specified by \a pos in the destination widget's
3346 coordinate system.
3347
3348 The \a actions indicate which types of drag and drop operation can
3349 be performed, and the drag data is stored as MIME-encoded data in \a data.
3350
3351 The states of the mouse buttons and keyboard modifiers at the time of
3352 the drop are specified by \a buttons and \a modifiers.
3353*/
3354QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
3355 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
3356 : QEvent(type), m_pos(pos), m_mouseState(buttons),
3357 m_modState(modifiers), m_actions(actions),
3358 m_data(data)
3359{
3360 m_defaultAction = m_dropAction =
3361 QGuiApplicationPrivate::platformIntegration()->drag()->defaultAction(m_actions, modifiers);
3362 ignore();
3363}
3364
3365/*! \internal */
3366QDropEvent::~QDropEvent()
3367{
3368}
3369
3370
3371/*!
3372 If the source of the drag operation is a widget in this
3373 application, this function returns that source; otherwise it
3374 returns \nullptr. The source of the operation is the first parameter to
3375 the QDrag object used instantiate the drag.
3376
3377 This is useful if your widget needs special behavior when dragging
3378 to itself.
3379
3380 \sa QDrag::QDrag()
3381*/
3382QObject* QDropEvent::source() const
3383{
3384 if (const QDragManager *manager = QDragManager::self())
3385 return manager->source();
3386 return nullptr;
3387}
3388
3389
3390void QDropEvent::setDropAction(Qt::DropAction action)
3391{
3392 if (!(action & m_actions) && action != Qt::IgnoreAction)
3393 action = m_defaultAction;
3394 m_dropAction = action;
3395}
3396
3397/*!
3398 \fn QPoint QDropEvent::pos() const
3399
3400 Returns the position where the drop was made.
3401*/
3402
3403/*!
3404 \fn const QPointF& QDropEvent::posF() const
3405
3406 Returns the position where the drop was made.
3407*/
3408
3409/*!
3410 \fn Qt::MouseButtons QDropEvent::mouseButtons() const
3411
3412 Returns the mouse buttons that are pressed..
3413*/
3414
3415/*!
3416 \fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
3417
3418 Returns the modifier keys that are pressed.
3419*/
3420
3421/*!
3422 \fn void QDropEvent::setDropAction(Qt::DropAction action)
3423
3424 Sets the \a action to be performed on the data by the target.
3425 Use this to override the \l{proposedAction()}{proposed action}
3426 with one of the \l{possibleActions()}{possible actions}.
3427
3428 If you set a drop action that is not one of the possible actions, the
3429 drag and drop operation will default to a copy operation.
3430
3431 Once you have supplied a replacement drop action, call accept()
3432 instead of acceptProposedAction().
3433
3434 \sa dropAction()
3435*/
3436
3437/*!
3438 \fn Qt::DropAction QDropEvent::dropAction() const
3439
3440 Returns the action to be performed on the data by the target. This may be
3441 different from the action supplied in proposedAction() if you have called
3442 setDropAction() to explicitly choose a drop action.
3443
3444 \sa setDropAction()
3445*/
3446
3447/*!
3448 \fn Qt::DropActions QDropEvent::possibleActions() const
3449
3450 Returns an OR-combination of possible drop actions.
3451
3452 \sa dropAction()
3453*/
3454
3455/*!
3456 \fn Qt::DropAction QDropEvent::proposedAction() const
3457
3458 Returns the proposed drop action.
3459
3460 \sa dropAction()
3461*/
3462
3463/*!
3464 \fn void QDropEvent::acceptProposedAction()
3465
3466 Sets the drop action to be the proposed action.
3467
3468 \sa setDropAction(), proposedAction(), {QEvent::accept()}{accept()}
3469*/
3470
3471/*!
3472 \class QDragEnterEvent
3473 \brief The QDragEnterEvent class provides an event which is sent
3474 to a widget when a drag and drop action enters it.
3475
3476 \ingroup events
3477 \ingroup draganddrop
3478 \inmodule QtGui
3479
3480 A widget must accept this event in order to receive the \l
3481 {QDragMoveEvent}{drag move events} that are sent while the drag
3482 and drop action is in progress. The drag enter event is always
3483 immediately followed by a drag move event.
3484
3485 QDragEnterEvent inherits most of its functionality from
3486 QDragMoveEvent, which in turn inherits most of its functionality
3487 from QDropEvent.
3488
3489 \sa QDragLeaveEvent, QDragMoveEvent, QDropEvent
3490*/
3491
3492/*!
3493 Constructs a QDragEnterEvent that represents a drag entering a
3494 widget at the given \a point with mouse and keyboard states specified by
3495 \a buttons and \a modifiers.
3496
3497 The drag data is passed as MIME-encoded information in \a data, and the
3498 specified \a actions describe the possible types of drag and drop
3499 operation that can be performed.
3500
3501 \warning Do not create a QDragEnterEvent yourself since these
3502 objects rely on Qt's internal state.
3503*/
3504QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, const QMimeData *data,
3505 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3506 : QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
3507{}
3508
3509/*! \internal
3510*/
3511QDragEnterEvent::~QDragEnterEvent()
3512{
3513}
3514
3515/*!
3516 \class QDragMoveEvent
3517 \brief The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress.
3518
3519 \ingroup events
3520 \ingroup draganddrop
3521 \inmodule QtGui
3522
3523 A widget will receive drag move events repeatedly while the drag
3524 is within its boundaries, if it accepts
3525 \l{QWidget::setAcceptDrops()}{drop events} and \l
3526 {QWidget::dragEnterEvent()}{enter events}. The widget should
3527 examine the event to see what kind of \l{mimeData()}{data} it
3528 provides, and call the accept() function to accept the drop if appropriate.
3529
3530 The rectangle supplied by the answerRect() function can be used to restrict
3531 drops to certain parts of the widget. For example, we can check whether the
3532 rectangle intersects with the geometry of a certain child widget and only
3533 call \l{QDropEvent::acceptProposedAction()}{acceptProposedAction()} if that
3534 is the case.
3535
3536 Note that this class inherits most of its functionality from
3537 QDropEvent.
3538
3539 \sa QDragEnterEvent, QDragLeaveEvent, QDropEvent
3540*/
3541
3542/*!
3543 \class QDragLeaveEvent
3544 \brief The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leaves it.
3545
3546 \ingroup events
3547 \ingroup draganddrop
3548 \inmodule QtGui
3549
3550 This event is always preceded by a QDragEnterEvent and a series
3551 of \l{QDragMoveEvent}s. It is not sent if a QDropEvent is sent
3552 instead.
3553
3554 \sa QDragEnterEvent, QDragMoveEvent, QDropEvent
3555*/
3556
3557/*!
3558 Constructs a QDragLeaveEvent.
3559
3560 \warning Do not create a QDragLeaveEvent yourself since these
3561 objects rely on Qt's internal state.
3562*/
3563QDragLeaveEvent::QDragLeaveEvent()
3564 : QEvent(DragLeave)
3565{}
3566
3567/*! \internal
3568*/
3569QDragLeaveEvent::~QDragLeaveEvent()
3570{
3571}
3572#endif // QT_CONFIG(draganddrop)
3573
3574/*!
3575 \class QHelpEvent
3576 \brief The QHelpEvent class provides an event that is used to request helpful information
3577 about a particular point in a widget.
3578
3579 \ingroup events
3580 \ingroup helpsystem
3581 \inmodule QtGui
3582
3583 This event can be intercepted in applications to provide tooltips
3584 or "What's This?" help for custom widgets. The type() can be
3585 either QEvent::ToolTip or QEvent::WhatsThis.
3586
3587 \sa QToolTip, QWhatsThis, QStatusTipEvent, QWhatsThisClickedEvent
3588*/
3589
3590/*!
3591 Constructs a help event with the given \a type corresponding to the
3592 widget-relative position specified by \a pos and the global position
3593 specified by \a globalPos.
3594
3595 \a type must be either QEvent::ToolTip or QEvent::WhatsThis.
3596
3597 \sa pos(), globalPos()
3598*/
3599QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
3600 : QEvent(type), m_pos(pos), m_globalPos(globalPos)
3601{}
3602
3603/*!
3604 \fn int QHelpEvent::x() const
3605
3606 Same as pos().x().
3607
3608 \sa y(), pos(), globalPos()
3609*/
3610
3611/*!
3612 \fn int QHelpEvent::y() const
3613
3614 Same as pos().y().
3615
3616 \sa x(), pos(), globalPos()
3617*/
3618
3619/*!
3620 \fn int QHelpEvent::globalX() const
3621
3622 Same as globalPos().x().
3623
3624 \sa x(), globalY(), globalPos()
3625*/
3626
3627/*!
3628 \fn int QHelpEvent::globalY() const
3629
3630 Same as globalPos().y().
3631
3632 \sa y(), globalX(), globalPos()
3633*/
3634
3635/*!
3636 \fn const QPoint &QHelpEvent::pos() const
3637
3638 Returns the mouse cursor position when the event was generated,
3639 relative to the widget to which the event is dispatched.
3640
3641 \sa globalPos(), x(), y()
3642*/
3643
3644/*!
3645 \fn const QPoint &QHelpEvent::globalPos() const
3646
3647 Returns the mouse cursor position when the event was generated
3648 in global coordinates.
3649
3650 \sa pos(), globalX(), globalY()
3651*/
3652
3653/*! \internal
3654*/
3655QHelpEvent::~QHelpEvent()
3656{
3657}
3658
3659#ifndef QT_NO_STATUSTIP
3660
3661/*!
3662 \class QStatusTipEvent
3663 \brief The QStatusTipEvent class provides an event that is used to show messages in a status bar.
3664
3665 \ingroup events
3666 \ingroup helpsystem
3667 \inmodule QtGui
3668
3669 Status tips can be set on a widget using the
3670 QWidget::setStatusTip() function. They are shown in the status
3671 bar when the mouse cursor enters the widget. For example:
3672
3673 \table 100%
3674 \row
3675 \li
3676 \snippet qstatustipevent/main.cpp 1
3677 \dots
3678 \snippet qstatustipevent/main.cpp 3
3679 \li
3680 \image qstatustipevent-widget.png Widget with status tip.
3681 \endtable
3682
3683 Status tips can also be set on actions using the
3684 QAction::setStatusTip() function:
3685
3686 \table 100%
3687 \row
3688 \li
3689 \snippet qstatustipevent/main.cpp 0
3690 \snippet qstatustipevent/main.cpp 2
3691 \dots
3692 \snippet qstatustipevent/main.cpp 3
3693 \li
3694 \image qstatustipevent-action.png Action with status tip.
3695 \endtable
3696
3697 Finally, status tips are supported for the item view classes
3698 through the Qt::StatusTipRole enum value.
3699
3700 \sa QStatusBar, QHelpEvent, QWhatsThisClickedEvent
3701*/
3702
3703/*!
3704 Constructs a status tip event with the text specified by \a tip.
3705
3706 \sa tip()
3707*/
3708QStatusTipEvent::QStatusTipEvent(const QString &tip)
3709 : QEvent(StatusTip), m_tip(tip)
3710{}
3711
3712/*! \internal
3713*/
3714QStatusTipEvent::~QStatusTipEvent()
3715{
3716}
3717
3718/*!
3719 \fn QString QStatusTipEvent::tip() const
3720
3721 Returns the message to show in the status bar.
3722
3723 \sa QStatusBar::showMessage()
3724*/
3725
3726#endif // QT_NO_STATUSTIP
3727
3728#if QT_CONFIG(whatsthis)
3729
3730/*!
3731 \class QWhatsThisClickedEvent
3732 \brief The QWhatsThisClickedEvent class provides an event that
3733 can be used to handle hyperlinks in a "What's This?" text.
3734
3735 \ingroup events
3736 \ingroup helpsystem
3737 \inmodule QtGui
3738
3739 \sa QWhatsThis, QHelpEvent, QStatusTipEvent
3740*/
3741
3742/*!
3743 Constructs an event containing a URL specified by \a href when a link
3744 is clicked in a "What's This?" message.
3745
3746 \sa href()
3747*/
3748QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
3749 : QEvent(WhatsThisClicked), m_href(href)
3750{}
3751
3752/*! \internal
3753*/
3754QWhatsThisClickedEvent::~QWhatsThisClickedEvent()
3755{
3756}
3757
3758/*!
3759 \fn QString QWhatsThisClickedEvent::href() const
3760
3761 Returns the URL that was clicked by the user in the "What's
3762 This?" text.
3763*/
3764
3765#endif // QT_CONFIG(whatsthis)
3766
3767#ifndef QT_NO_ACTION
3768
3769/*!
3770 \class QActionEvent
3771 \brief The QActionEvent class provides an event that is generated
3772 when a QAction is added, removed, or changed.
3773
3774 \ingroup events
3775 \inmodule QtGui
3776
3777 Actions can be added to controls, for example by using QWidget::addAction().
3778 This generates an \l ActionAdded event, which you can handle to provide
3779 custom behavior. For example, QToolBar reimplements
3780 QWidget::actionEvent() to create \l{QToolButton}s for the
3781 actions.
3782
3783 \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
3784*/
3785
3786/*!
3787 Constructs an action event. The \a type can be \l ActionChanged,
3788 \l ActionAdded, or \l ActionRemoved.
3789
3790 \a action is the action that is changed, added, or removed. If \a
3791 type is ActionAdded, the action is to be inserted before the
3792 action \a before. If \a before is \nullptr, the action is appended.
3793*/
3794QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
3795 : QEvent(static_cast<QEvent::Type>(type)), m_action(action), m_before(before)
3796{}
3797
3798/*! \internal
3799*/
3800QActionEvent::~QActionEvent()
3801{
3802}
3803
3804/*!
3805 \fn QAction *QActionEvent::action() const
3806
3807 Returns the action that is changed, added, or removed.
3808
3809 \sa before()
3810*/
3811
3812/*!
3813 \fn QAction *QActionEvent::before() const
3814
3815 If type() is \l ActionAdded, returns the action that should
3816 appear before action(). If this function returns \nullptr, the action
3817 should be appended to already existing actions on the same
3818 widget.
3819
3820 \sa action(), QWidget::actions()
3821*/
3822
3823#endif // QT_NO_ACTION
3824
3825/*!
3826 \class QHideEvent
3827 \brief The QHideEvent class provides an event which is sent after a widget is hidden.
3828
3829 \ingroup events
3830 \inmodule QtGui
3831
3832 This event is sent just before QWidget::hide() returns, and also
3833 when a top-level window has been hidden (iconified) by the user.
3834
3835 If spontaneous() is true, the event originated outside the
3836 application. In this case, the user hid the window using the
3837 window manager controls, either by iconifying the window or by
3838 switching to another virtual desktop where the window is not
3839 visible. The window will become hidden but not withdrawn. If the
3840 window was iconified, QWidget::isMinimized() returns \c true.
3841
3842 \sa QShowEvent
3843*/
3844
3845/*!
3846 Constructs a QHideEvent.
3847*/
3848QHideEvent::QHideEvent()
3849 : QEvent(Hide)
3850{}
3851
3852/*! \internal
3853*/
3854QHideEvent::~QHideEvent()
3855{
3856}
3857
3858/*!
3859 \class QShowEvent
3860 \brief The QShowEvent class provides an event that is sent when a widget is shown.
3861
3862 \ingroup events
3863 \inmodule QtGui
3864
3865 There are two kinds of show events: show events caused by the
3866 window system (spontaneous), and internal show events. Spontaneous (QEvent::spontaneous())
3867 show events are sent just after the window system shows the
3868 window; they are also sent when a top-level window is redisplayed
3869 after being iconified. Internal show events are delivered just
3870 before the widget becomes visible.
3871
3872 \sa QHideEvent
3873*/
3874
3875/*!
3876 Constructs a QShowEvent.
3877*/
3878QShowEvent::QShowEvent()
3879 : QEvent(Show)
3880{}
3881
3882/*! \internal
3883*/
3884QShowEvent::~QShowEvent()
3885{
3886}
3887
3888/*!
3889 \class QFileOpenEvent
3890 \brief The QFileOpenEvent class provides an event that will be
3891 sent when there is a request to open a file or a URL.
3892
3893 \ingroup events
3894 \inmodule QtGui
3895
3896 File open events will be sent to the QApplication::instance()
3897 when the operating system requests that a file or URL should be opened.
3898 This is a high-level event that can be caused by different user actions
3899 depending on the user's desktop environment; for example, double
3900 clicking on an file icon in the Finder on \macos.
3901
3902 This event is only used to notify the application of a request.
3903 It may be safely ignored.
3904
3905 \note This class is currently supported for \macos only.
3906
3907 \section1 \macos Example
3908
3909 In order to trigger the event on \macos, the application must be configured
3910 to let the OS know what kind of file(s) it should react on.
3911
3912 For example, the following \c Info.plist file declares that the application
3913 can act as a viewer for files with a PNG extension:
3914
3915 \snippet qfileopenevent/Info.plist Custom Info.plist
3916
3917 The following implementation of a QApplication subclass prints the path to
3918 the file that was, for example, dropped on the Dock icon of the application.
3919
3920 \snippet qfileopenevent/main.cpp QApplication subclass
3921*/
3922
3923/*!
3924 \internal
3925
3926 Constructs a file open event for the given \a file.
3927*/
3928QFileOpenEvent::QFileOpenEvent(const QString &file)
3929 : QEvent(FileOpen), m_file(file), m_url(QUrl::fromLocalFile(file))
3930{
3931}
3932
3933/*!
3934 \internal
3935
3936 Constructs a file open event for the given \a url.
3937*/
3938QFileOpenEvent::QFileOpenEvent(const QUrl &url)
3939 : QEvent(FileOpen), m_file(url.toLocalFile()), m_url(url)
3940{
3941}
3942
3943
3944/*! \internal
3945*/
3946QFileOpenEvent::~QFileOpenEvent()
3947{
3948}
3949
3950/*!
3951 \fn QString QFileOpenEvent::file() const
3952
3953 Returns the file that is being opened.
3954*/
3955
3956/*!
3957 \fn QUrl QFileOpenEvent::url() const
3958
3959 Returns the url that is being opened.
3960
3961 \since 4.6
3962*/
3963
3964/*!
3965 \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
3966
3967 Opens a QFile on the \a file referenced by this event in the mode specified
3968 by \a flags. Returns \c true if successful; otherwise returns \c false.
3969
3970 This is necessary as some files cannot be opened by name, but require specific
3971 information stored in this event.
3972
3973 \since 4.8
3974*/
3975bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
3976{
3977 file.setFileName(m_file);
3978 return file.open(flags);
3979}
3980
3981#ifndef QT_NO_TOOLBAR
3982/*!
3983 \internal
3984 \class QToolBarChangeEvent
3985 \brief The QToolBarChangeEvent class provides an event that is
3986 sent whenever a the toolbar button is clicked on \macos.
3987
3988 \ingroup events
3989 \inmodule QtGui
3990
3991 The QToolBarChangeEvent is sent when the toolbar button is clicked. On
3992 \macos, this is the long oblong button on the right side of the window
3993 title bar. The default implementation is to toggle the appearance (hidden or
3994 shown) of the associated toolbars for the window.
3995*/
3996
3997/*!
3998 \internal
3999
4000 Construct a QToolBarChangeEvent given the current button state in \a state.
4001*/
4002QToolBarChangeEvent::QToolBarChangeEvent(bool t)
4003 : QEvent(ToolBarChange), m_toggle(t)
4004{}
4005
4006/*! \internal
4007*/
4008QToolBarChangeEvent::~QToolBarChangeEvent()
4009{
4010}
4011
4012/*!
4013 \fn bool QToolBarChangeEvent::toggle() const
4014 \internal
4015*/
4016
4017/*
4018 \fn Qt::ButtonState QToolBarChangeEvent::state() const
4019
4020 Returns the keyboard modifier flags at the time of the event.
4021
4022 The returned value is a selection of the following values,
4023 combined using the OR operator:
4024 Qt::ShiftButton, Qt::ControlButton, Qt::MetaButton, and Qt::AltButton.
4025*/
4026
4027#endif // QT_NO_TOOLBAR
4028
4029#if QT_CONFIG(shortcut)
4030
4031/*!
4032 Constructs a shortcut event for the given \a key press,
4033 associated with the QShortcut ID \a id.
4034
4035 \a ambiguous specifies whether there is more than one QShortcut
4036 for the same key sequence.
4037*/
4038QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
4039 : QEvent(Shortcut), m_sequence(key), m_ambiguous(ambiguous), m_shortcutId(id)
4040{
4041}
4042
4043/*!
4044 Destroys the event object.
4045*/
4046QShortcutEvent::~QShortcutEvent()
4047{
4048}
4049
4050#endif // QT_CONFIG(shortcut)
4051
4052#ifndef QT_NO_DEBUG_STREAM
4053
4054static inline void formatTouchEvent(QDebug d, const QTouchEvent &t)
4055{
4056 d << "QTouchEvent(";
4057 QtDebugUtils::formatQEnum(d, t.type());
4058 d << " device: " << t.device()->name();
4059 d << " states: ";
4060 QtDebugUtils::formatQFlags(d, t.touchPointStates());
4061 d << ", " << t.points().size() << " points: " << t.points() << ')';
4062}
4063
4064static void formatUnicodeString(QDebug d, const QString &s)
4065{
4066 d << '"' << Qt::hex;
4067 for (int i = 0; i < s.size(); ++i) {
4068 if (i)
4069 d << ',';
4070 d << "U+" << s.at(i).unicode();
4071 }
4072 d << Qt::dec << '"';
4073}
4074
4075static inline void formatInputMethodEvent(QDebug d, const QInputMethodEvent *e)
4076{
4077 d << "QInputMethodEvent(";
4078 if (!e->preeditString().isEmpty()) {
4079 d << "preedit=";
4080 formatUnicodeString(d, e->preeditString());
4081 }
4082 if (!e->commitString().isEmpty()) {
4083 d << ", commit=";
4084 formatUnicodeString(d, e->commitString());
4085 }
4086 if (e->replacementLength()) {
4087 d << ", replacementStart=" << e->replacementStart() << ", replacementLength="
4088 << e->replacementLength();
4089 }
4090 if (const int attributeCount = e->attributes().size()) {
4091 d << ", attributes= {";
4092 for (int a = 0; a < attributeCount; ++a) {
4093 const QInputMethodEvent::Attribute &at = e->attributes().at(a);
4094 if (a)
4095 d << ',';
4096 d << "[type= " << at.type << ", start=" << at.start << ", length=" << at.length
4097 << ", value=" << at.value << ']';
4098 }
4099 d << '}';
4100 }
4101 d << ')';
4102}
4103
4104static inline void formatInputMethodQueryEvent(QDebug d, const QInputMethodQueryEvent *e)
4105{
4106 QDebugStateSaver saver(d);
4107 d.noquote();
4108 const Qt::InputMethodQueries queries = e->queries();
4109 d << "QInputMethodQueryEvent(queries=" << Qt::showbase << Qt::hex << int(queries)
4110 << Qt::noshowbase << Qt::dec << ", {";
4111 for (unsigned mask = 1; mask <= Qt::ImInputItemClipRectangle; mask<<=1) {
4112 if (queries & mask) {
4113 const Qt::InputMethodQuery query = static_cast<Qt::InputMethodQuery>(mask);
4114 const QVariant value = e->value(query);
4115 if (value.isValid()) {
4116 d << '[';
4117 QtDebugUtils::formatQEnum(d, query);
4118 d << '=';
4119 if (query == Qt::ImHints)
4120 QtDebugUtils::formatQFlags(d, Qt::InputMethodHints(value.toInt()));
4121 else
4122 d << value.toString();
4123 d << "],";
4124 }
4125 }
4126 }
4127 d << "})";
4128}
4129
4130static const char *eventClassName(QEvent::Type t)
4131{
4132 switch (t) {
4133 case QEvent::ActionAdded:
4134 case QEvent::ActionRemoved:
4135 case QEvent::ActionChanged:
4136 return "QActionEvent";
4137 case QEvent::MouseButtonPress:
4138 case QEvent::MouseButtonRelease:
4139 case QEvent::MouseButtonDblClick:
4140 case QEvent::MouseMove:
4141 case QEvent::NonClientAreaMouseMove:
4142 case QEvent::NonClientAreaMouseButtonPress:
4143 case QEvent::NonClientAreaMouseButtonRelease:
4144 case QEvent::NonClientAreaMouseButtonDblClick:
4145 return "QMouseEvent";
4146 case QEvent::DragEnter:
4147 return "QDragEnterEvent";
4148 case QEvent::DragMove:
4149 return "QDragMoveEvent";
4150 case QEvent::Drop:
4151 return "QDropEvent";
4152 case QEvent::KeyPress:
4153 case QEvent::KeyRelease:
4154 case QEvent::ShortcutOverride:
4155 return "QKeyEvent";
4156 case QEvent::FocusIn:
4157 case QEvent::FocusOut:
4158 case QEvent::FocusAboutToChange:
4159 return "QFocusEvent";
4160 case QEvent::ChildAdded:
4161 case QEvent::ChildPolished:
4162 case QEvent::ChildRemoved:
4163 return "QChildEvent";
4164 case QEvent::Paint:
4165 return "QPaintEvent";
4166 case QEvent::Move:
4167 return "QMoveEvent";
4168 case QEvent::Resize:
4169 return "QResizeEvent";
4170 case QEvent::Show:
4171 return "QShowEvent";
4172 case QEvent::Hide:
4173 return "QHideEvent";
4174 case QEvent::Enter:
4175 return "QEnterEvent";
4176 case QEvent::Close:
4177 return "QCloseEvent";
4178 case QEvent::FileOpen:
4179 return "QFileOpenEvent";
4180#ifndef QT_NO_GESTURES
4181 case QEvent::NativeGesture:
4182 return "QNativeGestureEvent";
4183 case QEvent::Gesture:
4184 case QEvent::GestureOverride:
4185 return "QGestureEvent";
4186#endif
4187 case QEvent::HoverEnter:
4188 case QEvent::HoverLeave:
4189 case QEvent::HoverMove:
4190 return "QHoverEvent";
4191 case QEvent::TabletEnterProximity:
4192 case QEvent::TabletLeaveProximity:
4193 case QEvent::TabletPress:
4194 case QEvent::TabletMove:
4195 case QEvent::TabletRelease:
4196 return "QTabletEvent";
4197 case QEvent::StatusTip:
4198 return "QStatusTipEvent";
4199 case QEvent::ToolTip:
4200 return "QHelpEvent";
4201 case QEvent::WindowStateChange:
4202 return "QWindowStateChangeEvent";
4203 case QEvent::Wheel:
4204 return "QWheelEvent";
4205 case QEvent::TouchBegin:
4206 case QEvent::TouchUpdate:
4207 case QEvent::TouchEnd:
4208 return "QTouchEvent";
4209 case QEvent::Shortcut:
4210 return "QShortcutEvent";
4211 case QEvent::InputMethod:
4212 return "QInputMethodEvent";
4213 case QEvent::InputMethodQuery:
4214 return "QInputMethodQueryEvent";
4215 case QEvent::OrientationChange:
4216 return "QScreenOrientationChangeEvent";
4217 case QEvent::ScrollPrepare:
4218 return "QScrollPrepareEvent";
4219 case QEvent::Scroll:
4220 return "QScrollEvent";
4221 case QEvent::GraphicsSceneMouseMove:
4222 case QEvent::GraphicsSceneMousePress:
4223 case QEvent::GraphicsSceneMouseRelease:
4224 case QEvent::GraphicsSceneMouseDoubleClick:
4225 return "QGraphicsSceneMouseEvent";
4226 case QEvent::GraphicsSceneContextMenu:
4227 case QEvent::GraphicsSceneHoverEnter:
4228 case QEvent::GraphicsSceneHoverMove:
4229 case QEvent::GraphicsSceneHoverLeave:
4230 case QEvent::GraphicsSceneHelp:
4231 case QEvent::GraphicsSceneDragEnter:
4232 case QEvent::GraphicsSceneDragMove:
4233 case QEvent::GraphicsSceneDragLeave:
4234 case QEvent::GraphicsSceneDrop:
4235 case QEvent::GraphicsSceneWheel:
4236 return "QGraphicsSceneEvent";
4237 case QEvent::Timer:
4238 return "QTimerEvent";
4239 case QEvent::PlatformSurface:
4240 return "QPlatformSurfaceEvent";
4241 default:
4242 break;
4243 }
4244 return "QEvent";
4245}
4246
4247# if QT_CONFIG(draganddrop)
4248
4249static void formatDropEvent(QDebug d, const QDropEvent *e)
4250{
4251 const QEvent::Type type = e->type();
4252 d << eventClassName(type) << "(dropAction=";
4253 QtDebugUtils::formatQEnum(d, e->dropAction());
4254 d << ", proposedAction=";
4255 QtDebugUtils::formatQEnum(d, e->proposedAction());
4256 d << ", possibleActions=";
4257 QtDebugUtils::formatQFlags(d, e->possibleActions());
4258 d << ", posF=";
4259 QtDebugUtils::formatQPoint(d, e->position());
4260 if (type == QEvent::DragMove || type == QEvent::DragEnter)
4261 d << ", answerRect=" << static_cast<const QDragMoveEvent *>(e)->answerRect();
4262 d << ", formats=" << e->mimeData()->formats();
4263 QtDebugUtils::formatNonNullQFlags(d, ", keyboardModifiers=", e->modifiers());
4264 d << ", ";
4265 QtDebugUtils::formatQFlags(d, e->buttons());
4266}
4267
4268# endif // QT_CONFIG(draganddrop)
4269
4270# if QT_CONFIG(tabletevent)
4271
4272static void formatTabletEvent(QDebug d, const QTabletEvent *e)
4273{
4274 const QEvent::Type type = e->type();
4275
4276 d << eventClassName(type) << '(';
4277 QtDebugUtils::formatQEnum(d, type);
4278 d << ", deviceType=";
4279 QtDebugUtils::formatQEnum(d, e->deviceType());
4280 d << ", pointerType=";
4281 QtDebugUtils::formatQEnum(d, e->pointerType());
4282 d << ", uniqueId=" << e->pointingDevice()->uniqueId().numericId()
4283 << ", pos=" << e->position()
4284 << ", z=" << e->z()
4285 << ", xTilt=" << e->xTilt()
4286 << ", yTilt=" << e->yTilt()
4287 << ", ";
4288 QtDebugUtils::formatQFlags(d, e->buttons());
4289 if (type == QEvent::TabletPress || type == QEvent::TabletMove)
4290 d << ", pressure=" << e->pressure();
4291 if (e->device()->hasCapability(QInputDevice::Capability::Rotation))
4292 d << ", rotation=" << e->rotation();
4293 if (e->deviceType() == QInputDevice::DeviceType::Airbrush)
4294 d << ", tangentialPressure=" << e->tangentialPressure();
4295}
4296
4297# endif // QT_CONFIG(tabletevent)
4298
4299QDebug operator<<(QDebug dbg, const QEventPoint *tp)
4300{
4301 if (!tp) {
4302 dbg << "QEventPoint(0x0)";
4303 return dbg;
4304 }
4305 return operator<<(dbg, *tp);
4306}
4307
4308QDebug operator<<(QDebug dbg, const QEventPoint &tp)
4309{
4310 QDebugStateSaver saver(dbg);
4311 dbg.nospace();
4312 dbg << "QEventPoint(" << tp.id() << " ts " << tp.timestamp() << " (";
4313 QtDebugUtils::formatQPoint(dbg, tp.position());
4314 dbg << " scene ";
4315 QtDebugUtils::formatQPoint(dbg, tp.scenePosition());
4316 dbg << " global ";
4317 QtDebugUtils::formatQPoint(dbg, tp.globalPosition());
4318 dbg << ") ";
4319 QtDebugUtils::formatQEnum(dbg, tp.state());
4320 dbg << " pressure " << tp.pressure() << " ellipse ("
4321 << tp.ellipseDiameters().width() << " x " << tp.ellipseDiameters().height()
4322 << " angle " << tp.rotation() << ") vel (";
4323 QtDebugUtils::formatQPoint(dbg, tp.velocity().toPointF());
4324 dbg << ") start (";
4325 QtDebugUtils::formatQPoint(dbg, tp.pressPosition());
4326 dbg << ") last (";
4327 QtDebugUtils::formatQPoint(dbg, tp.lastPosition());
4328 dbg << ") delta (";
4329 QtDebugUtils::formatQPoint(dbg, tp.position() - tp.lastPosition());
4330 dbg << ')';
4331 return dbg;
4332}
4333
4334QDebug operator<<(QDebug dbg, const QEvent *e)
4335{
4336 QDebugStateSaver saver(dbg);
4337 dbg.nospace();
4338 if (!e) {
4339 dbg << "QEvent(this = 0x0)";
4340 return dbg;
4341 }
4342 // More useful event output could be added here
4343 const QEvent::Type type = e->type();
4344 switch (type) {
4345 case QEvent::Expose:
4346QT_WARNING_PUSH
4347QT_WARNING_DISABLE_DEPRECATED
4348 dbg << "QExposeEvent(" << static_cast<const QExposeEvent *>(e)->region() << ')';
4349QT_WARNING_POP
4350 break;
4351 case QEvent::Paint:
4352 dbg << "QPaintEvent(" << static_cast<const QPaintEvent *>(e)->region() << ')';
4353 break;
4354 case QEvent::MouseButtonPress:
4355 case QEvent::MouseMove:
4356 case QEvent::MouseButtonRelease:
4357 case QEvent::MouseButtonDblClick:
4358 case QEvent::NonClientAreaMouseButtonPress:
4359 case QEvent::NonClientAreaMouseMove:
4360 case QEvent::NonClientAreaMouseButtonRelease:
4361 case QEvent::NonClientAreaMouseButtonDblClick:
4362 {
4363 const QMouseEvent *me = static_cast<const QMouseEvent*>(e);
4364 const Qt::MouseButton button = me->button();
4365 const Qt::MouseButtons buttons = me->buttons();
4366 dbg << "QMouseEvent(";
4367 QtDebugUtils::formatQEnum(dbg, type);
4368 if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) {
4369 dbg << ", ";
4370 QtDebugUtils::formatQEnum(dbg, button);
4371 }
4372 if (buttons && button != buttons) {
4373 dbg << ", buttons=";
4374 QtDebugUtils::formatQFlags(dbg, buttons);
4375 }
4376 QtDebugUtils::formatNonNullQFlags(dbg, ", ", me->modifiers());
4377 dbg << ", pos=";
4378 QtDebugUtils::formatQPoint(dbg, me->position());
4379 dbg << ", globalPos=";
4380 QtDebugUtils::formatQPoint(dbg, me->globalPosition());
4381 dbg << ", dev=" << me->device() << ')';
4382 }
4383 break;
4384# if QT_CONFIG(wheelevent)
4385 case QEvent::Wheel: {
4386 const QWheelEvent *we = static_cast<const QWheelEvent *>(e);
4387 dbg << "QWheelEvent(" << we->phase();
4388 if (!we->pixelDelta().isNull() || !we->angleDelta().isNull())
4389 dbg << ", pixelDelta=" << we->pixelDelta() << ", angleDelta=" << we->angleDelta();
4390 dbg << ')';
4391 }
4392 break;
4393# endif // QT_CONFIG(wheelevent)
4394 case QEvent::KeyPress:
4395 case QEvent::KeyRelease:
4396 case QEvent::ShortcutOverride:
4397 {
4398 const QKeyEvent *ke = static_cast<const QKeyEvent *>(e);
4399 dbg << "QKeyEvent(";
4400 QtDebugUtils::formatQEnum(dbg, type);
4401 dbg << ", ";
4402 QtDebugUtils::formatQEnum(dbg, static_cast<Qt::Key>(ke->key()));
4403 QtDebugUtils::formatNonNullQFlags(dbg, ", ", ke->modifiers());
4404 if (!ke->text().isEmpty())
4405 dbg << ", text=" << ke->text();
4406 if (ke->isAutoRepeat())
4407 dbg << ", autorepeat, count=" << ke->count();
4408 dbg << ')';
4409 }
4410 break;
4411#if QT_CONFIG(shortcut)
4412 case QEvent::Shortcut: {
4413 const QShortcutEvent *se = static_cast<const QShortcutEvent *>(e);
4414 dbg << "QShortcutEvent(" << se->key().toString() << ", id=" << se->shortcutId();
4415 if (se->isAmbiguous())
4416 dbg << ", ambiguous";
4417 dbg << ')';
4418 }
4419 break;
4420#endif
4421 case QEvent::FocusAboutToChange:
4422 case QEvent::FocusIn:
4423 case QEvent::FocusOut:
4424 dbg << "QFocusEvent(";
4425 QtDebugUtils::formatQEnum(dbg, type);
4426 dbg << ", ";
4427 QtDebugUtils::formatQEnum(dbg, static_cast<const QFocusEvent *>(e)->reason());
4428 dbg << ')';
4429 break;
4430 case QEvent::Move: {
4431 const QMoveEvent *me = static_cast<const QMoveEvent *>(e);
4432 dbg << "QMoveEvent(";
4433 QtDebugUtils::formatQPoint(dbg, me->pos());
4434 if (!me->spontaneous())
4435 dbg << ", non-spontaneous";
4436 dbg << ')';
4437 }
4438 break;
4439 case QEvent::Resize: {
4440 const QResizeEvent *re = static_cast<const QResizeEvent *>(e);
4441 dbg << "QResizeEvent(";
4442 QtDebugUtils::formatQSize(dbg, re->size());
4443 if (!re->spontaneous())
4444 dbg << ", non-spontaneous";
4445 dbg << ')';
4446 }
4447 break;
4448# if QT_CONFIG(draganddrop)
4449 case QEvent::DragEnter:
4450 case QEvent::DragMove:
4451 case QEvent::Drop:
4452 formatDropEvent(dbg, static_cast<const QDropEvent *>(e));
4453 break;
4454# endif // QT_CONFIG(draganddrop)
4455 case QEvent::InputMethod:
4456 formatInputMethodEvent(dbg, static_cast<const QInputMethodEvent *>(e));
4457 break;
4458 case QEvent::InputMethodQuery:
4459 formatInputMethodQueryEvent(dbg, static_cast<const QInputMethodQueryEvent *>(e));
4460 break;
4461 case QEvent::TouchBegin:
4462 case QEvent::TouchUpdate:
4463 case QEvent::TouchEnd:
4464 formatTouchEvent(dbg, *static_cast<const QTouchEvent*>(e));
4465 break;
4466 case QEvent::ChildAdded:
4467 case QEvent::ChildPolished:
4468 case QEvent::ChildRemoved:
4469 dbg << "QChildEvent(";
4470 QtDebugUtils::formatQEnum(dbg, type);
4471 dbg << ", " << (static_cast<const QChildEvent*>(e))->child() << ')';
4472 break;
4473# ifndef QT_NO_GESTURES
4474 case QEvent::NativeGesture: {
4475 const QNativeGestureEvent *ne = static_cast<const QNativeGestureEvent *>(e);
4476 dbg << "QNativeGestureEvent(";
4477 QtDebugUtils::formatQEnum(dbg, ne->gestureType());
4478 dbg << ", localPos=";
4479 QtDebugUtils::formatQPoint(dbg, ne->position());
4480 dbg << ", value=" << ne->value() << ')';
4481 }
4482 break;
4483# endif // !QT_NO_GESTURES
4484 case QEvent::ApplicationStateChange:
4485 dbg << "QApplicationStateChangeEvent(";
4486 QtDebugUtils::formatQEnum(dbg, static_cast<const QApplicationStateChangeEvent *>(e)->applicationState());
4487 dbg << ')';
4488 break;
4489# ifndef QT_NO_CONTEXTMENU
4490 case QEvent::ContextMenu:
4491 dbg << "QContextMenuEvent(" << static_cast<const QContextMenuEvent *>(e)->pos() << ')';
4492 break;
4493# endif // !QT_NO_CONTEXTMENU
4494# if QT_CONFIG(tabletevent)
4495 case QEvent::TabletEnterProximity:
4496 case QEvent::TabletLeaveProximity:
4497 case QEvent::TabletPress:
4498 case QEvent::TabletMove:
4499 case QEvent::TabletRelease:
4500 formatTabletEvent(dbg, static_cast<const QTabletEvent *>(e));
4501 break;
4502# endif // QT_CONFIG(tabletevent)
4503 case QEvent::Enter:
4504 dbg << "QEnterEvent(" << static_cast<const QEnterEvent *>(e)->position() << ')';
4505 break;
4506 case QEvent::Timer:
4507 dbg << "QTimerEvent(id=" << static_cast<const QTimerEvent *>(e)->timerId() << ')';
4508 break;
4509 case QEvent::PlatformSurface:
4510 dbg << "QPlatformSurfaceEvent(surfaceEventType=";
4511 switch (static_cast<const QPlatformSurfaceEvent *>(e)->surfaceEventType()) {
4512 case QPlatformSurfaceEvent::SurfaceCreated:
4513 dbg << "SurfaceCreated";
4514 break;
4515 case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed:
4516 dbg << "SurfaceAboutToBeDestroyed";
4517 break;
4518 }
4519 dbg << ')';
4520 break;
4521 case QEvent::ScrollPrepare: {
4522 const QScrollPrepareEvent *se = static_cast<const QScrollPrepareEvent *>(e);
4523 dbg << "QScrollPrepareEvent(viewportSize=" << se->viewportSize()
4524 << ", contentPosRange=" << se->contentPosRange()
4525 << ", contentPos=" << se->contentPos() << ')';
4526 }
4527 break;
4528 case QEvent::Scroll: {
4529 const QScrollEvent *se = static_cast<const QScrollEvent *>(e);
4530 dbg << "QScrollEvent(contentPos=" << se->contentPos()
4531 << ", overshootDistance=" << se->overshootDistance()
4532 << ", scrollState=" << se->scrollState() << ')';
4533 }
4534 break;
4535 default:
4536 dbg << eventClassName(type) << '(';
4537 QtDebugUtils::formatQEnum(dbg, type);
4538 dbg << ", " << (const void *)e << ')';
4539 break;
4540 }
4541 return dbg;
4542}
4543#endif // !QT_NO_DEBUG_STREAM
4544
4545/*!
4546 \class QShortcutEvent
4547 \brief The QShortcutEvent class provides an event which is generated when
4548 the user presses a key combination.
4549
4550 \ingroup events
4551 \inmodule QtGui
4552
4553 Normally you do not need to use this class directly; QShortcut
4554 provides a higher-level interface to handle shortcut keys.
4555
4556 \sa QShortcut
4557*/
4558
4559/*!
4560 \fn const QKeySequence &QShortcutEvent::key() const
4561
4562 Returns the key sequence that triggered the event.
4563*/
4564
4565/*!
4566 \fn int QShortcutEvent::shortcutId() const
4567
4568 Returns the ID of the QShortcut object for which this event was
4569 generated.
4570
4571 \sa QShortcut::id()
4572*/
4573
4574/*!
4575 \fn bool QShortcutEvent::isAmbiguous() const
4576
4577 Returns \c true if the key sequence that triggered the event is
4578 ambiguous.
4579
4580 \sa QShortcut::activatedAmbiguously()
4581*/
4582
4583/*!
4584 \class QWindowStateChangeEvent
4585 \ingroup events
4586 \inmodule QtGui
4587
4588 \brief The QWindowStateChangeEvent class provides the window state before a
4589 window state change.
4590*/
4591
4592/*! \fn Qt::WindowStates QWindowStateChangeEvent::oldState() const
4593
4594 Returns the state of the window before the change.
4595*/
4596
4597/*! \internal
4598 */
4599QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates oldState, bool isOverride)
4600 : QEvent(WindowStateChange), m_oldStates(oldState), m_override(isOverride)
4601{
4602}
4603
4604/*! \internal
4605 */
4606bool QWindowStateChangeEvent::isOverride() const
4607{
4608 return m_override;
4609}
4610
4611/*! \internal
4612*/
4613QWindowStateChangeEvent::~QWindowStateChangeEvent()
4614{
4615}
4616
4617
4618/*!
4619 \class QTouchEvent
4620 \brief The QTouchEvent class contains parameters that describe a touch event.
4621 \since 4.6
4622 \ingroup events
4623 \ingroup touch
4624 \inmodule QtGui
4625
4626 \section1 Enabling Touch Events
4627
4628 Touch events occur when pressing, releasing, or moving one or more touch points on a touch
4629 device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the
4630 Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the
4631 \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true.
4632
4633 When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents
4634 attribute on the scroll area's \l{QAbstractScrollArea::viewport()}{viewport}.
4635
4636 Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a
4637 widget, and the widget will receive all updates for the touch point until it is released.
4638 Note that it is possible for a widget to receive events for numerous touch points, and that
4639 multiple widgets may be receiving touch events at the same time.
4640
4641 \section1 Event Handling
4642
4643 All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd or
4644 QEvent::TouchCancel. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for
4645 widgets and QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
4646
4647 Unlike widgets, QWindows receive touch events always, there is no need to opt in. When working
4648 directly with a QWindow, it is enough to reimplement QWindow::touchEvent().
4649
4650 The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that
4651 accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not
4652 filtered by an event filter, then no further touch events are sent until the next
4653 QEvent::TouchBegin.
4654
4655 Some systems may send an event of type QEvent::TouchCancel. Upon receiving this event
4656 applications are requested to ignore the entire active touch sequence. For example in a
4657 composited system the compositor may decide to treat certain gestures as system-wide
4658 gestures. Whenever such a decision is made (the gesture is recognized), the clients will be
4659 notified with a QEvent::TouchCancel event so they can update their state accordingly.
4660
4661 The pointCount() and point() functions can be used to access and iterate individual
4662 touch points.
4663
4664 The points() function returns a list of all touch points contained in the event.
4665 Note that this list may be empty, for example in case of a QEvent::TouchCancel event.
4666 Each point is an instance of the QEventPoint class. The QEventPoint::State enum
4667 describes the different states that a touch point may have.
4668
4669 \note The list of points() will never be partial: A touch event will always contain a touch
4670 point for each existing physical touch contacts targetting the window or widget to which the
4671 event is sent. For instance, assuming that all touches target the same window or widget, an
4672 event with a condition of points().count()==2 is guaranteed to imply that the number of
4673 fingers touching the touchscreen or touchpad is exactly two.
4674
4675 \section1 Event Delivery and Propagation
4676
4677 By default, QGuiApplication translates the first touch point in a QTouchEvent into
4678 a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not
4679 normally handle QTouchEvent. See below for information on some special considerations needed
4680 when doing this.
4681
4682 QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event
4683 contains a special accept flag that indicates whether the receiver wants the event. By default,
4684 the event is accepted. You should call ignore() if the touch event is not handled by your
4685 widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget
4686 accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the
4687 QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event
4688 propagation for QGraphicsItems).
4689
4690 \section1 Touch Point Grouping
4691
4692 As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the
4693 same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same
4694 widget, which could theoretically happen during propagation if, for example, the user touched 2
4695 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
4696
4697 To avoid this, Qt will group new touch points together using the following rules:
4698
4699 \list
4700
4701 \li When the first touch point is detected, the destination widget is determined firstly by the
4702 location on screen and secondly by the propagation rules.
4703
4704 \li When additional touch points are detected, Qt first looks to see if there are any active
4705 touch points on any ancestor or descendent of the widget under the new touch point. If there
4706 are, the new touch point is grouped with the first, and the new touch point will be sent in a
4707 single QTouchEvent to the widget that handled the first touch point. (The widget under the new
4708 touch point will not receive an event).
4709
4710 \endlist
4711
4712 This makes it possible for sibling widgets to handle touch events independently while making
4713 sure that the sequence of QTouchEvents is always correct.
4714
4715 \section1 Mouse Events and Touch Event Synthesizing
4716
4717 QTouchEvent delivery is independent from that of QMouseEvent. The application flags
4718 Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents
4719 can be used to enable or disable automatic synthesizing of touch events to mouse events and
4720 mouse events to touch events.
4721
4722 \section1 Caveats
4723
4724 \list
4725
4726 \li As mentioned above, enabling touch events means multiple widgets can be receiving touch
4727 events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents,
4728 this gives you great flexibility in designing touch user interfaces. Be aware of the
4729 implications. For example, it is possible that the user is moving a QSlider with one finger and
4730 pressing a QPushButton with another. The signals emitted by these widgets will be
4731 interleaved.
4732
4733 \li Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or
4734 QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event
4735 recipients, recursion may cause problems, including but not limited to lost events
4736 and unexpected infinite recursion.
4737
4738 \li QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an
4739 \l{QApplication::activePopupWidget()}{active pop-up widget}. The behavior of QTouchEvents is
4740 undefined when opening a pop-up or grabbing the mouse while there are more than one active touch
4741 points.
4742
4743 \endlist
4744
4745 \sa QEventPoint, QEventPoint::State, Qt::WA_AcceptTouchEvents,
4746 QGraphicsItem::acceptTouchEvents()
4747*/
4748
4749/*!
4750 Constructs a QTouchEvent with the given \a eventType, \a device,
4751 \a touchPoints, and current keyboard \a modifiers at the time of the event.
4752*/
4753
4754QTouchEvent::QTouchEvent(QEvent::Type eventType,
4755 const QPointingDevice *device,
4756 Qt::KeyboardModifiers modifiers,
4757 const QList<QEventPoint> &touchPoints)
4758 : QPointerEvent(eventType, device, modifiers, touchPoints),
4759 m_target(nullptr)
4760{
4761 for (QEventPoint &point : m_points) {
4762 m_touchPointStates |= point.state();
4763 QMutableEventPoint::from(point).setDevice(device);
4764 }
4765}
4766
4767/*!
4768 \obsolete
4769 Try to use another constructor, because \a touchPointStates
4770 can be calculated from the given \a touchPoints.
4771
4772 Constructs a QTouchEvent with the given \a eventType, \a device, and
4773 \a touchPoints. The \a touchPointStates and \a modifiers are the current
4774 touch point states and keyboard modifiers at the time of the event.
4775*/
4776QTouchEvent::QTouchEvent(QEvent::Type eventType,
4777 const QPointingDevice *device,
4778 Qt::KeyboardModifiers modifiers,
4779 QEventPoint::States touchPointStates,
4780 const QList<QEventPoint> &touchPoints)
4781 : QPointerEvent(eventType, device, modifiers, touchPoints),
4782 m_target(nullptr),
4783 m_touchPointStates(touchPointStates)
4784{
4785 for (QEventPoint &point : m_points)
4786 QMutableEventPoint::from(point).setDevice(device);
4787}
4788
4789/*!
4790 Destroys the QTouchEvent.
4791*/
4792QTouchEvent::~QTouchEvent()
4793{ }
4794
4795/*!
4796 Returns true if this event includes at least one newly-pressed touchpoint.
4797*/
4798bool QTouchEvent::isBeginEvent() const
4799{
4800 return m_touchPointStates.testFlag(QEventPoint::State::Pressed);
4801}
4802
4803/*!
4804 Returns true if this event does not include newly-pressed or newly-released
4805 touchpoints.
4806*/
4807bool QTouchEvent::isUpdateEvent() const
4808{
4809 return !m_touchPointStates.testFlag(QEventPoint::State::Pressed) &&
4810 !m_touchPointStates.testFlag(QEventPoint::State::Released);
4811}
4812
4813/*!
4814 Returns true if this event includes at least one newly-released touchpoint.
4815*/
4816bool QTouchEvent::isEndEvent() const
4817{
4818 return m_touchPointStates.testFlag(QEventPoint::State::Released);
4819}
4820
4821/*! \fn QObject *QTouchEvent::target() const
4822
4823 Returns the target object within the window on which the event occurred.
4824 This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
4825*/
4826
4827/*! \fn QEventPoint::States QTouchEvent::touchPointStates() const
4828
4829 Returns a bitwise OR of all the touch point states for this event.
4830*/
4831
4832/*! \fn const QList<QEventPoint> &QTouchEvent::touchPoints() const
4833 \obsolete
4834 Deprecated since Qt 6.0. Use points() instead.
4835
4836 Returns a reference to the list of touch points contained in the touch event.
4837
4838 \sa QPointerEvent::point(), QPointerEvent::pointCount()
4839*/
4840
4841/*! \class QEventPoint
4842 \brief The QEventPoint class provides information about a point in a QPointerEvent.
4843 \since 6.0
4844 \inmodule QtGui
4845*/
4846
4847/*!
4848 \enum QEventPoint::State
4849
4850 Specifies the state of this event point.
4851
4852 \value Unknown
4853 Unknown state.
4854
4855 \value Stationary
4856 The event point did not move.
4857
4858 \value Pressed
4859 The touch point or button is pressed.
4860
4861 \value Updated
4862 The event point was updated.
4863
4864 \value Released
4865 The touch point or button was released.
4866*/
4867
4868/*! \fn int QEventPoint::id() const
4869
4870 Returns the ID number of this event point.
4871
4872 \note Do not assume that ID numbers start at zero or that they are
4873 sequential. Such an assumption is often false due to the way
4874 the underlying drivers work.
4875*/
4876
4877/*! \fn QPointingDeviceUniqueId QEventPoint::uniqueId() const
4878
4879 Returns the unique ID of this point or token, if any.
4880
4881 It is often invalid (see \l {QPointingDeviceUniqueId::isValid()} {isValid()}),
4882 because touchscreens cannot uniquely identify fingers.
4883
4884 When it comes from a QTabletEvent, it identifies the serial number of the
4885 stylus in use.
4886
4887 It may identify a specific token (fiducial object) when the TUIO driver is
4888 in use with a touchscreen that supports them.
4889*/
4890
4891/*! \fn QEventPoint::State QEventPoint::state() const
4892 Returns the current state of this point.
4893*/
4894
4895/*! \fn QPointF QEventPoint::position() const
4896
4897 Returns the position of this point, relative to the widget
4898 or item that received the event.
4899*/
4900
4901/*! \fn QPointF QEventPoint::pos() const
4902 \obsolete
4903 Deprecated since Qt 6.0. Use position() instead.
4904
4905 Returns the position of this point, relative to the widget
4906 or item that received the event.
4907*/
4908
4909/*! \fn QPointF QEventPoint::scenePosition() const
4910 Returns the position of this point relative to the window or scene.
4911
4912 The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
4913 in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
4914 or the window position in widget applications.
4915
4916 \sa scenePressPosition(), position(), globalPosition()
4917*/
4918
4919/*! \fn QPointF QEventPoint::globalPosition() const
4920 Returns the position of this point on the screen or virtual desktop.
4921
4922 \sa globalPressPosition(), position(), scenePosition()
4923*/
4924
4925/*! \fn QPointF QEventPoint::pressPosition() const
4926 Returns the position at which this point was pressed, relative to the
4927 widget or item that received the event.
4928
4929 \sa position()
4930*/
4931
4932/*! \fn QPointF QEventPoint::scenePressPosition() const
4933 Returns the scene position at which this point was pressed.
4934
4935 The scene position is the position relative to QQuickWindow if handled in QQuickItem::event(),
4936 in QGraphicsScene coordinates if handled by an override of QGraphicsItem::touchEvent(),
4937 or the window position in widget applications.
4938
4939 \sa scenePosition(), pressPosition(), globalPressPosition()
4940*/
4941
4942/*! \fn QPointF QEventPoint::globalPressPosition() const
4943 Returns the position at which this point was pressed on the screen or virtual desktop.
4944
4945 \sa globalPosition(), pressPosition(), scenePressPosition()
4946*/
4947
4948/*! \fn QPointF QEventPoint::lastPosition() const
4949 Returns the position of this point from the previous press or move event,
4950 relative to the widget or QGraphicsItem that received the event.
4951
4952 \sa position(), pressPosition()
4953*/
4954
4955/*! \fn QPointF QEventPoint::sceneLastPosition() const
4956 Returns the scene position of this point from the previous press or move event.
4957
4958 The scene position is the position in QGraphicsScene coordinates
4959 if the QTouchEvent is handled by a QGraphicsItem::touchEvent()
4960 reimplementation, and identical to the screen position for
4961 widgets.
4962
4963 \sa scenePosition(), scenePressPosition()
4964*/
4965
4966/*! \fn qreal QEventPoint::pressure() const
4967 Returns the pressure of this point. The return value is in
4968 the range \c 0.0 to \c 1.0.
4969*/
4970
4971/*! \fn qreal QEventPoint::rotation() const
4972
4973 Returns the angular orientation of this point. The return value is in degrees,
4974 where zero (the default) indicates the finger, token or stylus is pointing upwards,
4975 a negative angle means it's rotated to the left, and a positive angle means
4976 it's rotated to the right. Most touchscreens do not detect rotation, so
4977 zero is the most common value.
4978*/
4979
4980/*! \fn QSizeF QEventPoint::ellipseDiameters() const
4981
4982 Returns the width and height of the bounding ellipse of the touch point.
4983 The return value is in logical pixels. Most touchscreens do not detect the
4984 shape of the contact point, and no mice or tablet devices can detect it,
4985 so a null size is the most common value. On some touchscreens the diameters
4986 may be nonzero and always equal (the ellipse is approximated as a circle).
4987*/
4988
4989/*!
4990 \fn QVector2D QEventPoint::velocity() const
4991 Returns a velocity vector, in units of pixels per second, in the coordinate
4992 system of the screen or desktop.
4993
4994 \note If the device's capabilities include QInputDevice::Velocity, it means
4995 velocity comes from the operating system (perhaps the touch hardware or
4996 driver provides it). But usually the \c Velocity capability is not set,
4997 indicating that the velocity is calculated by Qt, using a simple Kalman
4998 filter to provide a smoothed average velocity rather than an instantaneous
4999 value. Effectively it tells how fast and in what direction the user has
5000 been dragging this point over the last few events, with the most recent
5001 event having the strongest influence.
5002
5003 \sa QInputDevice::capabilities(), QInputEvent::device()
5004*/
5005
5006/*! \fn ulong QEventPoint::timestamp() const
5007 Returns the most recent time at which this point was included in a QPointerEvent.
5008
5009 \sa QPointerEvent::timestamp()
5010*/
5011
5012/*!
5013 \class QScrollPrepareEvent
5014 \since 4.8
5015 \ingroup events
5016 \inmodule QtGui
5017
5018 \brief The QScrollPrepareEvent class is sent in preparation of scrolling.
5019
5020 The scroll prepare event is sent before scrolling (usually by QScroller) is started.
5021 The object receiving this event should set viewportSize, maxContentPos and contentPos.
5022 It also should accept this event to indicate that scrolling should be started.
5023
5024 It is not guaranteed that a QScrollEvent will be sent after an accepted
5025 QScrollPrepareEvent, e.g. in a case where the maximum content position is (0, 0).
5026
5027 \sa QScrollEvent, QScroller
5028*/
5029
5030/*!
5031 Creates new QScrollPrepareEvent
5032 The \a startPos is the position of a touch or mouse event that started the scrolling.
5033*/
5034QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos)
5035 : QEvent(QEvent::ScrollPrepare), m_startPos(startPos)
5036{
5037}
5038
5039/*!
5040 Destroys QScrollEvent.
5041*/
5042QScrollPrepareEvent::~QScrollPrepareEvent()
5043{
5044}
5045
5046/*!
5047 Returns the position of the touch or mouse event that started the scrolling.
5048*/
5049QPointF QScrollPrepareEvent::startPos() const
5050{
5051 return m_startPos;
5052}
5053
5054/*!
5055 Returns size of the area that is to be scrolled as set by setViewportSize
5056
5057 \sa setViewportSize()
5058*/
5059QSizeF QScrollPrepareEvent::viewportSize() const
5060{
5061 return m_viewportSize;
5062}
5063
5064/*!
5065 Returns the range of coordinates for the content as set by setContentPosRange().
5066*/
5067QRectF QScrollPrepareEvent::contentPosRange() const
5068{
5069 return m_contentPosRange;
5070}
5071
5072/*!
5073 Returns the current position of the content as set by setContentPos.
5074*/
5075QPointF QScrollPrepareEvent::contentPos() const
5076{
5077 return m_contentPos;
5078}
5079
5080
5081/*!
5082 Sets the size of the area that is to be scrolled to \a size.
5083
5084 \sa viewportSize()
5085*/
5086void QScrollPrepareEvent::setViewportSize(const QSizeF &size)
5087{
5088 m_viewportSize = size;
5089}
5090
5091/*!
5092 Sets the range of content coordinates to \a rect.
5093
5094 \sa contentPosRange()
5095*/
5096void QScrollPrepareEvent::setContentPosRange(const QRectF &rect)
5097{
5098 m_contentPosRange = rect;
5099}
5100
5101/*!
5102 Sets the current content position to \a pos.
5103
5104 \sa contentPos()
5105*/
5106void QScrollPrepareEvent::setContentPos(const QPointF &pos)
5107{
5108 m_contentPos = pos;
5109}
5110
5111
5112/*!
5113 \class QScrollEvent
5114 \since 4.8
5115 \ingroup events
5116 \inmodule QtGui
5117
5118 \brief The QScrollEvent class is sent when scrolling.
5119
5120 The scroll event is sent to indicate that the receiver should be scrolled.
5121 Usually the receiver should be something visual like QWidget or QGraphicsObject.
5122
5123 Some care should be taken that no conflicting QScrollEvents are sent from two
5124 sources. Using QScroller::scrollTo is save however.
5125
5126 \sa QScrollPrepareEvent, QScroller
5127*/
5128
5129/*!
5130 \enum QScrollEvent::ScrollState
5131
5132 This enum describes the states a scroll event can have.
5133
5134 \value ScrollStarted Set for the first scroll event of a scroll activity.
5135
5136 \value ScrollUpdated Set for all but the first and the last scroll event of a scroll activity.
5137
5138 \value ScrollFinished Set for the last scroll event of a scroll activity.
5139
5140 \sa QScrollEvent::scrollState()
5141*/
5142
5143/*!
5144 Creates a new QScrollEvent
5145 \a contentPos is the new content position, \a overshootDistance is the
5146 new overshoot distance while \a scrollState indicates if this scroll
5147 event is the first one, the last one or some event in between.
5148*/
5149QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDistance, ScrollState scrollState)
5150 : QEvent(QEvent::Scroll), m_contentPos(contentPos), m_overshoot(overshootDistance), m_state(scrollState)
5151{
5152}
5153
5154/*!
5155 Destroys QScrollEvent.
5156*/
5157QScrollEvent::~QScrollEvent()
5158{
5159}
5160
5161/*!
5162 Returns the new scroll position.
5163*/
5164QPointF QScrollEvent::contentPos() const
5165{
5166 return m_contentPos;
5167}
5168
5169/*!
5170 Returns the new overshoot distance.
5171 See QScroller for an explanation of the term overshoot.
5172
5173 \sa QScroller
5174*/
5175QPointF QScrollEvent::overshootDistance() const
5176{
5177 return m_overshoot;
5178}
5179
5180/*!
5181 Returns the current scroll state as a combination of ScrollStateFlag values.
5182 ScrollStarted (or ScrollFinished) will be set, if this scroll event is the first (or last) event in a scrolling activity.
5183 Please note that both values can be set at the same time, if the activity consists of a single QScrollEvent.
5184 All other scroll events in between will have their state set to ScrollUpdated.
5185
5186 A widget could for example revert selections when scrolling is started and stopped.
5187*/
5188QScrollEvent::ScrollState QScrollEvent::scrollState() const
5189{
5190 return m_state;
5191}
5192
5193/*!
5194 Creates a new QScreenOrientationChangeEvent
5195 \a screenOrientation is the new orientation of the \a screen.
5196*/
5197QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation screenOrientation)
5198 : QEvent(QEvent::OrientationChange), m_screen(screen), m_orientation(screenOrientation)
5199{
5200}
5201
5202/*!
5203 Destroys QScreenOrientationChangeEvent.
5204*/
5205QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent()
5206{
5207}
5208
5209/*!
5210 Returns the screen whose orientation changed.
5211*/
5212QScreen *QScreenOrientationChangeEvent::screen() const
5213{
5214 return m_screen;
5215}
5216
5217/*!
5218 Returns the orientation of the screen.
5219*/
5220Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const
5221{
5222 return m_orientation;
5223}
5224
5225/*!
5226 Creates a new QApplicationStateChangeEvent.
5227 \a applicationState is the new state.
5228*/
5229QApplicationStateChangeEvent::QApplicationStateChangeEvent(Qt::ApplicationState applicationState)
5230 : QEvent(QEvent::ApplicationStateChange), m_applicationState(applicationState)
5231{
5232}
5233
5234/*!
5235 Returns the state of the application.
5236*/
5237Qt::ApplicationState QApplicationStateChangeEvent::applicationState() const
5238{
5239 return m_applicationState;
5240}
5241
5242/*! \internal
5243 Add the given \a point.
5244*/
5245void QMutableTouchEvent::addPoint(const QEventPoint &point)
5246{
5247 m_points.append(point);
5248 auto &added = m_points.last();
5249 if (!added.device())
5250 QMutableEventPoint::from(added).setDevice(pointingDevice());
5251 m_touchPointStates |= point.state();
5252}
5253
5254/*!
5255 \class QPointingDeviceUniqueId
5256 \since 5.8
5257 \ingroup events
5258 \inmodule QtGui
5259
5260 \brief QPointingDeviceUniqueId identifies a unique object, such as a tagged token
5261 or stylus, which is used with a pointing device.
5262
5263 QPointingDeviceUniqueIds can be compared for equality, and can be used as keys in a QHash.
5264 You get access to the numerical ID via numericId(), if the device supports such IDs.
5265 For future extensions, though, you should not use that function, but compare objects
5266 of this type using the equality operator.
5267
5268 This class is a thin wrapper around an integer ID. You pass it into and out of
5269 functions by value.
5270
5271 \sa QEventPoint
5272*/
5273
5274/*!
5275 \fn QPointingDeviceUniqueId::QPointingDeviceUniqueId()
5276 Constructs an invalid unique pointer ID.
5277*/
5278
5279/*!
5280 Constructs a unique pointer ID from numeric ID \a id.
5281*/
5282QPointingDeviceUniqueId QPointingDeviceUniqueId::fromNumericId(qint64 id)
5283{
5284 QPointingDeviceUniqueId result;
5285 result.m_numericId = id;
5286 return result;
5287}
5288
5289/*!
5290 \fn bool QPointingDeviceUniqueId::isValid() const
5291
5292 Returns whether this unique pointer ID is valid, that is, it represents an actual
5293 pointer.
5294*/
5295
5296/*!
5297 \property QPointingDeviceUniqueId::numericId
5298 \brief the numeric unique ID of the token represented by a touchpoint
5299
5300 If the device provides a numeric ID, isValid() returns true, and this
5301 property provides the numeric ID;
5302 otherwise it is -1.
5303
5304 You should not use the value of this property in portable code, but
5305 instead rely on equality to identify pointers.
5306
5307 \sa isValid()
5308*/
5309qint64 QPointingDeviceUniqueId::numericId() const noexcept
5310{
5311 return m_numericId;
5312}
5313
5314/*!
5315 \relates QPointingDeviceUniqueId
5316 \since 5.8
5317
5318 Returns whether the two unique pointer IDs \a lhs and \a rhs identify the same pointer
5319 (\c true) or not (\c false).
5320*/
5321bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
5322{
5323 return lhs.numericId() == rhs.numericId();
5324}
5325
5326/*!
5327 \fn bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs)
5328 \relates QPointingDeviceUniqueId
5329 \since 5.8
5330
5331 Returns whether the two unique pointer IDs \a lhs and \a rhs identify different pointers
5332 (\c true) or not (\c false).
5333*/
5334
5335/*!
5336 \relates QPointingDeviceUniqueId
5337 \since 5.8
5338
5339 Returns the hash value for \a key, using \a seed to seed the calculation.
5340*/
5341size_t qHash(QPointingDeviceUniqueId key, size_t seed) noexcept
5342{
5343 return qHash(key.numericId(), seed);
5344}
5345
5346QT_END_NAMESPACE
5347