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