From: Joona Petrell Date: Fri, 18 Nov 2011 11:19:09 +0000 (+0200) Subject: Get rid of unused inputMethodQuery and inputMethodEvent functions in QQuickCanvas X-Git-Tag: qt-v5.0.0-alpha1~1038 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5aad0f5da641d778958a4127f33cbd9943e6a6c5;p=profile%2Fivi%2Fqtdeclarative.git Get rid of unused inputMethodQuery and inputMethodEvent functions in QQuickCanvas * in Qt5 input method events and queries are meant to be sent directly to QInputPanel::inputItem() instead of the focused QWindow * protected inputMethodEvent was actually never called by QWindow::event() like it called other specialized event functions Change-Id: I68cced106808098c320841d6a17a0cc170a8369f Reviewed-by: Lars Knoll --- diff --git a/src/declarative/items/qquickcanvas.cpp b/src/declarative/items/qquickcanvas.cpp index 765f9ec..c699a76 100644 --- a/src/declarative/items/qquickcanvas.cpp +++ b/src/declarative/items/qquickcanvas.cpp @@ -805,28 +805,6 @@ void QQuickCanvasPrivate::updateInputMethodData() qApp->inputPanel()->setInputItem(inputItem); } -/*! - Queries the Input Method. -*/ -QVariant QQuickCanvas::inputMethodQuery(Qt::InputMethodQuery query) const -{ - Q_D(const QQuickCanvas); - if (!d->activeFocusItem || !(QQuickItemPrivate::get(d->activeFocusItem)->flags & QQuickItem::ItemAcceptsInputMethod)) - return QVariant(); - QVariant value = d->activeFocusItem->inputMethodQuery(query); - - //map geometry types - QVariant::Type type = value.type(); - if (type == QVariant::RectF || type == QVariant::Rect) { - const QTransform transform = QQuickItemPrivate::get(d->activeFocusItem)->itemToCanvasTransform(); - value = transform.mapRect(value.toRectF()); - } else if (type == QVariant::PointF || type == QVariant::Point) { - const QTransform transform = QQuickItemPrivate::get(d->activeFocusItem)->itemToCanvasTransform(); - value = transform.map(value.toPointF()); - } - return value; -} - void QQuickCanvasPrivate::dirtyItem(QQuickItem *) { Q_Q(QQuickCanvas); @@ -998,14 +976,6 @@ void QQuickCanvas::keyReleaseEvent(QKeyEvent *e) sendEvent(d->activeFocusItem, e); } -void QQuickCanvas::inputMethodEvent(QInputMethodEvent *e) -{ - Q_D(QQuickCanvas); - - if (d->activeFocusItem) - sendEvent(d->activeFocusItem, e); -} - bool QQuickCanvasPrivate::deliverInitialMousePressEvent(QQuickItem *item, QMouseEvent *event) { Q_Q(QQuickCanvas); @@ -1591,14 +1561,6 @@ bool QQuickCanvas::sendEvent(QQuickItem *item, QEvent *e) QQuickItemPrivate::get(item)->deliverKeyEvent(static_cast(e)); } break; - case QEvent::InputMethod: - e->accept(); - QQuickItemPrivate::get(item)->deliverInputMethodEvent(static_cast(e)); - while (!e->isAccepted() && (item = item->parentItem())) { - e->accept(); - QQuickItemPrivate::get(item)->deliverInputMethodEvent(static_cast(e)); - } - break; case QEvent::FocusIn: case QEvent::FocusOut: QQuickItemPrivate::get(item)->deliverFocusEvent(static_cast(e)); diff --git a/src/declarative/items/qquickcanvas.h b/src/declarative/items/qquickcanvas.h index bf8693a..83e3087 100644 --- a/src/declarative/items/qquickcanvas.h +++ b/src/declarative/items/qquickcanvas.h @@ -85,8 +85,6 @@ public: bool sendEvent(QQuickItem *, QEvent *); - QVariant inputMethodQuery(Qt::InputMethodQuery query) const; - QSGEngine *sceneGraphEngine() const; void setVSyncAnimations(bool enabled); @@ -132,7 +130,6 @@ protected: virtual bool event(QEvent *); virtual void keyPressEvent(QKeyEvent *); virtual void keyReleaseEvent(QKeyEvent *); - virtual void inputMethodEvent(QInputMethodEvent *); virtual void mousePressEvent(QMouseEvent *); virtual void mouseReleaseEvent(QMouseEvent *); virtual void mouseDoubleClickEvent(QMouseEvent *); diff --git a/tests/auto/declarative/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/declarative/qquicktextedit/tst_qquicktextedit.cpp index 9efb734..ca585a4 100644 --- a/tests/auto/declarative/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/declarative/qquicktextedit/tst_qquicktextedit.cpp @@ -2320,24 +2320,39 @@ void tst_qquicktextedit::inputMethodComposing() void tst_qquicktextedit::cursorRectangleSize() { - QQuickView *canvas = new QQuickView(QUrl::fromLocalFile(TESTDATA("CursorRect.qml"))); + QQuickView *canvas = new QQuickView(QUrl::fromLocalFile(TESTDATA("positionAt.qml"))); QVERIFY(canvas->rootObject() != 0); + QQuickTextEdit *textEdit = qobject_cast(canvas->rootObject()); + + // make sure cursor rectangle is not at (0,0) + textEdit->setX(10); + textEdit->setY(10); + textEdit->setCursorPosition(3); + QVERIFY(textEdit != 0); + textEdit->setFocus(true); canvas->show(); canvas->requestActivateWindow(); QTest::qWaitForWindowShown(canvas); - QQuickTextEdit *textEdit = qobject_cast(canvas->rootObject()); - QVERIFY(textEdit != 0); - textEdit->setFocus(Qt::OtherFocusReason); - QRectF cursorRect = textEdit->positionToRectangle(textEdit->cursorPosition()); - QRectF microFocusFromScene = canvas->inputMethodQuery(Qt::ImCursorRectangle).toRectF(); QInputMethodQueryEvent event(Qt::ImCursorRectangle); qApp->sendEvent(qApp->inputPanel()->inputItem(), &event); + QRectF cursorRectFromQuery = event.value(Qt::ImCursorRectangle).toRectF(); + + QRect cursorRectFromItem = textEdit->cursorRectangle(); + QRectF cursorRectFromPositionToRectangle = textEdit->positionToRectangle(textEdit->cursorPosition()); + + // item and input query cursor rectangles match + QCOMPARE(cursorRectFromItem, cursorRectFromQuery.toRect()); + + // item cursor rectangle and positionToRectangle calculations match + QCOMPARE(cursorRectFromItem, cursorRectFromPositionToRectangle.toRect()); - QRectF microFocusFromApp = event.value(Qt::ImCursorRectangle).toRectF(); + // item-canvas transform and input item transform match + QCOMPARE(QQuickItemPrivate::get(textEdit)->itemToCanvasTransform(), qApp->inputPanel()->inputItemTransform()); - QCOMPARE(microFocusFromScene.size(), cursorRect.size()); - QCOMPARE(microFocusFromApp.size(), cursorRect.size()); + // input panel cursorRectangle property and tranformed item cursor rectangle match + QRectF sceneCursorRect = QQuickItemPrivate::get(textEdit)->itemToCanvasTransform().mapRect(cursorRectFromItem); + QCOMPARE(sceneCursorRect, qApp->inputPanel()->cursorRectangle()); delete canvas; } diff --git a/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp index 434c63a..7c794d6 100644 --- a/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp @@ -2553,22 +2553,37 @@ void tst_qquicktextinput::cursorRectangleSize() { QQuickView *canvas = new QQuickView(QUrl::fromLocalFile(TESTDATA("positionAt.qml"))); QVERIFY(canvas->rootObject() != 0); + QQuickTextInput *textInput = qobject_cast(canvas->rootObject()); + + // make sure cursor rectangle is not at (0,0) + textInput->setX(10); + textInput->setY(10); + textInput->setCursorPosition(3); + QVERIFY(textInput != 0); + textInput->setFocus(true); canvas->show(); canvas->requestActivateWindow(); QTest::qWaitForWindowShown(canvas); - QQuickTextInput *textInput = qobject_cast(canvas->rootObject()); - QVERIFY(textInput != 0); - textInput->setFocus(Qt::OtherFocusReason); - QRectF cursorRect = textInput->positionToRectangle(textInput->cursorPosition()); - QRectF microFocusFromScene = canvas->inputMethodQuery(Qt::ImCursorRectangle).toRectF(); QInputMethodQueryEvent event(Qt::ImCursorRectangle); qApp->sendEvent(qApp->inputPanel()->inputItem(), &event); + QRectF cursorRectFromQuery = event.value(Qt::ImCursorRectangle).toRectF(); + + QRect cursorRectFromItem = textInput->cursorRectangle(); + QRectF cursorRectFromPositionToRectangle = textInput->positionToRectangle(textInput->cursorPosition()); + + // item and input query cursor rectangles match + QCOMPARE(cursorRectFromItem, cursorRectFromQuery.toRect()); + + // item cursor rectangle and positionToRectangle calculations match + QCOMPARE(cursorRectFromItem, cursorRectFromPositionToRectangle.toRect()); - QRectF microFocusFromApp = event.value(Qt::ImCursorRectangle).toRectF(); + // item-canvas transform and input item transform match + QCOMPARE(QQuickItemPrivate::get(textInput)->itemToCanvasTransform(), qApp->inputPanel()->inputItemTransform()); - QCOMPARE(microFocusFromScene.size(), cursorRect.size()); - QCOMPARE(microFocusFromApp.size(), cursorRect.size()); + // input panel cursorRectangle property and tranformed item cursor rectangle match + QRectF sceneCursorRect = QQuickItemPrivate::get(textInput)->itemToCanvasTransform().mapRect(cursorRectFromItem); + QCOMPARE(sceneCursorRect, qApp->inputPanel()->cursorRectangle()); delete canvas; }