From 667652ddca50c8bd3d39a42ca3042eac1070b5b4 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 5 Aug 2011 10:25:58 +0200 Subject: [PATCH] Ported use of QInputContext to QPlatformInputContext for now MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I2e0e62cffd04c3a096d1402028a9be92d8b0a27c Reviewed-on: http://codereview.qt.nokia.com/2677 Reviewed-by: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/declarative/items/qsgcanvas.cpp | 40 +++++++++++++++++++++++++--------- src/declarative/items/qsgcanvas_p.h | 3 +++ src/declarative/items/qsgitem.cpp | 17 +++++---------- src/declarative/items/qsgtextedit.cpp | 20 +++++++---------- src/declarative/items/qsgtextinput.cpp | 11 ++++------ 5 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 4f76184..4257650 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -50,12 +50,14 @@ #include #include +#include +#include + #include #include #include #include -#include #include #include @@ -253,6 +255,27 @@ bool QSGCanvas::vsyncAnimations() const return d->vsyncAnimations; } +/*! + This function is an attempt to localize all uses of QInputContext::update in + one place up until the point where we have public API for the QInputContext API. + */ +void QSGCanvasPrivate::updateInputContext() +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->update(); +} +/*! + This function is an attempt to localize all uses of QInputContext::reset in + one place up until the point where we have public API for the QInputContext API. + */ +void QSGCanvasPrivate::resetInputContext() +{ + QPlatformInputContext *ic = QGuiApplicationPrivate::platformIntegration()->inputContext(); + if (ic) + ic->reset(); +} + void QSGCanvasPrivate::initializeSceneGraph() { @@ -350,11 +373,14 @@ void QSGCanvasPrivate::init(QSGCanvas *c) Q_Q(QSGCanvas); rootItem = new QSGRootItem; - rootItem->setFocus(true); QSGItemPrivate *rootItemPrivate = QSGItemPrivate::get(rootItem); rootItemPrivate->canvas = q; rootItemPrivate->flags |= QSGItem::ItemIsFocusScope; + // QML always has focus. It is important that this call happens after the rootItem + // has a canvas.. + rootItem->setFocus(true); + thread = new QSGCanvasRenderThread; thread->renderer = q; thread->d = this; @@ -516,10 +542,7 @@ void QSGCanvasPrivate::setFocusInScope(QSGItem *scope, QSGItem *item, FocusOptio if (oldActiveFocusItem) { #ifndef QT_NO_IM - // ### refactor: port properly... - qDebug("QSGCanvas: input context resetting is not implemented"); -// if (QInputContext *ic = inputContext()) -// ic->reset(); + resetInputContext(); #endif activeFocusItem = 0; @@ -628,10 +651,7 @@ void QSGCanvasPrivate::clearFocusInScope(QSGItem *scope, QSGItem *item, FocusOpt Q_ASSERT(oldActiveFocusItem); #ifndef QT_NO_IM - // ### refactor: port properly - qDebug("QSGCanvas: clear focus in scope, not implemented"); -// if (QInputContext *ic = inputContext()) -// ic->reset(); + resetInputContext(); #endif activeFocusItem = 0; diff --git a/src/declarative/items/qsgcanvas_p.h b/src/declarative/items/qsgcanvas_p.h index b147bb3..bb2c0f8 100644 --- a/src/declarative/items/qsgcanvas_p.h +++ b/src/declarative/items/qsgcanvas_p.h @@ -143,6 +143,9 @@ public: void syncSceneGraph(); void renderSceneGraph(const QSize &size); + void updateInputContext(); + void resetInputContext(); + QSGItem::UpdatePaintNodeData updatePaintNodeData; QSGItem *dirtyItemList; diff --git a/src/declarative/items/qsgitem.cpp b/src/declarative/items/qsgitem.cpp index cf521d9..6769489 100644 --- a/src/declarative/items/qsgitem.cpp +++ b/src/declarative/items/qsgitem.cpp @@ -53,7 +53,6 @@ #include #include #include -#include #include #include #include @@ -1723,12 +1722,10 @@ void QSGItem::setInputMethodHints(Qt::InputMethodHints hints) if (!d->canvas || d->canvas->activeFocusItem() != this) return; - QSGCanvasPrivate::get(d->canvas)->updateInputMethodData(); + QSGCanvasPrivate *cd = QSGCanvasPrivate::get(d->canvas); + cd->updateInputMethodData(); #ifndef QT_NO_IM - // ### refactor: port properly - qDebug("QSGItem: setInputMethodHints: not implemented"); -// if (QInputContext *inputContext = d->canvas->inputContext()) -// inputContext->update(); + cd->updateInputContext(); #endif } @@ -1736,12 +1733,8 @@ void QSGItem::updateMicroFocus() { #ifndef QT_NO_IM Q_D(QSGItem); - if (d->canvas) { - // ### refactor: port properly - qDebug("QSGItem: setInputMethodHints: not implemented"); - // if (QInputContext *inputContext = d->canvas->inputContext()) - // inputContext->update(); - } + if (d->canvas) + QSGCanvasPrivate::get(d->canvas)->updateInputContext(); #endif } diff --git a/src/declarative/items/qsgtextedit.cpp b/src/declarative/items/qsgtextedit.cpp index 6c529db..4ba5bec 100644 --- a/src/declarative/items/qsgtextedit.cpp +++ b/src/declarative/items/qsgtextedit.cpp @@ -1193,24 +1193,20 @@ void QSGTextEditPrivate::updateDefaultTextOption() void QSGTextEdit::openSoftwareInputPanel() { if (qApp) { - // ### refactor:port properly - qDebug("QSGTextEdit: opening of virtual keyboard not implemented"); -// if (canvas() && canvas() == qApp->focusWidget()) { -// QEvent event(QEvent::RequestSoftwareInputPanel); -// QApplication::sendEvent(canvas(), &event); -// } + if (canvas()) { + QEvent event(QEvent::RequestSoftwareInputPanel); + QApplication::sendEvent(canvas(), &event); + } } } void QSGTextEdit::closeSoftwareInputPanel() { if (qApp) { - // ### refactor: port properly - qDebug("QSGTextEdit: closing of virtual keyboard not implemented..."); -// if (canvas() && canvas() == qApp->focusWidget()) { -// QEvent event(QEvent::CloseSoftwareInputPanel); -// QApplication::sendEvent(canvas(), &event); -// } + if (canvas()) { + QEvent event(QEvent::CloseSoftwareInputPanel); + QApplication::sendEvent(canvas(), &event); + } } } diff --git a/src/declarative/items/qsgtextinput.cpp b/src/declarative/items/qsgtextinput.cpp index d55bdc8..405540d 100644 --- a/src/declarative/items/qsgtextinput.cpp +++ b/src/declarative/items/qsgtextinput.cpp @@ -1056,9 +1056,8 @@ void QSGTextInput::moveCursorSelection(int pos, SelectionMode mode) void QSGTextInput::openSoftwareInputPanel() { - QEvent event(QEvent::RequestSoftwareInputPanel); if (qApp) { - if (canvas() && canvas() == QGuiApplication::activeWindow()) { + if (canvas()) { QEvent event(QEvent::RequestSoftwareInputPanel); QApplication::sendEvent(canvas(), &event); } @@ -1068,11 +1067,9 @@ void QSGTextInput::openSoftwareInputPanel() void QSGTextInput::closeSoftwareInputPanel() { if (qApp) { - if (canvas() && canvas() == QGuiApplication::activeWindow()) { - // ### refactor: port properly - qDebug("QSGTextInput: closing virtual keyboard not implemented"); -// QEvent event(QEvent::CloseSoftwareInputPanel); -// QApplication::sendEvent(canvas(), &event); + if (canvas()) { + QEvent event(QEvent::CloseSoftwareInputPanel); + QApplication::sendEvent(canvas(), &event); } } } -- 2.7.4