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

source code of qtbase/src/gui/kernel/qevent.cpp