Start using the QInputPanel instead of the QPlatformInputContext.
Make sure we do something with both QInputMethodEvent and
QInputMethodQueryEvent. This gets input methods partially
working on TextInput fields.
Change-Id: I4655f5599673325ffb75207573635afccd069a65
Reviewed-on: http://codereview.qt-project.org/4404
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Vesa Rantanen <vesa.rantanen@nokia.com>
Reviewed-by: Andy Nichols
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
#include <private/qsgflashnode_p.h>
#include <private/qguiapplication_p.h>
-#include <QtGui/QPlatformInputContext>
+#include <QtGui/QInputPanel>
#include <private/qabstractanimation_p.h>
*/
void QSGCanvasPrivate::updateInputContext()
{
- QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext();
- if (ic)
- ic->update();
+ // ### finer grained updates would be good
+ qApp->inputPanel()->update(Qt::ImQueryAll);
}
/*!
This function is an attempt to localize all uses of QInputContext::reset in
*/
void QSGCanvasPrivate::resetInputContext()
{
- QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext();
- if (ic)
- ic->reset();
+ qApp->inputPanel()->reset();
}
void QSGCanvasPrivate::updateInputMethodData()
{
- // Q_Q(QSGCanvas);
- // ### refactor: port..
-// bool enabled = activeFocusItem
-// && (QSGItemPrivate::get(activeFocusItem)->flags & QSGItem::ItemAcceptsInputMethod);
-// q->setAttribute(Qt::WA_InputMethodEnabled, enabled);
-// q->setInputMethodHints(enabled ? activeFocusItem->inputMethodHints() : Qt::ImhNone);
+ qApp->inputPanel()->setInputItem(activeFocusItem);
+ qApp->inputPanel()->setInputItemTranform(QSGItemPrivate::get(activeFocusItem)->itemToCanvasTransform());
}
QVariant QSGCanvas::inputMethodQuery(Qt::InputMethodQuery query) const
#include <QtDeclarative/qdeclarativeinfo.h>
#include <QtGui/qpen.h>
#include <QtGui/qcursor.h>
+#include <QtGui/qguiapplication.h>
+#include <QtGui/qinputpanel.h>
#include <QtCore/qdebug.h>
#include <QtCore/qcoreevent.h>
#include <QtCore/qnumeric.h>
if (!d->canvas || d->canvas->activeFocusItem() != this)
return;
- QSGCanvasPrivate *cd = QSGCanvasPrivate::get(d->canvas);
- cd->updateInputMethodData();
-#ifndef QT_NO_IM
- cd->updateInputContext();
-#endif
+ QInputPanel *p = qApp->inputPanel();
+ if (p->inputItem() == this)
+ qApp->inputPanel()->update(Qt::ImHints);
}
void QSGItem::updateMicroFocus()
{
-#ifndef QT_NO_IM
- Q_D(QSGItem);
- if (d->canvas)
- QSGCanvasPrivate::get(d->canvas)->updateInputContext();
-#endif
+ QInputPanel *p = qApp->inputPanel();
+ if (p->inputItem() == this)
+ qApp->inputPanel()->update(Qt::ImMicroFocus);
}
QVariant QSGItem::inputMethodQuery(Qt::InputMethodQuery query) const
Q_D(const QSGItem);
QVariant v;
- if (d->keyHandler)
- v = d->keyHandler->inputMethodQuery(query);
+ switch (query) {
+ case Qt::ImEnabled:
+ v = (bool)(flags() & ItemAcceptsInputMethod);
+ break;
+ case Qt::ImHints:
+ v = (int)inputMethodHints();
+ break;
+ case Qt::ImMicroFocus:
+ case Qt::ImFont:
+ case Qt::ImCursorPosition:
+ case Qt::ImSurroundingText:
+ case Qt::ImCurrentSelection:
+ case Qt::ImMaximumTextLength:
+ case Qt::ImAnchorPosition:
+ case Qt::ImPreferredLanguage:
+ if (d->keyHandler)
+ v = d->keyHandler->inputMethodQuery(query);
+ default:
+ break;
+ }
return v;
}
bool QSGItem::event(QEvent *ev)
{
- return QObject::event(ev);
-
#if 0
if (ev->type() == QEvent::PolishRequest) {
Q_D(QSGItem);
return QObject::event(ev);
}
#endif
+ if (ev->type() == QEvent::InputMethodQuery) {
+ QInputMethodQueryEvent *query = static_cast<QInputMethodQueryEvent *>(ev);
+ query->setValue(inputMethodQuery(query->query()));
+ ev->accept();
+ return true;
+ } else if (ev->type() == QEvent::InputMethod) {
+ inputMethodEvent(static_cast<QInputMethodEvent *>(ev));
+ return true;
+ }
+ return QObject::event(ev);
}
#ifndef QT_NO_DEBUG_STREAM
#include <qsgtextnode_p.h>
#include <qsgsimplerectnode.h>
-#include <QtGui/qplatforminputcontext_qpa.h>
-#include <private/qguiapplication_p.h>
#include <QtGui/qstylehints.h>
+#include <QtGui/qinputpanel.h>
QT_BEGIN_NAMESPACE
bool QSGTextInputPrivate::sendMouseEventToInputContext(QMouseEvent *event)
{
#if !defined QT_NO_IM
- if (control->composeMode()) {
+ if (control->composeMode() && event->type() == QEvent::KeyRelease) {
int tmp_cursor = xToPos(event->localPos().x());
int mousePos = tmp_cursor - control->cursor();
if (mousePos < 0 || mousePos > control->preeditAreaText().length()) {
return true;
}
- QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext();
- if (ic)
- // may be causing reset() in some input methods
- ic->mouseHandler(mousePos, event);
+ // may be causing reset() in some input methods
+ qApp->inputPanel()->invokeAction(QInputPanel::Click, mousePos);
if (!control->preeditAreaText().isEmpty())
return true;
}