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 A context menu event is sent when a user performs an action that should
1911 open a contextual menu:
1912 \list
1913 \li clicking the right mouse button
1914 \li pressing a dedicated keyboard menu key (if the keyboard has one,
1915 such as the menu key on standard 104-key PC keyboards)
1916 \li pressing some other keyboard shortcut (such as "Ctrl+Return" by
1917 default on macOS 15 and newer)
1918 \endlist
1919
1920 The expected context menu should contain \l {QAction}{actions} that are
1921 relevant to some content within the application (the "context"). In Qt, the
1922 context is at least the particular \l {QWidget}{widget} or Qt Quick \l Item
1923 that receives the QContextMenuEvent. If there is a selection, that should
1924 probably be treated as the context. The context can be further refined
1925 using \l QContextMenuEvent::pos() to pinpoint the content within the
1926 widget, item or selection.
1927
1928 Widgets can override \l QWidget::contextMenuEvent() to handle this event.
1929 Many widgets already do that, and have useful context menus by default.
1930 Some widgets have a function such as
1931 \l {QLineEdit::createStandardContextMenu()}{createStandardContextMenu()}
1932 to populate the default set of actions into a \l QMenu, which can be
1933 customized further in your subclass and then shown.
1934
1935 In Qt Quick, the event can be handled via the
1936 \l {QtQuick.Controls::}{ContextMenu} attached property. Some
1937 \l {QtQuick.Controls} Controls already provide context menus by default.
1938
1939 Unlike most synthetic events (such as a QMouseEvent that is sent only after
1940 a QTouchEvent or QTabletEvent was not accepted), QContextMenuEvent is sent
1941 regardless of whether the original mouse or key event was already handled
1942 and \l {QEvent::isAccepted()}{accepted}. This is to accommodate the Windows
1943 UI pattern of selecting some kind of items (icons, drawing elements, or
1944 cells in an Item View) using the right mouse button (clicking or dragging),
1945 and then getting a context menu as soon as you release the right mouse
1946 button. (The actions on the menu are meant to apply to the selection.)
1947 Therefore, on Windows the QContextMenuEvent is sent on mouse release; while
1948 on other platforms, it's sent on press. Qt follows the
1949 \l {QStyleHints::contextMenuTrigger()}{platform convention} by default.
1950
1951 There are also some Qt Quick Controls such as \l {QtQuick.Controls::}{Pane}
1952 that accept mouse events, and nevertheless receive a QContextMenuEvent
1953 after a mouse press or click.
1954
1955 If you prefer to support the press-drag-release UI pattern to open a
1956 context menu on press, and drag over a menu item to select it on release,
1957 you will need to do that by handling \l {QMouseEvent}{QMouseEvents} directly
1958 (by overriding \l {QWidget::mousePressEvent()}{virtual functions} in
1959 QWidget subclasses, or using \l TapHandler to open a \l Menu in Qt Quick);
1960 and then the QContextMenuEvent will be redundant when the \l reason() is
1961 \c Mouse. You should \l ignore() the event in that case; but you should
1962 still ensure that the widget, custom control or application can respond to
1963 a QContextMenuEvent that \l {reason()}{comes from} the platform-specific
1964 keyboard shortcut.
1965
1966 When a QContextMenuEvent is \l {ignore()}{ignored}, Qt attempts to deliver
1967 it to other widgets and/or Items under the \l {pos()}{position} (which
1968 is usually translated from the cursor position).
1969*/
1970
1971#ifndef QT_NO_CONTEXTMENU
1972/*!
1973 Constructs a context menu event object with the accept parameter
1974 flag set to false.
1975
1976 The \a reason parameter must be QContextMenuEvent::Mouse or
1977 QContextMenuEvent::Keyboard.
1978
1979 The \a pos parameter specifies the mouse position relative to the
1980 receiving widget. \a globalPos is the mouse position in absolute
1981 coordinates. The \a modifiers holds the keyboard modifiers.
1982*/
1983QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
1984 Qt::KeyboardModifiers modifiers)
1985 : QInputEvent(ContextMenu, QPointingDevice::primaryPointingDevice(), modifiers), m_pos(pos), m_globalPos(globalPos), m_reason(reason)
1986{}
1987
1988Q_IMPL_EVENT_COMMON(QContextMenuEvent)
1989
1990#if QT_DEPRECATED_SINCE(6, 4)
1991/*!
1992 \deprecated [6.4] Use the other constructor instead (global position is required).
1993
1994 Constructs a context menu event object with the accept parameter
1995 flag set to false.
1996
1997 The \a reason parameter must be QContextMenuEvent::Mouse or
1998 QContextMenuEvent::Keyboard.
1999
2000 The \a pos parameter specifies the mouse position relative to the
2001 receiving widget.
2002
2003 The globalPos() is initialized to QCursor::pos(), which may not be
2004 appropriate. Use the other constructor to specify the global
2005 position explicitly.
2006*/
2007QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos)
2008 : QInputEvent(ContextMenu, QInputDevice::primaryKeyboard()), m_pos(pos), m_reason(reason)
2009{
2010#ifndef QT_NO_CURSOR
2011 m_globalPos = QCursor::pos();
2012#endif
2013}
2014#endif
2015
2016/*!
2017 \fn const QPoint &QContextMenuEvent::pos() const
2018
2019 Returns the position of the mouse pointer relative to the widget
2020 that received the event.
2021
2022 \note If the QContextMenuEvent did not come from the right mouse button,
2023 \c pos() may be \l {QPoint::isNull()}{null}.
2024
2025 \sa x(), y(), globalPos()
2026*/
2027
2028/*!
2029 \fn int QContextMenuEvent::x() const
2030
2031 Returns the x position of the mouse pointer, relative to the
2032 widget that received the event.
2033
2034 \sa y(), pos()
2035*/
2036
2037/*!
2038 \fn int QContextMenuEvent::y() const
2039
2040 Returns the y position of the mouse pointer, relative to the
2041 widget that received the event.
2042
2043 \sa x(), pos()
2044*/
2045
2046/*!
2047 \fn const QPoint &QContextMenuEvent::globalPos() const
2048
2049 Returns the global position of the mouse pointer at the time of
2050 the event.
2051
2052 \sa x(), y(), pos()
2053*/
2054
2055/*!
2056 \fn int QContextMenuEvent::globalX() const
2057
2058 Returns the global x position of the mouse pointer at the time of
2059 the event.
2060
2061 \sa globalY(), globalPos()
2062*/
2063
2064/*!
2065 \fn int QContextMenuEvent::globalY() const
2066
2067 Returns the global y position of the mouse pointer at the time of
2068 the event.
2069
2070 \sa globalX(), globalPos()
2071*/
2072#endif // QT_NO_CONTEXTMENU
2073
2074/*!
2075 \enum QContextMenuEvent::Reason
2076
2077 This enum describes the reason why the event was sent.
2078
2079 \value Mouse The mouse caused the event to be sent. Normally this
2080 means the right mouse button was clicked, but this is platform
2081 dependent.
2082
2083 \value Keyboard The keyboard caused this event to be sent. On
2084 Windows, this means the menu button was pressed.
2085
2086 \value Other The event was sent by some other means (i.e. not by
2087 the mouse or keyboard).
2088*/
2089
2090
2091/*!
2092 \fn QContextMenuEvent::Reason QContextMenuEvent::reason() const
2093
2094 Returns the reason for this context event.
2095*/
2096
2097
2098/*!
2099 \class QInputMethodEvent
2100 \brief The QInputMethodEvent class provides parameters for input method events.
2101 \inmodule QtGui
2102
2103 \ingroup events
2104
2105 Input method events are sent to widgets when an input method is
2106 used to enter text into a widget. Input methods are widely used
2107 to enter text for languages with non-Latin alphabets.
2108
2109 Note that when creating custom text editing widgets, the
2110 Qt::WA_InputMethodEnabled window attribute must be set explicitly
2111 (using the QWidget::setAttribute() function) in order to receive
2112 input method events.
2113
2114 The events are of interest to authors of keyboard entry widgets
2115 who want to be able to correctly handle languages with complex
2116 character input. Text input in such languages is usually a three
2117 step process:
2118
2119 \list 1
2120 \li \b{Starting to Compose}
2121
2122 When the user presses the first key on a keyboard, an input
2123 context is created. This input context will contain a string
2124 of the typed characters.
2125
2126 \li \b{Composing}
2127
2128 With every new key pressed, the input method will try to create a
2129 matching string for the text typed so far called preedit
2130 string. While the input context is active, the user can only move
2131 the cursor inside the string belonging to this input context.
2132
2133 \li \b{Completing}
2134
2135 At some point, the user will activate a user interface component
2136 (perhaps using a particular key) where they can choose from a
2137 number of strings matching the text they have typed so far. The
2138 user can either confirm their choice cancel the input; in either
2139 case the input context will be closed.
2140 \endlist
2141
2142 QInputMethodEvent models these three stages, and transfers the
2143 information needed to correctly render the intermediate result. A
2144 QInputMethodEvent has two main parameters: preeditString() and
2145 commitString(). The preeditString() parameter gives the currently
2146 active preedit string. The commitString() parameter gives a text
2147 that should get added to (or replace parts of) the text of the
2148 editor widget. It usually is a result of the input operations and
2149 has to be inserted to the widgets text directly before the preedit
2150 string.
2151
2152 If the commitString() should replace parts of the text in
2153 the editor, replacementLength() will contain the number of
2154 characters to be replaced. replacementStart() contains the position
2155 at which characters are to be replaced relative from the start of
2156 the preedit string.
2157
2158 A number of attributes control the visual appearance of the
2159 preedit string (the visual appearance of text outside the preedit
2160 string is controlled by the widget only). The AttributeType enum
2161 describes the different attributes that can be set.
2162
2163 A class implementing QWidget::inputMethodEvent() or
2164 QGraphicsItem::inputMethodEvent() should at least understand and
2165 honor the \l TextFormat and \l Cursor attributes.
2166
2167 Since input methods need to be able to query certain properties
2168 from the widget or graphics item, subclasses must also implement
2169 QWidget::inputMethodQuery() and QGraphicsItem::inputMethodQuery(),
2170 respectively.
2171
2172 When receiving an input method event, the text widget has to performs the
2173 following steps:
2174
2175 \list 1
2176 \li If the widget has selected text, the selected text should get
2177 removed.
2178
2179 \li Remove the text starting at replacementStart() with length
2180 replacementLength() and replace it by the commitString(). If
2181 replacementLength() is 0, replacementStart() gives the insertion
2182 position for the commitString().
2183
2184 When doing replacement the area of the preedit
2185 string is ignored, thus a replacement starting at -1 with a length
2186 of 2 will remove the last character before the preedit string and
2187 the first character afterwards, and insert the commit string
2188 directly before the preedit string.
2189
2190 If the widget implements undo/redo, this operation gets added to
2191 the undo stack.
2192
2193 \li If there is no current preedit string, insert the
2194 preeditString() at the current cursor position; otherwise replace
2195 the previous preeditString with the one received from this event.
2196
2197 If the widget implements undo/redo, the preeditString() should not
2198 influence the undo/redo stack in any way.
2199
2200 The widget should examine the list of attributes to apply to the
2201 preedit string. It has to understand at least the TextFormat and
2202 Cursor attributes and render them as specified.
2203 \endlist
2204
2205 \sa QInputMethod
2206*/
2207
2208/*!
2209 \enum QInputMethodEvent::AttributeType
2210
2211 \value TextFormat
2212 A QTextCharFormat for the part of the preedit string specified by
2213 start and length. value contains a QVariant of type QTextFormat
2214 specifying rendering of this part of the preedit string. There
2215 should be at most one format for every part of the preedit
2216 string. If several are specified for any character in the string the
2217 behaviour is undefined. A conforming implementation has to at least
2218 honor the backgroundColor, textColor and fontUnderline properties
2219 of the format.
2220
2221 \value Cursor If set, a cursor should be shown inside the preedit
2222 string at position start. The length variable determines whether
2223 the cursor is visible or not. If the length is 0 the cursor is
2224 invisible. If value is a QVariant of type QColor this color will
2225 be used for rendering the cursor, otherwise the color of the
2226 surrounding text will be used. There should be at most one Cursor
2227 attribute per event. If several are specified the behaviour is
2228 undefined.
2229
2230 \value Language
2231 The variant contains a QLocale object specifying the language of a
2232 certain part of the preedit string. There should be at most one
2233 language set for every part of the preedit string. If several are
2234 specified for any character in the string the behavior is undefined.
2235
2236 \value Ruby
2237 The ruby text for a part of the preedit string. There should be at
2238 most one ruby text set for every part of the preedit string. If
2239 several are specified for any character in the string the behaviour
2240 is undefined.
2241
2242 \value Selection
2243 If set, the edit cursor should be moved to the specified position
2244 in the editor text contents. In contrast with \c Cursor, this
2245 attribute does not work on the preedit text, but on the surrounding
2246 text. The cursor will be moved after the commit string has been
2247 committed, and the preedit string will be located at the new edit
2248 position.
2249 The start position specifies the new position and the length
2250 variable can be used to set a selection starting from that point.
2251 The value is unused.
2252
2253 \value MimeData
2254 If set, the variant contains a QMimeData object representing the
2255 committed text. The commitString() still provides the plain text
2256 representation of the committed text.
2257
2258 \sa Attribute
2259*/
2260
2261/*!
2262 \class QInputMethodEvent::Attribute
2263 \inmodule QtGui
2264 \brief The QInputMethodEvent::Attribute class stores an input method attribute.
2265*/
2266
2267/*!
2268 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length, QVariant value)
2269
2270 Constructs an input method attribute. \a type specifies the type
2271 of attribute, \a start and \a length the position of the
2272 attribute, and \a value the value of the attribute.
2273*/
2274
2275/*!
2276 \fn QInputMethodEvent::Attribute::Attribute(AttributeType type, int start, int length)
2277 \overload
2278 \since 5.7
2279
2280 Constructs an input method attribute with no value. \a type
2281 specifies the type of attribute, and \a start and \a length
2282 the position of the attribute.
2283*/
2284
2285/*!
2286 Constructs an event of type QEvent::InputMethod. The
2287 attributes(), preeditString(), commitString(), replacementStart(),
2288 and replacementLength() are initialized to default values.
2289
2290 \sa setCommitString()
2291*/
2292QInputMethodEvent::QInputMethodEvent()
2293 : QEvent(QEvent::InputMethod), m_replacementStart(0), m_replacementLength(0)
2294{
2295}
2296
2297/*!
2298 Constructs an event of type QEvent::InputMethod. The
2299 preedit text is set to \a preeditText, the attributes to
2300 \a attributes.
2301
2302 The commitString(), replacementStart(), and replacementLength()
2303 values can be set using setCommitString().
2304
2305 \sa preeditString(), attributes()
2306*/
2307QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes)
2308 : QEvent(QEvent::InputMethod), m_preedit(preeditText), m_attributes(attributes),
2309 m_replacementStart(0), m_replacementLength(0)
2310{
2311}
2312
2313Q_IMPL_EVENT_COMMON(QInputMethodEvent)
2314
2315/*!
2316 Sets the commit string to \a commitString.
2317
2318 The commit string is the text that should get added to (or
2319 replace parts of) the text of the editor widget. It usually is a
2320 result of the input operations and has to be inserted to the
2321 widgets text directly before the preedit string.
2322
2323 If the commit string should replace parts of the text in
2324 the editor, \a replaceLength specifies the number of
2325 characters to be replaced. \a replaceFrom specifies the position
2326 at which characters are to be replaced relative from the start of
2327 the preedit string.
2328
2329 \sa commitString(), replacementStart(), replacementLength()
2330*/
2331void QInputMethodEvent::setCommitString(const QString &commitString, int replaceFrom, int replaceLength)
2332{
2333 m_commit = commitString;
2334 m_replacementStart = replaceFrom;
2335 m_replacementLength = replaceLength;
2336}
2337
2338/*!
2339 \fn const QList<Attribute> &QInputMethodEvent::attributes() const
2340
2341 Returns the list of attributes passed to the QInputMethodEvent
2342 constructor. The attributes control the visual appearance of the
2343 preedit string (the visual appearance of text outside the preedit
2344 string is controlled by the widget only).
2345
2346 \sa preeditString(), Attribute
2347*/
2348
2349/*!
2350 \fn const QString &QInputMethodEvent::preeditString() const
2351
2352 Returns the preedit text, i.e. the text before the user started
2353 editing it.
2354
2355 \sa commitString(), attributes()
2356*/
2357
2358/*!
2359 \fn const QString &QInputMethodEvent::commitString() const
2360
2361 Returns the text that should get added to (or replace parts of)
2362 the text of the editor widget. It usually is a result of the
2363 input operations and has to be inserted to the widgets text
2364 directly before the preedit string.
2365
2366 \sa setCommitString(), preeditString(), replacementStart(), replacementLength()
2367*/
2368
2369/*!
2370 \fn int QInputMethodEvent::replacementStart() const
2371
2372 Returns the position at which characters are to be replaced relative
2373 from the start of the preedit string.
2374
2375 \sa replacementLength(), setCommitString()
2376*/
2377
2378/*!
2379 \fn int QInputMethodEvent::replacementLength() const
2380
2381 Returns the number of characters to be replaced in the preedit
2382 string.
2383
2384 \sa replacementStart(), setCommitString()
2385*/
2386
2387/*!
2388 \class QInputMethodQueryEvent
2389 \since 5.0
2390 \inmodule QtGui
2391
2392 \brief The QInputMethodQueryEvent class provides an event sent by the input context to input objects.
2393
2394 It is used by the
2395 input method to query a set of properties of the object to be
2396 able to support complex input method operations as support for
2397 surrounding text and reconversions.
2398
2399 queries() specifies which properties are queried.
2400
2401 The object should call setValue() on the event to fill in the requested
2402 data before calling accept().
2403*/
2404
2405/*!
2406 \fn Qt::InputMethodQueries QInputMethodQueryEvent::queries() const
2407
2408 Returns the properties queried by the event.
2409 */
2410
2411/*!
2412 Constructs a query event for properties given by \a queries.
2413 */
2414QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries)
2415 : QEvent(InputMethodQuery),
2416 m_queries(queries)
2417{
2418}
2419
2420Q_IMPL_EVENT_COMMON(QInputMethodQueryEvent)
2421
2422/*!
2423 Sets property \a query to \a value.
2424 */
2425void QInputMethodQueryEvent::setValue(Qt::InputMethodQuery query, const QVariant &value)
2426{
2427 for (int i = 0; i < m_values.size(); ++i) {
2428 if (m_values.at(i).query == query) {
2429 m_values[i].value = value;
2430 return;
2431 }
2432 }
2433 QueryPair pair = { .query: query, .value: value };
2434 m_values.append(t: pair);
2435}
2436
2437/*!
2438 Returns value of the property \a query.
2439 */
2440QVariant QInputMethodQueryEvent::value(Qt::InputMethodQuery query) const
2441{
2442 for (int i = 0; i < m_values.size(); ++i)
2443 if (m_values.at(i).query == query)
2444 return m_values.at(i).value;
2445 return QVariant();
2446}
2447
2448#if QT_CONFIG(tabletevent)
2449
2450/*!
2451 \class QTabletEvent
2452 \brief The QTabletEvent class contains parameters that describe a Tablet event.
2453 \inmodule QtGui
2454
2455 \ingroup events
2456
2457 \e{Tablet events} are generated from tablet peripherals such as Wacom
2458 tablets and various other brands, and electromagnetic stylus devices
2459 included with some types of tablet computers. (It is not the same as
2460 \l QTouchEvent which a touchscreen generates, even when a passive stylus is
2461 used on a touchscreen.)
2462
2463 Tablet events are similar to mouse events; for example, the \l x(), \l y(),
2464 \l pos(), \l globalX(), \l globalY(), and \l globalPos() accessors provide
2465 the cursor position, and you can see which \l buttons() are pressed
2466 (pressing the stylus tip against the tablet surface is equivalent to a left
2467 mouse button). But tablet events also pass through some extra information
2468 that the tablet device driver provides; for example, you might want to do
2469 subpixel rendering with higher resolution coordinates (\l globalPosF()),
2470 adjust color brightness based on the \l pressure() of the tool against the
2471 tablet surface, use different brushes depending on the type of tool in use
2472 (\l deviceType()), modulate the brush shape in some way according to the
2473 X-axis and Y-axis tilt of the tool with respect to the tablet surface
2474 (\l xTilt() and \l yTilt()), and use a virtual eraser instead of a brush if
2475 the user switches to the other end of a double-ended stylus
2476 (\l pointerType()).
2477
2478 Every event contains an accept flag that indicates whether the receiver
2479 wants the event. You should call QTabletEvent::accept() if you handle the
2480 tablet event; otherwise it will be sent to the parent widget. The exception
2481 are TabletEnterProximity and TabletLeaveProximity events: these are only
2482 sent to QApplication and do not check whether or not they are accepted.
2483
2484 The QWidget::setEnabled() function can be used to enable or disable
2485 mouse, tablet and keyboard events for a widget.
2486
2487 The event handler QWidget::tabletEvent() receives TabletPress,
2488 TabletRelease and TabletMove events. Qt will first send a
2489 tablet event, then if it is not accepted by any widget, it will send a
2490 mouse event. This allows users of applications that are not designed for
2491 tablets to use a tablet like a mouse. However high-resolution drawing
2492 applications should handle the tablet events, because they can occur at a
2493 higher frequency, which is a benefit for smooth and accurate drawing.
2494 If the tablet events are rejected, the synthetic mouse events may be
2495 compressed for efficiency.
2496
2497 Note that pressing the stylus button while the stylus hovers over the
2498 tablet will generate a button press on some types of tablets, while on
2499 other types it will be necessary to press the stylus against the tablet
2500 surface in order to register the simultaneous stylus button press.
2501
2502 \section1 Notes for X11 Users
2503
2504 If the tablet is configured in xorg.conf to use the Wacom driver, there
2505 will be separate XInput "devices" for the stylus, eraser, and (optionally)
2506 cursor and touchpad. Qt recognizes these by their names. Otherwise, if the
2507 tablet is configured to use the evdev driver, there will be only one device
2508 and applications may not be able to distinguish the stylus from the eraser.
2509
2510 \section1 Notes for Windows Users
2511
2512 Tablet support currently requires the WACOM windows driver providing the DLL
2513 \c{wintab32.dll} to be installed. It is contained in older packages,
2514 for example \c{pentablet_5.3.5-3.exe}.
2515
2516*/
2517
2518/*!
2519 Construct a tablet event of the given \a type.
2520
2521 The \a pos parameter indicates where the event occurred in the widget;
2522 \a globalPos is the corresponding position in absolute coordinates.
2523
2524 \a pressure gives the pressure exerted on the device \a dev.
2525
2526 \a xTilt and \a yTilt give the device's degree of tilt from the
2527 x and y axes respectively.
2528
2529 \a keyState specifies which keyboard modifiers are pressed (e.g.,
2530 \uicontrol{Ctrl}).
2531
2532 The \a z parameter gives the Z coordinate of the device on the tablet;
2533 this is usually given by a wheel on a 4D mouse. If the device does not
2534 support a Z-axis (i.e. \l QPointingDevice::capabilities() does not include
2535 \c ZPosition), pass \c 0 here.
2536
2537 The \a tangentialPressure parameter gives the tangential pressure
2538 thumbwheel value from an airbrush. If the device does not support
2539 tangential pressure (i.e. \l QPointingDevice::capabilities() does not
2540 include \c TangentialPressure), pass \c 0 here.
2541
2542 \a rotation gives the device's rotation in degrees.
2543 4D mice, the Wacom Art Pen, and the Apple Pencil support rotation.
2544 If the device does not support rotation (i.e. \l QPointingDevice::capabilities()
2545 does not include \c Rotation), pass \c 0 here.
2546
2547 The \a button that caused the event is given as a value from the
2548 \l Qt::MouseButton enum. If the event \a type is not \l TabletPress or
2549 \l TabletRelease, the appropriate button for this event is \l Qt::NoButton.
2550
2551 \a buttons is the state of all buttons at the time of the event.
2552
2553 \sa pos(), globalPos(), device(), pressure(), xTilt(), yTilt(), uniqueId(), rotation(),
2554 tangentialPressure(), z()
2555*/
2556QTabletEvent::QTabletEvent(Type type, const QPointingDevice *dev, const QPointF &pos, const QPointF &globalPos,
2557 qreal pressure, float xTilt, float yTilt,
2558 float tangentialPressure, qreal rotation, float z,
2559 Qt::KeyboardModifiers keyState,
2560 Qt::MouseButton button, Qt::MouseButtons buttons)
2561 : QSinglePointEvent(type, dev, pos, pos, globalPos, button, buttons, keyState),
2562 m_tangential(tangentialPressure),
2563 m_xTilt(xTilt),
2564 m_yTilt(yTilt),
2565 m_z(z)
2566{
2567 QEventPoint &p = point(i: 0);
2568 QMutableEventPoint::setPressure(p, arg: pressure);
2569 QMutableEventPoint::setRotation(p, arg: rotation);
2570}
2571
2572Q_IMPL_POINTER_EVENT(QTabletEvent)
2573
2574/*!
2575 \fn qreal QTabletEvent::tangentialPressure() const
2576
2577 Returns the tangential pressure for the device. This is typically given by a finger
2578 wheel on an airbrush tool. The range is from -1.0 to 1.0. 0.0 indicates a
2579 neutral position. Current airbrushes can only move in the positive
2580 direction from the neutrual position. If the device does not support
2581 tangential pressure, this value is always 0.0.
2582
2583 \note The value is stored as a single-precision float.
2584
2585 \sa pressure()
2586*/
2587
2588/*!
2589 \fn qreal QTabletEvent::rotation() const
2590
2591 Returns the rotation of the current tool in degrees, where zero means the
2592 tip of the stylus is pointing towards the top of the tablet, a positive
2593 value means it's turned to the right, and a negative value means it's
2594 turned to the left. This can be given by a 4D Mouse or a rotation-capable
2595 stylus (such as the Wacom Art Pen or the Apple Pencil). If the device does
2596 not support rotation, this value is always 0.0.
2597*/
2598
2599/*!
2600 \fn qreal QTabletEvent::pressure() const
2601
2602 Returns the pressure for the device. 0.0 indicates that the stylus is not
2603 on the tablet, 1.0 indicates the maximum amount of pressure for the stylus.
2604
2605 \sa tangentialPressure()
2606*/
2607
2608/*!
2609 \fn qreal QTabletEvent::xTilt() const
2610
2611 Returns the angle between the device (a pen, for example) and the
2612 perpendicular in the direction of the x axis.
2613 Positive values are towards the tablet's physical right. The angle
2614 is in the range -60 to +60 degrees.
2615
2616 \image qtabletevent-tilt.png
2617
2618 \note The value is stored as a single-precision float.
2619
2620 \sa yTilt()
2621*/
2622
2623/*!
2624 \fn qreal QTabletEvent::yTilt() const
2625
2626 Returns the angle between the device (a pen, for example) and the
2627 perpendicular in the direction of the y axis.
2628 Positive values are towards the bottom of the tablet. The angle is
2629 within the range -60 to +60 degrees.
2630
2631 \note The value is stored as a single-precision float.
2632
2633 \sa xTilt()
2634*/
2635
2636/*!
2637 \fn QPoint QTabletEvent::pos() const
2638 \deprecated [6.0] Use position().toPoint() instead.
2639
2640 Returns the position of the device, relative to the widget that
2641 received the event.
2642
2643 If you move widgets around in response to mouse events, use
2644 globalPos() instead of this function.
2645
2646 \sa x(), y(), globalPos()
2647*/
2648
2649/*!
2650 \fn int QTabletEvent::x() const
2651 \deprecated [6.0] Use position().x() instead.
2652
2653 Returns the x position of the device, relative to the widget that
2654 received the event.
2655
2656 \sa y(), pos()
2657*/
2658
2659/*!
2660 \fn int QTabletEvent::y() const
2661 \deprecated [6.0] Use position().y() instead.
2662
2663 Returns the y position of the device, relative to the widget that
2664 received the event.
2665
2666 \sa x(), pos()
2667*/
2668
2669/*!
2670 \fn qreal QTabletEvent::z() const
2671
2672 Returns the z position of the device. Typically this is represented by a
2673 wheel on a 4D Mouse. If the device does not support a Z-axis, this value is
2674 always zero. This is \b not the same as pressure.
2675
2676 \note The value is stored as a single-precision float.
2677
2678 \sa pressure()
2679*/
2680
2681/*!
2682 \fn QPoint QTabletEvent::globalPos() const
2683 \deprecated [6.0] Use globalPosition().toPoint() instead.
2684
2685 Returns the global position of the device \e{at the time of the
2686 event}. This is important on asynchronous windows systems like X11;
2687 whenever you move your widgets around in response to mouse events,
2688 globalPos() can differ significantly from the current position
2689 QCursor::pos().
2690
2691 \sa globalX(), globalY()
2692*/
2693
2694/*!
2695 \fn int QTabletEvent::globalX() const
2696 \deprecated [6.0] Use globalPosition().x() instead.
2697
2698 Returns the global x position of the mouse pointer at the time of
2699 the event.
2700
2701 \sa globalY(), globalPos()
2702*/
2703
2704/*!
2705 \fn int QTabletEvent::globalY() const
2706 \deprecated [6.0] Use globalPosition().y() instead.
2707
2708 Returns the global y position of the tablet device at the time of
2709 the event.
2710
2711 \sa globalX(), globalPos()
2712*/
2713
2714/*!
2715 \fn qint64 QTabletEvent::uniqueId() const
2716 \deprecated [6.0] Use pointingDevice().uniqueId() instead.
2717
2718 Returns a unique ID for the current device, making it possible
2719 to differentiate between multiple devices being used at the same
2720 time on the tablet.
2721
2722 Support of this feature is dependent on the tablet.
2723
2724 Values for the same device may vary from OS to OS.
2725
2726 Later versions of the Wacom driver for Linux will now report
2727 the ID information. If you have a tablet that supports unique ID
2728 and are not getting the information on Linux, consider upgrading
2729 your driver.
2730
2731 As of Qt 4.2, the unique ID is the same regardless of the orientation
2732 of the pen. Earlier versions would report a different value when using
2733 the eraser-end versus the pen-end of the stylus on some OS's.
2734
2735 \sa pointerType()
2736*/
2737
2738/*!
2739 \fn const QPointF &QTabletEvent::posF() const
2740 \deprecated [6.0] Use position() instead.
2741
2742 Returns the position of the device, relative to the widget that
2743 received the event.
2744
2745 If you move widgets around in response to mouse events, use
2746 globalPosF() instead of this function.
2747
2748 \sa globalPosF()
2749*/
2750
2751/*!
2752 \fn const QPointF &QTabletEvent::globalPosF() const
2753 \deprecated [6.0] Use globalPosition() instead.
2754 Returns the global position of the device \e{at the time of the
2755 event}. This is important on asynchronous windows systems like X11;
2756 whenever you move your widgets around in response to mouse events,
2757 globalPosF() can differ significantly from the current position
2758 QCursor::pos().
2759
2760 \sa posF()
2761*/
2762
2763#endif // QT_CONFIG(tabletevent)
2764
2765#ifndef QT_NO_GESTURES
2766/*!
2767 \class QNativeGestureEvent
2768 \since 5.2
2769 \brief The QNativeGestureEvent class contains parameters that describe a gesture event.
2770 \inmodule QtGui
2771 \ingroup events
2772
2773 Native gesture events are generated by the operating system, typically by
2774 interpreting trackpad touch events. Gesture events are high-level events
2775 such as zoom, rotate or pan. Several types hold incremental values: that is,
2776 value() and delta() provide the difference from the previous event to the
2777 current event.
2778
2779 \table
2780 \header
2781 \li Event Type
2782 \li Description
2783 \li Touch sequence
2784 \row
2785 \li Qt::ZoomNativeGesture
2786 \li Magnification delta in percent.
2787 \li \macos and Wayland: Two-finger pinch.
2788 \row
2789 \li Qt::SmartZoomNativeGesture
2790 \li Boolean magnification state.
2791 \li \macos: Two-finger douple tap (trackpad) / One-finger douple tap (magic mouse).
2792 \row
2793 \li Qt::RotateNativeGesture
2794 \li Rotation delta in degrees.
2795 \li \macos and Wayland: Two-finger rotate.
2796 \row
2797 \li Qt::SwipeNativeGesture
2798 \li Swipe angle in degrees.
2799 \li \macos: Configurable in trackpad settings.
2800 \row
2801 \li Qt::PanNativeGesture
2802 \li Displacement delta in pixels.
2803 \li Wayland: Three or more fingers moving as a group, in any direction.
2804 \endtable
2805
2806 In addition, BeginNativeGesture and EndNativeGesture are sent before and after
2807 gesture event streams:
2808
2809 BeginNativeGesture
2810 ZoomNativeGesture
2811 ZoomNativeGesture
2812 ZoomNativeGesture
2813 EndNativeGesture
2814
2815 The event stream may include interleaved gestures of different types:
2816 for example the two-finger pinch gesture generates a stream of Zoom and
2817 Rotate events, and PanNativeGesture may sometimes be interleaved with
2818 those, depending on the platform.
2819
2820 Other types are standalone events: SmartZoomNativeGesture and
2821 SwipeNativeGesture occur only once each time the gesture is detected.
2822
2823 \note On a touchpad, moving two fingers as a group (the two-finger flick gesture)
2824 is usually reserved for scrolling; in that case, Qt generates QWheelEvents.
2825 This is the reason that three or more fingers are needed to generate a
2826 PanNativeGesture.
2827
2828 \sa Qt::NativeGestureType, QGestureEvent, QWheelEvent
2829*/
2830
2831#if QT_DEPRECATED_SINCE(6, 2)
2832/*!
2833 \deprecated [6.2] Use the other constructor, because \a intValue is no longer stored separately.
2834
2835 Constructs a native gesture event of type \a type originating from \a device.
2836
2837 The points \a localPos, \a scenePos and \a globalPos specify the
2838 gesture position relative to the receiving widget or item,
2839 window, and screen or desktop, respectively.
2840
2841 \a realValue is the \macos event parameter, \a sequenceId and \a intValue are the Windows event parameters.
2842 \since 5.10
2843
2844 \note It's not possible to store realValue and \a intValue simultaneously:
2845 one or the other must be zero. If \a realValue == 0 and \a intValue != 0,
2846 it is stored in the same variable, such that value() returns the value
2847 given as \a intValue.
2848*/
2849QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device,
2850 const QPointF &localPos, const QPointF &scenePos,
2851 const QPointF &globalPos, qreal realValue, quint64 sequenceId,
2852 quint64 intValue)
2853 : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton,
2854 Qt::NoButton, Qt::NoModifier),
2855 m_sequenceId(sequenceId), m_realValue(realValue), m_gestureType(type)
2856{
2857 if (qIsNull(d: realValue) && intValue != 0)
2858 m_realValue = intValue;
2859}
2860#endif // deprecated
2861
2862/*!
2863 Constructs a native gesture event of type \a type originating from \a device
2864 describing a gesture at \a scenePos in which \a fingerCount fingers are involved.
2865
2866 The points \a localPos, \a scenePos and \a globalPos specify the gesture
2867 position relative to the receiving widget or item, window, and screen or
2868 desktop, respectively.
2869
2870 \a value has a gesture-dependent interpretation: for RotateNativeGesture or
2871 SwipeNativeGesture, it's an angle in degrees. For ZoomNativeGesture,
2872 \a value is an incremental scaling factor, usually much less than 1,
2873 indicating that the target item should have its scale adjusted like this:
2874 item.scale = item.scale * (1 + event.value)
2875
2876 For PanNativeGesture, \a delta gives the distance in pixels that the
2877 viewport, widget or item should be moved or panned.
2878
2879 \note The \a delta is stored in single precision (QVector2D), so \l delta()
2880 may return slightly different values in some cases. This is subject to change
2881 in future versions of Qt.
2882
2883 \since 6.2
2884*/
2885QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *device, int fingerCount,
2886 const QPointF &localPos, const QPointF &scenePos,
2887 const QPointF &globalPos, qreal value, const QPointF &delta,
2888 quint64 sequenceId)
2889 : QSinglePointEvent(QEvent::NativeGesture, device, localPos, scenePos, globalPos, Qt::NoButton,
2890 Qt::NoButton, Qt::NoModifier),
2891 m_sequenceId(sequenceId), m_delta(delta), m_realValue(value), m_gestureType(type), m_fingerCount(fingerCount)
2892{
2893 Q_ASSERT(fingerCount < 16); // we store it in 4 bits unsigned
2894}
2895
2896Q_IMPL_POINTER_EVENT(QNativeGestureEvent)
2897
2898/*!
2899 \fn QNativeGestureEvent::gestureType() const
2900 \since 5.2
2901
2902 Returns the gesture type.
2903*/
2904
2905/*!
2906 \fn QNativeGestureEvent::fingerCount() const
2907 \since 6.2
2908
2909 Returns the number of fingers participating in the gesture, if known.
2910 When gestureType() is Qt::BeginNativeGesture or Qt::EndNativeGesture, often
2911 this information is unknown, and fingerCount() returns \c 0.
2912*/
2913
2914/*!
2915 \fn QNativeGestureEvent::value() const
2916 \since 5.2
2917
2918 Returns the gesture value. The value should be interpreted based on the
2919 gesture type. For example, a Zoom gesture provides a scale factor delta while a Rotate
2920 gesture provides a rotation delta.
2921
2922 \sa QNativeGestureEvent, gestureType()
2923*/
2924
2925/*!
2926 \fn QNativeGestureEvent::delta() const
2927 \since 6.2
2928
2929 Returns the distance moved since the previous event, in pixels.
2930 A Pan gesture provides the distance in pixels by which the target widget,
2931 item or viewport contents should be moved.
2932
2933 \sa QPanGesture::delta()
2934*/
2935
2936/*!
2937 \fn QPoint QNativeGestureEvent::globalPos() const
2938 \since 5.2
2939 \deprecated [6.0] Use globalPosition().toPoint() instead.
2940
2941 Returns the position of the gesture as a QPointF in screen coordinates
2942*/
2943
2944/*!
2945 \fn QPoint QNativeGestureEvent::pos() const
2946 \since 5.2
2947 \deprecated [6.0] Use position().toPoint() instead.
2948
2949 Returns the position of the mouse cursor, relative to the widget
2950 or item that received the event.
2951*/
2952
2953/*!
2954 \fn QPointF QNativeGestureEvent::localPos() const
2955 \since 5.2
2956 \deprecated [6.0] Use position() instead.
2957
2958 Returns the position of the gesture as a QPointF, relative to the
2959 widget or item that received the event.
2960*/
2961
2962/*!
2963 \fn QPointF QNativeGestureEvent::screenPos() const
2964 \since 5.2
2965 \deprecated [6.0] Use globalPosition() instead.
2966
2967 Returns the position of the gesture as a QPointF in screen coordinates.
2968*/
2969
2970/*!
2971 \fn QPointF QNativeGestureEvent::windowPos() const
2972 \since 5.2
2973 \deprecated [6.0] Use scenePosition() instead.
2974
2975 Returns the position of the gesture as a QPointF, relative to the
2976 window that received the event.
2977*/
2978#endif // QT_NO_GESTURES
2979
2980#if QT_CONFIG(draganddrop)
2981/*!
2982 Creates a QDragMoveEvent of the required \a type indicating
2983 that the mouse is at position \a pos given within a widget.
2984
2985 The mouse and keyboard states are specified by \a buttons and
2986 \a modifiers, and the \a actions describe the types of drag
2987 and drop operation that are possible.
2988 The drag data is passed as MIME-encoded information in \a data.
2989
2990 \warning Do not attempt to create a QDragMoveEvent yourself.
2991 These objects rely on Qt's internal state.
2992*/
2993QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
2994 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
2995 : QDropEvent(pos, actions, data, buttons, modifiers, type)
2996 , m_rect(pos, QSize(1, 1))
2997{}
2998
2999Q_IMPL_EVENT_COMMON(QDragMoveEvent)
3000
3001/*!
3002 \fn void QDragMoveEvent::accept(const QRect &rectangle)
3003
3004 The same as accept(), but also notifies that future moves will
3005 also be acceptable if they remain within the \a rectangle
3006 given on the widget. This can improve performance, but may
3007 also be ignored by the underlying system.
3008
3009 If the rectangle is empty, drag move events will be sent
3010 continuously. This is useful if the source is scrolling in a
3011 timer event.
3012*/
3013
3014/*!
3015 \fn void QDragMoveEvent::accept()
3016
3017 \overload
3018
3019 Calls QDropEvent::accept().
3020*/
3021
3022/*!
3023 \fn void QDragMoveEvent::ignore()
3024
3025 \overload
3026
3027 Calls QDropEvent::ignore().
3028*/
3029
3030/*!
3031 \fn void QDragMoveEvent::ignore(const QRect &rectangle)
3032
3033 The opposite of the accept(const QRect&) function.
3034 Moves within the \a rectangle are not acceptable, and will be
3035 ignored.
3036*/
3037
3038/*!
3039 \fn QRect QDragMoveEvent::answerRect() const
3040
3041 Returns the rectangle in the widget where the drop will occur if accepted.
3042 You can use this information to restrict drops to certain places on the
3043 widget.
3044*/
3045
3046
3047/*!
3048 \class QDropEvent
3049 \ingroup events
3050 \ingroup draganddrop
3051 \inmodule QtGui
3052
3053 \brief The QDropEvent class provides an event which is sent when a
3054 drag and drop action is completed.
3055
3056 When a widget \l{QWidget::setAcceptDrops()}{accepts drop events}, it will
3057 receive this event if it has accepted the most recent QDragEnterEvent or
3058 QDragMoveEvent sent to it.
3059
3060 The drop event contains a proposed action, available from proposedAction(), for
3061 the widget to either accept or ignore. If the action can be handled by the
3062 widget, you should call the acceptProposedAction() function. Since the
3063 proposed action can be a combination of \l Qt::DropAction values, it may be
3064 useful to either select one of these values as a default action or ask
3065 the user to select their preferred action.
3066
3067 If the proposed drop action is not suitable, perhaps because your custom
3068 widget does not support that action, you can replace it with any of the
3069 \l{possibleActions()}{possible drop actions} by calling setDropAction()
3070 with your preferred action. If you set a value that is not present in the
3071 bitwise OR combination of values returned by possibleActions(), the default
3072 copy action will be used. Once a replacement drop action has been set, call
3073 accept() instead of acceptProposedAction() to complete the drop operation.
3074
3075 The mimeData() function provides the data dropped on the widget in a QMimeData
3076 object. This contains information about the MIME type of the data in addition to
3077 the data itself.
3078
3079 \sa QMimeData, QDrag, {Drag and Drop}
3080*/
3081
3082/*!
3083 \fn const QMimeData *QDropEvent::mimeData() const
3084
3085 Returns the data that was dropped on the widget and its associated MIME
3086 type information.
3087*/
3088
3089// ### pos is in which coordinate system?
3090/*!
3091 Constructs a drop event of a certain \a type corresponding to a
3092 drop at the point specified by \a pos in the destination widget's
3093 coordinate system.
3094
3095 The \a actions indicate which types of drag and drop operation can
3096 be performed, and the drag data is stored as MIME-encoded data in \a data.
3097
3098 The states of the mouse buttons and keyboard modifiers at the time of
3099 the drop are specified by \a buttons and \a modifiers.
3100*/
3101QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
3102 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type)
3103 : QEvent(type), m_pos(pos), m_mouseState(buttons),
3104 m_modState(modifiers), m_actions(actions),
3105 m_data(data)
3106{
3107 m_defaultAction = m_dropAction =
3108 QGuiApplicationPrivate::platformIntegration()->drag()->defaultAction(possibleActions: m_actions, modifiers);
3109 ignore();
3110}
3111
3112Q_IMPL_EVENT_COMMON(QDropEvent)
3113
3114
3115/*!
3116 If the source of the drag operation is a widget in this
3117 application, this function returns that source; otherwise it
3118 returns \nullptr. The source of the operation is the first parameter to
3119 the QDrag object used instantiate the drag.
3120
3121 This is useful if your widget needs special behavior when dragging
3122 to itself.
3123
3124 \sa QDrag::QDrag()
3125*/
3126QObject* QDropEvent::source() const
3127{
3128 if (const QDragManager *manager = QDragManager::self())
3129 return manager->source();
3130 return nullptr;
3131}
3132
3133
3134void QDropEvent::setDropAction(Qt::DropAction action)
3135{
3136 if (!(action & m_actions) && action != Qt::IgnoreAction)
3137 action = m_defaultAction;
3138 m_dropAction = action;
3139}
3140
3141/*!
3142 \fn QPoint QDropEvent::pos() const
3143 \deprecated [6.0] Use position().toPoint() instead.
3144
3145 Returns the position where the drop was made.
3146*/
3147
3148/*!
3149 \fn const QPointF& QDropEvent::posF() const
3150 \deprecated [6.0] Use position() instead.
3151
3152 Returns the position where the drop was made.
3153*/
3154
3155/*!
3156 \fn QPointF QDropEvent::position() const
3157 \since 6.0
3158
3159 Returns the position where the drop was made.
3160*/
3161
3162/*!
3163 \fn Qt::MouseButtons QDropEvent::mouseButtons() const
3164 \deprecated [6.0] Use buttons() instead.
3165
3166 Returns the mouse buttons that are pressed.
3167*/
3168
3169/*!
3170 \fn Qt::MouseButtons QDropEvent::buttons() const
3171 \since 6.0
3172
3173 Returns the mouse buttons that are pressed.
3174*/
3175
3176/*!
3177 \fn Qt::KeyboardModifiers QDropEvent::keyboardModifiers() const
3178 \deprecated [6.0] Use modifiers() instead.
3179
3180 Returns the modifier keys that are pressed.
3181*/
3182
3183/*!
3184 \fn Qt::KeyboardModifiers QDropEvent::modifiers() const
3185 \since 6.0
3186
3187 Returns the modifier keys that are pressed.
3188*/
3189
3190/*!
3191 \fn void QDropEvent::setDropAction(Qt::DropAction action)
3192
3193 Sets the \a action to be performed on the data by the target.
3194 Use this to override the \l{proposedAction()}{proposed action}
3195 with one of the \l{possibleActions()}{possible actions}.
3196
3197 If you set a drop action that is not one of the possible actions, the
3198 drag and drop operation will default to a copy operation.
3199
3200 Once you have supplied a replacement drop action, call accept()
3201 instead of acceptProposedAction().
3202
3203 \sa dropAction()
3204*/
3205
3206/*!
3207 \fn Qt::DropAction QDropEvent::dropAction() const
3208
3209 Returns the action to be performed on the data by the target. This may be
3210 different from the action supplied in proposedAction() if you have called
3211 setDropAction() to explicitly choose a drop action.
3212
3213 \sa setDropAction()
3214*/
3215
3216/*!
3217 \fn Qt::DropActions QDropEvent::possibleActions() const
3218
3219 Returns an OR-combination of possible drop actions.
3220
3221 \sa dropAction()
3222*/
3223
3224/*!
3225 \fn Qt::DropAction QDropEvent::proposedAction() const
3226
3227 Returns the proposed drop action.
3228
3229 \sa dropAction()
3230*/
3231
3232/*!
3233 \fn void QDropEvent::acceptProposedAction()
3234
3235 Sets the drop action to be the proposed action.
3236
3237 \sa setDropAction(), proposedAction(), {QEvent::accept()}{accept()}
3238*/
3239
3240/*!
3241 \class QDragEnterEvent
3242 \brief The QDragEnterEvent class provides an event which is sent
3243 to a widget when a drag and drop action enters it.
3244
3245 \ingroup events
3246 \ingroup draganddrop
3247 \inmodule QtGui
3248
3249 A widget must accept this event in order to receive the \l
3250 {QDragMoveEvent}{drag move events} that are sent while the drag
3251 and drop action is in progress. The drag enter event is always
3252 immediately followed by a drag move event.
3253
3254 QDragEnterEvent inherits most of its functionality from
3255 QDragMoveEvent, which in turn inherits most of its functionality
3256 from QDropEvent.
3257
3258 \sa QDragLeaveEvent, QDragMoveEvent, QDropEvent
3259*/
3260
3261/*!
3262 Constructs a QDragEnterEvent that represents a drag entering a
3263 widget at the given \a point with mouse and keyboard states specified by
3264 \a buttons and \a modifiers.
3265
3266 The drag data is passed as MIME-encoded information in \a data, and the
3267 specified \a actions describe the possible types of drag and drop
3268 operation that can be performed.
3269
3270 \warning Do not create a QDragEnterEvent yourself since these
3271 objects rely on Qt's internal state.
3272*/
3273QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, const QMimeData *data,
3274 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)
3275 : QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter)
3276{}
3277
3278Q_IMPL_EVENT_COMMON(QDragEnterEvent)
3279
3280/*!
3281 \class QDragMoveEvent
3282 \brief The QDragMoveEvent class provides an event which is sent while a drag and drop action is in progress.
3283
3284 \ingroup events
3285 \ingroup draganddrop
3286 \inmodule QtGui
3287
3288 A widget will receive drag move events repeatedly while the drag
3289 is within its boundaries, if it accepts
3290 \l{QWidget::setAcceptDrops()}{drop events} and \l
3291 {QWidget::dragEnterEvent()}{enter events}. The widget should
3292 examine the event to see what kind of \l{mimeData()}{data} it
3293 provides, and call the accept() function to accept the drop if appropriate.
3294
3295 The rectangle supplied by the answerRect() function can be used to restrict
3296 drops to certain parts of the widget. For example, we can check whether the
3297 rectangle intersects with the geometry of a certain child widget and only
3298 call \l{QDropEvent::acceptProposedAction()}{acceptProposedAction()} if that
3299 is the case.
3300
3301 Note that this class inherits most of its functionality from
3302 QDropEvent.
3303
3304 \sa QDragEnterEvent, QDragLeaveEvent, QDropEvent
3305*/
3306
3307/*!
3308 \class QDragLeaveEvent
3309 \brief The QDragLeaveEvent class provides an event that is sent to a widget when a drag and drop action leaves it.
3310
3311 \ingroup events
3312 \ingroup draganddrop
3313 \inmodule QtGui
3314
3315 This event is always preceded by a QDragEnterEvent and a series
3316 of \l{QDragMoveEvent}s. It is not sent if a QDropEvent is sent
3317 instead.
3318
3319 \sa QDragEnterEvent, QDragMoveEvent, QDropEvent
3320*/
3321
3322/*!
3323 Constructs a QDragLeaveEvent.
3324
3325 \warning Do not create a QDragLeaveEvent yourself since these
3326 objects rely on Qt's internal state.
3327*/
3328QDragLeaveEvent::QDragLeaveEvent()
3329 : QEvent(DragLeave)
3330{}
3331
3332Q_IMPL_EVENT_COMMON(QDragLeaveEvent)
3333
3334#endif // QT_CONFIG(draganddrop)
3335
3336/*!
3337 \class QHelpEvent
3338 \brief The QHelpEvent class provides an event that is used to request helpful information
3339 about a particular point in a widget.
3340
3341 \ingroup events
3342 \ingroup helpsystem
3343 \inmodule QtGui
3344
3345 This event can be intercepted in applications to provide tooltips
3346 or "What's This?" help for custom widgets. The type() can be
3347 either QEvent::ToolTip or QEvent::WhatsThis.
3348
3349 \sa QToolTip, QWhatsThis, QStatusTipEvent, QWhatsThisClickedEvent
3350*/
3351
3352/*!
3353 Constructs a help event with the given \a type corresponding to the
3354 widget-relative position specified by \a pos and the global position
3355 specified by \a globalPos.
3356
3357 \a type must be either QEvent::ToolTip or QEvent::WhatsThis.
3358
3359 \sa pos(), globalPos()
3360*/
3361QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos)
3362 : QEvent(type), m_pos(pos), m_globalPos(globalPos)
3363{}
3364
3365/*!
3366 \fn int QHelpEvent::x() const
3367
3368 Same as pos().x().
3369
3370 \sa y(), pos(), globalPos()
3371*/
3372
3373/*!
3374 \fn int QHelpEvent::y() const
3375
3376 Same as pos().y().
3377
3378 \sa x(), pos(), globalPos()
3379*/
3380
3381/*!
3382 \fn int QHelpEvent::globalX() const
3383
3384 Same as globalPos().x().
3385
3386 \sa x(), globalY(), globalPos()
3387*/
3388
3389/*!
3390 \fn int QHelpEvent::globalY() const
3391
3392 Same as globalPos().y().
3393
3394 \sa y(), globalX(), globalPos()
3395*/
3396
3397/*!
3398 \fn const QPoint &QHelpEvent::pos() const
3399
3400 Returns the mouse cursor position when the event was generated,
3401 relative to the widget to which the event is dispatched.
3402
3403 \sa globalPos(), x(), y()
3404*/
3405
3406/*!
3407 \fn const QPoint &QHelpEvent::globalPos() const
3408
3409 Returns the mouse cursor position when the event was generated
3410 in global coordinates.
3411
3412 \sa pos(), globalX(), globalY()
3413*/
3414
3415Q_IMPL_EVENT_COMMON(QHelpEvent)
3416
3417#ifndef QT_NO_STATUSTIP
3418
3419/*!
3420 \class QStatusTipEvent
3421 \brief The QStatusTipEvent class provides an event that is used to show messages in a status bar.
3422
3423 \ingroup events
3424 \ingroup helpsystem
3425 \inmodule QtGui
3426
3427 Status tips can be set on a widget using the
3428 QWidget::setStatusTip() function. They are shown in the status
3429 bar when the mouse cursor enters the widget. For example:
3430
3431 \table 100%
3432 \row
3433 \li
3434 \snippet qstatustipevent/main.cpp 1
3435 \dots
3436 \snippet qstatustipevent/main.cpp 3
3437 \li
3438 \image qstatustipevent-widget.png Widget with status tip.
3439 \endtable
3440
3441 Status tips can also be set on actions using the
3442 QAction::setStatusTip() function:
3443
3444 \table 100%
3445 \row
3446 \li
3447 \snippet qstatustipevent/main.cpp 0
3448 \snippet qstatustipevent/main.cpp 2
3449 \dots
3450 \snippet qstatustipevent/main.cpp 3
3451 \li
3452 \image qstatustipevent-action.png Action with status tip.
3453 \endtable
3454
3455 Finally, status tips are supported for the item view classes
3456 through the Qt::StatusTipRole enum value.
3457
3458 \sa QStatusBar, QHelpEvent, QWhatsThisClickedEvent
3459*/
3460
3461/*!
3462 Constructs a status tip event with the text specified by \a tip.
3463
3464 \sa tip()
3465*/
3466QStatusTipEvent::QStatusTipEvent(const QString &tip)
3467 : QEvent(StatusTip), m_tip(tip)
3468{}
3469
3470Q_IMPL_EVENT_COMMON(QStatusTipEvent)
3471
3472/*!
3473 \fn QString QStatusTipEvent::tip() const
3474
3475 Returns the message to show in the status bar.
3476
3477 \sa QStatusBar::showMessage()
3478*/
3479
3480#endif // QT_NO_STATUSTIP
3481
3482#if QT_CONFIG(whatsthis)
3483
3484/*!
3485 \class QWhatsThisClickedEvent
3486 \brief The QWhatsThisClickedEvent class provides an event that
3487 can be used to handle hyperlinks in a "What's This?" text.
3488
3489 \ingroup events
3490 \ingroup helpsystem
3491 \inmodule QtGui
3492
3493 \sa QWhatsThis, QHelpEvent, QStatusTipEvent
3494*/
3495
3496/*!
3497 Constructs an event containing a URL specified by \a href when a link
3498 is clicked in a "What's This?" message.
3499
3500 \sa href()
3501*/
3502QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href)
3503 : QEvent(WhatsThisClicked), m_href(href)
3504{}
3505
3506Q_IMPL_EVENT_COMMON(QWhatsThisClickedEvent)
3507
3508/*!
3509 \fn QString QWhatsThisClickedEvent::href() const
3510
3511 Returns the URL that was clicked by the user in the "What's
3512 This?" text.
3513*/
3514
3515#endif // QT_CONFIG(whatsthis)
3516
3517#ifndef QT_NO_ACTION
3518
3519/*!
3520 \class QActionEvent
3521 \brief The QActionEvent class provides an event that is generated
3522 when a QAction is added, removed, or changed.
3523
3524 \ingroup events
3525 \inmodule QtGui
3526
3527 Actions can be added to controls, for example by using QWidget::addAction().
3528 This generates an \l ActionAdded event, which you can handle to provide
3529 custom behavior. For example, QToolBar reimplements
3530 QWidget::actionEvent() to create \l{QToolButton}s for the
3531 actions.
3532
3533 \sa QAction, QWidget::addAction(), QWidget::removeAction(), QWidget::actions()
3534*/
3535
3536/*!
3537 Constructs an action event. The \a type can be \l ActionChanged,
3538 \l ActionAdded, or \l ActionRemoved.
3539
3540 \a action is the action that is changed, added, or removed. If \a
3541 type is ActionAdded, the action is to be inserted before the
3542 action \a before. If \a before is \nullptr, the action is appended.
3543*/
3544QActionEvent::QActionEvent(int type, QAction *action, QAction *before)
3545 : QEvent(static_cast<QEvent::Type>(type)), m_action(action), m_before(before)
3546{}
3547
3548Q_IMPL_EVENT_COMMON(QActionEvent)
3549
3550/*!
3551 \fn QAction *QActionEvent::action() const
3552
3553 Returns the action that is changed, added, or removed.
3554
3555 \sa before()
3556*/
3557
3558/*!
3559 \fn QAction *QActionEvent::before() const
3560
3561 If type() is \l ActionAdded, returns the action that should
3562 appear before action(). If this function returns \nullptr, the action
3563 should be appended to already existing actions on the same
3564 widget.
3565
3566 \sa action(), QWidget::actions()
3567*/
3568
3569#endif // QT_NO_ACTION
3570
3571/*!
3572 \class QHideEvent
3573 \brief The QHideEvent class provides an event which is sent after a widget is hidden.
3574
3575 \ingroup events
3576 \inmodule QtGui
3577
3578 This event is sent just before QWidget::hide() returns, and also
3579 when a top-level window has been hidden (iconified) by the user.
3580
3581 If spontaneous() is true, the event originated outside the
3582 application. In this case, the user hid the window using the
3583 window manager controls, either by iconifying the window or by
3584 switching to another virtual desktop where the window is not
3585 visible. The window will become hidden but not withdrawn. If the
3586 window was iconified, QWidget::isMinimized() returns \c true.
3587
3588 \sa QShowEvent
3589*/
3590
3591/*!
3592 Constructs a QHideEvent.
3593*/
3594QHideEvent::QHideEvent()
3595 : QEvent(Hide)
3596{}
3597
3598Q_IMPL_EVENT_COMMON(QHideEvent)
3599
3600/*!
3601 \class QShowEvent
3602 \brief The QShowEvent class provides an event that is sent when a widget is shown.
3603
3604 \ingroup events
3605 \inmodule QtGui
3606
3607 There are two kinds of show events: show events caused by the
3608 window system (spontaneous), and internal show events. Spontaneous (QEvent::spontaneous())
3609 show events are sent just after the window system shows the
3610 window; they are also sent when a top-level window is redisplayed
3611 after being iconified. Internal show events are delivered just
3612 before the widget becomes visible.
3613
3614 \sa QHideEvent
3615*/
3616
3617/*!
3618 Constructs a QShowEvent.
3619*/
3620QShowEvent::QShowEvent()
3621 : QEvent(Show)
3622{}
3623
3624Q_IMPL_EVENT_COMMON(QShowEvent)
3625
3626/*!
3627 \class QFileOpenEvent
3628 \brief The QFileOpenEvent class provides an event that will be
3629 sent when there is a request to open a file or a URL.
3630
3631 \ingroup events
3632 \inmodule QtGui
3633
3634 File open events will be sent to the QApplication::instance()
3635 when the operating system requests that a file or URL should be opened.
3636 This is a high-level event that can be caused by different user actions
3637 depending on the user's desktop environment; for example, double
3638 clicking on an file icon in the Finder on \macos.
3639
3640 This event is only used to notify the application of a request.
3641 It may be safely ignored.
3642
3643 \note This class is currently supported for \macos only.
3644
3645 \section1 \macos Example
3646
3647 In order to trigger the event on \macos, the application must be configured
3648 to let the OS know what kind of file(s) it should react on.
3649
3650 For example, the following \c Info.plist file declares that the application
3651 can act as a viewer for files with a PNG extension:
3652
3653 \snippet qfileopenevent/Info.plist Custom Info.plist
3654
3655 The following implementation of a QApplication subclass shows how to handle
3656 QFileOpenEvent to open the file that was, for example, dropped on the Dock
3657 icon of the application.
3658
3659 \snippet qfileopenevent/main.cpp QApplication subclass
3660
3661 Note how \c{QFileOpenEvent::file()} is not guaranteed to be the name of a
3662 local file that can be opened using QFile. The contents of the string depend
3663 on the source application.
3664*/
3665
3666/*!
3667 \internal
3668
3669 Constructs a file open event for the given \a file.
3670*/
3671QFileOpenEvent::QFileOpenEvent(const QString &file)
3672 : QEvent(FileOpen), m_file(file), m_url(QUrl::fromLocalFile(localfile: file))
3673{
3674}
3675
3676/*!
3677 \internal
3678
3679 Constructs a file open event for the given \a url.
3680*/
3681QFileOpenEvent::QFileOpenEvent(const QUrl &url)
3682 : QEvent(FileOpen), m_file(url.toLocalFile()), m_url(url)
3683{
3684}
3685
3686Q_IMPL_EVENT_COMMON(QFileOpenEvent)
3687
3688/*!
3689 \fn QString QFileOpenEvent::file() const
3690
3691 Returns the name of the file that the application should open.
3692
3693 This is not guaranteed to be the path to a local file.
3694*/
3695
3696/*!
3697 \fn QUrl QFileOpenEvent::url() const
3698
3699 Returns the url that the application should open.
3700
3701 \since 4.6
3702*/
3703
3704#if QT_DEPRECATED_SINCE(6, 6)
3705/*!
3706 \fn bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
3707 \deprecated [6.6] interpret the string returned by file()
3708
3709 Opens a QFile on the \a file referenced by this event in the mode specified
3710 by \a flags. Returns \c true if successful; otherwise returns \c false.
3711
3712 This is necessary as some files cannot be opened by name, but require specific
3713 information stored in this event.
3714
3715 \since 4.8
3716*/
3717bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const
3718{
3719 file.setFileName(m_file);
3720 return file.open(flags);
3721}
3722#endif
3723
3724#ifndef QT_NO_TOOLBAR
3725/*!
3726 \internal
3727 \class QToolBarChangeEvent
3728 \brief The QToolBarChangeEvent class provides an event that is
3729 sent whenever a the toolbar button is clicked on \macos.
3730
3731 \ingroup events
3732 \inmodule QtGui
3733
3734 The QToolBarChangeEvent is sent when the toolbar button is clicked. On
3735 \macos, this is the long oblong button on the right side of the window
3736 title bar. The default implementation is to toggle the appearance (hidden or
3737 shown) of the associated toolbars for the window.
3738*/
3739
3740/*!
3741 \internal
3742
3743 Construct a QToolBarChangeEvent given the current button state in \a state.
3744*/
3745QToolBarChangeEvent::QToolBarChangeEvent(bool t)
3746 : QEvent(ToolBarChange), m_toggle(t)
3747{}
3748
3749Q_IMPL_EVENT_COMMON(QToolBarChangeEvent)
3750
3751/*!
3752 \fn bool QToolBarChangeEvent::toggle() const
3753 \internal
3754*/
3755
3756/*
3757 \fn Qt::ButtonState QToolBarChangeEvent::state() const
3758
3759 Returns the keyboard modifier flags at the time of the event.
3760
3761 The returned value is a selection of the following values,
3762 combined using the OR operator:
3763 Qt::ShiftButton, Qt::ControlButton, Qt::MetaButton, and Qt::AltButton.
3764*/
3765
3766#endif // QT_NO_TOOLBAR
3767
3768#if QT_CONFIG(shortcut)
3769
3770/*!
3771 Constructs a shortcut event for the given \a key press,
3772 associated with the QShortcut ID \a id.
3773
3774 \deprecated use the other constructor
3775
3776 \a ambiguous specifies whether there is more than one QShortcut
3777 for the same key sequence.
3778*/
3779QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous)
3780 : QEvent(Shortcut), m_sequence(key), m_shortcutId(id), m_ambiguous(ambiguous)
3781{
3782}
3783
3784/*!
3785 Constructs a shortcut event for the given \a key press,
3786 associated with the QShortcut \a shortcut.
3787 \since 6.5
3788
3789 \a ambiguous specifies whether there is more than one QShortcut
3790 for the same key sequence.
3791*/
3792QShortcutEvent::QShortcutEvent(const QKeySequence &key, const QShortcut *shortcut, bool ambiguous)
3793 : QEvent(Shortcut), m_sequence(key), m_shortcutId(0), m_ambiguous(ambiguous)
3794{
3795 if (shortcut) {
3796 auto priv = static_cast<const QShortcutPrivate *>(QShortcutPrivate::get(o: shortcut));
3797 auto index = priv->sc_sequences.indexOf(t: key);
3798 if (index < 0) {
3799 qWarning() << "Given QShortcut does not contain key-sequence " << key;
3800 return;
3801 }
3802 m_shortcutId = priv->sc_ids[index];
3803 }
3804}
3805
3806Q_IMPL_EVENT_COMMON(QShortcutEvent)
3807
3808#endif // QT_CONFIG(shortcut)
3809
3810#ifndef QT_NO_DEBUG_STREAM
3811
3812static inline void formatTouchEvent(QDebug d, const QTouchEvent &t)
3813{
3814 d << "QTouchEvent(";
3815 QtDebugUtils::formatQEnum(debug&: d, value: t.type());
3816 d << " device: " << t.device()->name();
3817 d << " states: ";
3818 QtDebugUtils::formatQFlags(debug&: d, value: t.touchPointStates());
3819 d << ", " << t.points().size() << " points: " << t.points() << ')';
3820}
3821
3822static void formatUnicodeString(QDebug d, const QString &s)
3823{
3824 d << '"' << Qt::hex;
3825 for (int i = 0; i < s.size(); ++i) {
3826 if (i)
3827 d << ',';
3828 d << "U+" << s.at(i).unicode();
3829 }
3830 d << Qt::dec << '"';
3831}
3832
3833static QDebug operator<<(QDebug dbg, const QInputMethodEvent::Attribute &attr)
3834{
3835 dbg << "[type= " << attr.type << ", start=" << attr.start << ", length=" << attr.length
3836 << ", value=" << attr.value << ']';
3837 return dbg;
3838}
3839
3840static inline void formatInputMethodEvent(QDebug d, const QInputMethodEvent *e)
3841{
3842 d << "QInputMethodEvent(";
3843 if (!e->preeditString().isEmpty()) {
3844 d << "preedit=";
3845 formatUnicodeString(d, s: e->preeditString());
3846 }
3847 if (!e->commitString().isEmpty()) {
3848 d << ", commit=";
3849 formatUnicodeString(d, s: e->commitString());
3850 }
3851 if (e->replacementLength()) {
3852 d << ", replacementStart=" << e->replacementStart() << ", replacementLength="
3853 << e->replacementLength();
3854 }
3855 const auto attributes = e->attributes();
3856 auto it = attributes.cbegin();
3857 const auto end = attributes.cend();
3858 if (it != end) {
3859 d << ", attributes= {";
3860 d << *it;
3861 ++it;
3862 for (; it != end; ++it)
3863 d << ',' << *it;
3864 d << '}';
3865 }
3866 d << ')';
3867}
3868
3869static inline void formatInputMethodQueryEvent(QDebug d, const QInputMethodQueryEvent *e)
3870{
3871 QDebugStateSaver saver(d);
3872 d.noquote();
3873 const Qt::InputMethodQueries queries = e->queries();
3874 d << "QInputMethodQueryEvent(queries=" << Qt::showbase << Qt::hex << int(queries)
3875 << Qt::noshowbase << Qt::dec << ", {";
3876 for (unsigned mask = 1; mask <= Qt::ImInputItemClipRectangle; mask<<=1) {
3877 if (queries & mask) {
3878 const Qt::InputMethodQuery query = static_cast<Qt::InputMethodQuery>(mask);
3879 const QVariant value = e->value(query);
3880 if (value.isValid()) {
3881 d << '[';
3882 QtDebugUtils::formatQEnum(debug&: d, value: query);
3883 d << '=';
3884 if (query == Qt::ImHints)
3885 QtDebugUtils::formatQFlags(debug&: d, value: Qt::InputMethodHints(value.toInt()));
3886 else
3887 d << value.toString();
3888 d << "],";
3889 }
3890 }
3891 }
3892 d << "})";
3893}
3894
3895static const char *eventClassName(QEvent::Type t)
3896{
3897 switch (t) {
3898 case QEvent::ActionAdded:
3899 case QEvent::ActionRemoved:
3900 case QEvent::ActionChanged:
3901 return "QActionEvent";
3902 case QEvent::MouseButtonPress:
3903 case QEvent::MouseButtonRelease:
3904 case QEvent::MouseButtonDblClick:
3905 case QEvent::MouseMove:
3906 case QEvent::NonClientAreaMouseMove:
3907 case QEvent::NonClientAreaMouseButtonPress:
3908 case QEvent::NonClientAreaMouseButtonRelease:
3909 case QEvent::NonClientAreaMouseButtonDblClick:
3910 return "QMouseEvent";
3911 case QEvent::DragEnter:
3912 return "QDragEnterEvent";
3913 case QEvent::DragMove:
3914 return "QDragMoveEvent";
3915 case QEvent::Drop:
3916 return "QDropEvent";
3917 case QEvent::KeyPress:
3918 case QEvent::KeyRelease:
3919 case QEvent::ShortcutOverride:
3920 return "QKeyEvent";
3921 case QEvent::FocusIn:
3922 case QEvent::FocusOut:
3923 case QEvent::FocusAboutToChange:
3924 return "QFocusEvent";
3925 case QEvent::ChildAdded:
3926 case QEvent::ChildPolished:
3927 case QEvent::ChildRemoved:
3928 return "QChildEvent";
3929 case QEvent::Paint:
3930 return "QPaintEvent";
3931 case QEvent::Move:
3932 return "QMoveEvent";
3933 case QEvent::Resize:
3934 return "QResizeEvent";
3935 case QEvent::Show:
3936 return "QShowEvent";
3937 case QEvent::Hide:
3938 return "QHideEvent";
3939 case QEvent::Enter:
3940 return "QEnterEvent";
3941 case QEvent::Close:
3942 return "QCloseEvent";
3943 case QEvent::FileOpen:
3944 return "QFileOpenEvent";
3945#ifndef QT_NO_GESTURES
3946 case QEvent::NativeGesture:
3947 return "QNativeGestureEvent";
3948 case QEvent::Gesture:
3949 case QEvent::GestureOverride:
3950 return "QGestureEvent";
3951#endif
3952 case QEvent::HoverEnter:
3953 case QEvent::HoverLeave:
3954 case QEvent::HoverMove:
3955 return "QHoverEvent";
3956 case QEvent::TabletEnterProximity:
3957 case QEvent::TabletLeaveProximity:
3958 case QEvent::TabletPress:
3959 case QEvent::TabletMove:
3960 case QEvent::TabletRelease:
3961 return "QTabletEvent";
3962 case QEvent::StatusTip:
3963 return "QStatusTipEvent";
3964 case QEvent::ToolTip:
3965 return "QHelpEvent";
3966 case QEvent::WindowStateChange:
3967 return "QWindowStateChangeEvent";
3968 case QEvent::Wheel:
3969 return "QWheelEvent";
3970 case QEvent::TouchBegin:
3971 case QEvent::TouchUpdate:
3972 case QEvent::TouchEnd:
3973 return "QTouchEvent";
3974 case QEvent::Shortcut:
3975 return "QShortcutEvent";
3976 case QEvent::InputMethod:
3977 return "QInputMethodEvent";
3978 case QEvent::InputMethodQuery:
3979 return "QInputMethodQueryEvent";
3980 case QEvent::OrientationChange:
3981 return "QScreenOrientationChangeEvent";
3982 case QEvent::ScrollPrepare:
3983 return "QScrollPrepareEvent";
3984 case QEvent::Scroll:
3985 return "QScrollEvent";
3986 case QEvent::GraphicsSceneMouseMove:
3987 case QEvent::GraphicsSceneMousePress:
3988 case QEvent::GraphicsSceneMouseRelease:
3989 case QEvent::GraphicsSceneMouseDoubleClick:
3990 return "QGraphicsSceneMouseEvent";
3991 case QEvent::GraphicsSceneContextMenu:
3992 case QEvent::GraphicsSceneHoverEnter:
3993 case QEvent::GraphicsSceneHoverMove:
3994 case QEvent::GraphicsSceneHoverLeave:
3995 case QEvent::GraphicsSceneHelp:
3996 case QEvent::GraphicsSceneDragEnter:
3997 case QEvent::GraphicsSceneDragMove:
3998 case QEvent::GraphicsSceneDragLeave:
3999 case QEvent::GraphicsSceneDrop:
4000 case QEvent::GraphicsSceneWheel:
4001 return "QGraphicsSceneEvent";
4002 case QEvent::Timer:
4003 return "QTimerEvent";
4004 case QEvent::PlatformSurface:
4005 return "QPlatformSurfaceEvent";
4006 default:
4007 break;
4008 }
4009 return "QEvent";
4010}
4011
4012# if QT_CONFIG(draganddrop)
4013
4014static void formatDropEvent(QDebug d, const QDropEvent *e)
4015{
4016 const QEvent::Type type = e->type();
4017 d << eventClassName(t: type) << "(dropAction=";
4018 QtDebugUtils::formatQEnum(debug&: d, value: e->dropAction());
4019 d << ", proposedAction=";
4020 QtDebugUtils::formatQEnum(debug&: d, value: e->proposedAction());
4021 d << ", possibleActions=";
4022 QtDebugUtils::formatQFlags(debug&: d, value: e->possibleActions());
4023 d << ", posF=";
4024 QtDebugUtils::formatQPoint(debug&: d, point: e->position());
4025 if (type == QEvent::DragMove || type == QEvent::DragEnter)
4026 d << ", answerRect=" << static_cast<const QDragMoveEvent *>(e)->answerRect();
4027 d << ", formats=" << e->mimeData()->formats();
4028 QtDebugUtils::formatNonNullQFlags(debug&: d, prefix: ", keyboardModifiers=", value: e->modifiers());
4029 d << ", ";
4030 QtDebugUtils::formatQFlags(debug&: d, value: e->buttons());
4031}
4032
4033# endif // QT_CONFIG(draganddrop)
4034
4035# if QT_CONFIG(tabletevent)
4036
4037static void formatTabletEvent(QDebug d, const QTabletEvent *e)
4038{
4039 const QEvent::Type type = e->type();
4040
4041 d << eventClassName(t: type) << '(';
4042 QtDebugUtils::formatQEnum(debug&: d, value: type);
4043 d << ' ';
4044 QtDebugUtils::formatQFlags(debug&: d, value: e->buttons());
4045 d << " pos=";
4046 QtDebugUtils::formatQPoint(debug&: d, point: e->position());
4047 d << " z=" << e->z()
4048 << " xTilt=" << e->xTilt()
4049 << " yTilt=" << e->yTilt();
4050 if (type == QEvent::TabletPress || type == QEvent::TabletMove)
4051 d << " pressure=" << e->pressure();
4052 if (e->device()->hasCapability(cap: QInputDevice::Capability::Rotation))
4053 d << " rotation=" << e->rotation();
4054 if (e->deviceType() == QInputDevice::DeviceType::Airbrush)
4055 d << " tangentialPressure=" << e->tangentialPressure();
4056 d << " dev=" << e->device() << ')';
4057}
4058
4059# endif // QT_CONFIG(tabletevent)
4060
4061QDebug operator<<(QDebug dbg, const QEventPoint *tp)
4062{
4063 if (!tp)
4064 return dbg << "QEventPoint(0x0)";
4065
4066 return operator<<(dbg, *tp);
4067}
4068
4069QDebug operator<<(QDebug dbg, const QEventPoint &tp)
4070{
4071 QDebugStateSaver saver(dbg);
4072 dbg.nospace();
4073 dbg << "QEventPoint(id=" << tp.id() << " ts=" << tp.timestamp();
4074 dbg << " pos=";
4075 QtDebugUtils::formatQPoint(debug&: dbg, point: tp.position());
4076 dbg << " scn=";
4077 QtDebugUtils::formatQPoint(debug&: dbg, point: tp.scenePosition());
4078 dbg << " gbl=";
4079 QtDebugUtils::formatQPoint(debug&: dbg, point: tp.globalPosition());
4080 dbg << ' ';
4081 QtDebugUtils::formatQEnum(debug&: dbg, value: tp.state());
4082 if (!qFuzzyIsNull(d: tp.pressure()) && !qFuzzyCompare(p1: tp.pressure(), p2: 1))
4083 dbg << " pressure=" << tp.pressure();
4084 if (!tp.ellipseDiameters().isEmpty() || !qFuzzyIsNull(d: tp.rotation())) {
4085 dbg << " ellipse=("
4086 << tp.ellipseDiameters().width() << "x" << tp.ellipseDiameters().height()
4087 << " \u2221 " << tp.rotation() << ')';
4088 }
4089 dbg << " vel=";
4090 QtDebugUtils::formatQPoint(debug&: dbg, point: tp.velocity().toPointF());
4091 dbg << " press=";
4092 QtDebugUtils::formatQPoint(debug&: dbg, point: tp.pressPosition());
4093 dbg << " last=";
4094 QtDebugUtils::formatQPoint(debug&: dbg, point: tp.lastPosition());
4095 dbg << " \u0394 ";
4096 QtDebugUtils::formatQPoint(debug&: dbg, point: tp.position() - tp.lastPosition());
4097 dbg << ')';
4098 return dbg;
4099}
4100
4101QDebug operator<<(QDebug dbg, const QEvent *e)
4102{
4103 QDebugStateSaver saver(dbg);
4104 dbg.nospace();
4105 if (!e)
4106 return dbg << "QEvent(0x0)";
4107
4108 // More useful event output could be added here
4109 const QEvent::Type type = e->type();
4110 bool isMouse = false;
4111 switch (type) {
4112 case QEvent::Expose:
4113 dbg << "QExposeEvent()";
4114 break;
4115 case QEvent::Paint:
4116 dbg << "QPaintEvent(" << static_cast<const QPaintEvent *>(e)->region() << ')';
4117 break;
4118 case QEvent::MouseButtonPress:
4119 case QEvent::MouseMove:
4120 case QEvent::MouseButtonRelease:
4121 case QEvent::MouseButtonDblClick:
4122 case QEvent::NonClientAreaMouseButtonPress:
4123 case QEvent::NonClientAreaMouseMove:
4124 case QEvent::NonClientAreaMouseButtonRelease:
4125 case QEvent::NonClientAreaMouseButtonDblClick:
4126 isMouse = true;
4127 Q_FALLTHROUGH();
4128 case QEvent::HoverEnter:
4129 case QEvent::HoverMove:
4130 case QEvent::HoverLeave:
4131 {
4132 const QSinglePointEvent *spe = static_cast<const QSinglePointEvent*>(e);
4133 const Qt::MouseButton button = spe->button();
4134 const Qt::MouseButtons buttons = spe->buttons();
4135 dbg << eventClassName(t: type) << '(';
4136 QtDebugUtils::formatQEnum(debug&: dbg, value: type);
4137 dbg << " ts=" << spe->timestamp();
4138 if (isMouse) {
4139 if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) {
4140 dbg << ' ';
4141 QtDebugUtils::formatQEnum(debug&: dbg, value: button);
4142 }
4143 if (buttons && button != buttons) {
4144 dbg << " btns=";
4145 QtDebugUtils::formatQFlags(debug&: dbg, value: buttons);
4146 }
4147 }
4148 QtDebugUtils::formatNonNullQFlags(debug&: dbg, prefix: ", ", value: spe->modifiers());
4149 dbg << " pos=";
4150 QtDebugUtils::formatQPoint(debug&: dbg, point: spe->position());
4151 dbg << " scn=";
4152 QtDebugUtils::formatQPoint(debug&: dbg, point: spe->scenePosition());
4153 dbg << " gbl=";
4154 QtDebugUtils::formatQPoint(debug&: dbg, point: spe->globalPosition());
4155 dbg << " dev=" << spe->device() << ')';
4156 if (isMouse) {
4157 auto src = static_cast<const QMouseEvent*>(e)->source();
4158 if (src != Qt::MouseEventNotSynthesized) {
4159 dbg << " source=";
4160 QtDebugUtils::formatQEnum(debug&: dbg, value: src);
4161 }
4162 }
4163 }
4164 break;
4165# if QT_CONFIG(wheelevent)
4166 case QEvent::Wheel: {
4167 const QWheelEvent *we = static_cast<const QWheelEvent *>(e);
4168 dbg << "QWheelEvent(" << we->phase();
4169 if (!we->pixelDelta().isNull() || !we->angleDelta().isNull())
4170 dbg << ", pixelDelta=" << we->pixelDelta() << ", angleDelta=" << we->angleDelta();
4171 dbg << " dev=" << we->device() << ')';
4172 dbg << ')';
4173 }
4174 break;
4175# endif // QT_CONFIG(wheelevent)
4176 case QEvent::KeyPress:
4177 case QEvent::KeyRelease:
4178 case QEvent::ShortcutOverride:
4179 {
4180 const QKeyEvent *ke = static_cast<const QKeyEvent *>(e);
4181 dbg << "QKeyEvent(";
4182 QtDebugUtils::formatQEnum(debug&: dbg, value: type);
4183 dbg << ", ";
4184 QtDebugUtils::formatQEnum(debug&: dbg, value: static_cast<Qt::Key>(ke->key()));
4185 QtDebugUtils::formatNonNullQFlags(debug&: dbg, prefix: ", ", value: ke->modifiers());
4186 if (!ke->text().isEmpty())
4187 dbg << ", text=" << ke->text();
4188 if (ke->isAutoRepeat())
4189 dbg << ", autorepeat, count=" << ke->count();
4190 if (dbg.verbosity() > QDebug::DefaultVerbosity) {
4191 dbg << ", nativeScanCode=" << ke->nativeScanCode();
4192 dbg << ", nativeVirtualKey=" << ke->nativeVirtualKey();
4193 }
4194 dbg << ')';
4195 }
4196 break;
4197#if QT_CONFIG(shortcut)
4198 case QEvent::Shortcut: {
4199 const QShortcutEvent *se = static_cast<const QShortcutEvent *>(e);
4200 dbg << "QShortcutEvent(" << se->key().toString() << ", id=" << se->shortcutId();
4201 if (se->isAmbiguous())
4202 dbg << ", ambiguous";
4203 dbg << ')';
4204 }
4205 break;
4206#endif
4207 case QEvent::FocusAboutToChange:
4208 case QEvent::FocusIn:
4209 case QEvent::FocusOut:
4210 dbg << "QFocusEvent(";
4211 QtDebugUtils::formatQEnum(debug&: dbg, value: type);
4212 dbg << ", ";
4213 QtDebugUtils::formatQEnum(debug&: dbg, value: static_cast<const QFocusEvent *>(e)->reason());
4214 dbg << ')';
4215 break;
4216 case QEvent::Move: {
4217 const QMoveEvent *me = static_cast<const QMoveEvent *>(e);
4218 dbg << "QMoveEvent(";
4219 QtDebugUtils::formatQPoint(debug&: dbg, point: me->pos());
4220 if (!me->spontaneous())
4221 dbg << ", non-spontaneous";
4222 dbg << ')';
4223 }
4224 break;
4225 case QEvent::Resize: {
4226 const QResizeEvent *re = static_cast<const QResizeEvent *>(e);
4227 dbg << "QResizeEvent(";
4228 QtDebugUtils::formatQSize(debug&: dbg, size: re->size());
4229 if (!re->spontaneous())
4230 dbg << ", non-spontaneous";
4231 dbg << ')';
4232 }
4233 break;
4234# if QT_CONFIG(draganddrop)
4235 case QEvent::DragEnter:
4236 case QEvent::DragMove:
4237 case QEvent::Drop:
4238 formatDropEvent(d: dbg, e: static_cast<const QDropEvent *>(e));
4239 break;
4240# endif // QT_CONFIG(draganddrop)
4241 case QEvent::InputMethod:
4242 formatInputMethodEvent(d: dbg, e: static_cast<const QInputMethodEvent *>(e));
4243 break;
4244 case QEvent::InputMethodQuery:
4245 formatInputMethodQueryEvent(d: dbg, e: static_cast<const QInputMethodQueryEvent *>(e));
4246 break;
4247 case QEvent::TouchBegin:
4248 case QEvent::TouchUpdate:
4249 case QEvent::TouchEnd:
4250 formatTouchEvent(d: dbg, t: *static_cast<const QTouchEvent*>(e));
4251 break;
4252 case QEvent::ChildAdded:
4253 case QEvent::ChildPolished:
4254 case QEvent::ChildRemoved:
4255 dbg << "QChildEvent(";
4256 QtDebugUtils::formatQEnum(debug&: dbg, value: type);
4257 dbg << ", " << (static_cast<const QChildEvent*>(e))->child() << ')';
4258 break;
4259# ifndef QT_NO_GESTURES
4260 case QEvent::NativeGesture: {
4261 const QNativeGestureEvent *ne = static_cast<const QNativeGestureEvent *>(e);
4262 dbg << "QNativeGestureEvent(";
4263 QtDebugUtils::formatQEnum(debug&: dbg, value: ne->gestureType());
4264 dbg << ", fingerCount=" << ne->fingerCount() << ", localPos=";
4265 QtDebugUtils::formatQPoint(debug&: dbg, point: ne->position());
4266 if (!qIsNull(d: ne->value()))
4267 dbg << ", value=" << ne->value();
4268 if (!ne->delta().isNull()) {
4269 dbg << ", delta=";
4270 QtDebugUtils::formatQPoint(debug&: dbg, point: ne->delta());
4271 }
4272 dbg << ')';
4273 }
4274 break;
4275# endif // !QT_NO_GESTURES
4276 case QEvent::ApplicationStateChange:
4277 dbg << "QApplicationStateChangeEvent(";
4278 QtDebugUtils::formatQEnum(debug&: dbg, value: static_cast<const QApplicationStateChangeEvent *>(e)->applicationState());
4279 dbg << ')';
4280 break;
4281# ifndef QT_NO_CONTEXTMENU
4282 case QEvent::ContextMenu:
4283 dbg << "QContextMenuEvent(" << static_cast<const QContextMenuEvent *>(e)->pos() << ')';
4284 break;
4285# endif // !QT_NO_CONTEXTMENU
4286# if QT_CONFIG(tabletevent)
4287 case QEvent::TabletEnterProximity:
4288 case QEvent::TabletLeaveProximity:
4289 case QEvent::TabletPress:
4290 case QEvent::TabletMove:
4291 case QEvent::TabletRelease:
4292 formatTabletEvent(d: dbg, e: static_cast<const QTabletEvent *>(e));
4293 break;
4294# endif // QT_CONFIG(tabletevent)
4295 case QEvent::Enter:
4296 dbg << "QEnterEvent(" << static_cast<const QEnterEvent *>(e)->position() << ')';
4297 break;
4298 case QEvent::Timer:
4299 dbg << "QTimerEvent(id=" << static_cast<const QTimerEvent *>(e)->timerId() << ')';
4300 break;
4301 case QEvent::PlatformSurface:
4302 dbg << "QPlatformSurfaceEvent(surfaceEventType=";
4303 switch (static_cast<const QPlatformSurfaceEvent *>(e)->surfaceEventType()) {
4304 case QPlatformSurfaceEvent::SurfaceCreated:
4305 dbg << "SurfaceCreated";
4306 break;
4307 case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed:
4308 dbg << "SurfaceAboutToBeDestroyed";
4309 break;
4310 }
4311 dbg << ')';
4312 break;
4313 case QEvent::ScrollPrepare: {
4314 const QScrollPrepareEvent *se = static_cast<const QScrollPrepareEvent *>(e);
4315 dbg << "QScrollPrepareEvent(viewportSize=" << se->viewportSize()
4316 << ", contentPosRange=" << se->contentPosRange()
4317 << ", contentPos=" << se->contentPos() << ')';
4318 }
4319 break;
4320 case QEvent::Scroll: {
4321 const QScrollEvent *se = static_cast<const QScrollEvent *>(e);
4322 dbg << "QScrollEvent(contentPos=" << se->contentPos()
4323 << ", overshootDistance=" << se->overshootDistance()
4324 << ", scrollState=" << se->scrollState() << ')';
4325 }
4326 break;
4327 default:
4328 dbg << eventClassName(t: type) << '(';
4329 QtDebugUtils::formatQEnum(debug&: dbg, value: type);
4330 dbg << ", " << (const void *)e << ')';
4331 break;
4332 }
4333 return dbg;
4334}
4335#endif // !QT_NO_DEBUG_STREAM
4336
4337/*!
4338 \class QShortcutEvent
4339 \brief The QShortcutEvent class provides an event which is generated when
4340 the user presses a key combination.
4341
4342 \ingroup events
4343 \inmodule QtGui
4344
4345 Normally you do not need to use this class directly; QShortcut
4346 provides a higher-level interface to handle shortcut keys.
4347
4348 \sa QShortcut
4349*/
4350
4351/*!
4352 \fn const QKeySequence &QShortcutEvent::key() const
4353
4354 Returns the key sequence that triggered the event.
4355*/
4356
4357/*!
4358 \fn int QShortcutEvent::shortcutId() const
4359
4360 \deprecated
4361
4362 Returns the ID of the QShortcut object for which this event was
4363 generated.
4364
4365 \sa QShortcut::id()
4366*/
4367
4368/*!
4369 \fn bool QShortcutEvent::isAmbiguous() const
4370
4371 Returns \c true if the key sequence that triggered the event is
4372 ambiguous.
4373
4374 \sa QShortcut::activatedAmbiguously()
4375*/
4376
4377/*!
4378 \class QWindowStateChangeEvent
4379 \ingroup events
4380 \inmodule QtGui
4381
4382 \brief The QWindowStateChangeEvent class provides the window state before a
4383 window state change.
4384*/
4385
4386/*! \fn Qt::WindowStates QWindowStateChangeEvent::oldState() const
4387
4388 Returns the state of the window before the change.
4389*/
4390
4391/*! \internal
4392 */
4393QWindowStateChangeEvent::QWindowStateChangeEvent(Qt::WindowStates oldState, bool isOverride)
4394 : QEvent(WindowStateChange), m_oldStates(oldState), m_override(isOverride)
4395{
4396}
4397
4398/*! \internal
4399 */
4400bool QWindowStateChangeEvent::isOverride() const
4401{
4402 return m_override;
4403}
4404
4405Q_IMPL_EVENT_COMMON(QWindowStateChangeEvent)
4406
4407
4408/*!
4409 \class QTouchEvent
4410 \brief The QTouchEvent class contains parameters that describe a touch event.
4411 \since 4.6
4412 \ingroup events
4413 \ingroup touch
4414 \inmodule QtGui
4415
4416 \section1 Enabling Touch Events
4417
4418 Touch events occur when pressing, releasing, or moving one or more touch points on a touch
4419 device (such as a touch-screen or track-pad). To receive touch events, widgets have to have the
4420 Qt::WA_AcceptTouchEvents attribute set and graphics items need to have the
4421 \l{QGraphicsItem::setAcceptTouchEvents()}{acceptTouchEvents} attribute set to true.
4422
4423 When using QAbstractScrollArea based widgets, you should enable the Qt::WA_AcceptTouchEvents
4424 attribute on the scroll area's \l{QAbstractScrollArea::viewport()}{viewport}.
4425
4426 Similarly to QMouseEvent, Qt automatically grabs each touch point on the first press inside a
4427 widget, and the widget will receive all updates for the touch point until it is released.
4428 Note that it is possible for a widget to receive events for numerous touch points, and that
4429 multiple widgets may be receiving touch events at the same time.
4430
4431 \section1 Event Handling
4432
4433 All touch events are of type QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd or
4434 QEvent::TouchCancel. Reimplement QWidget::event() or QAbstractScrollArea::viewportEvent() for
4435 widgets and QGraphicsItem::sceneEvent() for items in a graphics view to receive touch events.
4436
4437 Unlike widgets, QWindows receive touch events always, there is no need to opt in. When working
4438 directly with a QWindow, it is enough to reimplement QWindow::touchEvent().
4439
4440 The QEvent::TouchUpdate and QEvent::TouchEnd events are sent to the widget or item that
4441 accepted the QEvent::TouchBegin event. If the QEvent::TouchBegin event is not accepted and not
4442 filtered by an event filter, then no further touch events are sent until the next
4443 QEvent::TouchBegin.
4444
4445 Some systems may send an event of type QEvent::TouchCancel. Upon receiving this event
4446 applications are requested to ignore the entire active touch sequence. For example in a
4447 composited system the compositor may decide to treat certain gestures as system-wide
4448 gestures. Whenever such a decision is made (the gesture is recognized), the clients will be
4449 notified with a QEvent::TouchCancel event so they can update their state accordingly.
4450
4451 The pointCount() and point() functions can be used to access and iterate individual
4452 touch points.
4453
4454 The points() function returns a list of all touch points contained in the event.
4455 Note that this list may be empty, for example in case of a QEvent::TouchCancel event.
4456 Each point is an instance of the QEventPoint class. The QEventPoint::State enum
4457 describes the different states that a touch point may have.
4458
4459 \note The list of points() will never be partial: A touch event will always contain a touch
4460 point for each existing physical touch contacts targeting the window or widget to which the
4461 event is sent. For instance, assuming that all touches target the same window or widget, an
4462 event with a condition of points().count()==2 is guaranteed to imply that the number of
4463 fingers touching the touchscreen or touchpad is exactly two.
4464
4465 \section1 Event Delivery and Propagation
4466
4467 By default, QGuiApplication translates the first touch point in a QTouchEvent into
4468 a QMouseEvent. This makes it possible to enable touch events on existing widgets that do not
4469 normally handle QTouchEvent. See below for information on some special considerations needed
4470 when doing this.
4471
4472 QEvent::TouchBegin is the first touch event sent to a widget. The QEvent::TouchBegin event
4473 contains a special accept flag that indicates whether the receiver wants the event. By default,
4474 the event is accepted. You should call ignore() if the touch event is not handled by your
4475 widget. The QEvent::TouchBegin event is propagated up the parent widget chain until a widget
4476 accepts it with accept(), or an event filter consumes it. For QGraphicsItems, the
4477 QEvent::TouchBegin event is propagated to items under the mouse (similar to mouse event
4478 propagation for QGraphicsItems).
4479
4480 \section1 Touch Point Grouping
4481
4482 As mentioned above, it is possible that several widgets can be receiving QTouchEvents at the
4483 same time. However, Qt makes sure to never send duplicate QEvent::TouchBegin events to the same
4484 widget, which could theoretically happen during propagation if, for example, the user touched 2
4485 separate widgets in a QGroupBox and both widgets ignored the QEvent::TouchBegin event.
4486
4487 To avoid this, Qt will group new touch points together using the following rules:
4488
4489 \list
4490
4491 \li When the first touch point is detected, the destination widget is determined firstly by the
4492 location on screen and secondly by the propagation rules.
4493
4494 \li When additional touch points are detected, Qt first looks to see if there are any active
4495 touch points on any ancestor or descendent of the widget under the new touch point. If there
4496 are, the new touch point is grouped with the first, and the new touch point will be sent in a
4497 single QTouchEvent to the widget that handled the first touch point. (The widget under the new
4498 touch point will not receive an event).
4499
4500 \endlist
4501
4502 This makes it possible for sibling widgets to handle touch events independently while making
4503 sure that the sequence of QTouchEvents is always correct.
4504
4505 \section1 Mouse Events and Touch Event Synthesizing
4506
4507 QTouchEvent delivery is independent from that of QMouseEvent. The application flags
4508 Qt::AA_SynthesizeTouchForUnhandledMouseEvents and Qt::AA_SynthesizeMouseForUnhandledTouchEvents
4509 can be used to enable or disable automatic synthesizing of touch events to mouse events and
4510 mouse events to touch events.
4511
4512 \section1 Caveats
4513
4514 \list
4515
4516 \li As mentioned above, enabling touch events means multiple widgets can be receiving touch
4517 events simultaneously. Combined with the default QWidget::event() handling for QTouchEvents,
4518 this gives you great flexibility in designing touch user interfaces. Be aware of the
4519 implications. For example, it is possible that the user is moving a QSlider with one finger and
4520 pressing a QPushButton with another. The signals emitted by these widgets will be
4521 interleaved.
4522
4523 \li Recursion into the event loop using one of the exec() methods (e.g., QDialog::exec() or
4524 QMenu::exec()) in a QTouchEvent event handler is not supported. Since there are multiple event
4525 recipients, recursion may cause problems, including but not limited to lost events
4526 and unexpected infinite recursion.
4527
4528 \li QTouchEvents are not affected by a \l{QWidget::grabMouse()}{mouse grab} or an
4529 \l{QApplication::activePopupWidget()}{active pop-up widget}. The behavior of QTouchEvents is
4530 undefined when opening a pop-up or grabbing the mouse while there are more than one active touch
4531 points.
4532
4533 \endlist
4534
4535 \sa QEventPoint, QEventPoint::State, Qt::WA_AcceptTouchEvents,
4536 QGraphicsItem::acceptTouchEvents()
4537*/
4538
4539/*!
4540 Constructs a QTouchEvent with the given \a eventType, \a device,
4541 \a touchPoints, and current keyboard \a modifiers at the time of the event.
4542*/
4543
4544QTouchEvent::QTouchEvent(QEvent::Type eventType,
4545 const QPointingDevice *device,
4546 Qt::KeyboardModifiers modifiers,
4547 const QList<QEventPoint> &touchPoints)
4548 : QPointerEvent(eventType, device, modifiers, touchPoints),
4549 m_target(nullptr)
4550{
4551 for (QEventPoint &point : m_points) {
4552 m_touchPointStates |= point.state();
4553 QMutableEventPoint::setDevice(p&: point, arg: device);
4554 }
4555}
4556
4557#if QT_DEPRECATED_SINCE(6, 0)
4558/*!
4559 \deprecated [6.0] Use another constructor.
4560
4561 Constructs a QTouchEvent with the given \a eventType, \a device, and
4562 \a touchPoints. The \a touchPointStates and \a modifiers are the current
4563 touch point states and keyboard modifiers at the time of the event.
4564*/
4565QTouchEvent::QTouchEvent(QEvent::Type eventType,
4566 const QPointingDevice *device,
4567 Qt::KeyboardModifiers modifiers,
4568 QEventPoint::States touchPointStates,
4569 const QList<QEventPoint> &touchPoints)
4570 : QPointerEvent(eventType, device, modifiers, touchPoints),
4571 m_target(nullptr),
4572 m_touchPointStates(touchPointStates)
4573{
4574 for (QEventPoint &point : m_points)
4575 QMutableEventPoint::setDevice(p&: point, arg: device);
4576}
4577#endif // QT_DEPRECATED_SINCE(6, 0)
4578
4579Q_IMPL_POINTER_EVENT(QTouchEvent)
4580
4581/*!
4582 Returns true if this event includes at least one newly-pressed touchpoint.
4583*/
4584bool QTouchEvent::isBeginEvent() const
4585{
4586 return m_touchPointStates.testFlag(flag: QEventPoint::State::Pressed);
4587}
4588
4589/*!
4590 Returns true if this event does not include newly-pressed or newly-released
4591 touchpoints.
4592*/
4593bool QTouchEvent::isUpdateEvent() const
4594{
4595 return !m_touchPointStates.testFlag(flag: QEventPoint::State::Pressed) &&
4596 !m_touchPointStates.testFlag(flag: QEventPoint::State::Released);
4597}
4598
4599/*!
4600 Returns true if this event includes at least one newly-released touchpoint.
4601*/
4602bool QTouchEvent::isEndEvent() const
4603{
4604 return m_touchPointStates.testFlag(flag: QEventPoint::State::Released);
4605}
4606
4607/*! \fn QObject *QTouchEvent::target() const
4608
4609 Returns the target object within the window on which the event occurred.
4610 This is typically a QWidget or a QQuickItem. May be 0 when no specific target is available.
4611*/
4612
4613/*! \fn QEventPoint::States QTouchEvent::touchPointStates() const
4614
4615 Returns a bitwise OR of all the touch point states for this event.
4616*/
4617
4618/*! \fn const QList<QEventPoint> &QTouchEvent::touchPoints() const
4619 \deprecated [6.0] Use points() instead.
4620
4621 Returns a reference to the list of touch points contained in the touch event.
4622
4623 \sa QPointerEvent::point(), QPointerEvent::pointCount()
4624*/
4625
4626/*!
4627 \class QScrollPrepareEvent
4628 \since 4.8
4629 \ingroup events
4630 \inmodule QtGui
4631
4632 \brief The QScrollPrepareEvent class is sent in preparation of scrolling.
4633
4634 The scroll prepare event is sent before scrolling (usually by QScroller) is started.
4635 The object receiving this event should set viewportSize, maxContentPos and contentPos.
4636 It also should accept this event to indicate that scrolling should be started.
4637
4638 It is not guaranteed that a QScrollEvent will be sent after an accepted
4639 QScrollPrepareEvent, e.g. in a case where the maximum content position is (0, 0).
4640
4641 \sa QScrollEvent, QScroller
4642*/
4643
4644/*!
4645 Creates new QScrollPrepareEvent
4646 The \a startPos is the position of a touch or mouse event that started the scrolling.
4647*/
4648QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos)
4649 : QEvent(QEvent::ScrollPrepare), m_startPos(startPos)
4650{
4651}
4652
4653Q_IMPL_EVENT_COMMON(QScrollPrepareEvent)
4654
4655/*!
4656 \fn QPointF QScrollPrepareEvent::startPos() const
4657
4658 Returns the position of the touch or mouse event that started the scrolling.
4659*/
4660
4661/*!
4662 \fn QSizeF QScrollPrepareEvent::viewportSize() const
4663 Returns size of the area that is to be scrolled as set by setViewportSize
4664
4665 \sa setViewportSize()
4666*/
4667
4668/*!
4669 \fn QRectF QScrollPrepareEvent::contentPosRange() const
4670 Returns the range of coordinates for the content as set by setContentPosRange().
4671*/
4672
4673/*!
4674 \fn QPointF QScrollPrepareEvent::contentPos() const
4675 Returns the current position of the content as set by setContentPos.
4676*/
4677
4678/*!
4679 Sets the size of the area that is to be scrolled to \a size.
4680
4681 \sa viewportSize()
4682*/
4683void QScrollPrepareEvent::setViewportSize(const QSizeF &size)
4684{
4685 m_viewportSize = size;
4686}
4687
4688/*!
4689 Sets the range of content coordinates to \a rect.
4690
4691 \sa contentPosRange()
4692*/
4693void QScrollPrepareEvent::setContentPosRange(const QRectF &rect)
4694{
4695 m_contentPosRange = rect;
4696}
4697
4698/*!
4699 Sets the current content position to \a pos.
4700
4701 \sa contentPos()
4702*/
4703void QScrollPrepareEvent::setContentPos(const QPointF &pos)
4704{
4705 m_contentPos = pos;
4706}
4707
4708
4709/*!
4710 \class QScrollEvent
4711 \since 4.8
4712 \ingroup events
4713 \inmodule QtGui
4714
4715 \brief The QScrollEvent class is sent when scrolling.
4716
4717 The scroll event is sent to indicate that the receiver should be scrolled.
4718 Usually the receiver should be something visual like QWidget or QGraphicsObject.
4719
4720 Some care should be taken that no conflicting QScrollEvents are sent from two
4721 sources. Using QScroller::scrollTo is save however.
4722
4723 \sa QScrollPrepareEvent, QScroller
4724*/
4725
4726/*!
4727 \enum QScrollEvent::ScrollState
4728
4729 This enum describes the states a scroll event can have.
4730
4731 \value ScrollStarted Set for the first scroll event of a scroll activity.
4732
4733 \value ScrollUpdated Set for all but the first and the last scroll event of a scroll activity.
4734
4735 \value ScrollFinished Set for the last scroll event of a scroll activity.
4736
4737 \sa QScrollEvent::scrollState()
4738*/
4739
4740/*!
4741 Creates a new QScrollEvent
4742 \a contentPos is the new content position, \a overshootDistance is the
4743 new overshoot distance while \a scrollState indicates if this scroll
4744 event is the first one, the last one or some event in between.
4745*/
4746QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDistance, ScrollState scrollState)
4747 : QEvent(QEvent::Scroll), m_contentPos(contentPos), m_overshoot(overshootDistance), m_state(scrollState)
4748{
4749}
4750
4751Q_IMPL_EVENT_COMMON(QScrollEvent)
4752
4753/*!
4754 \fn QPointF QScrollEvent::contentPos() const
4755
4756 Returns the new scroll position.
4757*/
4758
4759/*!
4760 \fn QPointF QScrollEvent::overshootDistance() const
4761
4762 Returns the new overshoot distance.
4763 See QScroller for an explanation of the term overshoot.
4764
4765 \sa QScroller
4766*/
4767
4768/*!
4769 \fn QScrollEvent::ScrollState QScrollEvent::scrollState() const
4770
4771 Returns the current scroll state as a combination of ScrollStateFlag values.
4772 ScrollStarted (or ScrollFinished) will be set, if this scroll event is the first (or last) event in a scrolling activity.
4773 Please note that both values can be set at the same time, if the activity consists of a single QScrollEvent.
4774 All other scroll events in between will have their state set to ScrollUpdated.
4775
4776 A widget could for example revert selections when scrolling is started and stopped.
4777*/
4778
4779/*!
4780 Creates a new QScreenOrientationChangeEvent
4781 \a screenOrientation is the new orientation of the \a screen.
4782*/
4783QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation screenOrientation)
4784 : QEvent(QEvent::OrientationChange), m_screen(screen), m_orientation(screenOrientation)
4785{
4786}
4787
4788Q_IMPL_EVENT_COMMON(QScreenOrientationChangeEvent)
4789
4790/*!
4791 \fn QScreen *QScreenOrientationChangeEvent::screen() const
4792
4793 Returns the screen whose orientation changed.
4794*/
4795
4796/*!
4797 \fn Qt::ScreenOrientation QScreenOrientationChangeEvent::orientation() const
4798
4799 Returns the orientation of the screen.
4800*/
4801
4802/*!
4803 Creates a new QApplicationStateChangeEvent.
4804 \a applicationState is the new state.
4805*/
4806QApplicationStateChangeEvent::QApplicationStateChangeEvent(Qt::ApplicationState applicationState)
4807 : QEvent(QEvent::ApplicationStateChange), m_applicationState(applicationState)
4808{
4809}
4810
4811Q_IMPL_EVENT_COMMON(QApplicationStateChangeEvent)
4812
4813/*!
4814 \fn Qt::ApplicationState QApplicationStateChangeEvent::applicationState() const
4815
4816 Returns the state of the application.
4817*/
4818
4819/*!
4820 \class QChildWindowEvent
4821 \inmodule QtGui
4822 \since 6.7
4823 \brief The QChildWindowEvent class contains event parameters for
4824 child window changes.
4825
4826 \ingroup events
4827
4828 Child window events are sent to windows when children are
4829 added or removed.
4830
4831 In both cases you can only rely on the child being a QWindow
4832 — not any subclass thereof. This is because in the
4833 QEvent::ChildWindowAdded case the subclass is not yet fully
4834 constructed, and in the QEvent::ChildWindowRemoved case it
4835 might have already been destructed.
4836*/
4837
4838/*!
4839 Constructs a child window event object of a particular \a type
4840 for the \a childWindow.
4841
4842 \a type can be QEvent::ChildWindowAdded or QEvent::ChildWindowRemoved.
4843
4844 \sa child()
4845*/
4846QChildWindowEvent::QChildWindowEvent(Type type, QWindow *childWindow)
4847 : QEvent(type), c(childWindow)
4848{
4849}
4850
4851Q_IMPL_EVENT_COMMON(QChildWindowEvent)
4852
4853/*!
4854 \fn QWindow *QChildWindowEvent::child() const
4855
4856 Returns the child window that was added or removed.
4857*/
4858
4859QMutableTouchEvent::~QMutableTouchEvent()
4860 = default;
4861
4862/*! \internal
4863 Add the given \a point.
4864*/
4865void QMutableTouchEvent::addPoint(QTouchEvent *e, const QEventPoint &point)
4866{
4867 e->m_points.append(t: point);
4868 auto &added = e->m_points.last();
4869 if (!added.device())
4870 QMutableEventPoint::setDevice(p&: added, arg: e->pointingDevice());
4871 e->m_touchPointStates |= point.state();
4872}
4873
4874
4875QMutableSinglePointEvent::~QMutableSinglePointEvent()
4876 = default;
4877
4878/*! \internal
4879 Add the given \a point.
4880*/
4881void QMutableTouchEvent::addPoint(const QEventPoint &point)
4882{
4883 addPoint(e: this, point);
4884}
4885
4886QT_END_NAMESPACE
4887
4888#include "moc_qevent.cpp"
4889

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