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 <marc.mutz@kdab.com>bb10
parent
717724b17a
commit
b169b5a4f3
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue