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#ifndef QEVENT_H
5#define QEVENT_H
6
7#if 0
8#pragma qt_class(QtEvents)
9#endif
10
11#include <QtGui/qtguiglobal.h>
12
13#include <QtCore/qcoreevent.h>
14#include <QtCore/qiodevice.h>
15#include <QtCore/qlist.h>
16#include <QtCore/qnamespace.h>
17#include <QtCore/qpointer.h>
18#include <QtCore/qstring.h>
19#include <QtCore/qurl.h>
20#include <QtCore/qvariant.h>
21#include <QtGui/qeventpoint.h>
22#include <QtGui/qpointingdevice.h>
23#include <QtGui/qregion.h>
24#include <QtGui/qwindowdefs.h>
25
26#if QT_CONFIG(shortcut)
27# include <QtGui/qkeysequence.h>
28#endif
29
30class tst_QEvent;
31
32QT_BEGIN_NAMESPACE
33
34class QFile;
35class QAction;
36class QMouseEvent;
37class QPointerEvent;
38class QScreen;
39#if QT_CONFIG(shortcut)
40class QShortcut;
41#endif
42class QTabletEvent;
43class QTouchEvent;
44#if QT_CONFIG(gestures)
45class QGesture;
46#endif
47
48class Q_GUI_EXPORT QInputEvent : public QEvent
49{
50 Q_DECL_EVENT_COMMON(QInputEvent)
51public:
52 explicit QInputEvent(Type type, const QInputDevice *m_dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
53
54 const QInputDevice *device() const { return m_dev; }
55 QInputDevice::DeviceType deviceType() const { return m_dev ? m_dev->type() : QInputDevice::DeviceType::Unknown; }
56 inline Qt::KeyboardModifiers modifiers() const { return m_modState; }
57 inline void setModifiers(Qt::KeyboardModifiers modifiers) { m_modState = modifiers; }
58 inline quint64 timestamp() const { return m_timeStamp; }
59 virtual void setTimestamp(quint64 timestamp) { m_timeStamp = timestamp; }
60
61protected:
62 QInputEvent(Type type, PointerEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
63 QInputEvent(Type type, SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
64
65 const QInputDevice *m_dev = nullptr;
66 quint64 m_timeStamp = 0;
67 Qt::KeyboardModifiers m_modState = Qt::NoModifier;
68 // fill up to the closest 8-byte aligned size: 48
69 quint32 m_reserved = 0;
70};
71
72class Q_GUI_EXPORT QPointerEvent : public QInputEvent
73{
74 Q_DECL_EVENT_COMMON(QPointerEvent)
75public:
76 explicit QPointerEvent(Type type, const QPointingDevice *dev,
77 Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QList<QEventPoint> &points = {});
78
79 const QPointingDevice *pointingDevice() const;
80 QPointingDevice::PointerType pointerType() const {
81 return pointingDevice() ? pointingDevice()->pointerType() : QPointingDevice::PointerType::Unknown;
82 }
83 void setTimestamp(quint64 timestamp) override;
84 qsizetype pointCount() const { return m_points.size(); }
85 QEventPoint &point(qsizetype i);
86 const QList<QEventPoint> &points() const { return m_points; }
87 QEventPoint *pointById(int id);
88 bool allPointsGrabbed() const;
89 virtual bool isBeginEvent() const { return false; }
90 virtual bool isUpdateEvent() const { return false; }
91 virtual bool isEndEvent() const { return false; }
92 bool allPointsAccepted() const;
93 virtual void setAccepted(bool accepted) override;
94 QObject *exclusiveGrabber(const QEventPoint &point) const;
95 void setExclusiveGrabber(const QEventPoint &point, QObject *exclusiveGrabber);
96 QList<QPointer <QObject>> passiveGrabbers(const QEventPoint &point) const;
97 void clearPassiveGrabbers(const QEventPoint &point);
98 bool addPassiveGrabber(const QEventPoint &point, QObject *grabber);
99 bool removePassiveGrabber(const QEventPoint &point, QObject *grabber);
100
101protected:
102 QPointerEvent(Type type, SinglePointEventTag, const QInputDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
103
104 QList<QEventPoint> m_points;
105};
106
107class Q_GUI_EXPORT QSinglePointEvent : public QPointerEvent
108{
109 Q_GADGET
110 Q_PROPERTY(QObject *exclusivePointGrabber READ exclusivePointGrabber
111 WRITE setExclusivePointGrabber)
112
113 Q_DECL_EVENT_COMMON(QSinglePointEvent)
114public:
115 inline Qt::MouseButton button() const { return m_button; }
116 inline Qt::MouseButtons buttons() const { return m_mouseState; }
117
118 inline QPointF position() const
119 { Q_ASSERT(!m_points.isEmpty()); return m_points.first().position(); }
120 inline QPointF scenePosition() const
121 { Q_ASSERT(!m_points.isEmpty()); return m_points.first().scenePosition(); }
122 inline QPointF globalPosition() const
123 { Q_ASSERT(!m_points.isEmpty()); return m_points.first().globalPosition(); }
124
125 bool isBeginEvent() const override;
126 bool isUpdateEvent() const override;
127 bool isEndEvent() const override;
128
129 QObject *exclusivePointGrabber() const
130 { return QPointerEvent::exclusiveGrabber(point: points().first()); }
131 void setExclusivePointGrabber(QObject *exclusiveGrabber)
132 { QPointerEvent::setExclusiveGrabber(point: points().first(), exclusiveGrabber); }
133
134protected:
135 friend class ::tst_QEvent;
136 QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point,
137 Qt::MouseButton button, Qt::MouseButtons buttons,
138 Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
139 QSinglePointEvent(Type type, const QPointingDevice *dev, const QPointF &localPos,
140 const QPointF &scenePos, const QPointF &globalPos,
141 Qt::MouseButton button, Qt::MouseButtons buttons,
142 Qt::KeyboardModifiers modifiers,
143 Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
144
145 Qt::MouseButton m_button = Qt::NoButton;
146 Qt::MouseButtons m_mouseState = Qt::NoButton;
147 Qt::MouseEventSource m_source;
148 /*
149 Fill up to the next 8-byte aligned size: 88
150 We have 32bits left, use some for QSinglePointEvent subclasses so that
151 we don't end up with gaps.
152 */
153 // split this in two quint16; with a quint32, MSVC would 32-bit align it
154 quint16 m_reserved;
155 quint16 m_reserved2 : 11;
156 // for QMouseEvent
157 quint16 m_doubleClick : 1;
158 // for QWheelEvent
159 quint16 m_phase : 3;
160 quint16 m_invertedScrolling : 1;
161};
162
163class Q_GUI_EXPORT QEnterEvent : public QSinglePointEvent
164{
165 Q_DECL_EVENT_COMMON(QEnterEvent)
166public:
167 QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
168 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
169
170#if QT_DEPRECATED_SINCE(6, 0)
171#ifndef QT_NO_INTEGER_EVENT_COORDINATES
172 QT_DEPRECATED_VERSION_X_6_0("Use position()")
173 inline QPoint pos() const { return position().toPoint(); }
174 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
175 inline QPoint globalPos() const { return globalPosition().toPoint(); }
176 QT_DEPRECATED_VERSION_X_6_0("Use position()")
177 inline int x() const { return qRound(d: position().x()); }
178 QT_DEPRECATED_VERSION_X_6_0("Use position()")
179 inline int y() const { return qRound(d: position().y()); }
180 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
181 inline int globalX() const { return qRound(d: globalPosition().x()); }
182 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
183 inline int globalY() const { return qRound(d: globalPosition().y()); }
184#endif
185 QT_DEPRECATED_VERSION_X_6_0("Use position()")
186 QPointF localPos() const { return position(); }
187 QT_DEPRECATED_VERSION_X_6_0("Use scenePosition()")
188 QPointF windowPos() const { return scenePosition(); }
189 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
190 QPointF screenPos() const { return globalPosition(); }
191#endif // QT_DEPRECATED_SINCE(6, 0)
192};
193
194class Q_GUI_EXPORT QMouseEvent : public QSinglePointEvent
195{
196 Q_DECL_EVENT_COMMON(QMouseEvent)
197public:
198#if QT_DEPRECATED_SINCE(6, 4)
199 QT_DEPRECATED_VERSION_X_6_4("Use another constructor")
200 QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
201 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
202 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
203#endif
204 QMouseEvent(Type type, const QPointF &localPos, const QPointF &globalPos,
205 Qt::MouseButton button, Qt::MouseButtons buttons,
206 Qt::KeyboardModifiers modifiers,
207 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
208 QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
209 Qt::MouseButton button, Qt::MouseButtons buttons,
210 Qt::KeyboardModifiers modifiers,
211 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
212 QMouseEvent(Type type, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
213 Qt::MouseButton button, Qt::MouseButtons buttons,
214 Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source,
215 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
216
217#ifndef QT_NO_INTEGER_EVENT_COORDINATES
218 inline QPoint pos() const { return position().toPoint(); }
219#endif
220#if QT_DEPRECATED_SINCE(6, 0)
221#ifndef QT_NO_INTEGER_EVENT_COORDINATES
222 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
223 inline QPoint globalPos() const { return globalPosition().toPoint(); }
224 QT_DEPRECATED_VERSION_X_6_0("Use position()")
225 inline int x() const { return qRound(d: position().x()); }
226 QT_DEPRECATED_VERSION_X_6_0("Use position()")
227 inline int y() const { return qRound(d: position().y()); }
228 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
229 inline int globalX() const { return qRound(d: globalPosition().x()); }
230 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
231 inline int globalY() const { return qRound(d: globalPosition().y()); }
232#endif // QT_NO_INTEGER_EVENT_COORDINATES
233 QT_DEPRECATED_VERSION_X_6_0("Use position()")
234 QPointF localPos() const { return position(); }
235 QT_DEPRECATED_VERSION_X_6_0("Use scenePosition()")
236 QPointF windowPos() const { return scenePosition(); }
237 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
238 QPointF screenPos() const { return globalPosition(); }
239#endif // QT_DEPRECATED_SINCE(6, 0)
240 Qt::MouseEventSource source() const;
241 Qt::MouseEventFlags flags() const;
242};
243
244class Q_GUI_EXPORT QHoverEvent : public QSinglePointEvent
245{
246 Q_DECL_EVENT_COMMON(QHoverEvent)
247public:
248 QHoverEvent(Type type, const QPointF &scenePos, const QPointF &globalPos, const QPointF &oldPos,
249 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
250 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
251#if QT_DEPRECATED_SINCE(6, 3)
252 QT_DEPRECATED_VERSION_X_6_3("Use the other constructor")
253 QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos,
254 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
255 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
256#endif
257
258#if QT_DEPRECATED_SINCE(6, 0)
259#ifndef QT_NO_INTEGER_EVENT_COORDINATES
260 QT_DEPRECATED_VERSION_X_6_0("Use position()")
261 inline QPoint pos() const { return position().toPoint(); }
262#endif
263
264 QT_DEPRECATED_VERSION_X_6_0("Use position()")
265 inline QPointF posF() const { return position(); }
266#endif // QT_DEPRECATED_SINCE(6, 0)
267
268 bool isUpdateEvent() const override { return true; }
269
270 // TODO deprecate when we figure out an actual replacement (point history?)
271 inline QPoint oldPos() const { return m_oldPos.toPoint(); }
272 inline QPointF oldPosF() const { return m_oldPos; }
273
274protected:
275 QPointF m_oldPos; // TODO remove?
276};
277
278#if QT_CONFIG(wheelevent)
279class Q_GUI_EXPORT QWheelEvent : public QSinglePointEvent
280{
281 Q_GADGET
282 Q_PROPERTY(const QPointingDevice *device READ pointingDevice)
283 Q_PROPERTY(QPoint pixelDelta READ pixelDelta)
284 Q_PROPERTY(QPoint angleDelta READ angleDelta)
285 Q_PROPERTY(Qt::ScrollPhase phase READ phase)
286 Q_PROPERTY(bool inverted READ inverted)
287
288 Q_DECL_EVENT_COMMON(QWheelEvent)
289public:
290 enum { DefaultDeltasPerStep = 120 };
291
292 QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
293 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
294 bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized,
295 const QPointingDevice *device = QPointingDevice::primaryPointingDevice());
296
297 inline QPoint pixelDelta() const { return m_pixelDelta; }
298 inline QPoint angleDelta() const { return m_angleDelta; }
299
300 inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(m_phase); }
301 inline bool inverted() const { return m_invertedScrolling; }
302 inline bool isInverted() const { return m_invertedScrolling; }
303 inline bool hasPixelDelta() const { return !m_pixelDelta.isNull(); }
304
305 bool isBeginEvent() const override;
306 bool isUpdateEvent() const override;
307 bool isEndEvent() const override;
308 Qt::MouseEventSource source() const { return Qt::MouseEventSource(m_source); }
309
310protected:
311 QPoint m_pixelDelta;
312 QPoint m_angleDelta;
313};
314#endif
315
316#if QT_CONFIG(tabletevent)
317class Q_GUI_EXPORT QTabletEvent : public QSinglePointEvent
318{
319 Q_DECL_EVENT_COMMON(QTabletEvent)
320public:
321 QTabletEvent(Type t, const QPointingDevice *device,
322 const QPointF &pos, const QPointF &globalPos,
323 qreal pressure, float xTilt, float yTilt,
324 float tangentialPressure, qreal rotation, float z,
325 Qt::KeyboardModifiers keyState,
326 Qt::MouseButton button, Qt::MouseButtons buttons);
327
328#if QT_DEPRECATED_SINCE(6, 0)
329 QT_DEPRECATED_VERSION_X_6_0("Use position()")
330 inline QPoint pos() const { return position().toPoint(); }
331 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
332 inline QPoint globalPos() const { return globalPosition().toPoint(); }
333
334 QT_DEPRECATED_VERSION_X_6_0("Use position()")
335 inline const QPointF posF() const { return position(); }
336 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
337 inline const QPointF globalPosF() const { return globalPosition(); }
338 QT_DEPRECATED_VERSION_X_6_0("Use position().x()")
339 inline int x() const { return qRound(d: position().x()); }
340 QT_DEPRECATED_VERSION_X_6_0("Use position().y()")
341 inline int y() const { return qRound(d: position().y()); }
342 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition().x()")
343 inline int globalX() const { return qRound(d: globalPosition().x()); }
344 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition().y()")
345 inline int globalY() const { return qRound(d: globalPosition().y()); }
346 QT_DEPRECATED_VERSION_X_6_0("use globalPosition().x()")
347 inline qreal hiResGlobalX() const { return globalPosition().x(); }
348 QT_DEPRECATED_VERSION_X_6_0("use globalPosition().y()")
349 inline qreal hiResGlobalY() const { return globalPosition().y(); }
350 QT_DEPRECATED_VERSION_X_6_0("use pointingDevice().uniqueId()")
351 inline qint64 uniqueId() const { return pointingDevice() ? pointingDevice()->uniqueId().numericId() : -1; }
352#endif
353 inline qreal pressure() const { Q_ASSERT(!points().isEmpty()); return points().first().pressure(); }
354 inline qreal rotation() const { Q_ASSERT(!points().isEmpty()); return points().first().rotation(); }
355 inline qreal z() const { return m_z; }
356 inline qreal tangentialPressure() const { return m_tangential; }
357 inline qreal xTilt() const { return m_xTilt; }
358 inline qreal yTilt() const { return m_yTilt; }
359
360protected:
361 float m_tangential;
362 float m_xTilt;
363 float m_yTilt;
364 float m_z;
365};
366#endif // QT_CONFIG(tabletevent)
367
368#if QT_CONFIG(gestures)
369class Q_GUI_EXPORT QNativeGestureEvent : public QSinglePointEvent
370{
371 Q_DECL_EVENT_COMMON(QNativeGestureEvent)
372public:
373#if QT_DEPRECATED_SINCE(6, 2)
374 QT_DEPRECATED_VERSION_X_6_2("Use the other constructor")
375 QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, const QPointF &localPos, const QPointF &scenePos,
376 const QPointF &globalPos, qreal value, quint64 sequenceId, quint64 intArgument);
377#endif
378 QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, int fingerCount,
379 const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos,
380 qreal value, const QPointF &delta, quint64 sequenceId = UINT64_MAX);
381
382 Qt::NativeGestureType gestureType() const { return m_gestureType; }
383 int fingerCount() const { return m_fingerCount; }
384 qreal value() const { return m_realValue; }
385 QPointF delta() const {
386#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
387 return m_delta.toPointF();
388#else
389 return m_delta;
390#endif
391 }
392
393#if QT_DEPRECATED_SINCE(6, 0)
394#ifndef QT_NO_INTEGER_EVENT_COORDINATES
395 QT_DEPRECATED_VERSION_X_6_0("Use position().toPoint()")
396 inline const QPoint pos() const { return position().toPoint(); }
397 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition().toPoint()")
398 inline const QPoint globalPos() const { return globalPosition().toPoint(); }
399#endif
400 QT_DEPRECATED_VERSION_X_6_0("Use position()")
401 QPointF localPos() const { return position(); }
402 QT_DEPRECATED_VERSION_X_6_0("Use scenePosition()")
403 QPointF windowPos() const { return scenePosition(); }
404 QT_DEPRECATED_VERSION_X_6_0("Use globalPosition()")
405 QPointF screenPos() const { return globalPosition(); }
406#endif
407
408protected:
409 quint64 m_sequenceId;
410#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
411 QVector2D m_delta;
412#else
413 QPointF m_delta;
414#endif
415 qreal m_realValue;
416 Qt::NativeGestureType m_gestureType;
417 quint32 m_fingerCount : 4;
418 quint32 m_reserved : 28;
419};
420#endif // QT_CONFIG(gestures)
421
422class Q_GUI_EXPORT QKeyEvent : public QInputEvent
423{
424 Q_DECL_EVENT_COMMON(QKeyEvent)
425public:
426 QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(),
427 bool autorep = false, quint16 count = 1);
428 QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
429 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
430 const QString &text = QString(), bool autorep = false, quint16 count = 1,
431 const QInputDevice *device = QInputDevice::primaryKeyboard());
432
433 int key() const { return m_key; }
434#if QT_CONFIG(shortcut)
435 bool matches(QKeySequence::StandardKey key) const;
436#endif
437 Qt::KeyboardModifiers modifiers() const;
438 QKeyCombination keyCombination() const
439 {
440 return QKeyCombination(modifiers(), Qt::Key(m_key));
441 }
442 inline QString text() const { return m_text; }
443 inline bool isAutoRepeat() const { return m_autoRepeat; }
444 inline int count() const { return int(m_count); }
445
446 inline quint32 nativeScanCode() const { return m_scanCode; }
447 inline quint32 nativeVirtualKey() const { return m_virtualKey; }
448 inline quint32 nativeModifiers() const { return m_nativeModifiers; }
449
450#if QT_CONFIG(shortcut)
451 friend inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key)
452 { return (e ? e->matches(key) : false); }
453 friend inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e)
454 { return (e ? e->matches(key) : false); }
455#endif // QT_CONFIG(shortcut)
456
457protected:
458 QString m_text;
459 int m_key;
460 quint32 m_scanCode;
461 quint32 m_virtualKey;
462 quint32 m_nativeModifiers;
463 quint16 m_count : 15;
464 quint16 m_autoRepeat : 1;
465};
466
467
468class Q_GUI_EXPORT QFocusEvent : public QEvent
469{
470 Q_DECL_EVENT_COMMON(QFocusEvent)
471public:
472 explicit QFocusEvent(Type type, Qt::FocusReason reason=Qt::OtherFocusReason);
473
474 inline bool gotFocus() const { return type() == FocusIn; }
475 inline bool lostFocus() const { return type() == FocusOut; }
476
477 Qt::FocusReason reason() const;
478
479private:
480 Qt::FocusReason m_reason;
481};
482
483
484class Q_GUI_EXPORT QPaintEvent : public QEvent
485{
486 Q_DECL_EVENT_COMMON(QPaintEvent)
487public:
488 explicit QPaintEvent(const QRegion& paintRegion);
489 explicit QPaintEvent(const QRect &paintRect);
490
491 inline const QRect &rect() const { return m_rect; }
492 inline const QRegion &region() const { return m_region; }
493
494protected:
495 QRect m_rect;
496 QRegion m_region;
497 bool m_erased;
498};
499
500class Q_GUI_EXPORT QMoveEvent : public QEvent
501{
502 Q_DECL_EVENT_COMMON(QMoveEvent)
503public:
504 QMoveEvent(const QPoint &pos, const QPoint &oldPos);
505
506 inline const QPoint &pos() const { return m_pos; }
507 inline const QPoint &oldPos() const { return m_oldPos;}
508protected:
509 QPoint m_pos, m_oldPos;
510 friend class QApplication;
511};
512
513class Q_GUI_EXPORT QExposeEvent : public QEvent
514{
515 Q_DECL_EVENT_COMMON(QExposeEvent)
516public:
517 explicit QExposeEvent(const QRegion &m_region);
518
519#if QT_DEPRECATED_SINCE(6, 0)
520 QT_DEPRECATED_VERSION_X_6_0("Handle QPaintEvent instead")
521 inline const QRegion &region() const { return m_region; }
522#endif
523
524protected:
525 QRegion m_region;
526 friend class QWidgetWindow;
527};
528
529class Q_GUI_EXPORT QPlatformSurfaceEvent : public QEvent
530{
531 Q_DECL_EVENT_COMMON(QPlatformSurfaceEvent)
532public:
533 enum SurfaceEventType {
534 SurfaceCreated,
535 SurfaceAboutToBeDestroyed
536 };
537
538 explicit QPlatformSurfaceEvent(SurfaceEventType surfaceEventType);
539
540 inline SurfaceEventType surfaceEventType() const { return m_surfaceEventType; }
541
542protected:
543 SurfaceEventType m_surfaceEventType;
544};
545
546class Q_GUI_EXPORT QResizeEvent : public QEvent
547{
548 Q_DECL_EVENT_COMMON(QResizeEvent)
549public:
550 QResizeEvent(const QSize &size, const QSize &oldSize);
551
552 inline const QSize &size() const { return m_size; }
553 inline const QSize &oldSize()const { return m_oldSize;}
554protected:
555 QSize m_size, m_oldSize;
556 friend class QApplication;
557};
558
559
560class Q_GUI_EXPORT QCloseEvent : public QEvent
561{
562 Q_DECL_EVENT_COMMON(QCloseEvent)
563public:
564 QCloseEvent();
565};
566
567
568class Q_GUI_EXPORT QIconDragEvent : public QEvent
569{
570 Q_DECL_EVENT_COMMON(QIconDragEvent)
571public:
572 QIconDragEvent();
573};
574
575
576class Q_GUI_EXPORT QShowEvent : public QEvent
577{
578 Q_DECL_EVENT_COMMON(QShowEvent)
579public:
580 QShowEvent();
581};
582
583
584class Q_GUI_EXPORT QHideEvent : public QEvent
585{
586 Q_DECL_EVENT_COMMON(QHideEvent)
587public:
588 QHideEvent();
589};
590
591#ifndef QT_NO_CONTEXTMENU
592class Q_GUI_EXPORT QContextMenuEvent : public QInputEvent
593{
594 Q_DECL_EVENT_COMMON(QContextMenuEvent)
595public:
596 enum Reason { Mouse, Keyboard, Other };
597
598 QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
599 Qt::KeyboardModifiers modifiers = Qt::NoModifier);
600#if QT_DEPRECATED_SINCE(6, 4)
601 QT_DEPRECATED_VERSION_X_6_4("Use the other constructor")
602 QContextMenuEvent(Reason reason, const QPoint &pos);
603#endif
604
605 inline int x() const { return m_pos.x(); }
606 inline int y() const { return m_pos.y(); }
607 inline int globalX() const { return m_globalPos.x(); }
608 inline int globalY() const { return m_globalPos.y(); }
609
610 inline const QPoint& pos() const { return m_pos; }
611 inline const QPoint& globalPos() const { return m_globalPos; }
612
613 inline Reason reason() const { return Reason(m_reason); }
614
615protected:
616 QPoint m_pos;
617 QPoint m_globalPos;
618 uint m_reason : 8;
619};
620#endif // QT_NO_CONTEXTMENU
621
622#ifndef QT_NO_INPUTMETHOD
623class Q_GUI_EXPORT QInputMethodEvent : public QEvent
624{
625 Q_DECL_EVENT_COMMON(QInputMethodEvent)
626public:
627 enum AttributeType {
628 TextFormat,
629 Cursor,
630 Language,
631 Ruby,
632 Selection
633 };
634 class Attribute {
635 public:
636 Attribute(AttributeType typ, int s, int l, QVariant val) : type(typ), start(s), length(l), value(std::move(val)) {}
637 Attribute(AttributeType typ, int s, int l) : type(typ), start(s), length(l), value() {}
638
639 AttributeType type;
640 int start;
641 int length;
642 QVariant value;
643 };
644 QInputMethodEvent();
645 QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes);
646
647 void setCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0);
648 inline const QList<Attribute> &attributes() const { return m_attributes; }
649 inline const QString &preeditString() const { return m_preedit; }
650
651 inline const QString &commitString() const { return m_commit; }
652 inline int replacementStart() const { return m_replacementStart; }
653 inline int replacementLength() const { return m_replacementLength; }
654
655 inline friend bool operator==(const QInputMethodEvent::Attribute &lhs,
656 const QInputMethodEvent::Attribute &rhs)
657 {
658 return lhs.type == rhs.type && lhs.start == rhs.start
659 && lhs.length == rhs.length && lhs.value == rhs.value;
660 }
661
662 inline friend bool operator!=(const QInputMethodEvent::Attribute &lhs,
663 const QInputMethodEvent::Attribute &rhs)
664 {
665 return !(lhs == rhs);
666 }
667
668private:
669 QString m_preedit;
670 QString m_commit;
671 QList<Attribute> m_attributes;
672 int m_replacementStart;
673 int m_replacementLength;
674};
675Q_DECLARE_TYPEINFO(QInputMethodEvent::Attribute, Q_RELOCATABLE_TYPE);
676
677class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent
678{
679 Q_DECL_EVENT_COMMON(QInputMethodQueryEvent)
680public:
681 explicit QInputMethodQueryEvent(Qt::InputMethodQueries queries);
682
683 Qt::InputMethodQueries queries() const { return m_queries; }
684
685 void setValue(Qt::InputMethodQuery query, const QVariant &value);
686 QVariant value(Qt::InputMethodQuery query) const;
687private:
688 Qt::InputMethodQueries m_queries;
689 struct QueryPair {
690 Qt::InputMethodQuery query;
691 QVariant value;
692 };
693 friend QTypeInfo<QueryPair>;
694 QList<QueryPair> m_values;
695};
696Q_DECLARE_TYPEINFO(QInputMethodQueryEvent::QueryPair, Q_RELOCATABLE_TYPE);
697
698#endif // QT_NO_INPUTMETHOD
699
700#if QT_CONFIG(draganddrop)
701
702class QMimeData;
703
704class Q_GUI_EXPORT QDropEvent : public QEvent
705{
706 Q_DECL_EVENT_COMMON(QDropEvent)
707public:
708 QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
709 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = Drop);
710
711#if QT_DEPRECATED_SINCE(6, 0)
712 QT_DEPRECATED_VERSION_X_6_0("Use position().toPoint()")
713 inline QPoint pos() const { return position().toPoint(); }
714 QT_DEPRECATED_VERSION_X_6_0("Use position()")
715 inline QPointF posF() const { return position(); }
716 QT_DEPRECATED_VERSION_X_6_0("Use buttons()")
717 inline Qt::MouseButtons mouseButtons() const { return buttons(); }
718 QT_DEPRECATED_VERSION_X_6_0("Use modifiers()")
719 inline Qt::KeyboardModifiers keyboardModifiers() const { return modifiers(); }
720#endif // QT_DEPRECATED_SINCE(6, 0)
721
722 QPointF position() const { return m_pos; }
723 inline Qt::MouseButtons buttons() const { return m_mouseState; }
724 inline Qt::KeyboardModifiers modifiers() const { return m_modState; }
725
726 inline Qt::DropActions possibleActions() const { return m_actions; }
727 inline Qt::DropAction proposedAction() const { return m_defaultAction; }
728 inline void acceptProposedAction() { m_dropAction = m_defaultAction; accept(); }
729
730 inline Qt::DropAction dropAction() const { return m_dropAction; }
731 void setDropAction(Qt::DropAction action);
732
733 QObject* source() const;
734 inline const QMimeData *mimeData() const { return m_data; }
735
736protected:
737 friend class QApplication;
738 QPointF m_pos;
739 Qt::MouseButtons m_mouseState;
740 Qt::KeyboardModifiers m_modState;
741 Qt::DropActions m_actions;
742 Qt::DropAction m_dropAction;
743 Qt::DropAction m_defaultAction;
744 const QMimeData *m_data;
745};
746
747
748class Q_GUI_EXPORT QDragMoveEvent : public QDropEvent
749{
750 Q_DECL_EVENT_COMMON(QDragMoveEvent)
751public:
752 QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
753 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = DragMove);
754
755 inline QRect answerRect() const { return m_rect; }
756
757 inline void accept() { QDropEvent::accept(); }
758 inline void ignore() { QDropEvent::ignore(); }
759
760 inline void accept(const QRect & r) { accept(); m_rect = r; }
761 inline void ignore(const QRect & r) { ignore(); m_rect = r; }
762
763protected:
764 QRect m_rect;
765};
766
767
768class Q_GUI_EXPORT QDragEnterEvent : public QDragMoveEvent
769{
770 Q_DECL_EVENT_COMMON(QDragEnterEvent)
771public:
772 QDragEnterEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
773 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
774};
775
776
777class Q_GUI_EXPORT QDragLeaveEvent : public QEvent
778{
779 Q_DECL_EVENT_COMMON(QDragLeaveEvent)
780public:
781 QDragLeaveEvent();
782};
783#endif // QT_CONFIG(draganddrop)
784
785
786class Q_GUI_EXPORT QHelpEvent : public QEvent
787{
788 Q_DECL_EVENT_COMMON(QHelpEvent)
789public:
790 QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos);
791
792 inline int x() const { return m_pos.x(); }
793 inline int y() const { return m_pos.y(); }
794 inline int globalX() const { return m_globalPos.x(); }
795 inline int globalY() const { return m_globalPos.y(); }
796
797 inline const QPoint& pos() const { return m_pos; }
798 inline const QPoint& globalPos() const { return m_globalPos; }
799
800private:
801 QPoint m_pos;
802 QPoint m_globalPos;
803};
804
805#ifndef QT_NO_STATUSTIP
806class Q_GUI_EXPORT QStatusTipEvent : public QEvent
807{
808 Q_DECL_EVENT_COMMON(QStatusTipEvent)
809public:
810 explicit QStatusTipEvent(const QString &tip);
811
812 inline QString tip() const { return m_tip; }
813private:
814 QString m_tip;
815};
816#endif
817
818#if QT_CONFIG(whatsthis)
819class Q_GUI_EXPORT QWhatsThisClickedEvent : public QEvent
820{
821 Q_DECL_EVENT_COMMON(QWhatsThisClickedEvent)
822public:
823 explicit QWhatsThisClickedEvent(const QString &href);
824
825 inline QString href() const { return m_href; }
826private:
827 QString m_href;
828};
829#endif
830
831#if QT_CONFIG(action)
832class Q_GUI_EXPORT QActionEvent : public QEvent
833{
834 Q_DECL_EVENT_COMMON(QActionEvent)
835public:
836 QActionEvent(int type, QAction *action, QAction *before = nullptr);
837
838 inline QAction *action() const { return m_action; }
839 inline QAction *before() const { return m_before; }
840private:
841 QAction *m_action;
842 QAction *m_before;
843};
844#endif // QT_CONFIG(action)
845
846class Q_GUI_EXPORT QFileOpenEvent : public QEvent
847{
848 Q_DECL_EVENT_COMMON(QFileOpenEvent)
849public:
850 explicit QFileOpenEvent(const QString &file);
851 explicit QFileOpenEvent(const QUrl &url);
852
853 inline QString file() const { return m_file; }
854 QUrl url() const { return m_url; }
855#if QT_DEPRECATED_SINCE(6, 6)
856 QT_DEPRECATED_VERSION_X_6_6("Interpret the string returned by file()")
857 bool openFile(QFile &file, QIODevice::OpenMode flags) const;
858#endif
859private:
860 QString m_file;
861 QUrl m_url;
862};
863
864#ifndef QT_NO_TOOLBAR
865class Q_GUI_EXPORT QToolBarChangeEvent : public QEvent
866{
867 Q_DECL_EVENT_COMMON(QToolBarChangeEvent)
868public:
869 explicit QToolBarChangeEvent(bool t);
870
871 inline bool toggle() const { return m_toggle; }
872private:
873 bool m_toggle;
874};
875#endif
876
877#if QT_CONFIG(shortcut)
878class Q_GUI_EXPORT QShortcutEvent : public QEvent
879{
880 Q_DECL_EVENT_COMMON(QShortcutEvent)
881public:
882 // Note this is publicly deprecated, but should remain as internal constructor:
883 QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false);
884 QShortcutEvent(const QKeySequence &key, const QShortcut *shortcut = nullptr, bool ambiguous = false);
885
886 inline const QKeySequence &key() const { return m_sequence; }
887 // Note this is publicly deprecated, but should remain as internal getter:
888 inline int shortcutId() const { return m_shortcutId; }
889 inline bool isAmbiguous() const { return m_ambiguous; }
890protected:
891 QKeySequence m_sequence;
892 int m_shortcutId;
893 bool m_ambiguous;
894};
895#endif
896
897class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent
898{
899 Q_DECL_EVENT_COMMON(QWindowStateChangeEvent)
900public:
901 explicit QWindowStateChangeEvent(Qt::WindowStates oldState, bool isOverride = false);
902
903 inline Qt::WindowStates oldState() const { return m_oldStates; }
904 bool isOverride() const;
905
906private:
907 Qt::WindowStates m_oldStates;
908 bool m_override;
909};
910
911#ifndef QT_NO_DEBUG_STREAM
912Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *);
913#endif
914
915class Q_GUI_EXPORT QTouchEvent : public QPointerEvent
916{
917 Q_DECL_EVENT_COMMON(QTouchEvent)
918public:
919 using TouchPoint = QEventPoint; // source compat
920
921 explicit QTouchEvent(QEvent::Type eventType,
922 const QPointingDevice *device = nullptr,
923 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
924 const QList<QEventPoint> &touchPoints = {});
925#if QT_DEPRECATED_SINCE(6, 0)
926 QT_DEPRECATED_VERSION_X_6_0("Use another constructor")
927 explicit QTouchEvent(QEvent::Type eventType,
928 const QPointingDevice *device,
929 Qt::KeyboardModifiers modifiers,
930 QEventPoint::States touchPointStates,
931 const QList<QEventPoint> &touchPoints = {});
932#endif
933
934 inline QObject *target() const { return m_target; }
935 inline QEventPoint::States touchPointStates() const { return m_touchPointStates; }
936#if QT_DEPRECATED_SINCE(6, 0)
937 QT_DEPRECATED_VERSION_X_6_0("Use points()")
938 const QList<QEventPoint> &touchPoints() const { return points(); }
939#endif
940 bool isBeginEvent() const override;
941 bool isUpdateEvent() const override;
942 bool isEndEvent() const override;
943
944protected:
945 QObject *m_target = nullptr;
946 QEventPoint::States m_touchPointStates = QEventPoint::State::Unknown;
947 quint32 m_reserved : 24;
948};
949
950class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent
951{
952 Q_DECL_EVENT_COMMON(QScrollPrepareEvent)
953public:
954 explicit QScrollPrepareEvent(const QPointF &startPos);
955
956 QPointF startPos() const { return m_startPos; }
957
958 QSizeF viewportSize() const { return m_viewportSize; }
959 QRectF contentPosRange() const { return m_contentPosRange; }
960 QPointF contentPos() const { return m_contentPos; }
961
962 void setViewportSize(const QSizeF &size);
963 void setContentPosRange(const QRectF &rect);
964 void setContentPos(const QPointF &pos);
965
966private:
967 QRectF m_contentPosRange;
968 QSizeF m_viewportSize;
969 QPointF m_startPos;
970 QPointF m_contentPos;
971};
972
973
974class Q_GUI_EXPORT QScrollEvent : public QEvent
975{
976 Q_DECL_EVENT_COMMON(QScrollEvent)
977public:
978 enum ScrollState
979 {
980 ScrollStarted,
981 ScrollUpdated,
982 ScrollFinished
983 };
984
985 QScrollEvent(const QPointF &contentPos, const QPointF &overshoot, ScrollState scrollState);
986
987 QPointF contentPos() const { return m_contentPos; }
988 QPointF overshootDistance() const { return m_overshoot; }
989 ScrollState scrollState() const { return m_state; }
990
991private:
992 QPointF m_contentPos;
993 QPointF m_overshoot;
994 QScrollEvent::ScrollState m_state;
995};
996
997class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent
998{
999 Q_DECL_EVENT_COMMON(QScreenOrientationChangeEvent)
1000public:
1001 QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation orientation);
1002
1003 QScreen *screen() const { return m_screen; }
1004 Qt::ScreenOrientation orientation() const { return m_orientation; }
1005
1006private:
1007 QScreen *m_screen;
1008 Qt::ScreenOrientation m_orientation;
1009};
1010
1011class Q_GUI_EXPORT QApplicationStateChangeEvent : public QEvent
1012{
1013 Q_DECL_EVENT_COMMON(QApplicationStateChangeEvent)
1014public:
1015 explicit QApplicationStateChangeEvent(Qt::ApplicationState state);
1016
1017 Qt::ApplicationState applicationState() const { return m_applicationState; }
1018
1019private:
1020 Qt::ApplicationState m_applicationState;
1021};
1022
1023QT_END_NAMESPACE
1024
1025#endif // QEVENT_H
1026

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