diff --git a/src/gui/platform/darwin/qapplekeymapper.mm b/src/gui/platform/darwin/qapplekeymapper.mm index 1238104186..7aefe64c6a 100644 --- a/src/gui/platform/darwin/qapplekeymapper.mm +++ b/src/gui/platform/darwin/qapplekeymapper.mm @@ -383,7 +383,7 @@ Qt::Key QAppleKeyMapper::fromCocoaKey(QChar keyCode) // ------------------------------------------------ -Qt::KeyboardModifiers QAppleKeyMapper::queryKeyboardModifiers() +Qt::KeyboardModifiers QAppleKeyMapper::queryKeyboardModifiers() const { return fromCocoaModifiers(NSEvent.modifierFlags); } @@ -537,9 +537,9 @@ const QAppleKeyMapper::KeyMap &QAppleKeyMapper::keyMapForKey(VirtualKeyCode virt where each modifier-key combination has been mapped to the key it will produce. */ -QList QAppleKeyMapper::possibleKeys(const QKeyEvent *event) const +QList QAppleKeyMapper::possibleKeyCombinations(const QKeyEvent *event) const { - QList ret; + QList ret; qCDebug(lcQpaKeyMapper) << "Computing possible keys for" << event; @@ -557,7 +557,7 @@ QList QAppleKeyMapper::possibleKeys(const QKeyEvent *event) const // The complete set of event modifiers, along with the // unmodified key, is always a valid key combination, // and the first priority. - ret << int(eventModifiers) + int(unmodifiedKey); + ret << QKeyCombination::fromCombined(int(eventModifiers) + int(unmodifiedKey)); // FIXME: We only compute the first 8 combinations. Why? for (int i = 1; i < 8; ++i) { @@ -574,14 +574,14 @@ QList QAppleKeyMapper::possibleKeys(const QKeyEvent *event) const // If the event includes more modifiers than the candidate they // will need to be included in the resulting key combination. auto additionalModifiers = eventModifiers & ~candidateModifiers; - ret << int(additionalModifiers) + int(keyAfterApplyingModifiers); + ret << QKeyCombination::fromCombined( + int(additionalModifiers) + int(keyAfterApplyingModifiers)); } } if (lcQpaKeyMapper().isDebugEnabled()) { qCDebug(lcQpaKeyMapper) << "Possible keys:"; - for (int keyAndModifiers : ret) { - auto keyCombination = QKeyCombination::fromCombined(keyAndModifiers); + for (auto keyCombination : ret) { auto keySequence = QKeySequence(keyCombination); qCDebug(lcQpaKeyMapper).verbosity(0) << "\t-" << keyCombination << "/" << keySequence << "/" diff --git a/src/gui/platform/darwin/qapplekeymapper_p.h b/src/gui/platform/darwin/qapplekeymapper_p.h index 0f096e9537..910990eabb 100644 --- a/src/gui/platform/darwin/qapplekeymapper_p.h +++ b/src/gui/platform/darwin/qapplekeymapper_p.h @@ -29,11 +29,12 @@ QT_BEGIN_NAMESPACE -class Q_GUI_EXPORT QAppleKeyMapper +class Q_GUI_EXPORT QAppleKeyMapper : public QPlatformKeyMapper { public: - static Qt::KeyboardModifiers queryKeyboardModifiers(); - QList possibleKeys(const QKeyEvent *event) const; + Qt::KeyboardModifiers queryKeyboardModifiers() const override; + QList possibleKeyCombinations(const QKeyEvent *event) const override; + static Qt::Key fromNSString(Qt::KeyboardModifiers qtMods, NSString *characters, NSString *charactersIgnoringModifiers, QString &text); #ifdef Q_OS_MACOS diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index 09904efbaf..664700cf51 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -84,8 +84,7 @@ public: QCocoaServices *services() const override; QVariant styleHint(StyleHint hint) const override; - Qt::KeyboardModifiers queryKeyboardModifiers() const override; - QList possibleKeys(const QKeyEvent *event) const override; + QPlatformKeyMapper *keyMapper() const override; void setApplicationIcon(const QIcon &icon) const override; void setApplicationBadge(qint64 number) override; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 86b4206094..1e609026cf 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -400,14 +400,9 @@ QVariant QCocoaIntegration::styleHint(StyleHint hint) const return QPlatformIntegration::styleHint(hint); } -Qt::KeyboardModifiers QCocoaIntegration::queryKeyboardModifiers() const +QPlatformKeyMapper *QCocoaIntegration::keyMapper() const { - return QAppleKeyMapper::queryKeyboardModifiers(); -} - -QList QCocoaIntegration::possibleKeys(const QKeyEvent *event) const -{ - return mKeyboardMapper->possibleKeys(event); + return mKeyboardMapper.data(); } void QCocoaIntegration::setApplicationIcon(const QIcon &icon) const