summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/corelib/global/qnamespace.h156
-rw-r--r--src/corelib/global/qnamespace.qdoc199
-rw-r--r--src/corelib/io/qdebug.h11
-rw-r--r--src/corelib/serialization/qdatastream.h14
-rw-r--r--src/corelib/tools/qhashfunctions.h2
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp6
-rw-r--r--src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp2
-rw-r--r--src/gui/kernel/qevent.cpp9
-rw-r--r--src/gui/kernel/qevent.h4
-rw-r--r--src/gui/kernel/qguivariant.cpp3
-rw-r--r--src/gui/kernel/qkeymapper.cpp25
-rw-r--r--src/gui/kernel/qkeysequence.cpp25
-rw-r--r--src/gui/kernel/qkeysequence.h8
-rw-r--r--src/gui/kernel/qkeysequence_p.h2
-rw-r--r--src/gui/kernel/qplatformtheme.cpp2
-rw-r--r--src/gui/kernel/qshortcutmap.cpp14
-rw-r--r--src/gui/platform/unix/dbusmenu/qdbusmenutypes.cpp2
-rw-r--r--src/gui/platform/unix/qxkbcommon.cpp4
-rw-r--r--src/testlib/qtestkeyboard.h8
-rw-r--r--src/widgets/dialogs/qfiledialog.cpp2
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp2
-rw-r--r--src/widgets/kernel/qwhatsthis.cpp2
-rw-r--r--src/widgets/widgets/qkeysequenceedit.cpp6
-rw-r--r--src/widgets/widgets/qkeysequenceedit_p.h2
-rw-r--r--src/widgets/widgets/qmenu.cpp2
25 files changed, 461 insertions, 51 deletions
diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h
index a531bc627b..0c4b4fc8bf 100644
--- a/src/corelib/global/qnamespace.h
+++ b/src/corelib/global/qnamespace.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2020 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
@@ -1094,6 +1095,8 @@ namespace Qt {
ALT = Qt::AltModifier,
MODIFIER_MASK = KeyboardModifierMask,
};
+ Q_DECLARE_FLAGS(Modifiers, Modifier)
+ Q_DECLARE_OPERATORS_FOR_FLAGS(Modifiers)
enum ArrowType {
NoArrow,
@@ -1785,6 +1788,9 @@ namespace Qt {
Q_ENUM_NS(SortOrder)
Q_ENUM_NS(CaseSensitivity)
Q_FLAG_NS(MatchFlags)
+ Q_ENUM_NS(Modifier)
+ Q_FLAG_NS(Modifiers)
+ Q_ENUM_NS(KeyboardModifier)
Q_FLAG_NS(KeyboardModifiers)
Q_FLAG_NS(MouseButtons)
Q_ENUM_NS(WindowType)
@@ -1863,6 +1869,156 @@ public:
static bool activateCallbacks(Callback, void **);
};
+class QKeyCombination
+{
+ int combination;
+
+public:
+ constexpr /* implicit */ QKeyCombination(Qt::Key key = Qt::Key_unknown) noexcept
+ : combination(int(key))
+ {}
+
+ constexpr explicit QKeyCombination(Qt::Modifiers modifiers, Qt::Key key = Qt::Key_unknown) noexcept
+ : combination(int(modifiers) | int(key))
+ {}
+
+ constexpr explicit QKeyCombination(Qt::KeyboardModifiers modifiers, Qt::Key key = Qt::Key_unknown) noexcept
+ : combination(int(modifiers) | int(key))
+ {}
+
+ constexpr Qt::KeyboardModifiers keyboardModifiers() const noexcept
+ {
+ return Qt::KeyboardModifiers(combination & Qt::KeyboardModifierMask);
+ }
+
+ constexpr Qt::Key key() const noexcept
+ {
+ return Qt::Key(combination & ~Qt::KeyboardModifierMask);
+ }
+
+ static constexpr QKeyCombination fromCombined(int combined)
+ {
+ QKeyCombination result;
+ result.combination = combined;
+ return result;
+ }
+
+ constexpr int toCombined() const noexcept
+ {
+ return combination;
+ }
+
+#if QT_DEPRECATED_SINCE(6, 0)
+ QT_DEPRECATED_VERSION_X(6, 0, "Use QKeyCombination instead of int")
+ constexpr /* implicit */ operator int() const noexcept
+ {
+ return combination;
+ }
+#endif
+
+ friend constexpr bool operator==(QKeyCombination lhs, QKeyCombination rhs) noexcept
+ {
+ return lhs.combination == rhs.combination;
+ }
+
+ friend constexpr bool operator!=(QKeyCombination lhs, QKeyCombination rhs) noexcept
+ {
+ return lhs.combination != rhs.combination;
+ }
+};
+
+Q_DECLARE_TYPEINFO(QKeyCombination, Q_MOVABLE_TYPE);
+
+constexpr QKeyCombination operator|(Qt::Modifier modifier, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+constexpr QKeyCombination operator|(Qt::Modifiers modifiers, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+
+constexpr QKeyCombination operator|(Qt::KeyboardModifier modifier, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+constexpr QKeyCombination operator|(Qt::KeyboardModifiers modifiers, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+
+constexpr QKeyCombination operator|(Qt::Key key, Qt::Modifier modifier) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+constexpr QKeyCombination operator|(Qt::Key key, Qt::Modifiers modifiers) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+
+constexpr QKeyCombination operator|(Qt::Key key, Qt::KeyboardModifier modifier) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+constexpr QKeyCombination operator|(Qt::Key key, Qt::KeyboardModifiers modifiers) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+
+#if QT_DEPRECATED_SINCE(6, 0)
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::Modifier modifier, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::Modifiers modifiers, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::KeyboardModifier modifier, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::KeyboardModifiers modifiers, Qt::Key key) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::Key key, Qt::Modifier modifier) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::Key key, Qt::Modifiers modifiers) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::Key key, Qt::KeyboardModifier modifier) noexcept
+{
+ return QKeyCombination(modifier, key);
+}
+
+QT_DEPRECATED_VERSION_X(6, 0, "Use operator| instead")
+constexpr QKeyCombination operator+(Qt::Key key, Qt::KeyboardModifiers modifiers) noexcept
+{
+ return QKeyCombination(modifiers, key);
+}
+#endif
+
QT_END_NAMESPACE
#endif // QNAMESPACE_H
diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc
index 95a73c4439..b5d44cb1cb 100644
--- a/src/corelib/global/qnamespace.qdoc
+++ b/src/corelib/global/qnamespace.qdoc
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2020 The Qt Company Ltd.
+** Copyright (C) 2020 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -3246,3 +3247,201 @@
\sa QLabel::picture()
\sa QLabel::pixmap()
*/
+
+/*!
+ \class QKeyCombination
+ \inmodule QtCore
+ \since 6.0
+ \brief The QKeyCombination class stores a combination of a key with optional modifiers.
+
+ The QKeyCombination class can be used to represent a combination of a key
+ with zero or more keyboard modifiers.
+
+ \sa QKeySequence
+*/
+
+/*!
+ \fn QKeyCombination::QKeyCombination(Qt::Key key = Qt::Key_unknown) noexcept
+
+ Constructs a QKeyCombination object that represents the key \a key
+ and no modifiers.
+
+ \sa key()
+*/
+
+/*!
+ \fn QKeyCombination::QKeyCombination(Qt::Modifiers modifiers, Qt::Key key = Qt::Key_unknown) noexcept
+
+ Constructs a QKeyCombination object that represents the combination
+ of \a key with the modifiers \a modifiers.
+
+ \sa key(), keyboardModifiers()
+*/
+
+/*!
+ \fn QKeyCombination::QKeyCombination(Qt::KeyboardModifiers modifiers, Qt::Key key = Qt::Key_unknown) noexcept
+
+ Constructs a QKeyCombination object that represents the combination
+ of \a key with the modifiers \a modifiers.
+
+ \sa key(), keyboardModifiers()
+*/
+
+/*!
+ \fn Qt::KeyboardModifiers QKeyCombination::keyboardModifiers() const noexcept
+
+ Returns the keyboard modifiers represented by this QKeyCombination object.
+
+ \sa key()
+*/
+
+/*!
+ \fn Qt::Key QKeyCombination::key() const noexcept
+
+ Returns the key represented by this QKeyCombination object.
+
+ \sa keyboardModifiers()
+*/
+
+/*!
+ \fn QKeyCombination QKeyCombination::fromCombined(int combined)
+
+ Constructs a QKeyCombination object by extracting the key and the
+ modifiers out of \a combined, which must be the result of a bitwise
+ OR between a value of type Qt::Key and value of type
+ Qt::KeyboardModifiers. toCombined() can be used in order to produce
+ valid values for \a combined.
+
+ \sa toCombined()
+*/
+
+/*!
+ \fn int QKeyCombination::toCombined() const noexcept
+
+ Returns an integer value obtained by applying a bitwise OR between
+ the values of key() and keyboardModifiers() represented
+ by this object. A QKeyCombination object can be created from the
+ returned integer value by using fromCombined().
+
+ \sa fromCombined(), key(), keyboardModifiers()
+*/
+
+#if QT_DEPRECATED_SINCE(6, 0)
+/*!
+ \fn QKeyCombination::operator int() const noexcept
+ \obsolete
+
+ Use toCombined() instead.
+*/
+#endif
+
+/*!
+ \fn bool operator==(QKeyCombination lhs, QKeyCombination rhs) noexcept
+ \relates QKeyCombination
+
+ Returns \c true if \a lhs and \a rhs have the same combination
+ of key and modifiers, and \c false otherwise.
+*/
+
+/*!
+ \fn bool operator!=(QKeyCombination lhs, QKeyCombination rhs) noexcept
+ \relates QKeyCombination
+
+ Returns \c true if \a lhs and \a rhs have different combinations
+ of key and modifiers, otherwise \c false.
+*/
+
+/*!
+ \fn QKeyCombination operator|(Qt::Modifier modifier, Qt::Key key) noexcept
+ \fn QKeyCombination operator|(Qt::KeyboardModifier modifier, Qt::Key key) noexcept
+ \fn QKeyCombination operator|(Qt::Key key, Qt::Modifier modifier) noexcept
+ \fn QKeyCombination operator|(Qt::Key key, Qt::KeyboardModifier modifier) noexcept
+
+ \relates QKeyCombination
+
+ Returns a QKeyCombination object that represents the combination
+ of \a key with the modifier \a modifier.
+*/
+
+/*!
+ \fn QKeyCombination operator|(Qt::Modifiers modifiers, Qt::Key key) noexcept
+ \fn QKeyCombination operator|(Qt::KeyboardModifiers modifiers, Qt::Key key) noexcept
+ \fn QKeyCombination operator|(Qt::Key key, Qt::Modifiers modifiers) noexcept
+ \fn QKeyCombination operator|(Qt::Key key, Qt::KeyboardModifiers modifiers) noexcept
+
+ \relates QKeyCombination
+
+ Returns a QKeyCombination object that represents the combination
+ of \a key with the modifiers \a modifiers.
+*/
+
+/*!
+ \fn QKeyCombination operator+(Qt::Modifier modifier, Qt::Key key) noexcept
+ \fn QKeyCombination operator+(Qt::KeyboardModifier modifier, Qt::Key key) noexcept
+ \fn QKeyCombination operator+(Qt::Key key, Qt::Modifier modifier) noexcept
+ \fn QKeyCombination operator+(Qt::Key key, Qt::KeyboardModifier modifier) noexcept
+
+ \relates QKeyCombination
+ \obsolete
+
+ Use operator| instead.
+
+ Returns a QKeyCombination object that represents the combination
+ of \a key with the modifier \a modifier.
+*/
+
+/*!
+ \fn QKeyCombination operator+(Qt::Modifiers modifiers, Qt::Key key) noexcept
+ \fn QKeyCombination operator+(Qt::KeyboardModifiers modifiers, Qt::Key key) noexcept
+ \fn QKeyCombination operator+(Qt::Key key, Qt::Modifiers modifiers) noexcept
+ \fn QKeyCombination operator+(Qt::Key key, Qt::KeyboardModifiers modifiers) noexcept
+
+ \relates QKeyCombination
+ \obsolete
+
+ Use operator| instead.
+
+ Returns a QKeyCombination object that represents the combination
+ of \a key with the modifiers \a modifiers.
+*/
+
+/*!
+ \fn size_t qHash(QKeyCombination key, size_t seed = 0) noexcept
+ \relates QKeyCombination
+
+ Returns the hash value for the \a key, using \a seed to seed the calculation.
+*/
+
+#ifndef QT_NO_DEBUG_STREAM
+/*!
+ \fn QDebug operator<<(QDebug debug, QKeyCombination combination)
+ \relates QKeyCombination
+
+ Writes the combination \a combination into the debug object \a debug for
+ debugging purposes.
+
+ \sa {Debugging Techniques}
+*/
+#endif
+
+#ifndef QT_NO_DATASTREAM
+/*!
+ \fn QDataStream &operator<<(QDataStream &out, QKeyCombination combination)
+ \relates QKeyCombination
+
+ Writes the combination \a combination into the stream \a out.
+ Returns \a out.
+
+ \sa {Serializing Qt Data Types}
+*/
+
+/*!
+ \fn QDataStream &operator>>(QDataStream &in, QKeyCombination &combination)
+ \relates QKeyCombination
+
+ Reads the combination \a combination from the stream \a in.
+ Returns \a in.
+
+ \sa {Serializing Qt Data Types}
+*/
+#endif
diff --git a/src/corelib/io/qdebug.h b/src/corelib/io/qdebug.h
index 2463095743..b3787f9e78 100644
--- a/src/corelib/io/qdebug.h
+++ b/src/corelib/io/qdebug.h
@@ -446,6 +446,17 @@ inline QDebug operator<<(QDebug debug, const QFlags<T> &flags)
return qt_QMetaEnum_flagDebugOperator_helper(debug, flags);
}
+inline QDebug operator<<(QDebug debug, QKeyCombination combination)
+{
+ QDebugStateSaver saver(debug);
+ debug.nospace() << "QKeyCombination("
+ << combination.keyboardModifiers()
+ << ", "
+ << combination.key()
+ << ")";
+ return debug;
+}
+
#ifdef Q_OS_MAC
// We provide QDebug stream operators for commonly used Core Foundation
diff --git a/src/corelib/serialization/qdatastream.h b/src/corelib/serialization/qdatastream.h
index 19188c3d91..32ccf7d6cc 100644
--- a/src/corelib/serialization/qdatastream.h
+++ b/src/corelib/serialization/qdatastream.h
@@ -43,6 +43,7 @@
#include <QtCore/qscopedpointer.h>
#include <QtCore/qiodevicebase.h>
#include <QtCore/qcontainerfwd.h>
+#include <QtCore/qnamespace.h>
#ifdef Status
#error qdatastream.h must be included before any header file that defines Status
@@ -510,6 +511,19 @@ inline QDataStreamIfHasOStreamOperators<T1, T2> operator<<(QDataStream& s, const
}
#endif
+inline QDataStream &operator>>(QDataStream &s, QKeyCombination &combination)
+{
+ int combined;
+ s >> combined;
+ combination = QKeyCombination::fromCombined(combined);
+ return s;
+}
+
+inline QDataStream &operator<<(QDataStream &s, QKeyCombination combination)
+{
+ return s << combination.toCombined();
+}
+
#endif // QT_NO_DATASTREAM
QT_END_NAMESPACE
diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h
index 716b81e186..94c6e13b1c 100644
--- a/src/corelib/tools/qhashfunctions.h
+++ b/src/corelib/tools/qhashfunctions.h
@@ -162,6 +162,8 @@ inline Q_DECL_PURE_FUNCTION size_t qHash(const QString &key, size_t seed = 0) no
#endif
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QBitArray &key, size_t seed = 0) noexcept;
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QLatin1String key, size_t seed = 0) noexcept;
+Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(QKeyCombination key, size_t seed = 0) noexcept
+{ return qHash(key.toCombined(), seed); }
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key, uint chained = 0) noexcept;
template<typename T> inline size_t qHash(const T &t, size_t seed)
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp
index 2994bb60cf..4be214ad64 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qkeysequence.cpp
@@ -62,13 +62,15 @@ struct Wrapper : public QWidget
QKeySequence(QKeySequence::Print);
QKeySequence(tr("Ctrl+P"));
QKeySequence(tr("Ctrl+p"));
-QKeySequence(Qt::CTRL + Qt::Key_P);
+QKeySequence(Qt::CTRL | Qt::Key_P);
+QKeySequence(Qt::CTRL + Qt::Key_P); // deprecated
//! [0]
//! [1]
QKeySequence(tr("Ctrl+X, Ctrl+C"));
-QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C);
+QKeySequence(Qt::CTRL | Qt::Key_X, Qt::CTRL | Qt::Key_C);
+QKeySequence(Qt::CTRL + Qt::Key_X, Qt::CTRL + Qt::Key_C); // deprecated
//! [1]
*/ // Wrap non-compilable code snippet
diff --git a/src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp b/src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp
index bac264fcfc..370afd0679 100644
--- a/src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp
+++ b/src/gui/doc/snippets/code/src_gui_kernel_qshortcut.cpp
@@ -60,6 +60,6 @@ setKey(QKeySequence()); // no signal emitted
setKey(0x3b1); // Greek letter alpha
setKey(Qt::Key_D); // 'd', e.g. to delete
setKey('q'); // 'q', e.g. to quit
-setKey(Qt::CTRL + Qt::Key_P); // Ctrl+P, e.g. to print document
+setKey(Qt::CTRL | Qt::Key_P); // Ctrl+P, e.g. to print document
setKey("Ctrl+P"); // Ctrl+P, e.g. to print document
//! [1]
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 1a6a43a4cb..b4880eff53 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -1285,6 +1285,15 @@ Qt::KeyboardModifiers QKeyEvent::modifiers() const
return QInputEvent::modifiers();
}
+/*!
+ \fn QKeyCombination QKeyEvent::keyCombination() const
+
+ Returns a QKeyCombination object containing both the key() and
+ the modifiers() carried by this event.
+
+ \since 6.0
+*/
+
#if QT_CONFIG(shortcut)
/*!
\fn bool QKeyEvent::matches(QKeySequence::StandardKey key) const
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 2c0325296d..c8402b6632 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -480,6 +480,10 @@ public:
bool matches(QKeySequence::StandardKey key) const;
#endif
Qt::KeyboardModifiers modifiers() const;
+ QKeyCombination keyCombination() const
+ {
+ return QKeyCombination(modifiers(), Qt::Key(m_key));
+ }
inline QString text() const { return m_text; }
inline bool isAutoRepeat() const { return m_autoRepeat; }
inline int count() const { return int(m_count); }
diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp
index ebb180dc8e..1af0692173 100644
--- a/src/gui/kernel/qguivariant.cpp
+++ b/src/gui/kernel/qguivariant.cpp
@@ -99,7 +99,6 @@ struct GuiTypesFilter {
};
};
-
static const struct : QMetaTypeModuleHelper
{
#define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \
@@ -146,7 +145,7 @@ static const struct : QMetaTypeModuleHelper
);
QMETATYPE_CONVERTER(QKeySequence, QString, result = source; return true;);
QMETATYPE_CONVERTER(Int, QKeySequence,
- result = source.isEmpty() ? 0 : source[0];
+ result = source.isEmpty() ? 0 : source[0].toCombined();
return true;
);
QMETATYPE_CONVERTER(QKeySequence, Int, result = source; return true;);
diff --git a/src/gui/kernel/qkeymapper.cpp b/src/gui/kernel/qkeymapper.cpp
index f0ea66dc79..89eacc944a 100644
--- a/src/gui/kernel/qkeymapper.cpp
+++ b/src/gui/kernel/qkeymapper.cpp
@@ -71,17 +71,20 @@ QKeyMapper::~QKeyMapper()
{
}
-QList<int> QKeyMapper::possibleKeys(QKeyEvent *e)
+static QList<int> extractKeyFromEvent(QKeyEvent *e)
{
QList<int> result;
+ if (e->key() && (e->key() != Qt::Key_unknown))
+ result << e->keyCombination().toCombined();
+ else if (!e->text().isEmpty())
+ result << int(e->text().at(0).unicode() + (int)e->modifiers());
+ return result;
+}
- if (!e->nativeScanCode()) {
- if (e->key() && (e->key() != Qt::Key_unknown))
- result << int(e->key() + e->modifiers());
- else if (!e->text().isEmpty())
- result << int(e->text().at(0).unicode() + e->modifiers());
- return result;
- }
+QList<int> QKeyMapper::possibleKeys(QKeyEvent *e)
+{
+ if (!e->nativeScanCode())
+ return extractKeyFromEvent(e);
return instance()->d_func()->possibleKeys(e);
}
@@ -132,11 +135,7 @@ QList<int> QKeyMapperPrivate::possibleKeys(QKeyEvent *e)
if (!result.isEmpty())
return result;
- if (e->key() && (e->key() != Qt::Key_unknown))
- result << int(e->key() + e->modifiers());
- else if (!e->text().isEmpty())
- result << int(e->text().at(0).unicode() + e->modifiers());
- return result;
+ return extractKeyFromEvent(e);
}
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp
index 13e6a058cb..5d52ba139d 100644
--- a/src/gui/kernel/qkeysequence.cpp
+++ b/src/gui/kernel/qkeysequence.cpp
@@ -870,6 +870,17 @@ QKeySequence::QKeySequence(int k1, int k2, int k3, int k4)
}
/*!
+ Constructs a key sequence with up to 4 keys \a k1, \a k2,
+ \a k3 and \a k4.
+
+ \sa QKeyCombination
+*/
+QKeySequence::QKeySequence(QKeyCombination k1, QKeyCombination k2, QKeyCombination k3, QKeyCombination k4)
+ : QKeySequence(k1.toCombined(), k2.toCombined(), k3.toCombined(), k4.toCombined())
+{
+}
+
+/*!
Copy constructor. Makes a copy of \a keysequence.
*/
QKeySequence::QKeySequence(const QKeySequence& keysequence)
@@ -908,11 +919,11 @@ QKeySequence::~QKeySequence()
delivery.
*/
-void QKeySequence::setKey(int key, int index)
+void QKeySequence::setKey(QKeyCombination key, int index)
{
Q_ASSERT_X(index >= 0 && index < QKeySequencePrivate::MaxKeyCount, "QKeySequence::setKey", "index out of range");
qAtomicDetach(d);
- d->key[index] = key;
+ d->key[index] = key.toCombined();
}
static_assert(QKeySequencePrivate::MaxKeyCount == 4, "Change docs below");
@@ -967,7 +978,7 @@ QKeySequence QKeySequence::mnemonic(const QString &text)
if (c.isPrint()) {
if (!found) {
c = c.toUpper();
- ret = QKeySequence(c.unicode() + Qt::ALT);
+ ret = QKeySequence(QKeyCombination(Qt::ALT, Qt::Key(c.unicode())));
#ifdef QT_NO_DEBUG
return ret;
#else
@@ -1377,8 +1388,8 @@ QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const
SequenceMatch match = (userN == seqN ? ExactMatch : PartialMatch);
for (uint i = 0; i < userN; ++i) {
- int userKey = (*this)[i],
- sequenceKey = seq[i];
+ QKeyCombination userKey = (*this)[i],
+ sequenceKey = seq[i];
if (userKey != sequenceKey)
return NoMatch;
}
@@ -1397,10 +1408,10 @@ QKeySequence::operator QVariant() const
Returns a reference to the element at position \a index in the key
sequence. This can only be used to read an element.
*/
-int QKeySequence::operator[](uint index) const
+QKeyCombination QKeySequence::operator[](uint index) const
{
Q_ASSERT_X(index < QKeySequencePrivate::MaxKeyCount, "QKeySequence::operator[]", "index out of range");
- return d->key[index];
+ return QKeyCombination::fromCombined(d->key[index]);
}
diff --git a/src/gui/kernel/qkeysequence.h b/src/gui/kernel/qkeysequence.h
index 8b7ff12bed..880d0a581a 100644
--- a/src/gui/kernel/qkeysequence.h
+++ b/src/gui/kernel/qkeysequence.h
@@ -155,6 +155,10 @@ public:
QKeySequence();
QKeySequence(const QString &key, SequenceFormat format = NativeText);
QKeySequence(int k1, int k2 = 0, int k3 = 0, int k4 = 0);
+ QKeySequence(QKeyCombination k1,
+ QKeyCombination k2 = QKeyCombination::fromCombined(0),
+ QKeyCombination k3 = QKeyCombination::fromCombined(0),
+ QKeyCombination k4 = QKeyCombination::fromCombined(0));
QKeySequence(const QKeySequence &ks);
QKeySequence(StandardKey key);
~QKeySequence();
@@ -179,7 +183,7 @@ public:
static QList<QKeySequence> keyBindings(StandardKey key);
operator QVariant() const;
- int operator[](uint i) const;
+ QKeyCombination operator[](uint i) const;
QKeySequence &operator=(const QKeySequence &other);
QKeySequence &operator=(QKeySequence &&other) noexcept { swap(other); return *this; }
void swap(QKeySequence &other) noexcept { qSwap(d, other.d); }
@@ -201,7 +205,7 @@ private:
static QString encodeString(int key);
int assign(const QString &str);
int assign(const QString &str, SequenceFormat format);
- void setKey(int key, int index);
+ void setKey(QKeyCombination key, int index);
QKeySequencePrivate *d;
diff --git a/src/gui/kernel/qkeysequence_p.h b/src/gui/kernel/qkeysequence_p.h
index 8c59505561..99d17e98d1 100644
--- a/src/gui/kernel/qkeysequence_p.h
+++ b/src/gui/kernel/qkeysequence_p.h
@@ -64,7 +64,7 @@ struct QKeyBinding
{
QKeySequence::StandardKey standardKey;
uchar priority;
- uint shortcut;
+ QKeyCombination shortcut;
uint platform;
};
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp
index 81c897def7..5de1c98127 100644
--- a/src/gui/kernel/qplatformtheme.cpp
+++ b/src/gui/kernel/qplatformtheme.cpp
@@ -645,7 +645,7 @@ QList<QKeySequence> QPlatformTheme::keyBindings(QKeySequence::StandardKey key) c
if (!(it->platform & platform))
continue;
- uint shortcut = it->shortcut;
+ uint shortcut = it->shortcut.toCombined();
if (it->priority > 0)
list.prepend(QKeySequence(shortcut));
diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp
index 4b6368a749..e79aaacd1a 100644
--- a/src/gui/kernel/qshortcutmap.cpp
+++ b/src/gui/kernel/qshortcutmap.cpp
@@ -543,12 +543,12 @@ void QShortcutMap::createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, in
curKsl.setKey(curSeq[2], 2);
curKsl.setKey(curSeq[3], 3);
} else {
- curKsl.setKey(0, 0);
- curKsl.setKey(0, 1);
- curKsl.setKey(0, 2);
- curKsl.setKey(0, 3);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 0);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 1);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 2);
+ curKsl.setKey(QKeyCombination::fromCombined(0), 3);
}
- curKsl.setKey(possibleKeys.at(pkNum) & ~ignoredModifiers, index);
+ curKsl.setKey(QKeyCombination::fromCombined(possibleKeys.at(pkNum) & ~ignoredModifiers), index);
}
}
}
@@ -574,8 +574,8 @@ QKeySequence::SequenceMatch QShortcutMap::matches(const QKeySequence &seq1,
: QKeySequence::PartialMatch);
for (uint i = 0; i < userN; ++i) {
- int userKey = seq1[i],
- sequenceKey = seq2[i];
+ int userKey = seq1[i].toCombined(),
+ sequenceKey = seq2[i].toCombined();
if ((userKey & Qt::Key_unknown) == Qt::Key_hyphen)
userKey = (userKey & Qt::KeyboardModifierMask) | Qt::Key_Minus;
if ((sequenceKey & Qt::Key_unknown) == Qt::Key_hyphen)
diff --git a/src/gui/platform/unix/dbusmenu/qdbusmenutypes.cpp b/src/gui/platform/unix/dbusmenu/qdbusmenutypes.cpp
index 73ff0aee69..c5bc4a1889 100644
--- a/src/gui/platform/unix/dbusmenu/qdbusmenutypes.cpp
+++ b/src/gui/platform/unix/dbusmenu/qdbusmenutypes.cpp
@@ -241,7 +241,7 @@ QDBusMenuShortcut QDBusMenuItem::convertKeySequence(const QKeySequence &sequence
QDBusMenuShortcut shortcut;
for (int i = 0; i < sequence.count(); ++i) {
QStringList tokens;
- int key = sequence[i];
+ int key = sequence[i].toCombined();
if (key & Qt::MetaModifier)
tokens << QStringLiteral("Super");
if (key & Qt::ControlModifier)
diff --git a/src/gui/platform/unix/qxkbcommon.cpp b/src/gui/platform/unix/qxkbcommon.cpp
index ff19ebd5d5..71f1cfd24a 100644
--- a/src/gui/platform/unix/qxkbcommon.cpp
+++ b/src/gui/platform/unix/qxkbcommon.cpp
@@ -656,7 +656,7 @@ QList<int> QXkbCommon::possibleKeys(xkb_state *state, const QKeyEvent *event,
int baseQtKey = keysymToQtKey_internal(sym, modifiers, queryState, keycode, superAsMeta, hyperAsMeta);
if (baseQtKey)
- result += (baseQtKey + modifiers);
+ result += (baseQtKey + int(modifiers));
xkb_mod_index_t shiftMod = xkb_keymap_mod_get_index(keymap, "Shift");
xkb_mod_index_t altMod = xkb_keymap_mod_get_index(keymap, "Alt");
@@ -711,7 +711,7 @@ QList<int> QXkbCommon::possibleKeys(xkb_state *state, const QKeyEvent *event,
if (ambiguous)
continue;
- result += (qtKey + mods);
+ result += (qtKey + int(mods));
}
}
diff --git a/src/testlib/qtestkeyboard.h b/src/testlib/qtestkeyboard.h
index 1882c858c1..deee6da753 100644
--- a/src/testlib/qtestkeyboard.h
+++ b/src/testlib/qtestkeyboard.h
@@ -172,8 +172,8 @@ namespace QTest
Q_DECL_UNUSED inline static void keySequence(QWindow *window, const QKeySequence &keySequence)
{
for (int i = 0; i < keySequence.count(); ++i) {
- const Qt::Key key = Qt::Key(keySequence[i] & ~Qt::KeyboardModifierMask);
- const Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(keySequence[i] & Qt::KeyboardModifierMask);
+ const Qt::Key key = keySequence[i].key();
+ const Qt::KeyboardModifiers modifiers = keySequence[i].keyboardModifiers();
keyClick(window, key, modifiers);
}
}
@@ -313,8 +313,8 @@ namespace QTest
inline static void keySequence(QWidget *widget, const QKeySequence &keySequence)
{
for (int i = 0; i < keySequence.count(); ++i) {
- const Qt::Key key = Qt::Key(keySequence[i] & ~Qt::KeyboardModifierMask);
- const Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(keySequence[i] & Qt::KeyboardModifierMask);
+ const Qt::Key key = keySequence[i].key();
+ const Qt::KeyboardModifiers modifiers = keySequence[i].keyboardModifiers();
keyClick(widget, key, modifiers);
}
}
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
index 81e182c352..c4df58b6aa 100644
--- a/src/widgets/dialogs/qfiledialog.cpp
+++ b/src/widgets/dialogs/qfiledialog.cpp
@@ -3287,7 +3287,7 @@ void QFileDialogPrivate::createMenuActions()
QAction *goHomeAction = new QAction(q);
#ifndef QT_NO_SHORTCUT
- goHomeAction->setShortcut(Qt::CTRL + Qt::Key_H + Qt::SHIFT);
+ goHomeAction->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_H);
#endif
QObject::connect(goHomeAction, SIGNAL(triggered()), q, SLOT(_q_goHome()));
q->addAction(goHomeAction);
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index 4183098274..566263f1e0 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -1522,7 +1522,7 @@ void QMessageBox::keyPressEvent(QKeyEvent *e)
const QList<QAbstractButton *> buttons = d->buttonBox->buttons();
for (auto *pb : buttons) {
QKeySequence shortcut = pb->shortcut();
- if (!shortcut.isEmpty() && key == int(shortcut[0] & ~Qt::MODIFIER_MASK)) {
+ if (!shortcut.isEmpty() && key == shortcut[0].key()) {
pb->animateClick();
return;
}
diff --git a/src/widgets/kernel/qwhatsthis.cpp b/src/widgets/kernel/qwhatsthis.cpp
index 7ca50f9dab..b483655a71 100644
--- a/src/widgets/kernel/qwhatsthis.cpp
+++ b/src/widgets/kernel/qwhatsthis.cpp
@@ -510,7 +510,7 @@ QWhatsThisAction::QWhatsThisAction(QObject *parent) : QAction(tr("What's This?")
setCheckable(true);
connect(this, SIGNAL(triggered()), this, SLOT(actionTriggered()));
#ifndef QT_NO_SHORTCUT
- setShortcut(Qt::ShiftModifier + Qt::Key_F1);
+ setShortcut(Qt::ShiftModifier | Qt::Key_F1);
#endif
}
diff --git a/src/widgets/widgets/qkeysequenceedit.cpp b/src/widgets/widgets/qkeysequenceedit.cpp
index a38250c195..97ee915037 100644
--- a/src/widgets/widgets/qkeysequenceedit.cpp
+++ b/src/widgets/widgets/qkeysequenceedit.cpp
@@ -63,7 +63,7 @@ void QKeySequenceEditPrivate::init()
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(lineEdit);
- key[0] = key[1] = key[2] = key[3] = 0;
+ std::fill_n(key, QKeySequencePrivate::MaxKeyCount, QKeyCombination::fromCombined(0));
lineEdit->setFocusProxy(q);
lineEdit->installEventFilter(q);
@@ -186,7 +186,7 @@ void QKeySequenceEdit::setKeySequence(const QKeySequence &keySequence)
d->keySequence = keySequence;
- d->key[0] = d->key[1] = d->key[2] = d->key[3] = 0;
+ d->key[0] = d->key[1] = d->key[2] = d->key[3] = QKeyCombination::fromCombined(0);
d->keyNum = keySequence.count();
for (int i = 0; i < d->keyNum; ++i)
d->key[i] = keySequence[i];
@@ -286,7 +286,7 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)
}
- d->key[d->keyNum] = nextKey;
+ d->key[d->keyNum] = QKeyCombination::fromCombined(nextKey);
d->keyNum++;
QKeySequence key(d->key[0], d->key[1], d->key[2], d->key[3]);
diff --git a/src/widgets/widgets/qkeysequenceedit_p.h b/src/widgets/widgets/qkeysequenceedit_p.h
index 7af034e735..8cd58de68f 100644
--- a/src/widgets/widgets/qkeysequenceedit_p.h
+++ b/src/widgets/widgets/qkeysequenceedit_p.h
@@ -76,7 +76,7 @@ public:
QLineEdit *lineEdit;
QKeySequence keySequence;
int keyNum;
- int key[QKeySequencePrivate::MaxKeyCount];
+ QKeyCombination key[QKeySequencePrivate::MaxKeyCount];
int prevKey;
int releaseTimer;
};
diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp
index c2ef383d28..9007d2af78 100644
--- a/src/widgets/widgets/qmenu.cpp
+++ b/src/widgets/widgets/qmenu.cpp
@@ -3406,7 +3406,7 @@ void QMenu::keyPressEvent(QKeyEvent *e)
continue;
QAction *act = d->actions.at(i);
QKeySequence sequence = QKeySequence::mnemonic(act->text());
- int key = sequence[0] & 0xffff;
+ int key = sequence[0].toCombined() & 0xffff; // suspicious
if (key == c.unicode()) {
clashCount++;
if (!first)