Implement QAppleKeyMapper in terms of QPlatformKeyMapper

Change-Id: Icef9cbe2cbb50c856496d7d9a20784d94d66a079
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2023-09-21 01:03:18 +02:00
parent 09953c4332
commit 097037d2a0
4 changed files with 14 additions and 19 deletions

View File

@ -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<int> QAppleKeyMapper::possibleKeys(const QKeyEvent *event) const
QList<QKeyCombination> QAppleKeyMapper::possibleKeyCombinations(const QKeyEvent *event) const
{
QList<int> ret;
QList<QKeyCombination> ret;
qCDebug(lcQpaKeyMapper) << "Computing possible keys for" << event;
@ -557,7 +557,7 @@ QList<int> 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<int> 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 << "/"

View File

@ -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<int> possibleKeys(const QKeyEvent *event) const;
Qt::KeyboardModifiers queryKeyboardModifiers() const override;
QList<QKeyCombination> possibleKeyCombinations(const QKeyEvent *event) const override;
static Qt::Key fromNSString(Qt::KeyboardModifiers qtMods, NSString *characters,
NSString *charactersIgnoringModifiers, QString &text);
#ifdef Q_OS_MACOS

View File

@ -84,8 +84,7 @@ public:
QCocoaServices *services() const override;
QVariant styleHint(StyleHint hint) const override;
Qt::KeyboardModifiers queryKeyboardModifiers() const override;
QList<int> possibleKeys(const QKeyEvent *event) const override;
QPlatformKeyMapper *keyMapper() const override;
void setApplicationIcon(const QIcon &icon) const override;
void setApplicationBadge(qint64 number) override;

View File

@ -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<int> QCocoaIntegration::possibleKeys(const QKeyEvent *event) const
{
return mKeyboardMapper->possibleKeys(event);
return mKeyboardMapper.data();
}
void QCocoaIntegration::setApplicationIcon(const QIcon &icon) const