diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-09-21 00:53:59 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-10-11 01:48:13 +0200 |
commit | f8f5e2c122eeb1dc4d1fc1984e066bc6d9bd07ec (patch) | |
tree | 25ea5c3dd60d2f876a92cd4cd74367da41e18c51 | |
parent | 8af35d27e8f02bbb99aef4ac495ed406e50e3cca (diff) |
Make QKeyMapper::possibleKeys() return list of QKeyCombinations
Having the explicit type instead of the opaque int makes it clearer
what we're dealing with.
Task-number: QTBUG-116873
Change-Id: I19e42ed329e15ab25a958602ecfb99b1c9d52a99
Reviewed-by: Liang Qi <liang.qi@qt.io>
-rw-r--r-- | src/gui/kernel/qkeymapper.cpp | 12 | ||||
-rw-r--r-- | src/gui/kernel/qkeymapper_p.h | 2 | ||||
-rw-r--r-- | src/gui/kernel/qshortcutmap.cpp | 5 | ||||
-rw-r--r-- | src/widgets/widgets/qkeysequenceedit.cpp | 11 |
4 files changed, 14 insertions, 16 deletions
diff --git a/src/gui/kernel/qkeymapper.cpp b/src/gui/kernel/qkeymapper.cpp index bd7dbd90e9..76ec7eba0d 100644 --- a/src/gui/kernel/qkeymapper.cpp +++ b/src/gui/kernel/qkeymapper.cpp @@ -35,21 +35,17 @@ QKeyMapper::~QKeyMapper() { } -QList<int> QKeyMapper::possibleKeys(const QKeyEvent *e) +QList<QKeyCombination> QKeyMapper::possibleKeys(const QKeyEvent *e) { - QList<int> result; - const auto *platformIntegration = QGuiApplicationPrivate::platformIntegration(); const auto *platformKeyMapper = platformIntegration->keyMapper(); - const auto keyCombinations = platformKeyMapper->possibleKeyCombinations(e); - for (auto keyCombination : keyCombinations) - result << keyCombination.toCombined(); + QList<QKeyCombination> result = platformKeyMapper->possibleKeyCombinations(e); if (result.isEmpty()) { if (e->key() && (e->key() != Qt::Key_unknown)) - result << e->keyCombination().toCombined(); + result << e->keyCombination(); else if (!e->text().isEmpty()) - result << int(e->text().at(0).unicode() + (int)e->modifiers()); + result << (Qt::Key(e->text().at(0).unicode()) | e->modifiers()); } return result; diff --git a/src/gui/kernel/qkeymapper_p.h b/src/gui/kernel/qkeymapper_p.h index 5c6f89ab82..1a6a9a608f 100644 --- a/src/gui/kernel/qkeymapper_p.h +++ b/src/gui/kernel/qkeymapper_p.h @@ -33,7 +33,7 @@ public: ~QKeyMapper(); static QKeyMapper *instance(); - static QList<int> possibleKeys(const QKeyEvent *e); + static QList<QKeyCombination> possibleKeys(const QKeyEvent *e); QT_DECLARE_NATIVE_INTERFACE_ACCESSOR(QKeyMapper) diff --git a/src/gui/kernel/qshortcutmap.cpp b/src/gui/kernel/qshortcutmap.cpp index a2acf467e1..800e703ac2 100644 --- a/src/gui/kernel/qshortcutmap.cpp +++ b/src/gui/kernel/qshortcutmap.cpp @@ -493,7 +493,7 @@ void QShortcutMap::clearSequence(QList<QKeySequence> &ksl) void QShortcutMap::createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, int ignoredModifiers) { Q_D(QShortcutMap); - QList<int> possibleKeys = QKeyMapper::possibleKeys(e); + QList<QKeyCombination> possibleKeys = QKeyMapper::possibleKeys(e); qCDebug(lcShortcutMap) << "Creating new sequences for" << e << "with ignoredModifiers=" << Qt::KeyboardModifiers(ignoredModifiers); int pkTotal = possibleKeys.size(); @@ -522,7 +522,8 @@ void QShortcutMap::createNewSequences(QKeyEvent *e, QList<QKeySequence> &ksl, in curKsl.setKey(QKeyCombination::fromCombined(0), 2); curKsl.setKey(QKeyCombination::fromCombined(0), 3); } - curKsl.setKey(QKeyCombination::fromCombined(possibleKeys.at(pkNum) & ~ignoredModifiers), index); + const int key = possibleKeys.at(pkNum).toCombined(); + curKsl.setKey(QKeyCombination::fromCombined(key & ~ignoredModifiers), index); } } } diff --git a/src/widgets/widgets/qkeysequenceedit.cpp b/src/widgets/widgets/qkeysequenceedit.cpp index 0b39d5c1c6..65ed7a465a 100644 --- a/src/widgets/widgets/qkeysequenceedit.cpp +++ b/src/widgets/widgets/qkeysequenceedit.cpp @@ -344,22 +344,23 @@ void QKeySequenceEdit::keyPressEvent(QKeyEvent *e) return; if (e->modifiers() & Qt::ShiftModifier) { - const QList<int> possibleKeys = QKeyMapper::possibleKeys(e); + const QList<QKeyCombination> possibleKeys = QKeyMapper::possibleKeys(e); int pkTotal = possibleKeys.size(); if (!pkTotal) return; bool found = false; for (int i = 0; i < possibleKeys.size(); ++i) { - if (possibleKeys.at(i) - nextKey == int(e->modifiers()) - || (possibleKeys.at(i) == nextKey && e->modifiers() == Qt::ShiftModifier)) { - nextKey = possibleKeys.at(i); + const int key = possibleKeys.at(i).toCombined(); + if (key - nextKey == int(e->modifiers()) + || (key == nextKey && e->modifiers() == Qt::ShiftModifier)) { + nextKey = key; found = true; break; } } // Use as fallback if (!found) - nextKey = possibleKeys.first(); + nextKey = possibleKeys.first().toCombined(); } else { nextKey |= d->translateModifiers(e->modifiers(), e->text()); } |