1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtGui module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
45 #include <QtGui/qwindowdefs.h>
46 #include <QtCore/qobject.h>
47 #include <QtGui/qregion.h>
48 #include <QtCore/qnamespace.h>
49 #include <QtCore/qstring.h>
50 #include <QtGui/qkeysequence.h>
51 #include <QtCore/qcoreevent.h>
52 #include <QtGui/qmime.h>
53 #include <QtCore/qvariant.h>
54 #include <QtCore/qmap.h>
55 #include <QtCore/qset.h>
56 #include <QtCore/qfile.h>
69 #ifndef QT_NO_GESTURES
73 class Q_GUI_EXPORT QInputEvent : public QEvent
76 QInputEvent(Type type, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
78 inline Qt::KeyboardModifiers modifiers() const { return modState; }
79 inline void setModifiers(Qt::KeyboardModifiers amodifiers) { modState = amodifiers; }
81 Qt::KeyboardModifiers modState;
84 class Q_GUI_EXPORT QMouseEvent : public QInputEvent
87 QMouseEvent(Type type, const QPointF &pos, Qt::MouseButton button,
88 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
89 QMouseEvent(Type type, const QPointF &pos, const QPointF &globalPos,
90 Qt::MouseButton button, Qt::MouseButtons buttons,
91 Qt::KeyboardModifiers modifiers);
94 inline QPoint pos() const { return p.toPoint(); }
95 inline QPoint globalPos() const { return g.toPoint(); }
96 inline int x() const { return qRound(p.x()); }
97 inline int y() const { return qRound(p.y()); }
98 inline int globalX() const { return qRound(g.x()); }
99 inline int globalY() const { return qRound(g.y()); }
100 inline Qt::MouseButton button() const { return b; }
101 inline Qt::MouseButtons buttons() const { return mouseState; }
103 const QPointF &posF() const { return p; }
104 const QPointF &globalPosF() const { return g; }
109 Qt::MouseButtons mouseState;
112 class Q_GUI_EXPORT QHoverEvent : public QInputEvent
115 QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
118 inline QPoint pos() const { return p.toPoint(); }
119 inline QPoint oldPos() const { return op.toPoint(); }
121 inline const QPointF &posF() const { return p; }
122 inline const QPointF &oldPosF() const { return op; }
128 #ifndef QT_NO_WHEELEVENT
129 class Q_GUI_EXPORT QWheelEvent : public QInputEvent
132 QWheelEvent(const QPointF &pos, int delta,
133 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
134 Qt::Orientation orient = Qt::Vertical);
135 QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta,
136 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
137 Qt::Orientation orient = Qt::Vertical);
140 inline int delta() const { return d; }
141 inline QPoint pos() const { return p.toPoint(); }
142 inline QPoint globalPos() const { return g.toPoint(); }
143 inline int x() const { return p.x(); }
144 inline int y() const { return p.y(); }
145 inline int globalX() const { return g.x(); }
146 inline int globalY() const { return g.y(); }
148 inline Qt::MouseButtons buttons() const { return mouseState; }
149 Qt::Orientation orientation() const { return o; }
151 inline const QPointF &posF() const { return p; }
152 inline const QPointF &globalPosF() const { return g; }
158 Qt::MouseButtons mouseState;
163 #ifndef QT_NO_TABLETEVENT
164 class Q_GUI_EXPORT QTabletEvent : public QInputEvent
167 enum TabletDevice { NoDevice, Puck, Stylus, Airbrush, FourDMouse,
168 XFreeEraser /*internal*/, RotationStylus };
169 enum PointerType { UnknownPointer, Pen, Cursor, Eraser };
170 QTabletEvent(Type t, const QPoint &pos, const QPoint &globalPos, const QPointF &hiResGlobalPos,
171 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
172 qreal tangentialPressure, qreal rotation, int z,
173 Qt::KeyboardModifiers keyState, qint64 uniqueID);
176 inline const QPoint &pos() const { return mPos; }
177 inline const QPoint &globalPos() const { return mGPos; }
178 inline const QPointF &hiResGlobalPos() const { return mHiResGlobalPos; }
179 inline int x() const { return mPos.x(); }
180 inline int y() const { return mPos.y(); }
181 inline int globalX() const { return mGPos.x(); }
182 inline int globalY() const { return mGPos.y(); }
183 inline qreal hiResGlobalX() const { return mHiResGlobalPos.x(); }
184 inline qreal hiResGlobalY() const { return mHiResGlobalPos.y(); }
185 inline TabletDevice device() const { return TabletDevice(mDev); }
186 inline PointerType pointerType() const { return PointerType(mPointerType); }
187 inline qint64 uniqueId() const { return mUnique; }
188 inline qreal pressure() const { return mPress; }
189 inline int z() const { return mZ; }
190 inline qreal tangentialPressure() const { return mTangential; }
191 inline qreal rotation() const { return mRot; }
192 inline int xTilt() const { return mXT; }
193 inline int yTilt() const { return mYT; }
197 QPointF mHiResGlobalPos;
198 int mDev, mPointerType, mXT, mYT, mZ;
199 qreal mPress, mTangential, mRot;
202 // I don't know what the future holds for tablets but there could be some
203 // new devices coming along, and there seem to be "holes" in the
204 // OS-specific events for this.
207 #endif // QT_NO_TABLETEVENT
209 class Q_GUI_EXPORT QKeyEvent : public QInputEvent
212 QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(),
213 bool autorep = false, ushort count = 1);
216 int key() const { return k; }
217 #ifndef QT_NO_SHORTCUT
218 bool matches(QKeySequence::StandardKey key) const;
220 Qt::KeyboardModifiers modifiers() const;
221 inline QString text() const { return txt; }
222 inline bool isAutoRepeat() const { return autor; }
223 inline int count() const { return int(c); }
225 // Functions for the extended key event information
226 static QKeyEvent *createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
227 quint32 nativeScanCode, quint32 nativeVirtualKey,
228 quint32 nativeModifiers,
229 const QString& text = QString(), bool autorep = false,
231 inline bool hasExtendedInfo() const { return reinterpret_cast<const QKeyEvent*>(d) == this; }
232 quint32 nativeScanCode() const;
233 quint32 nativeVirtualKey() const;
234 quint32 nativeModifiers() const;
244 class Q_GUI_EXPORT QFocusEvent : public QEvent
247 QFocusEvent(Type type, Qt::FocusReason reason=Qt::OtherFocusReason);
250 inline bool gotFocus() const { return type() == FocusIn; }
251 inline bool lostFocus() const { return type() == FocusOut; }
253 Qt::FocusReason reason();
254 Qt::FocusReason reason() const;
257 Qt::FocusReason m_reason;
261 class Q_GUI_EXPORT QPaintEvent : public QEvent
264 QPaintEvent(const QRegion& paintRegion);
265 QPaintEvent(const QRect &paintRect);
268 inline const QRect &rect() const { return m_rect; }
269 inline const QRegion ®ion() const { return m_region; }
272 friend class QApplication;
273 friend class QCoreApplication;
279 // ### Qt5: make internal
280 class Q_GUI_EXPORT QUpdateLaterEvent : public QEvent
283 QUpdateLaterEvent(const QRegion& paintRegion);
284 ~QUpdateLaterEvent();
286 inline const QRegion ®ion() const { return m_region; }
292 class Q_GUI_EXPORT QMoveEvent : public QEvent
295 QMoveEvent(const QPoint &pos, const QPoint &oldPos);
298 inline const QPoint &pos() const { return p; }
299 inline const QPoint &oldPos() const { return oldp;}
302 friend class QApplication;
303 friend class QCoreApplication;
306 class Q_GUI_EXPORT QExposeEvent : public QEvent
309 QExposeEvent(const QRegion &rgn);
312 inline const QRegion ®ion() const { return rgn; }
318 class Q_GUI_EXPORT QResizeEvent : public QEvent
321 QResizeEvent(const QSize &size, const QSize &oldSize);
324 inline const QSize &size() const { return s; }
325 inline const QSize &oldSize()const { return olds;}
328 friend class QApplication;
329 friend class QCoreApplication;
333 class Q_GUI_EXPORT QCloseEvent : public QEvent
341 class Q_GUI_EXPORT QIconDragEvent : public QEvent
349 class Q_GUI_EXPORT QShowEvent : public QEvent
357 class Q_GUI_EXPORT QHideEvent : public QEvent
364 #ifndef QT_NO_CONTEXTMENU
365 class Q_GUI_EXPORT QContextMenuEvent : public QInputEvent
368 enum Reason { Mouse, Keyboard, Other };
370 QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos,
371 Qt::KeyboardModifiers modifiers);
372 QContextMenuEvent(Reason reason, const QPoint &pos, const QPoint &globalPos);
373 QContextMenuEvent(Reason reason, const QPoint &pos);
374 ~QContextMenuEvent();
376 inline int x() const { return p.x(); }
377 inline int y() const { return p.y(); }
378 inline int globalX() const { return gp.x(); }
379 inline int globalY() const { return gp.y(); }
381 inline const QPoint& pos() const { return p; }
382 inline const QPoint& globalPos() const { return gp; }
384 inline Reason reason() const { return Reason(reas); }
391 #endif // QT_NO_CONTEXTMENU
393 #ifndef QT_NO_INPUTMETHOD
394 class Q_GUI_EXPORT QInputMethodEvent : public QEvent
406 Attribute(AttributeType t, int s, int l, QVariant val) : type(t), start(s), length(l), value(val) {}
414 QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes);
415 void setCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0);
417 inline const QList<Attribute> &attributes() const { return attrs; }
418 inline const QString &preeditString() const { return preedit; }
420 inline const QString &commitString() const { return commit; }
421 inline int replacementStart() const { return replace_from; }
422 inline int replacementLength() const { return replace_length; }
424 QInputMethodEvent(const QInputMethodEvent &other);
428 QList<Attribute> attrs;
434 class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent
437 QInputMethodQueryEvent(Qt::InputMethodQuery query);
438 ~QInputMethodQueryEvent();
440 Qt::InputMethodQuery query() const { return m_query; }
442 void setValue(const QVariant &v) { m_value = v; }
443 QVariant value() const { return m_value; }
445 Qt::InputMethodQuery m_query;
449 #endif // QT_NO_INPUTMETHOD
451 #ifndef QT_NO_DRAGANDDROP
455 class Q_GUI_EXPORT QDropEvent : public QEvent
461 QDropEvent(const QPoint& pos, Qt::DropActions actions, const QMimeData *data,
462 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = Drop);
465 inline const QPoint &pos() const { return p; }
466 inline Qt::MouseButtons mouseButtons() const { return mouseState; }
467 inline Qt::KeyboardModifiers keyboardModifiers() const { return modState; }
469 inline Qt::DropActions possibleActions() const { return act; }
470 inline Qt::DropAction proposedAction() const { return default_action; }
471 inline void acceptProposedAction() { drop_action = default_action; accept(); }
473 inline Qt::DropAction dropAction() const { return drop_action; }
474 void setDropAction(Qt::DropAction action);
476 QObject* source() const;
477 inline const QMimeData *mimeData() const { return mdata; }
480 const char* format(int n = 0) const;
481 QByteArray encodedData(const char*) const;
482 bool provides(const char*) const;
487 friend class QApplication;
489 Qt::MouseButtons mouseState;
490 Qt::KeyboardModifiers modState;
492 Qt::DropAction drop_action;
493 Qt::DropAction default_action;
494 const QMimeData *mdata;
495 mutable QList<QByteArray> fmts; // only used for QT3_SUPPORT
499 class Q_GUI_EXPORT QDragMoveEvent : public QDropEvent
502 QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
503 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = DragMove);
506 inline QRect answerRect() const { return rect; }
508 inline void accept() { QDropEvent::accept(); }
509 inline void ignore() { QDropEvent::ignore(); }
511 inline void accept(const QRect & r) { accept(); rect = r; }
512 inline void ignore(const QRect & r) { ignore(); rect = r; }
515 friend class QApplication;
520 class Q_GUI_EXPORT QDragEnterEvent : public QDragMoveEvent
523 QDragEnterEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data,
524 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
529 class Q_GUI_EXPORT QDragLeaveEvent : public QEvent
535 #endif // QT_NO_DRAGANDDROP
538 class Q_GUI_EXPORT QHelpEvent : public QEvent
541 QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos);
544 inline int x() const { return p.x(); }
545 inline int y() const { return p.y(); }
546 inline int globalX() const { return gp.x(); }
547 inline int globalY() const { return gp.y(); }
549 inline const QPoint& pos() const { return p; }
550 inline const QPoint& globalPos() const { return gp; }
557 #ifndef QT_NO_STATUSTIP
558 class Q_GUI_EXPORT QStatusTipEvent : public QEvent
561 QStatusTipEvent(const QString &tip);
564 inline QString tip() const { return s; }
570 #ifndef QT_NO_WHATSTHIS
571 class Q_GUI_EXPORT QWhatsThisClickedEvent : public QEvent
574 QWhatsThisClickedEvent(const QString &href);
575 ~QWhatsThisClickedEvent();
577 inline QString href() const { return s; }
584 class Q_GUI_EXPORT QActionEvent : public QEvent
588 QActionEvent(int type, QAction *action, QAction *before = 0);
591 inline QAction *action() const { return act; }
592 inline QAction *before() const { return bef; }
596 class Q_GUI_EXPORT QFileOpenEvent : public QEvent
599 QFileOpenEvent(const QString &file);
600 QFileOpenEvent(const QUrl &url);
602 QFileOpenEvent(const RFile &fileHandle);
606 inline QString file() const { return f; }
608 bool openFile(QFile &file, QIODevice::OpenMode flags) const;
613 #ifndef QT_NO_TOOLBAR
614 class Q_GUI_EXPORT QToolBarChangeEvent : public QEvent
617 QToolBarChangeEvent(bool t);
618 ~QToolBarChangeEvent();
620 inline bool toggle() const { return tog; }
626 #ifndef QT_NO_SHORTCUT
627 class Q_GUI_EXPORT QShortcutEvent : public QEvent
630 QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false);
633 inline const QKeySequence &key() { return sequence; }
634 inline const QKeySequence &key() const { return sequence; }
635 inline int shortcutId() { return sid; }
636 inline int shortcutId() const { return sid; }
637 inline bool isAmbiguous() { return ambig; }
638 inline bool isAmbiguous() const { return ambig; }
640 QKeySequence sequence;
646 #ifndef QT_NO_CLIPBOARD
647 class Q_GUI_EXPORT QClipboardEvent : public QEvent
650 QClipboardEvent(QEventPrivate *data);
653 QEventPrivate *data() { return d; }
657 class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent
660 QWindowStateChangeEvent(Qt::WindowStates aOldState);
661 QWindowStateChangeEvent(Qt::WindowStates aOldState, bool isOverride);
662 ~QWindowStateChangeEvent();
664 inline Qt::WindowStates oldState() const { return ostate; }
665 bool isOverride() const;
668 Qt::WindowStates ostate;
671 #ifndef QT_NO_DEBUG_STREAM
672 Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *);
675 #ifndef QT_NO_SHORTCUT
676 inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? e->matches(key) : false);}
677 inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);}
678 #endif // QT_NO_SHORTCUT
680 class QTouchEventTouchPointPrivate;
681 class Q_GUI_EXPORT QTouchEvent : public QInputEvent
684 class Q_GUI_EXPORT TouchPoint
687 TouchPoint(int id = -1);
688 TouchPoint(const QTouchEvent::TouchPoint &other);
693 Qt::TouchPointState state() const;
694 bool isPrimary() const;
697 QPointF startPos() const;
698 QPointF lastPos() const;
700 QPointF scenePos() const;
701 QPointF startScenePos() const;
702 QPointF lastScenePos() const;
704 QPointF screenPos() const;
705 QPointF startScreenPos() const;
706 QPointF lastScreenPos() const;
708 QPointF normalizedPos() const;
709 QPointF startNormalizedPos() const;
710 QPointF lastNormalizedPos() const;
713 QRectF sceneRect() const;
714 QRectF screenRect() const;
716 qreal pressure() const;
720 void setState(Qt::TouchPointStates state);
721 void setPos(const QPointF &pos);
722 void setScenePos(const QPointF &scenePos);
723 void setScreenPos(const QPointF &screenPos);
724 void setNormalizedPos(const QPointF &normalizedPos);
725 void setStartPos(const QPointF &startPos);
726 void setStartScenePos(const QPointF &startScenePos);
727 void setStartScreenPos(const QPointF &startScreenPos);
728 void setStartNormalizedPos(const QPointF &startNormalizedPos);
729 void setLastPos(const QPointF &lastPos);
730 void setLastScenePos(const QPointF &lastScenePos);
731 void setLastScreenPos(const QPointF &lastScreenPos);
732 void setLastNormalizedPos(const QPointF &lastNormalizedPos);
733 void setRect(const QRectF &rect);
734 void setSceneRect(const QRectF &sceneRect);
735 void setScreenRect(const QRectF &screenRect);
736 void setPressure(qreal pressure);
737 QTouchEvent::TouchPoint &operator=(const QTouchEvent::TouchPoint &other);
740 QTouchEventTouchPointPrivate *d;
741 friend class QApplication;
742 friend class QApplicationPrivate;
750 QTouchEvent(QEvent::Type eventType,
751 QTouchEvent::DeviceType deviceType = TouchScreen,
752 Qt::KeyboardModifiers modifiers = Qt::NoModifier,
753 Qt::TouchPointStates touchPointStates = 0,
754 const QList<QTouchEvent::TouchPoint> &touchPoints = QList<QTouchEvent::TouchPoint>());
757 inline QWidget *widget() const { return _widget; }
758 inline QTouchEvent::DeviceType deviceType() const { return _deviceType; }
759 inline Qt::TouchPointStates touchPointStates() const { return _touchPointStates; }
760 inline const QList<QTouchEvent::TouchPoint> &touchPoints() const { return _touchPoints; }
763 inline void setWidget(QWidget *awidget) { _widget = awidget; }
764 inline void setDeviceType(DeviceType adeviceType) { _deviceType = adeviceType; }
765 inline void setTouchPointStates(Qt::TouchPointStates aTouchPointStates) { _touchPointStates = aTouchPointStates; }
766 inline void setTouchPoints(const QList<QTouchEvent::TouchPoint> &atouchPoints) { _touchPoints = atouchPoints; }
770 QTouchEvent::DeviceType _deviceType;
771 Qt::TouchPointStates _touchPointStates;
772 QList<QTouchEvent::TouchPoint> _touchPoints;
774 friend class QApplication;
775 friend class QApplicationPrivate;
779 class QScrollPrepareEventPrivate;
780 class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent
783 QScrollPrepareEvent(const QPointF &startPos);
784 ~QScrollPrepareEvent();
786 QPointF startPos() const;
788 QSizeF viewportSize() const;
789 QRectF contentPosRange() const;
790 QPointF contentPos() const;
792 void setViewportSize(const QSizeF &size);
793 void setContentPosRange(const QRectF &rect);
794 void setContentPos(const QPointF &pos);
797 QScrollPrepareEventPrivate *d_func();
798 const QScrollPrepareEventPrivate *d_func() const;
802 class QScrollEventPrivate;
803 class Q_GUI_EXPORT QScrollEvent : public QEvent
813 QScrollEvent(const QPointF &contentPos, const QPointF &overshoot, ScrollState scrollState);
816 QPointF contentPos() const;
817 QPointF overshootDistance() const;
818 ScrollState scrollState() const;
821 QScrollEventPrivate *d_func();
822 const QScrollEventPrivate *d_func() const;
825 class QScreenOrientationChangeEventPrivate;
826 class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent
832 PortraitInverted = 4,
833 LandscapeInverted = 8
835 QScreenOrientationChangeEvent(qint32 screenOrientationInDegrees);
836 QScreenOrientationChangeEvent(Orientation screenOrientation);
837 ~QScreenOrientationChangeEvent();
839 bool isValid() const;
840 qint32 orientationInDegrees() const;
841 Orientation orientation() const;
844 QScreenOrientationChangeEventPrivate *d_func();
845 const QScreenOrientationChangeEventPrivate *d_func() const;