From 3b188889820462658ac2078c6a41c9f8a6963d48 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 21 Mar 2016 15:44:32 +0100 Subject: [PATCH] QTextEdit: translate IM argument before passing it on to QWidgetTextControl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we now have the possibility of providing an extra position argument when querying for Qt::ImCursorPosition, we need to ensure that we translate it from scroll view to local coordinates before passing it on to QWidgetTextControl. Change-Id: I4383ae3ea984b6140d8e9b4198047aec8b7e100b Reviewed-by: Jan Arve Sæther --- src/widgets/widgets/qplaintextedit.cpp | 20 +++++++++++++++++++- src/widgets/widgets/qtextedit.cpp | 20 +++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qplaintextedit.cpp b/src/widgets/widgets/qplaintextedit.cpp index 17eac9db58..35ec88b881 100644 --- a/src/widgets/widgets/qplaintextedit.cpp +++ b/src/widgets/widgets/qplaintextedit.cpp @@ -2199,8 +2199,26 @@ QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant a Q_D(const QPlainTextEdit); if (query == Qt::ImHints) return QWidget::inputMethodQuery(query); - const QVariant v = d->control->inputMethodQuery(query, argument); + const QPointF offset = contentOffset(); + switch (argument.type()) { + case QVariant::RectF: + argument = argument.toRectF().translated(-offset); + break; + case QVariant::PointF: + argument = argument.toPointF() - offset; + break; + case QVariant::Rect: + argument = argument.toRect().translated(-offset.toPoint()); + break; + case QVariant::Point: + argument = argument.toPoint() - offset; + break; + default: + break; + } + + const QVariant v = d->control->inputMethodQuery(query, argument); switch (v.type()) { case QVariant::RectF: return v.toRectF().translated(offset); diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 1dd774cf7a..68b6ea6cbe 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -1729,8 +1729,26 @@ QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery query, QVariant argume Q_D(const QTextEdit); if (query == Qt::ImHints) return QWidget::inputMethodQuery(query); - const QVariant v = d->control->inputMethodQuery(query, argument); + const QPointF offset(-d->horizontalOffset(), -d->verticalOffset()); + switch (argument.type()) { + case QVariant::RectF: + argument = argument.toRectF().translated(-offset); + break; + case QVariant::PointF: + argument = argument.toPointF() - offset; + break; + case QVariant::Rect: + argument = argument.toRect().translated(-offset.toPoint()); + break; + case QVariant::Point: + argument = argument.toPoint() - offset; + break; + default: + break; + } + + const QVariant v = d->control->inputMethodQuery(query, argument); switch (v.type()) { case QVariant::RectF: return v.toRectF().translated(offset);