summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-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 fd674225ae..505e89b44d 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 1642cd006b..7761bab944 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 4c639f4eef..18a13b73f5 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 57238f362f..5c419a79dd 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 e49edf0b98..a0b77b8208 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);
}