iOS: Pass the text to handleExtendedKeyEvent when known

This will ensure that the QKeyEvent also has this information passed on
as appropriate.

Change-Id: I52436404115b453664b9b3414f8ec4e715dd6a28
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 5540c9c10754963375cd34f740e64b068c440a3e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Andy Shaw 2021-02-05 11:59:02 +01:00 committed by Qt Cherry-pick Bot
parent a363e1e8ea
commit 7f22edc00c
3 changed files with 13 additions and 6 deletions

View File

@ -74,7 +74,7 @@ static Qt::KeyboardModifiers swapModifiersIfNeeded(const Qt::KeyboardModifiers m
} }
Qt::Key QAppleKeyMapper::fromNSString(Qt::KeyboardModifiers qtModifiers, NSString *characters, Qt::Key QAppleKeyMapper::fromNSString(Qt::KeyboardModifiers qtModifiers, NSString *characters,
NSString *charactersIgnoringModifiers) NSString *charactersIgnoringModifiers, QString &text)
{ {
if ([characters isEqualToString:@"\t"]) { if ([characters isEqualToString:@"\t"]) {
if (qtModifiers & Qt::ShiftModifier) if (qtModifiers & Qt::ShiftModifier)
@ -93,6 +93,10 @@ Qt::Key QAppleKeyMapper::fromNSString(Qt::KeyboardModifiers qtModifiers, NSStrin
} else if ([characters length] != 0) { } else if ([characters length] != 0) {
ch = QChar([characters characterAtIndex:0]); ch = QChar([characters characterAtIndex:0]);
} }
if (!(qtModifiers & (Qt::ControlModifier | Qt::MetaModifier)) &&
(ch.unicode() < 0xf700 || ch.unicode() > 0xf8ff)) {
text = QString::fromNSString(characters);
}
if (!ch.isNull()) if (!ch.isNull())
return Qt::Key(ch.toUpper().unicode()); return Qt::Key(ch.toUpper().unicode());
} }

View File

@ -57,7 +57,7 @@ public:
static Qt::KeyboardModifiers queryKeyboardModifiers(); static Qt::KeyboardModifiers queryKeyboardModifiers();
QList<int> possibleKeys(const QKeyEvent *event) const; QList<int> possibleKeys(const QKeyEvent *event) const;
static Qt::Key fromNSString(Qt::KeyboardModifiers qtMods, NSString *characters, static Qt::Key fromNSString(Qt::KeyboardModifiers qtMods, NSString *characters,
NSString *charactersIgnoringModifiers); NSString *charactersIgnoringModifiers, QString &text);
#ifdef Q_OS_MACOS #ifdef Q_OS_MACOS
static Qt::KeyboardModifiers fromCocoaModifiers(NSEventModifierFlags cocoaModifiers); static Qt::KeyboardModifiers fromCocoaModifiers(NSEventModifierFlags cocoaModifiers);
static NSEventModifierFlags toCocoaModifiers(Qt::KeyboardModifiers); static NSEventModifierFlags toCocoaModifiers(Qt::KeyboardModifiers);

View File

@ -574,7 +574,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
QWindowSystemInterface::handleTouchCancelEvent(self.platformWindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice()); QWindowSystemInterface::handleTouchCancelEvent(self.platformWindow->window(), ulong(timestamp * 1000), iosIntegration->touchDevice());
} }
- (int)mapPressTypeToKey:(UIPress*)press withModifiers:(Qt::KeyboardModifiers)qtModifiers - (int)mapPressTypeToKey:(UIPress*)press withModifiers:(Qt::KeyboardModifiers)qtModifiers text:(QString &)text
{ {
switch (press.type) { switch (press.type) {
case UIPressTypeUpArrow: return Qt::Key_Up; case UIPressTypeUpArrow: return Qt::Key_Up;
@ -592,7 +592,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
if (key != Qt::Key_unknown) if (key != Qt::Key_unknown)
return key; return key;
return QAppleKeyMapper::fromNSString(qtModifiers, press.key.characters, return QAppleKeyMapper::fromNSString(qtModifiers, press.key.characters,
charactersIgnoringModifiers); charactersIgnoringModifiers, text);
} }
#endif #endif
return Qt::Key_unknown; return Qt::Key_unknown;
@ -611,11 +611,14 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet")
if (@available(ios 13.4, *)) if (@available(ios 13.4, *))
qtModifiers = QAppleKeyMapper::fromUIKitModifiers(press.key.modifierFlags); qtModifiers = QAppleKeyMapper::fromUIKitModifiers(press.key.modifierFlags);
#endif #endif
int key = [self mapPressTypeToKey:press withModifiers:qtModifiers]; QString text;
int key = [self mapPressTypeToKey:press withModifiers:qtModifiers text:text];
if (key == Qt::Key_unknown) if (key == Qt::Key_unknown)
continue; continue;
if (QWindowSystemInterface::handleKeyEvent(self.platformWindow->window(), type, key, qtModifiers)) if (QWindowSystemInterface::handleKeyEvent(self.platformWindow->window(), type, key,
qtModifiers, text)) {
handled = true; handled = true;
}
} }
return handled; return handled;