From b169b5a4f36c4c8bd0acb5d91dec2e5d3f1e056d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 23 Mar 2016 14:44:31 +0100 Subject: [PATCH] QPlainTextEdit: Take vertical offset into account when answering input method queries. Determine offset point to similar to QTextEdit::inputMethodQuery() and add an autotest. Task-number: QTBUG-51923 Change-Id: I8232eb348063e2cd95d0632fe74a6eb30c897eda Reviewed-by: Marc Mutz --- src/widgets/widgets/qplaintextedit.cpp | 10 +++++----- .../widgets/qplaintextedit/tst_qplaintextedit.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 91788a3383..bb933362da 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2198,15 +2198,15 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery property, QVarian break; default: v = d->control->inputMethodQuery(property, argument); - const QPoint offset(-d->horizontalOffset(), -0); + const QPointF offset = contentOffset(); if (v.type() == QVariant::RectF) - v = v.toRectF().toRect().translated(offset); + v = v.toRectF().translated(offset); else if (v.type() == QVariant::PointF) - v = v.toPointF().toPoint() + offset; + v = v.toPointF() + offset; else if (v.type() == QVariant::Rect) - v = v.toRect().translated(offset); + v = v.toRect().translated(offset.toPoint()); else if (v.type() == QVariant::Point) - v = v.toPoint() + offset; + v = v.toPoint() + offset.toPoint(); } return v; diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp index 2145260013..d466489acb 100644 --- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp +++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp @@ -154,6 +154,7 @@ private slots: #ifndef QT_NO_CONTEXTMENU void contextMenu(); #endif + void inputMethodCursorRect(); private: void createSelection(); @@ -1727,5 +1728,17 @@ void tst_QPlainTextEdit::contextMenu() } #endif // QT_NO_CONTEXTMENU +// QTBUG-51923: Verify that the cursor rectangle returned by the input +// method query correctly reflects the viewport offset. +void tst_QPlainTextEdit::inputMethodCursorRect() +{ + ed->setPlainText("Line1\nLine2Line3\nLine3"); + ed->moveCursor(QTextCursor::End); + const QRectF cursorRect = ed->cursorRect(); + const QVariant cursorRectV = ed->inputMethodQuery(Qt::ImCursorRectangle); + QCOMPARE(cursorRectV.type(), QVariant::RectF); + QCOMPARE(cursorRectV.toRect(), cursorRect.toRect()); +} + QTEST_MAIN(tst_QPlainTextEdit) #include "tst_qplaintextedit.moc"