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