diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index a28c5959ce..202ad6cc11 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -570,42 +570,43 @@ static QTouchDevice *touchDevice = 0; return qtMods; } -- (void)handleKeyEvent:(NSEvent *)theEvent eventType:(int)eventType +- (void)handleKeyEvent:(NSEvent *)nsevent eventType:(int)eventType { - NSTimeInterval timestamp = [theEvent timestamp]; + NSTimeInterval timestamp = [nsevent timestamp]; ulong qt_timestamp = timestamp * 1000; - QString characters = QString::fromUtf8([[theEvent characters] UTF8String]); - Qt::KeyboardModifiers modifiers = [self convertKeyModifiers : [theEvent modifierFlags]]; - QChar ch([[theEvent charactersIgnoringModifiers] characterAtIndex:0]); - int keyCode = [self convertKeyCode : ch]; + QString characters = QString::fromUtf8([[nsevent characters] UTF8String]); + Qt::KeyboardModifiers modifiers = [self convertKeyModifiers:[nsevent modifierFlags]]; + QChar ch([[nsevent charactersIgnoringModifiers] characterAtIndex:0]); + int keyCode = [self convertKeyCode:ch]; - QWindowSystemInterface::handleKeyEvent(m_window, qt_timestamp, QEvent::Type(eventType), keyCode, modifiers, characters); -} + if (eventType == QEvent::KeyPress) { + if (!m_keyEventsAccepted && m_composingText.isEmpty()) + m_keyEventsAccepted = QWindowSystemInterface::tryHandleSynchronousShortcutEvent(m_window, qt_timestamp, keyCode, modifiers, characters); -- (void)keyDown:(NSEvent *)theEvent -{ - QObject *fo = QGuiApplication::focusObject(); - m_keyEventsAccepted = false; - if (fo) { - QInputMethodQueryEvent queryEvent(Qt::ImHints); - if (QCoreApplication::sendEvent(fo, &queryEvent)) { - Qt::InputMethodHints hints = static_cast(queryEvent.value(Qt::ImHints).toUInt()); - if (!(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText)) { - [self interpretKeyEvents:[NSArray arrayWithObject: theEvent]]; + QObject *fo = QGuiApplication::focusObject(); + if (!m_keyEventsAccepted && fo) { + QInputMethodQueryEvent queryEvent(Qt::ImHints); + if (QCoreApplication::sendEvent(fo, &queryEvent)) { + Qt::InputMethodHints hints = static_cast(queryEvent.value(Qt::ImHints).toUInt()); + if (!(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText)) + [self interpretKeyEvents:[NSArray arrayWithObject:nsevent]]; } } } - if (!m_keyEventsAccepted && m_composingText.isEmpty()) { - [self handleKeyEvent : theEvent eventType :int(QEvent::KeyPress)]; - } + if (!m_keyEventsAccepted && m_composingText.isEmpty()) + QWindowSystemInterface::handleKeyEvent(m_window, qt_timestamp, QEvent::Type(eventType), keyCode, modifiers, characters); } -- (void)keyUp:(NSEvent *)theEvent +- (void)keyDown:(NSEvent *)nsevent { - if (!m_keyEventsAccepted && m_composingText.isEmpty()) { - [self handleKeyEvent : theEvent eventType :int(QEvent::KeyRelease)]; - } + m_keyEventsAccepted = false; + [self handleKeyEvent:nsevent eventType:int(QEvent::KeyPress)]; +} + +- (void)keyUp:(NSEvent *)nsevent +{ + [self handleKeyEvent:nsevent eventType:int(QEvent::KeyRelease)]; } - (void) doCommandBySelector:(SEL)aSelector