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