XCB/Input methods: Implement IBus HidePreeditText and ShowPreeditText

IBus engines that call HidePreeditText() or ShowPreeditText() not work
correctly on Qt5 because the ibus platforminputcontext plugin does not
implement this functions.

Patch-By: Fuminobu Takeyama
Task-number: QTBUG-48412
Change-Id: I936d4c46518b5bee7c5ad2b03d8c24202ab1074e
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Takao Fujiwara <takao.fujiwara1@gmail.com>
bb10
Sebastian Sauer 2016-11-23 20:59:11 +01:00 committed by Takao Fujiwara
parent aa4e6345bb
commit 5a918ad866
2 changed files with 33 additions and 3 deletions

View File

@ -90,6 +90,7 @@ public:
bool valid;
bool busConnected;
QString predit;
QList<QInputMethodEvent::Attribute> attributes;
bool needsSurroundingText;
QLocale locale;
};
@ -154,6 +155,7 @@ void QIBusPlatformInputContext::reset()
d->context->Reset();
d->predit = QString();
d->attributes.clear();
}
void QIBusPlatformInputContext::commit()
@ -166,6 +168,7 @@ void QIBusPlatformInputContext::commit()
QObject *input = qApp->focusObject();
if (!input) {
d->predit = QString();
d->attributes.clear();
return;
}
@ -177,6 +180,7 @@ void QIBusPlatformInputContext::commit()
d->context->Reset();
d->predit = QString();
d->attributes.clear();
}
@ -263,6 +267,7 @@ void QIBusPlatformInputContext::commitText(const QDBusVariant &text)
QCoreApplication::sendEvent(input, &event);
d->predit = QString();
d->attributes.clear();
}
void QIBusPlatformInputContext::updatePreeditText(const QDBusVariant &text, uint cursorPos, bool visible)
@ -281,11 +286,11 @@ void QIBusPlatformInputContext::updatePreeditText(const QDBusVariant &text, uint
if (debug)
qDebug() << "preedit text:" << t.text;
QList<QInputMethodEvent::Attribute> attributes = t.attributes.imAttributes();
d->attributes = t.attributes.imAttributes();
if (!t.text.isEmpty())
attributes += QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPos, visible ? 1 : 0);
d->attributes += QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPos, visible ? 1 : 0, QVariant());
QInputMethodEvent event(t.text, attributes);
QInputMethodEvent event(t.text, d->attributes);
QCoreApplication::sendEvent(input, &event);
d->predit = t.text;
@ -313,6 +318,27 @@ void QIBusPlatformInputContext::deleteSurroundingText(int offset, uint n_chars)
QCoreApplication::sendEvent(input, &event);
}
void QIBusPlatformInputContext::hidePreeditText()
{
QObject *input = QGuiApplication::focusObject();
if (!input)
return;
QList<QInputMethodEvent::Attribute> attributes;
QInputMethodEvent event(QString(), attributes);
QCoreApplication::sendEvent(input, &event);
}
void QIBusPlatformInputContext::showPreeditText()
{
QObject *input = QGuiApplication::focusObject();
if (!input)
return;
QInputMethodEvent event(d->predit, d->attributes);
QCoreApplication::sendEvent(input, &event);
}
bool QIBusPlatformInputContext::filterEvent(const QEvent *event)
{
if (!d->busConnected)
@ -487,6 +513,8 @@ void QIBusPlatformInputContext::connectToContextSignals()
connect(d->context, SIGNAL(UpdatePreeditText(QDBusVariant,uint,bool)), this, SLOT(updatePreeditText(QDBusVariant,uint,bool)));
connect(d->context, SIGNAL(DeleteSurroundingText(int,uint)), this, SLOT(deleteSurroundingText(int,uint)));
connect(d->context, SIGNAL(RequireSurroundingText()), this, SLOT(surroundingTextRequired()));
connect(d->context, SIGNAL(HidePreeditText()), this, SLOT(hidePreeditText()));
connect(d->context, SIGNAL(ShowPreeditText()), this, SLOT(showPreeditText()));
}
}

View File

@ -102,6 +102,8 @@ public Q_SLOTS:
void cursorRectChanged();
void deleteSurroundingText(int offset, uint n_chars);
void surroundingTextRequired();
void hidePreeditText();
void showPreeditText();
void filterEventFinished(QDBusPendingCallWatcher *call);
void socketChanged(const QString &str);
void connectToBus();