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