summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <[email protected]>2012-04-04 15:36:21 -0300
committerQt by Nokia <[email protected]>2012-04-05 05:21:42 +0200
commite915d310107878a12652dc77a2a1f8dbb9c98972 (patch)
tree6316ba1dae8b5f546d3f67f9f7f9cd1490fe456f
parent8c4a17aace015964674d93046776abcb75ef2342 (diff)
Get rid of QKeyEventEx
This class was added when we needed more information in QKeyEvent but couldn't extend it. And we couldn't use the d pointer because the copy constructor and copy assignment operators in QEvent were implicit. That is now fixed. But since this is Qt 5, we can change QKeyEvent to include the extra information. Task-number: QTBUG-25070 Change-Id: Iba4ac3378ca70583fcaa8caf96bca8ef75e30701 Reviewed-by: Marius Storm-Olsen <[email protected]>
-rw-r--r--src/gui/kernel/qevent.cpp92
-rw-r--r--src/gui/kernel/qevent.h30
-rw-r--r--src/gui/kernel/qevent_p.h18
-rw-r--r--src/gui/kernel/qguiapplication.cpp5
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.cpp2
5 files changed, 62 insertions, 85 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index fd674225aea..505e89b44d1 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -717,11 +717,41 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos,
*/
QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text,
bool autorep, ushort count)
- : QInputEvent(type, modifiers), txt(text), k(key), c(count), autor(autorep)
+ : QInputEvent(type, modifiers), txt(text), k(key),
+ nScanCode(0), nVirtualKey(0), nModifiers(0),
+ c(count), autor(autorep)
{
}
/*!
+ Constructs a key event object.
+
+ The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease,
+ or QEvent::ShortcutOverride.
+
+ Int \a key is the code for the Qt::Key that the event loop should listen
+ for. If \a key is 0, the event is not a result of a known key; for
+ example, it may be the result of a compose sequence or keyboard macro.
+ The \a modifiers holds the keyboard modifiers, and the given \a text
+ is the Unicode text that the key generated. If \a autorep is true,
+ isAutoRepeat() will be true. \a count is the number of keys involved
+ in the event.
+
+ In addition to the normal key event data, also contains \a nativeScanCode,
+ \a nativeVirtualKey and \a nativeModifiers. This extra data is used by the
+ shortcut system, to determine which shortcuts to trigger.
+*/
+QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
+ quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
+ const QString &text, bool autorep, ushort count)
+ : QInputEvent(type, modifiers), txt(text), k(key),
+ nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers),
+ c(count), autor(autorep)
+{
+}
+
+
+/*!
\internal
*/
QKeyEvent::~QKeyEvent()
@@ -729,16 +759,9 @@ QKeyEvent::~QKeyEvent()
}
/*!
+ \fn QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString& text, bool autorep, ushort count)
\internal
*/
-QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
- quint32 nativeScanCode, quint32 nativeVirtualKey,
- quint32 nativeModifiers,
- const QString& text, bool autorep, ushort count)
-{
- return new QKeyEventEx(type, key, modifiers, text, autorep, count,
- nativeScanCode, nativeVirtualKey, nativeModifiers);
-}
/*!
\fn bool QKeyEvent::hasExtendedInfo() const
@@ -746,6 +769,7 @@ QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardMod
*/
/*!
+ \fn quint32 QKeyEvent::nativeScanCode() const
\since 4.2
Returns the native scan code of the key event. If the key event
@@ -758,13 +782,9 @@ QKeyEvent *QKeyEvent::createExtendedKeyEvent(Type type, int key, Qt::KeyboardMod
way to get the scan code from Carbon or Cocoa. The function always
returns 1 (or 0 in the case explained above).
*/
-quint32 QKeyEvent::nativeScanCode() const
-{
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nScanCode);
-}
/*!
+ \fn quint32 QKeyEvent::nativeVirtualKey() const
\since 4.2
Returns the native virtual key, or key sym of the key event.
@@ -772,13 +792,9 @@ quint32 QKeyEvent::nativeScanCode() const
Note: The native virtual key may be 0, even if the key event contains extended information.
*/
-quint32 QKeyEvent::nativeVirtualKey() const
-{
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nVirtualKey);
-}
/*!
+ \fn quint32 QKeyEvent::nativeModifiers() const
\since 4.2
Returns the native modifiers of a key event.
@@ -786,44 +802,6 @@ quint32 QKeyEvent::nativeVirtualKey() const
Note: The native modifiers may be 0, even if the key event contains extended information.
*/
-quint32 QKeyEvent::nativeModifiers() const
-{
- return (reinterpret_cast<const QKeyEvent*>(d) != this
- ? 0 : reinterpret_cast<const QKeyEventEx*>(this)->nModifiers);
-}
-
-/*!
- \internal
- Creates an extended key event object, which in addition to the normal key event data, also
- contains the native scan code, virtual key and modifiers. This extra data is used by the
- shortcut system, to determine which shortcuts to trigger.
-*/
-QKeyEventEx::QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
- const QString &text, bool autorep, ushort count,
- quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers)
- : QKeyEvent(type, key, modifiers, text, autorep, count),
- nScanCode(nativeScanCode), nVirtualKey(nativeVirtualKey), nModifiers(nativeModifiers)
-{
- d = reinterpret_cast<QEventPrivate*>(this);
-}
-
-/*!
- \internal
- Creates a copy of an other extended key event.
-*/
-QKeyEventEx::QKeyEventEx(const QKeyEventEx &other)
- : QKeyEvent(QEvent::Type(other.t), other.k, other.modState, other.txt, other.autor, other.c),
- nScanCode(other.nScanCode), nVirtualKey(other.nVirtualKey), nModifiers(other.nModifiers)
-{
- d = reinterpret_cast<QEventPrivate*>(this);
-}
-
-/*!
- \internal
-*/
-QKeyEventEx::~QKeyEventEx()
-{
-}
/*!
\fn int QKeyEvent::key() const
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 1642cd006b1..7761bab9443 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -243,6 +243,9 @@ class Q_GUI_EXPORT QKeyEvent : public QInputEvent
public:
QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(),
bool autorep = false, ushort count = 1);
+ QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
+ quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers,
+ const QString &text = QString(), bool autorep = false, ushort count = 1);
~QKeyEvent();
int key() const { return k; }
@@ -254,22 +257,35 @@ public:
inline bool isAutoRepeat() const { return autor; }
inline int count() const { return int(c); }
+ inline quint32 nativeScanCode() const { return nScanCode; }
+ inline quint32 nativeVirtualKey() const { return nVirtualKey; }
+ inline quint32 nativeModifiers() const { return nModifiers; }
+
// Functions for the extended key event information
- static QKeyEvent *createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
+#if QT_DEPRECATED_SINCE(5, 0)
+ static inline QKeyEvent *createExtendedKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers,
quint32 nativeScanCode, quint32 nativeVirtualKey,
quint32 nativeModifiers,
const QString& text = QString(), bool autorep = false,
- ushort count = 1);
- inline bool hasExtendedInfo() const { return reinterpret_cast<const QKeyEvent*>(d) == this; }
- quint32 nativeScanCode() const;
- quint32 nativeVirtualKey() const;
- quint32 nativeModifiers() const;
+ ushort count = 1)
+ {
+ return new QKeyEvent(type, key, modifiers,
+ nativeScanCode, nativeVirtualKey, nativeModifiers,
+ text, autorep, count);
+ }
+
+ inline bool hasExtendedInfo() const { return true; }
+#endif
protected:
QString txt;
int k;
+ quint32 nScanCode;
+ quint32 nVirtualKey;
+ quint32 nModifiers;
ushort c;
- uint autor:1;
+ ushort autor:1;
+ // ushort reserved:15;
};
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h
index 4c639f4eef9..18a13b73f55 100644
--- a/src/gui/kernel/qevent_p.h
+++ b/src/gui/kernel/qevent_p.h
@@ -60,24 +60,6 @@ QT_BEGIN_NAMESPACE
// We mean it.
//
-// ### Qt 5: remove
-class QKeyEventEx : public QKeyEvent
-{
-public:
- QKeyEventEx(Type type, int key, Qt::KeyboardModifiers modifiers,
- const QString &text, bool autorep, ushort count,
- quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers);
- QKeyEventEx(const QKeyEventEx &other);
-
- ~QKeyEventEx();
-
-protected:
- quint32 nScanCode;
- quint32 nVirtualKey;
- quint32 nModifiers;
- friend class QKeyEvent;
-};
-
class QTouchEventTouchPointPrivate
{
public:
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 57238f362fc..5c419a79dde 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1122,8 +1122,9 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
if (!window)
return;
- QKeyEventEx ev(e->keyType, e->key, e->modifiers, e->unicode, e->repeat, e->repeatCount,
- e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers);
+ QKeyEvent ev(e->keyType, e->key, e->modifiers,
+ e->nativeScanCode, e->nativeVirtualKey, e->nativeModifiers,
+ e->unicode, e->repeat, e->repeatCount);
ev.setTimestamp(e->timestamp);
QGuiApplication::sendSpontaneousEvent(window, &ev);
}
diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
index e49edf0b98a..a0b77b8208a 100644
--- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp
+++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp
@@ -180,7 +180,7 @@ bool QWindowSystemInterface::tryHandleSynchronousExtendedShortcutEvent(QWindow *
{
QGuiApplicationPrivate::modifier_buttons = mods;
- QKeyEventEx qevent(QEvent::ShortcutOverride, k, mods, text, autorep, count, nativeScanCode, nativeVirtualKey, nativeModifiers);
+ QKeyEvent qevent(QEvent::ShortcutOverride, k, mods, nativeScanCode, nativeVirtualKey, nativeModifiers, text, autorep, count);
qevent.setTimestamp(timestamp);
return QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(w, &qevent);
}