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