source: trunk/src/gui/kernel/qevent.h@ 471

Last change on this file since 471 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 22.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QEVENT_H
43#define QEVENT_H
44
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 <QtGui/qdrag.h>
54#include <QtCore/qvariant.h>
55
56QT_BEGIN_HEADER
57
58QT_BEGIN_NAMESPACE
59
60QT_MODULE(Gui)
61
62class QAction;
63
64class Q_GUI_EXPORT QInputEvent : public QEvent
65{
66public:
67 QInputEvent(Type type, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
68 ~QInputEvent();
69 inline Qt::KeyboardModifiers modifiers() const { return modState; }
70protected:
71 Qt::KeyboardModifiers modState;
72};
73
74class Q_GUI_EXPORT QMouseEvent : public QInputEvent
75{
76public:
77 QMouseEvent(Type type, const QPoint &pos, Qt::MouseButton button,
78 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
79 QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
80 Qt::MouseButton button, Qt::MouseButtons buttons,
81 Qt::KeyboardModifiers modifiers);
82 ~QMouseEvent();
83
84 inline const QPoint &pos() const { return p; }
85 inline const QPoint &globalPos() const { return g; }
86 inline int x() const { return p.x(); }
87 inline int y() const { return p.y(); }
88 inline int globalX() const { return g.x(); }
89 inline int globalY() const { return g.y(); }
90 inline Qt::MouseButton button() const { return b; }
91 inline Qt::MouseButtons buttons() const { return mouseState; }
92
93 static QMouseEvent *createExtendedMouseEvent(Type type, const QPointF &pos,
94 const QPoint &globalPos, Qt::MouseButton button,
95 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers);
96 inline bool hasExtendedInfo() const { return reinterpret_cast<const QMouseEvent *>(d) == this; }
97 QPointF posF() const;
98
99#ifdef QT3_SUPPORT
100 QT3_SUPPORT_CONSTRUCTOR QMouseEvent(Type type, const QPoint &pos, Qt::ButtonState button, int state);
101 QT3_SUPPORT_CONSTRUCTOR QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos,
102 Qt::ButtonState button, int state);
103 inline QT3_SUPPORT Qt::ButtonState state() const
104 { return Qt::ButtonState((mouseState^b)|int(modifiers())); }
105 inline QT3_SUPPORT Qt::ButtonState stateAfter() const
106 { return Qt::ButtonState(int(mouseState)|int(modifiers())); }
107#endif
108protected:
109 QPoint p, g;
110 Qt::MouseButton b;
111 Qt::MouseButtons mouseState;
112};
113
114class Q_GUI_EXPORT QHoverEvent : public QEvent
115{
116public:
117 QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos);
118 ~QHoverEvent();
119
120 inline const QPoint &pos() const { return p; }
121 inline const QPoint &oldPos() const { return op; }
122
123protected:
124 QPoint p, op;
125};
126
127#ifndef QT_NO_WHEELEVENT
128class Q_GUI_EXPORT QWheelEvent : public QInputEvent
129{
130public:
131 QWheelEvent(const QPoint &pos, int delta,
132 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
133 Qt::Orientation orient = Qt::Vertical);
134 QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta,
135 Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers,
136 Qt::Orientation orient = Qt::Vertical);
137 ~QWheelEvent();
138
139 inline int delta() const { return d; }
140 inline const QPoint &pos() const { return p; }
141 inline const QPoint &globalPos() const { return g; }
142 inline int x() const { return p.x(); }
143 inline int y() const { return p.y(); }
144 inline int globalX() const { return g.x(); }
145 inline int globalY() const { return g.y(); }
146
147 inline Qt::MouseButtons buttons() const { return mouseState; }
148 Qt::Orientation orientation() const { return o; }
149
150#ifdef QT3_SUPPORT
151 QT3_SUPPORT_CONSTRUCTOR QWheelEvent(const QPoint &pos, int delta, int state,
152 Qt::Orientation orient = Qt::Vertical);
153 QT3_SUPPORT_CONSTRUCTOR QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, int state,
154 Qt::Orientation orient = Qt::Vertical);
155 inline QT3_SUPPORT Qt::ButtonState state() const
156 { return static_cast<Qt::ButtonState>(int(buttons())|int(modifiers())); }
157#endif
158protected:
159 QPoint p;
160 QPoint g;
161 int d;
162 Qt::MouseButtons mouseState;
163 Qt::Orientation o;
164};
165#endif
166
167#ifndef QT_NO_TABLETEVENT
168class Q_GUI_EXPORT QTabletEvent : public QInputEvent
169{
170public:
171 enum TabletDevice { NoDevice, Puck, Stylus, Airbrush, FourDMouse,
172 XFreeEraser /*internal*/, RotationStylus };
173 enum PointerType { UnknownPointer, Pen, Cursor, Eraser };
174 QTabletEvent(Type t, const QPoint &pos, const QPoint &globalPos, const QPointF &hiResGlobalPos,
175 int device, int pointerType, qreal pressure, int xTilt, int yTilt,
176 qreal tangentialPressure, qreal rotation, int z,
177 Qt::KeyboardModifiers keyState, qint64 uniqueID);
178 ~QTabletEvent();
179
180 inline const QPoint &pos() const { return mPos; }
181 inline const QPoint &globalPos() const { return mGPos; }
182 inline const QPointF &hiResGlobalPos() const { return mHiResGlobalPos; }
183 inline int x() const { return mPos.x(); }
184 inline int y() const { return mPos.y(); }
185 inline int globalX() const { return mGPos.x(); }
186 inline int globalY() const { return mGPos.y(); }
187 inline qreal hiResGlobalX() const { return mHiResGlobalPos.x(); }
188 inline qreal hiResGlobalY() const { return mHiResGlobalPos.y(); }
189 inline TabletDevice device() const { return TabletDevice(mDev); }
190 inline PointerType pointerType() const { return PointerType(mPointerType); }
191 inline qint64 uniqueId() const { return mUnique; }
192 inline qreal pressure() const { return mPress; }
193 inline int z() const { return mZ; }
194 inline qreal tangentialPressure() const { return mTangential; }
195 inline qreal rotation() const { return mRot; }
196 inline int xTilt() const { return mXT; }
197 inline int yTilt() const { return mYT; }
198
199protected:
200 QPoint mPos, mGPos;
201 QPointF mHiResGlobalPos;
202 int mDev, mPointerType, mXT, mYT, mZ;
203 qreal mPress, mTangential, mRot;
204 qint64 mUnique;
205
206 // I don't know what the future holds for tablets but there could be some
207 // new devices coming along, and there seem to be "holes" in the
208 // OS-specific events for this.
209 void *mExtra;
210};
211#endif // QT_NO_TABLETEVENT
212
213class Q_GUI_EXPORT QKeyEvent : public QInputEvent
214{
215public:
216 QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(),
217 bool autorep = false, ushort count = 1);
218 ~QKeyEvent();
219
220 int key() const { return k; }
221#ifndef QT_NO_SHORTCUT
222 bool matches(QKeySequence::StandardKey key) const;
223#endif
224 Qt::KeyboardModifiers modifiers() const;
225 inline QString text() const { return txt; }
226 inline bool isAutoRepeat() const { return autor; }
227 inline int count() const { return int(c); }
228
229 // Functions for the extended key event information
230 static QKeyEvent *createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
231 quint32 nativeScanCode, quint32 nativeVirtualKey,
232 quint32 nativeModifiers,
233 const QString& text = QString(), bool autorep = false,
234 ushort count = 1);
235 inline bool hasExtendedInfo() const { return reinterpret_cast<const QKeyEvent*>(d) == this; }
236 quint32 nativeScanCode() const;
237 quint32 nativeVirtualKey() const;
238 quint32 nativeModifiers() const;
239
240#ifdef QT3_SUPPORT
241 inline QT3_SUPPORT_CONSTRUCTOR QKeyEvent(Type type, int key, int /*ascii*/,
242 int modifiers, const QString& text = QString(),
243 bool autorep = false, ushort count = 1)
244 : QInputEvent(type, (Qt::KeyboardModifiers)(modifiers & (int)Qt::KeyButtonMask)), txt(text), k(key),
245 c(count), autor(autorep)
246 {
247 if (key >= Qt::Key_Back && key <= Qt::Key_MediaLast)
248 ignore();
249 }
250 inline QT3_SUPPORT int ascii() const
251 { return (txt.length() ? txt.unicode()->toLatin1() : 0); }
252 inline QT3_SUPPORT Qt::ButtonState state() const { return Qt::ButtonState(QInputEvent::modifiers()); }
253 inline QT3_SUPPORT Qt::ButtonState stateAfter() const { return Qt::ButtonState(modifiers()); }
254#endif
255
256protected:
257 QString txt;
258 int k;
259 ushort c;
260 uint autor:1;
261};
262
263
264class Q_GUI_EXPORT QFocusEvent : public QEvent
265{
266public:
267 QFocusEvent(Type type, Qt::FocusReason reason=Qt::OtherFocusReason);
268 ~QFocusEvent();
269
270 inline bool gotFocus() const { return type() == FocusIn; }
271 inline bool lostFocus() const { return type() == FocusOut; }
272
273#ifdef QT3_SUPPORT
274 enum Reason { Mouse=Qt::MouseFocusReason, Tab=Qt::TabFocusReason,
275 Backtab=Qt::BacktabFocusReason, MenuBar=Qt::MenuBarFocusReason,
276 ActiveWindow=Qt::ActiveWindowFocusReason, Other=Qt::OtherFocusReason,
277 Popup=Qt::PopupFocusReason, Shortcut=Qt::ShortcutFocusReason };
278#endif
279 Qt::FocusReason reason();
280 Qt::FocusReason reason() const;
281
282private:
283 Qt::FocusReason m_reason;
284};
285
286
287class Q_GUI_EXPORT QPaintEvent : public QEvent
288{
289public:
290 QPaintEvent(const QRegion& paintRegion);
291 QPaintEvent(const QRect &paintRect);
292 ~QPaintEvent();
293
294 inline const QRect &rect() const { return m_rect; }
295 inline const QRegion &region() const { return m_region; }
296
297#ifdef QT3_SUPPORT
298 QT3_SUPPORT_CONSTRUCTOR QPaintEvent(const QRegion &paintRegion, const QRect &paintRect);
299 inline QT3_SUPPORT bool erased() const { return m_erased; }
300 inline QT3_SUPPORT void setErased(bool b) { m_erased = b; }
301#endif
302
303protected:
304 friend class QApplication;
305 friend class QCoreApplication;
306 QRect m_rect;
307 QRegion m_region;
308 bool m_erased;
309};
310
311class QUpdateLaterEvent : public QEvent
312{
313public:
314 QUpdateLaterEvent(const QRegion& paintRegion);
315 ~QUpdateLaterEvent();
316
317 inline const QRegion &region() const { return m_region; }
318
319protected:
320 QRegion m_region;
321};