QTextEdit::inputMethodQuery(): Preserve types when applying offset.
The old code converted QRectF into QRect when applying the offset. Change the offset point to QPointF and change the conversions accordingly. Add an autotest similar to that of QPlainTextEdit. This minimizes rounding errors and prevents conversions since the input method logic mostly uses qreal. Task-number: QTBUG-51923 Change-Id: I0c2f80ccae028d8bbbb97ec603f8782f69959c76 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>bb10
parent
c35795b413
commit
086317d72a
|
|
@ -1726,15 +1726,15 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume
|
|||
break;
|
||||
default:
|
||||
v = d->control->inputMethodQuery(query, argument);
|
||||
const QPoint offset(-d->horizontalOffset(), -d->verticalOffset());
|
||||
const QPointF offset(-d->horizontalOffset(), -d->verticalOffset());
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -191,6 +191,7 @@ private slots:
|
|||
void inputMethodQuery();
|
||||
void inputMethodQueryImHints_data();
|
||||
void inputMethodQueryImHints();
|
||||
void inputMethodCursorRect();
|
||||
|
||||
void highlightLongLine();
|
||||
|
||||
|
|
@ -2473,6 +2474,18 @@ void tst_QTextEdit::inputMethodQueryImHints()
|
|||
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
|
||||
}
|
||||
|
||||
// QTBUG-51923: Verify that the cursor rectangle returned by the input
|
||||
// method query correctly reflects the viewport offset.
|
||||
void tst_QTextEdit::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());
|
||||
}
|
||||
|
||||
void tst_QTextEdit::highlightLongLine()
|
||||
{
|
||||
QTextEdit edit;
|
||||
|
|
|
|||
Loading…
Reference in New Issue