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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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