Check if Qt::ImEnabled is true before handling im events on Mac
Key events were not sent to items on graphics view after the change
412dbdf410
. This is because the change
only checks if QGuiApplication::focusObject() exists. Qt::ImEnabled
needs to be checked too.
Change-Id: I2a78af717a7a1a5d84fbc8b521253bdc25b43286
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
This commit is contained in:
parent
fd379ae7d3
commit
68f44a7f98
@ -59,7 +59,8 @@ public:
|
|||||||
virtual void reset();
|
virtual void reset();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void inputItemChanged();
|
void connectSignals();
|
||||||
|
void focusObjectChanged(QObject *focusObject);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<QWindow> mWindow;
|
QPointer<QWindow> mWindow;
|
||||||
|
@ -83,7 +83,7 @@ QCocoaInputContext::QCocoaInputContext()
|
|||||||
: QPlatformInputContext()
|
: QPlatformInputContext()
|
||||||
, mWindow(QGuiApplication::focusWindow())
|
, mWindow(QGuiApplication::focusWindow())
|
||||||
{
|
{
|
||||||
connect(qApp->inputMethod(), SIGNAL(inputItemChanged()), this, SLOT(inputItemChanged()));
|
QMetaObject::invokeMethod(this, "connectSignals", Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
QCocoaInputContext::~QCocoaInputContext()
|
QCocoaInputContext::~QCocoaInputContext()
|
||||||
@ -114,7 +114,13 @@ void QCocoaInputContext::reset()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCocoaInputContext::inputItemChanged()
|
void QCocoaInputContext::connectSignals()
|
||||||
|
{
|
||||||
|
connect(qApp, SIGNAL(focusObjectChanged(QObject*)), this, SLOT(focusObjectChanged(QObject*)));
|
||||||
|
focusObjectChanged(qApp->focusObject());
|
||||||
|
}
|
||||||
|
|
||||||
|
void QCocoaInputContext::focusObjectChanged(QObject *focusObject)
|
||||||
{
|
{
|
||||||
mWindow = QGuiApplication::focusWindow();
|
mWindow = QGuiApplication::focusWindow();
|
||||||
}
|
}
|
||||||
|
@ -614,10 +614,11 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
|
|
||||||
QObject *fo = QGuiApplication::focusObject();
|
QObject *fo = QGuiApplication::focusObject();
|
||||||
if (!m_keyEventsAccepted && fo) {
|
if (!m_keyEventsAccepted && fo) {
|
||||||
QInputMethodQueryEvent queryEvent(Qt::ImHints);
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImHints);
|
||||||
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
|
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
|
||||||
|
bool imEnabled = queryEvent.value(Qt::ImEnabled).toBool();
|
||||||
Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(queryEvent.value(Qt::ImHints).toUInt());
|
Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(queryEvent.value(Qt::ImHints).toUInt());
|
||||||
if (!(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText))
|
if (imEnabled && !(hints & Qt::ImhDigitsOnly || hints & Qt::ImhFormattedNumbersOnly || hints & Qt::ImhHiddenText))
|
||||||
[self interpretKeyEvents:[NSArray arrayWithObject:nsevent]];
|
[self interpretKeyEvents:[NSArray arrayWithObject:nsevent]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -654,10 +655,15 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
}
|
}
|
||||||
QObject *fo = QGuiApplication::focusObject();
|
QObject *fo = QGuiApplication::focusObject();
|
||||||
if (fo) {
|
if (fo) {
|
||||||
QInputMethodEvent e;
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
|
||||||
e.setCommitString(commitString);
|
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
|
||||||
QCoreApplication::sendEvent(fo, &e);
|
if (queryEvent.value(Qt::ImEnabled).toBool()) {
|
||||||
m_keyEventsAccepted = true;
|
QInputMethodEvent e;
|
||||||
|
e.setCommitString(commitString);
|
||||||
|
QCoreApplication::sendEvent(fo, &e);
|
||||||
|
m_keyEventsAccepted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_composingText.clear();
|
m_composingText.clear();
|
||||||
@ -715,9 +721,14 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
|
|
||||||
QObject *fo = QGuiApplication::focusObject();
|
QObject *fo = QGuiApplication::focusObject();
|
||||||
if (fo) {
|
if (fo) {
|
||||||
QInputMethodEvent e(preeditString, attrs);
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
|
||||||
QCoreApplication::sendEvent(fo, &e);
|
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
|
||||||
m_keyEventsAccepted = true;
|
if (queryEvent.value(Qt::ImEnabled).toBool()) {
|
||||||
|
QInputMethodEvent e(preeditString, attrs);
|
||||||
|
QCoreApplication::sendEvent(fo, &e);
|
||||||
|
m_keyEventsAccepted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,9 +737,14 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
if (!m_composingText.isEmpty()) {
|
if (!m_composingText.isEmpty()) {
|
||||||
QObject *fo = QGuiApplication::focusObject();
|
QObject *fo = QGuiApplication::focusObject();
|
||||||
if (fo) {
|
if (fo) {
|
||||||
QInputMethodEvent e;
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
|
||||||
e.setCommitString(m_composingText);
|
if (QCoreApplication::sendEvent(fo, &queryEvent)) {
|
||||||
QCoreApplication::sendEvent(fo, &e);
|
if (queryEvent.value(Qt::ImEnabled).toBool()) {
|
||||||
|
QInputMethodEvent e;
|
||||||
|
e.setCommitString(m_composingText);
|
||||||
|
QCoreApplication::sendEvent(fo, &e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_composingText.clear();
|
m_composingText.clear();
|
||||||
@ -749,9 +765,11 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
QObject *fo = QGuiApplication::focusObject();
|
QObject *fo = QGuiApplication::focusObject();
|
||||||
if (!fo)
|
if (!fo)
|
||||||
return nil;
|
return nil;
|
||||||
QInputMethodQueryEvent queryEvent(Qt::ImCurrentSelection);
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImCurrentSelection);
|
||||||
if (!QCoreApplication::sendEvent(fo, &queryEvent))
|
if (!QCoreApplication::sendEvent(fo, &queryEvent))
|
||||||
return nil;
|
return nil;
|
||||||
|
if (!queryEvent.value(Qt::ImEnabled).toBool())
|
||||||
|
return nil;
|
||||||
|
|
||||||
QString selectedText = queryEvent.value(Qt::ImCurrentSelection).toString();
|
QString selectedText = queryEvent.value(Qt::ImCurrentSelection).toString();
|
||||||
if (selectedText.isEmpty())
|
if (selectedText.isEmpty())
|
||||||
@ -785,9 +803,12 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
QObject *fo = QGuiApplication::focusObject();
|
QObject *fo = QGuiApplication::focusObject();
|
||||||
if (!fo)
|
if (!fo)
|
||||||
return selRange;
|
return selRange;
|
||||||
QInputMethodQueryEvent queryEvent(Qt::ImCurrentSelection);
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImCurrentSelection);
|
||||||
if (!QCoreApplication::sendEvent(fo, &queryEvent))
|
if (!QCoreApplication::sendEvent(fo, &queryEvent))
|
||||||
return selRange;
|
return selRange;
|
||||||
|
if (!queryEvent.value(Qt::ImEnabled).toBool())
|
||||||
|
return selRange;
|
||||||
|
|
||||||
QString selectedText = queryEvent.value(Qt::ImCurrentSelection).toString();
|
QString selectedText = queryEvent.value(Qt::ImCurrentSelection).toString();
|
||||||
|
|
||||||
if (!selectedText.isEmpty()) {
|
if (!selectedText.isEmpty()) {
|
||||||
@ -804,6 +825,12 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
if (!fo)
|
if (!fo)
|
||||||
return NSZeroRect;
|
return NSZeroRect;
|
||||||
|
|
||||||
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
|
||||||
|
if (!QCoreApplication::sendEvent(fo, &queryEvent))
|
||||||
|
return NSZeroRect;
|
||||||
|
if (!queryEvent.value(Qt::ImEnabled).toBool())
|
||||||
|
return NSZeroRect;
|
||||||
|
|
||||||
if (!m_window)
|
if (!m_window)
|
||||||
return NSZeroRect;
|
return NSZeroRect;
|
||||||
|
|
||||||
@ -828,10 +855,19 @@ static QTouchDevice *touchDevice = 0;
|
|||||||
|
|
||||||
- (NSArray*) validAttributesForMarkedText
|
- (NSArray*) validAttributesForMarkedText
|
||||||
{
|
{
|
||||||
|
if (m_window != QGuiApplication::focusWindow())
|
||||||
|
return nil;
|
||||||
|
|
||||||
QObject *fo = QGuiApplication::focusObject();
|
QObject *fo = QGuiApplication::focusObject();
|
||||||
if (!fo)
|
if (!fo)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
|
QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
|
||||||
|
if (!QCoreApplication::sendEvent(fo, &queryEvent))
|
||||||
|
return nil;
|
||||||
|
if (!queryEvent.value(Qt::ImEnabled).toBool())
|
||||||
|
return nil;
|
||||||
|
|
||||||
// Support only underline color/style.
|
// Support only underline color/style.
|
||||||
return [NSArray arrayWithObjects:NSUnderlineColorAttributeName,
|
return [NSArray arrayWithObjects:NSUnderlineColorAttributeName,
|
||||||
NSUnderlineStyleAttributeName, nil];
|
NSUnderlineStyleAttributeName, nil];
|
||||||
|
Loading…
Reference in New Issue
Block a user