1/****************************************************************************
2**
3** Copyright (C) 2016 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#include <QtGui/qwindowdefs.h>
45#include <QtGui/qregion.h>
46#include <QtCore/qnamespace.h>
47#include <QtCore/qstring.h>
48#include <QtGui/qkeysequence.h>
49#include <QtCore/qcoreevent.h>
50#include <QtCore/qvariant.h>
51#include <QtCore/qmap.h> // ### Qt 6: Remove
52#include <QtCore/qvector.h>
53#include <QtCore/qset.h> // ### Qt 6: Remove
54#include <QtCore/qurl.h>
55#include <QtCore/qfile.h> // ### Qt 6: Replace by <QtCore/qiodevice.h> and forward declare QFile
56#include <QtGui/qvector2d.h>
57#include <QtGui/qtouchdevice.h> // ### Qt 6: Replace by forward declaration
58
59QT_BEGIN_NAMESPACE
60
61
62class QAction;
63#ifndef QT_NO_GESTURES
64class QGesture;
65#endif
66class QScreen;
67
68class Q_GUI_EXPORT QInputEvent : public QEvent
69{
70public:
71 explicit QInputEvent(Type type, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
72 ~QInputEvent();
73 inline Qt::KeyboardModifiers modifiers() const { return modState; }
74 inline void setModifiers(Qt::KeyboardModifiers amodifiers) { modState = amodifiers; }
75 inline ulong timestamp() const { return ts; }
76 inline void setTimestamp(ulong atimestamp) { ts = atimestamp; }
77protected:
78 Qt::KeyboardModifiers modState;
79 ulong ts;
80};
81
82class Q_GUI_EXPORT QEnterEvent : public QEvent
83{
84public:
85 QEnterEvent(const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos);
86 ~QEnterEvent();
87
88#ifndef QT_NO_INTEGER_EVENT_COORDINATES
89 inline QPoint pos() const { return l.toPoint(); }
90 inline QPoint globalPos() const { return s.toPoint(); }
91 inline int x() const { return qRound(l.x()); }
92 inline int y() const { return qRound(l.y()); }
93 inline int globalX() const { return qRound(s.x()); }
94 inline int globalY() const { return qRound(s.y()); }
95#endif
96 const QPointF &localPos() const { return l; }
97 const QPointF &windowPos() const { return w; }
98 const QPointF &screenPos() const { return s; }
99
100protected:
101 QPointF l, w, s;
102};
103
104class Q_GUI_EXPORT QMouseEvent : public QInputEvent
105{
106public:
107 QMouseEvent(Type type, const QPointF &localPos, Qt::MouseButton button,
108 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
109 QMouseEvent(Type type, const QPointF &localPos, const QPointF &screenPos,
110 Qt::MouseButton button, Qt::MouseButtons buttons,
111 Qt::KeyboardModifiers modifiers);
112 QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
113 Qt::MouseButton button, Qt::MouseButtons buttons,
114 Qt::KeyboardModifiers modifiers);
115 QMouseEvent(Type type, const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos,
116 Qt::MouseButton button, Qt::MouseButtons buttons,
117 Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source);
118 ~QMouseEvent();
119
120#ifndef QT_NO_INTEGER_EVENT_COORDINATES
121 inline QPoint pos() const { return l.toPoint(); }
122 inline QPoint globalPos() const { return s.toPoint(); }
123 inline int x() const { return qRound(l.x()); }
124 inline int y() const { return qRound(l.y()); }
125 inline int globalX() const { return qRound(s.x()); }
126 inline int globalY() const { return qRound(s.y()); }
127#endif
128 const QPointF &localPos() const { return l; }
129 const QPointF &windowPos() const { return w; }
130 const QPointF &screenPos() const { return s; }
131
132 inline Qt::MouseButton button() const { return b; }
133 inline Qt::MouseButtons buttons() const { return mouseState; }
134
135 inline void setLocalPos(const QPointF &localPosition) { l = localPosition; }
136
137#if QT_DEPRECATED_SINCE(5, 0)
138 QT_DEPRECATED inline QPointF posF() const { return l; }
139#endif
140
141 Qt::MouseEventSource source() const;
142 Qt::MouseEventFlags flags() const;
143
144protected:
145 QPointF l, w, s;
146 Qt::MouseButton b;
147 Qt::MouseButtons mouseState;
148 int caps;
149 QVector2D velocity;
150
151 friend class QGuiApplicationPrivate;
152};
153
154class Q_GUI_EXPORT QHoverEvent : public QInputEvent
155{
156public:
157 QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
158 ~QHoverEvent();
159
160#ifndef QT_NO_INTEGER_EVENT_COORDINATES
161 inline QPoint pos() const { return p.toPoint(); }
162 inline QPoint oldPos() const { return op.toPoint(); }
163#endif
164
165 inline const QPointF &posF() const { return p; }
166 inline const QPointF &oldPosF() const { return op; }
167
168protected:
169 QPointF p, op;
170};
171
172#if QT_CONFIG(wheelevent)
173class Q_GUI_EXPORT QWheelEvent : public QInputEvent
174{
175public:
176 enum { DefaultDeltasPerStep = 120 };
177
178#if QT_DEPRECATED_SINCE(5, 15)
179 // Actually deprecated since 5.0, in docs
180 QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
181 QWheelEvent(const QPointF &pos, int delta,
182 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
183 Qt::Orientation orient = Qt::Vertical);
184 // Actually deprecated since 5.0, in docs
185 QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
186 QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
187 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
188 Qt::Orientation orient = Qt::Vertical);
189 QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
190 QWheelEvent(const QPointF &pos, const QPointF& globalPos,
191 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
192 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
193 QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
194 QWheelEvent(const QPointF &pos, const QPointF& globalPos,
195 QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation,
196 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase);
197 QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
198 QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
199 int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
200 Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source);
201 QT_DEPRECATED_VERSION_X_5_15("Use the last QWheelEvent constructor taking pixelDelta, angleDelta, phase, and inverted")
202 QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pixelDelta, QPoint angleDelta,
203 int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons,
204 Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source, bool inverted);
205#endif
206
207 QWheelEvent(QPointF pos, QPointF globalPos, QPoint pixelDelta, QPoint angleDelta,
208 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase,
209 bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized);
210 ~QWheelEvent();
211
212
213 inline QPoint pixelDelta() const { return pixelD; }
214 inline QPoint angleDelta() const { return angleD; }
215
216#if QT_DEPRECATED_SINCE(5, 15)
217 // Actually deprecated since 5.0, in docs
218 QT_DEPRECATED_VERSION_X_5_15("Use angleDelta()")
219 inline int delta() const { return qt4D; }
220 // Actually deprecated since 5.0, in docs
221 QT_DEPRECATED_VERSION_X_5_15("Use angleDelta()")
222 inline Qt::Orientation orientation() const { return qt4O; }
223#ifndef QT_NO_INTEGER_EVENT_COORDINATES
224 QT_DEPRECATED_VERSION_X_5_15("Use position()")
225 inline QPoint pos() const { return p.toPoint(); }
226 QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
227 inline QPoint globalPos() const { return g.toPoint(); }
228 QT_DEPRECATED_VERSION_X_5_15("Use position()")
229 inline int x() const { return int(p.x()); }
230 QT_DEPRECATED_VERSION_X_5_15("Use position()")
231 inline int y() const { return int(p.y()); }
232 QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
233 inline int globalX() const { return int(g.x()); }
234 QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
235 inline int globalY() const { return int(g.y()); }
236#endif
237 QT_DEPRECATED_VERSION_X_5_15("Use position()")
238 inline const QPointF &posF() const { return p; }
239 QT_DEPRECATED_VERSION_X_5_15("Use globalPosition()")
240 inline const QPointF &globalPosF() const { return g; }
241#endif // QT_DEPRECATED_SINCE(5, 15)
242
243 inline QPointF position() const { return p; }
244 inline QPointF globalPosition() const { return g; }
245
246 inline Qt::MouseButtons buttons() const { return mouseState; }
247
248 inline Qt::ScrollPhase phase() const { return Qt::ScrollPhase(ph); }
249 inline bool inverted() const { return invertedScrolling; }
250
251 Qt::MouseEventSource source() const { return Qt::MouseEventSource(src); }
252
253protected:
254 QPointF p;
255 QPointF g;
256 QPoint pixelD;
257 QPoint angleD;
258 int qt4D = 0;
259 Qt::Orientation qt4O = Qt::Vertical;
260 Qt::MouseButtons mouseState = Qt::NoButton;
261 uint _unused_ : 2; // Kept for binary compatibility
262 uint src: 2;
263 bool invertedScrolling : 1;
264 uint ph : 3;
265 int reserved : 24;
266
267 friend class QApplication;
268};
269#endif
270
271#if QT_CONFIG(tabletevent)
272class Q_GUI_EXPORT QTabletEvent : public QInputEvent
273{
274 Q_GADGET
275public:
276 enum TabletDevice { NoDevice, Puck, Stylus, Airbrush, FourDMouse,
277 XFreeEraser /*internal*/, RotationStylus };
278 Q_ENUM(TabletDevice)
279 enum PointerType { UnknownPointer, Pen, Cursor, Eraser };
280 Q_ENUM(PointerType)
281 QTabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
282 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
283 qreal tangentialPressure, qreal rotation, int z,
284 Qt::KeyboardModifiers keyState, qint64 uniqueID); // ### remove in Qt 6
285 QTabletEvent(Type t, const QPointF &pos, const QPointF &globalPos,
286 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
287 qreal tangentialPressure, qreal rotation, int z,
288 Qt::KeyboardModifiers keyState, qint64 uniqueID,
289 Qt::MouseButton button, Qt::MouseButtons buttons);
290 ~QTabletEvent();
291
292 inline QPoint pos() const { return mPos.toPoint(); }
293 inline QPoint globalPos() const { return mGPos.toPoint(); }
294#if QT_DEPRECATED_SINCE(5,0)
295 QT_DEPRECATED inline const QPointF &hiResGlobalPos() const { return mPos; }
296#endif
297
298 inline const QPointF &posF() const { return mPos; }
299 inline const QPointF &globalPosF() const { return mGPos; }
300
301 inline int x() const { return qRound(mPos.x()); }
302 inline int y() const { return qRound(mPos.y()); }
303 inline int globalX() const { return qRound(mGPos.x()); }
304 inline int globalY() const { return qRound(mGPos.y()); }
305 inline qreal hiResGlobalX() const { return mGPos.x(); }
306 inline qreal hiResGlobalY() const { return mGPos.y(); }
307 inline TabletDevice device() const { return TabletDevice(mDev); }
308 inline PointerType pointerType() const { return PointerType(mPointerType); }
309 inline qint64 uniqueId() const { return mUnique; }
310 inline qreal pressure() const { return mPress; }
311 inline int z() const { return mZ; }
312 inline qreal tangentialPressure() const { return mTangential; }
313 inline qreal rotation() const { return mRot; }
314 inline int xTilt() const { return mXT; }
315 inline int yTilt() const { return mYT; }
316 Qt::MouseButton button() const;
317 Qt::MouseButtons buttons() const;
318
319protected:
320 QPointF mPos, mGPos;
321 int mDev, mPointerType, mXT, mYT, mZ;
322 qreal mPress, mTangential, mRot;
323 qint64 mUnique;
324
325 // QTabletEventPrivate for extra storage.
326 // ### Qt 6: QPointingEvent will have Buttons, QTabletEvent will inherit
327 void *mExtra;
328};
329#endif // QT_CONFIG(tabletevent)
330
331#ifndef QT_NO_GESTURES
332class Q_GUI_EXPORT QNativeGestureEvent : public QInputEvent
333{
334public:
335#if QT_DEPRECATED_SINCE(5, 10)
336 QT_DEPRECATED QNativeGestureEvent(Qt::NativeGestureType type, const QPointF &localPos, const QPointF &windowPos,
337 const QPointF &screenPos, qreal value, ulong sequenceId, quint64 intArgument);
338#endif
339 QNativeGestureEvent(Qt::NativeGestureType type, const QTouchDevice *dev, const QPointF &localPos, const QPointF &windowPos,
340 const QPointF &screenPos, qreal value, ulong sequenceId, quint64 intArgument);
341 ~QNativeGestureEvent();
342 Qt::NativeGestureType gestureType() const { return mGestureType; }
343 qreal value() const { return mRealValue; }
344
345#ifndef QT_NO_INTEGER_EVENT_COORDINATES
346 inline const QPoint pos() const { return mLocalPos.toPoint(); }
347 inline const QPoint globalPos() const { return mScreenPos.toPoint(); }
348#endif
349 const QPointF &localPos() const { return mLocalPos; }
350 const QPointF &windowPos() const { return mWindowPos; }
351 const QPointF &screenPos() const { return mScreenPos; }
352
353 const QTouchDevice *device() const;
354
355protected:
356 Qt::NativeGestureType mGestureType;
357 QPointF mLocalPos;
358 QPointF mWindowPos;
359 QPointF mScreenPos;
360 qreal mRealValue;
361 ulong mSequenceId;
362 quint64 mIntValue;
363};
364#endif // QT_NO_GESTURES
365
366class Q_GUI_EXPORT QKeyEvent : public QInputEvent
367{
368public:
369 QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(),
370 bool autorep = false, ushort count = 1);
371 QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
372 quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
373 const QString &text = QString(), bool autorep = false, ushort count = 1);
374 ~QKeyEvent();
375
376 int key() const { return k; }
377#ifndef QT_NO_SHORTCUT
378 bool matches(QKeySequence::StandardKey key) const;
379#endif
380 Qt::KeyboardModifiers modifiers() const;
381 inline QString text() const { return txt; }
382 inline bool isAutoRepeat() const { return autor; }
383 inline int count() const { return int(c); }
384
385 inline quint32 nativeScanCode() const { return nScanCode; }
386 inline quint32 nativeVirtualKey() const { return nVirtualKey; }
387 inline quint32 nativeModifiers() const { return nModifiers; }
388
389 // Functions for the extended key event information
390#if QT_DEPRECATED_SINCE(5, 0)
391 static inline QKeyEvent *createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
392 quint32 nativeScanCode, quint32 nativeVirtualKey,
393 quint32 nativeModifiers,
394 const QString& text = QString(), bool autorep = false,
395 ushort count = 1)
396 {
397 return new QKeyEvent(type, key, modifiers,
398 nativeScanCode, nativeVirtualKey, nativeModifiers,
399 text, autorep, count);
400 }
401
402 inline bool hasExtendedInfo() const { return true; }
403#endif
404
405protected:
406 QString txt;
407 int k;
408 quint32 nScanCode;
409 quint32 nVirtualKey;
410 quint32 nModifiers;
411 ushort c;
412 ushort autor:1;
413 // ushort reserved:15;
414};
415
416
417class Q_GUI_EXPORT QFocusEvent : public QEvent
418{
419public:
420 explicit QFocusEvent(Type type, Qt::FocusReason reason=Qt::OtherFocusReason);
421 ~QFocusEvent();
422
423 inline bool gotFocus() const { return type() == FocusIn; }
424 inline bool lostFocus() const { return type() == FocusOut; }
425
426 Qt::FocusReason reason() const;
427
428private:
429 Qt::FocusReason m_reason;
430};
431
432
433class Q_GUI_EXPORT QPaintEvent : public QEvent
434{
435public:
436 explicit QPaintEvent(const QRegion& paintRegion);
437 explicit QPaintEvent(const QRect &paintRect);
438 ~QPaintEvent();
439
440 inline const QRect &rect() const { return m_rect; }
441 inline const QRegion &region() const { return m_region; }
442
443protected:
444 QRect m_rect;
445 QRegion m_region;
446 bool m_erased;
447};
448
449class Q_GUI_EXPORT QMoveEvent : public QEvent
450{
451public:
452 QMoveEvent(const QPoint &pos, const QPoint &oldPos);
453 ~QMoveEvent();
454
455 inline const QPoint &pos() const { return p; }
456 inline const QPoint &oldPos() const { return oldp;}
457protected:
458 QPoint p, oldp;
459 friend class QApplication;
460};
461
462class Q_GUI_EXPORT QExposeEvent : public QEvent
463{
464public:
465 explicit QExposeEvent(const QRegion &rgn);
466 ~QExposeEvent();
467
468 inline const QRegion &region() const { return rgn; }
469
470protected:
471 QRegion rgn;
472};
473
474class Q_GUI_EXPORT QPlatformSurfaceEvent : public QEvent
475{
476public:
477 enum SurfaceEventType {
478 SurfaceCreated,
479 SurfaceAboutToBeDestroyed
480 };
481
482 explicit QPlatformSurfaceEvent(SurfaceEventType surfaceEventType);
483 ~QPlatformSurfaceEvent();
484
485 inline SurfaceEventType surfaceEventType() const { return m_surfaceEventType; }
486
487protected:
488 SurfaceEventType m_surfaceEventType;
489};
490
491class Q_GUI_EXPORT QResizeEvent : public QEvent
492{
493public:
494 QResizeEvent(const QSize &size, const QSize &oldSize);
495 ~QResizeEvent();
496
497 inline const QSize &size() const { return s; }
498 inline const QSize &oldSize()const { return olds;}
499protected:
500 QSize s, olds;
501 friend class QApplication;
502};
503
504
505class Q_GUI_EXPORT QCloseEvent : public QEvent
506{
507public:
508 QCloseEvent();
509 ~QCloseEvent();
510};
511
512
513class Q_GUI_EXPORT QIconDragEvent : public QEvent
514{
515public:
516 QIconDragEvent();
517 ~QIconDragEvent();
518};
519
520
521class Q_GUI_EXPORT QShowEvent : public QEvent
522{
523public:
524 QShowEvent();
525 ~QShowEvent();
526};
527
528
529class Q_GUI_EXPORT QHideEvent : public QEvent
530{
531public:
532 QHideEvent();
533 ~QHideEvent();
534};
535
536#ifndef QT_NO_CONTEXTMENU
537class Q_GUI_EXPORT QContextMenuEvent : public QInputEvent
538{
539public:
540 enum Reason { Mouse, Keyboard, Other };
541
542 QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
543 Qt::KeyboardModifiers modifiers);
544 QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos);
545 QContextMenuEvent(Reason reason, const QPoint &pos);
546 ~QContextMenuEvent();
547
548 inline int x() const { return p.x(); }
549 inline int y() const { return p.y(); }
550 inline int globalX() const { return gp.x(); }
551 inline int globalY() const { return gp.y(); }
552
553 inline const QPoint& pos() const { return p; }
554 inline const QPoint& globalPos() const { return gp; }
555
556 inline Reason reason() const { return Reason(reas); }
557
558protected:
559 QPoint p;
560 QPoint gp;
561 uint reas : 8;
562};
563#endif // QT_NO_CONTEXTMENU
564
565#ifndef QT_NO_INPUTMETHOD
566class Q_GUI_EXPORT QInputMethodEvent : public QEvent
567{
568public:
569 enum AttributeType {
570 TextFormat,
571 Cursor,
572 Language,
573 Ruby,
574 Selection
575 };
576 class Attribute {
577 public:
578 Attribute(AttributeType typ, int s, int l, QVariant val) : type(typ), start(s), length(l), value(std::move(val)) {}
579 Attribute(AttributeType typ, int s, int l) : type(typ), start(s), length(l), value() {}
580
581 AttributeType type;
582 int start;
583 int length;
584 QVariant value;
585 };
586 QInputMethodEvent();
587 QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes);
588 ~QInputMethodEvent();
589
590 void setCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0);
591 inline const QList<Attribute> &attributes() const { return attrs; }
592 inline const QString &preeditString() const { return preedit; }
593
594 inline const QString &commitString() const { return commit; }
595 inline int replacementStart() const { return replace_from; }
596 inline int replacementLength() const { return replace_length; }
597
598 QInputMethodEvent(const QInputMethodEvent &other);
599
600private:
601 QString preedit;
602 QList<Attribute> attrs;
603 QString commit;
604 int replace_from;
605 int replace_length;
606};
607Q_DECLARE_TYPEINFO(QInputMethodEvent::Attribute, Q_MOVABLE_TYPE);
608
609class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent
610{
611public:
612 explicit QInputMethodQueryEvent(Qt::InputMethodQueries queries);
613 ~QInputMethodQueryEvent();
614
615 Qt::InputMethodQueries queries() const { return m_queries; }
616
617 void setValue(Qt::InputMethodQuery query, const QVariant &value);
618 QVariant value(Qt::InputMethodQuery query) const;
619private:
620 Qt::InputMethodQueries m_queries;
621 struct QueryPair {
622 Qt::InputMethodQuery query;
623 QVariant value;
624 };
625 friend QTypeInfo<QueryPair>;
626 QVector<QueryPair> m_values;
627};
628Q_DECLARE_TYPEINFO(QInputMethodQueryEvent::QueryPair, Q_MOVABLE_TYPE);
629
630#endif // QT_NO_INPUTMETHOD
631
632#if QT_CONFIG(draganddrop)
633
634class QMimeData;
635
636class Q_GUI_EXPORT QDropEvent : public QEvent
637{
638public:
639 QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data,
640 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = Drop);
641 ~QDropEvent();
642
643 inline QPoint pos() const { return p.toPoint(); }
644 inline const QPointF &posF() const { return p; }
645 inline Qt::MouseButtons mouseButtons() const { return mouseState; }
646 inline Qt::KeyboardModifiers keyboardModifiers() const { return modState; }
647
648 inline Qt::DropActions possibleActions() const { return act; }
649 inline Qt::DropAction proposedAction() const { return default_action; }
650 inline void acceptProposedAction() { drop_action = default_action; accept(); }
651
652 inline Qt::DropAction dropAction() const { return drop_action; }
653 void setDropAction(Qt::DropAction action);
654
655 QObject* source() const;
656 inline const QMimeData *mimeData() const { return mdata; }
657
658protected:
659 friend class QApplication;
660 QPointF p;
661 Qt::MouseButtons mouseState;
662 Qt::KeyboardModifiers modState;
663 Qt::DropActions act;
664 Qt::DropAction drop_action;
665 Qt::DropAction default_action;
666 const QMimeData *mdata;
667};
668
669
670class Q_GUI_EXPORT QDragMoveEvent : public QDropEvent
671{
672public:
673 QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
674 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = DragMove);
675 ~QDragMoveEvent();
676
677 inline QRect answerRect() const { return rect; }
678
679 inline void accept() { QDropEvent::accept(); }
680 inline void ignore() { QDropEvent::ignore(); }
681
682 inline void accept(const QRect & r) { accept(); rect = r; }
683 inline void ignore(const QRect & r) { ignore(); rect = r; }
684
685protected:
686 QRect rect;
687};
688
689
690class Q_GUI_EXPORT QDragEnterEvent : public QDragMoveEvent
691{
692public:
693 QDragEnterEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
694 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
695 ~QDragEnterEvent();
696};
697
698
699class Q_GUI_EXPORT QDragLeaveEvent : public QEvent
700{
701public:
702 QDragLeaveEvent();
703 ~QDragLeaveEvent();
704};
705#endif // QT_CONFIG(draganddrop)
706
707
708class Q_GUI_EXPORT QHelpEvent : public QEvent
709{
710public:
711 QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos);
712 ~QHelpEvent();
713
714 inline int x() const { return p.x(); }
715 inline int y() const { return p.y(); }
716 inline int globalX() const { return gp.x(); }
717 inline int globalY() const { return gp.y(); }
718
719 inline const QPoint& pos() const { return p; }
720 inline const QPoint& globalPos() const { return gp; }
721
722private:
723 QPoint p;
724 QPoint gp;
725};
726
727#ifndef QT_NO_STATUSTIP
728class Q_GUI_EXPORT QStatusTipEvent : public QEvent
729{
730public:
731 explicit QStatusTipEvent(const QString &tip);
732 ~QStatusTipEvent();
733
734 inline QString tip() const { return s; }
735private:
736 QString s;
737};
738#endif
739
740#if QT_CONFIG(whatsthis)
741class Q_GUI_EXPORT QWhatsThisClickedEvent : public QEvent
742{
743public:
744 explicit QWhatsThisClickedEvent(const QString &href);
745 ~QWhatsThisClickedEvent();
746
747 inline QString href() const { return s; }
748private:
749 QString s;
750};
751#endif
752
753#ifndef QT_NO_ACTION
754class Q_GUI_EXPORT QActionEvent : public QEvent
755{
756 QAction *act, *bef;
757public:
758 QActionEvent(int type, QAction *action, QAction *before = nullptr);
759 ~QActionEvent();
760
761 inline QAction *action() const { return act; }
762 inline QAction *before() const { return bef; }
763};
764#endif
765
766class Q_GUI_EXPORT QFileOpenEvent : public QEvent
767{
768public:
769 explicit QFileOpenEvent(const QString &file);
770 explicit QFileOpenEvent(const QUrl &url);
771 ~QFileOpenEvent();
772
773 inline QString file() const { return f; }
774 QUrl url() const { return m_url; }
775 bool openFile(QFile &file, QIODevice::OpenMode flags) const;
776private:
777 QString f;
778 QUrl m_url;
779};
780
781#ifndef QT_NO_TOOLBAR
782class Q_GUI_EXPORT QToolBarChangeEvent : public QEvent
783{
784public:
785 explicit QToolBarChangeEvent(bool t);
786 ~QToolBarChangeEvent();
787
788 inline bool toggle() const { return tog; }
789private:
790 uint tog : 1;
791};
792#endif
793
794#ifndef QT_NO_SHORTCUT
795class Q_GUI_EXPORT QShortcutEvent : public QEvent
796{
797public:
798 QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false);
799 ~QShortcutEvent();
800
801 inline const QKeySequence &key() const { return sequence; }
802 inline int shortcutId() const { return sid; }
803 inline bool isAmbiguous() const { return ambig; }
804protected:
805 QKeySequence sequence;
806 bool ambig;
807 int sid;
808};
809#endif
810
811class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent
812{
813public:
814 explicit QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride = false);
815 ~QWindowStateChangeEvent();
816
817 inline Qt::WindowStates oldState() const { return ostate; }
818 bool isOverride() const;
819
820private:
821 Qt::WindowStates ostate;
822 bool m_override;
823};
824
825#ifndef QT_NO_DEBUG_STREAM
826Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *);
827#endif
828
829#ifndef QT_NO_SHORTCUT
830inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? e->matches(key) : false);}
831inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);}
832#endif // QT_NO_SHORTCUT
833
834class Q_GUI_EXPORT QPointingDeviceUniqueId
835{
836 Q_GADGET
837 Q_PROPERTY(qint64 numericId READ numericId CONSTANT)
838public:
839 Q_ALWAYS_INLINE
840 Q_DECL_CONSTEXPR QPointingDeviceUniqueId() noexcept : m_numericId(-1) {}
841 // compiler-generated copy/move ctor/assignment operators are ok!
842 // compiler-generated dtor is ok!
843
844 static QPointingDeviceUniqueId fromNumericId(qint64 id);
845
846 Q_ALWAYS_INLINE Q_DECL_CONSTEXPR bool isValid() const noexcept { return m_numericId != -1; }
847 qint64 numericId() const noexcept;
848
849private:
850 // TODO: for TUIO 2, or any other type of complex token ID, an internal
851 // array (or hash) can be added to hold additional properties.
852 // In this case, m_numericId will then turn into an index into that array (or hash).
853 qint64 m_numericId;
854};
855Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_MOVABLE_TYPE);
856template <> class QList<QPointingDeviceUniqueId> {}; // to prevent instantiation: use QVector instead
857
858Q_GUI_EXPORT bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept;
859inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept
860{ return !operator==(lhs, rhs); }
861Q_GUI_EXPORT uint qHash(QPointingDeviceUniqueId key, uint seed = 0) noexcept;
862
863
864
865class QTouchEventTouchPointPrivate;
866class Q_GUI_EXPORT QTouchEvent : public QInputEvent
867{
868public:
869 class Q_GUI_EXPORT TouchPoint
870 {
871 public:
872 enum InfoFlag {
873 Pen = 0x0001,
874 Token = 0x0002
875 };
876#ifndef Q_MOC_RUN
877 // otherwise moc gives
878 // Error: Meta object features not supported for nested classes
879 Q_DECLARE_FLAGS(InfoFlags, InfoFlag)
880#endif
881
882 explicit TouchPoint(int id = -1);
883 TouchPoint(const TouchPoint &other);
884 TouchPoint(TouchPoint &&other) noexcept
885 : d(nullptr)
886 { qSwap(d, other.d); }
887 TouchPoint &operator=(TouchPoint &&other) noexcept
888 { qSwap(d, other.d); return *this; }
889 ~TouchPoint();
890
891 TouchPoint &operator=(const TouchPoint &other)
892 { if ( d != other.d ) { TouchPoint copy(other); swap(copy); } return *this; }
893
894 void swap(TouchPoint &other) noexcept
895 { qSwap(d, other.d); }
896
897 int id() const;
898 QPointingDeviceUniqueId uniqueId() const;
899
900 Qt::TouchPointState state() const;
901
902 QPointF pos() const;
903 QPointF startPos() const;
904 QPointF lastPos() const;
905
906 QPointF scenePos() const;
907 QPointF startScenePos() const;
908 QPointF lastScenePos() const;
909
910 QPointF screenPos() const;
911 QPointF startScreenPos() const;
912 QPointF lastScreenPos() const;
913
914 QPointF normalizedPos() const;
915 QPointF startNormalizedPos() const;
916 QPointF lastNormalizedPos() const;
917
918 QRectF rect() const;
919 QRectF sceneRect() const;
920 QRectF screenRect() const;
921
922 qreal pressure() const;
923 qreal rotation() const;
924 QSizeF ellipseDiameters() const;
925
926 QVector2D velocity() const;
927 InfoFlags flags() const;
928 QVector<QPointF> rawScreenPositions() const;
929
930 // internal
931 void setId(int id);
932 void setUniqueId(qint64 uid);
933 void setState(Qt::TouchPointStates state);
934 void setPos(const QPointF &pos);
935 void setScenePos(const QPointF &scenePos);
936 void setScreenPos(const QPointF &screenPos);
937 void setNormalizedPos(const QPointF &normalizedPos);
938 void setStartPos(const QPointF &startPos);
939 void setStartScenePos(const QPointF &startScenePos);
940 void setStartScreenPos(const QPointF &startScreenPos);
941 void setStartNormalizedPos(const QPointF &startNormalizedPos);
942 void setLastPos(const QPointF &lastPos);
943 void setLastScenePos(const QPointF &lastScenePos);
944 void setLastScreenPos(const QPointF &lastScreenPos);
945 void setLastNormalizedPos(const QPointF &lastNormalizedPos);
946 void setRect(const QRectF &rect); // deprecated
947 void setSceneRect(const QRectF &sceneRect); // deprecated
948 void setScreenRect(const QRectF &screenRect); // deprecated
949 void setPressure(qreal pressure);
950 void setRotation(qreal angle);
951 void setEllipseDiameters(const QSizeF &dia);
952 void setVelocity(const QVector2D &v);
953 void setFlags(InfoFlags flags);
954 void setRawScreenPositions(const QVector<QPointF> &positions);
955
956 private:
957 QTouchEventTouchPointPrivate *d;
958 friend class QGuiApplication;
959 friend class QGuiApplicationPrivate;
960 friend class QApplication;
961 friend class QApplicationPrivate;
962 };
963
964#if QT_DEPRECATED_SINCE(5, 0)
965 enum DeviceType {
966 TouchScreen,
967 TouchPad
968 };
969#endif
970
971 explicit QTouchEvent(QEvent::Type eventType,
972 QTouchDevice *device = nullptr,
973 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
974 Qt::TouchPointStates touchPointStates = Qt::TouchPointStates(),
975 const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
976 ~QTouchEvent();
977
978 inline QWindow *window() const { return _window; }
979 inline QObject *target() const { return _target; }
980#if QT_DEPRECATED_SINCE(5, 0)
981 QT_DEPRECATED inline QTouchEvent::DeviceType deviceType() const { return static_cast<DeviceType>(int(_device->type())); }
982#endif
983 inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
984 inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; }
985 inline QTouchDevice *device() const { return _device; }
986
987 // internal
988 inline void setWindow(QWindow *awindow) { _window = awindow; }
989 inline void setTarget(QObject *atarget) { _target = atarget; }
990 inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; }
991 inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
992 inline void setDevice(QTouchDevice *adevice) { _device = adevice; }
993
994protected:
995 QWindow *_window;
996 QObject *_target;
997 QTouchDevice *_device;
998 Qt::TouchPointStates _touchPointStates;
999 QList<QTouchEvent::TouchPoint> _touchPoints;
1000
1001 friend class QGuiApplication;
1002 friend class QGuiApplicationPrivate;
1003 friend class QApplication;
1004 friend class QApplicationPrivate;
1005#ifndef QT_NO_GRAPHICSVIEW
1006 friend class QGraphicsScenePrivate; // direct access to _touchPoints
1007#endif
1008};
1009Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE);
1010Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags)
1011
1012#ifndef QT_NO_DEBUG_STREAM
1013Q_GUI_EXPORT QDebug operator<<(QDebug, const QTouchEvent::TouchPoint &);
1014#endif
1015
1016class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent
1017{
1018public:
1019 explicit QScrollPrepareEvent(const QPointF &startPos);
1020 ~QScrollPrepareEvent();
1021
1022 QPointF startPos() const;
1023
1024 QSizeF viewportSize() const;
1025 QRectF contentPosRange() const;
1026 QPointF contentPos() const;
1027
1028 void setViewportSize(const QSizeF &size);
1029 void setContentPosRange(const QRectF &rect);
1030 void setContentPos(const QPointF &pos);
1031
1032private:
1033 QObject* m_target; // Qt 6 remove.
1034 QPointF m_startPos;
1035 QSizeF m_viewportSize;
1036 QRectF m_contentPosRange;
1037 QPointF m_contentPos;
1038};
1039
1040
1041class Q_GUI_EXPORT QScrollEvent : public QEvent
1042{
1043public:
1044 enum ScrollState
1045 {
1046 ScrollStarted,
1047 ScrollUpdated,
1048 ScrollFinished
1049 };
1050
1051 QScrollEvent(const QPointF &contentPos, const QPointF &overshoot, ScrollState scrollState);
1052 ~QScrollEvent();
1053
1054 QPointF contentPos() const;
1055 QPointF overshootDistance() const;
1056 ScrollState scrollState() const;
1057
1058private:
1059 QPointF m_contentPos;
1060 QPointF m_overshoot;
1061 QScrollEvent::ScrollState m_state;
1062};
1063
1064class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent
1065{
1066public:
1067 QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation orientation);
1068 ~QScreenOrientationChangeEvent();
1069
1070 QScreen *screen() const;
1071 Qt::ScreenOrientation orientation() const;
1072
1073private:
1074 QScreen *m_screen;
1075 Qt::ScreenOrientation m_orientation;
1076};
1077
1078class Q_GUI_EXPORT QApplicationStateChangeEvent : public QEvent
1079{
1080public:
1081 explicit QApplicationStateChangeEvent(Qt::ApplicationState state);
1082 Qt::ApplicationState applicationState() const;
1083
1084private:
1085 Qt::ApplicationState m_applicationState;
1086};
1087
1088QT_END_NAMESPACE
1089
1090#endif // QEVENT_H
1091