Fixed inputMethodQuery() for Qt::ImHints

to return QWidget::inputMethodHints()

Change-Id: I46735c553e0cb4689cd0c53a69d07ed61ba56bf6
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
This commit is contained in:
Tasuku Suzuki 2012-05-22 08:14:34 +09:00 committed by Qt by Nokia
parent 0a6dc44f24
commit 197b145a23
4 changed files with 77 additions and 20 deletions

View File

@ -2127,16 +2127,24 @@ void QPlainTextEdit::scrollContentsBy(int dx, int /*dy*/)
QVariant QPlainTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const
{
Q_D(const QPlainTextEdit);
QVariant v = d->control->inputMethodQuery(property);
const QPoint offset(-d->horizontalOffset(), -0);
if (v.type() == QVariant::RectF)
v = v.toRectF().toRect().translated(offset);
else if (v.type() == QVariant::PointF)
v = v.toPointF().toPoint() + offset;
else if (v.type() == QVariant::Rect)
v = v.toRect().translated(offset);
else if (v.type() == QVariant::Point)
v = v.toPoint() + offset;
QVariant v;
switch (property) {
case Qt::ImHints:
v = QWidget::inputMethodQuery(property);
break;
default:
v = d->control->inputMethodQuery(property);
const QPoint offset(-d->horizontalOffset(), -0);
if (v.type() == QVariant::RectF)
v = v.toRectF().toRect().translated(offset);
else if (v.type() == QVariant::PointF)
v = v.toPointF().toPoint() + offset;
else if (v.type() == QVariant::Rect)
v = v.toRect().translated(offset);
else if (v.type() == QVariant::Point)
v = v.toPoint() + offset;
}
return v;
}

View File

@ -1665,16 +1665,24 @@ void QTextEdit::scrollContentsBy(int dx, int dy)
QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const
{
Q_D(const QTextEdit);
QVariant v = d->control->inputMethodQuery(property);
const QPoint offset(-d->horizontalOffset(), -d->verticalOffset());
if (v.type() == QVariant::RectF)
v = v.toRectF().toRect().translated(offset);
else if (v.type() == QVariant::PointF)
v = v.toPointF().toPoint() + offset;
else if (v.type() == QVariant::Rect)
v = v.toRect().translated(offset);
else if (v.type() == QVariant::Point)
v = v.toPoint() + offset;
QVariant v;
switch (property) {
case Qt::ImHints:
v = QWidget::inputMethodQuery(property);
break;
default:
v = d->control->inputMethodQuery(property);
const QPoint offset(-d->horizontalOffset(), -d->verticalOffset());
if (v.type() == QVariant::RectF)
v = v.toRectF().toRect().translated(offset);
else if (v.type() == QVariant::PointF)
v = v.toPointF().toPoint() + offset;
else if (v.type() == QVariant::Rect)
v = v.toRect().translated(offset);
else if (v.type() == QVariant::Point)
v = v.toPoint() + offset;
}
return v;
}

View File

@ -148,6 +148,8 @@ private slots:
void selectionChanged();
void blockCountChanged();
void insertAndScrollToBottom();
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
private:
void createSelection();
@ -1516,6 +1518,24 @@ void tst_QPlainTextEdit::insertAndScrollToBottom()
QCOMPARE(ed->verticalScrollBar()->value(), ed->verticalScrollBar()->maximum());
}
Q_DECLARE_METATYPE(Qt::InputMethodHints)
void tst_QPlainTextEdit::inputMethodQueryImHints_data()
{
QTest::addColumn<Qt::InputMethodHints>("hints");
QTest::newRow("None") << static_cast<Qt::InputMethodHints>(Qt::ImhNone);
QTest::newRow("Password") << static_cast<Qt::InputMethodHints>(Qt::ImhHiddenText);
QTest::newRow("Normal") << static_cast<Qt::InputMethodHints>(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
}
void tst_QPlainTextEdit::inputMethodQueryImHints()
{
QFETCH(Qt::InputMethodHints, hints);
ed->setInputMethodHints(hints);
QVariant value = ed->inputMethodQuery(Qt::ImHints);
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
}
QTEST_MAIN(tst_QPlainTextEdit)
#include "tst_qplaintextedit.moc"

View File

@ -209,6 +209,8 @@ private slots:
void inputMethodEvent();
void inputMethodSelection();
void inputMethodQuery();
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
private:
void createSelection();
@ -2462,5 +2464,24 @@ void tst_QTextEdit::inputMethodQuery()
QCOMPARE(event.value(Qt::ImEnabled).toBool(), false);
}
Q_DECLARE_METATYPE(Qt::InputMethodHints)
void tst_QTextEdit::inputMethodQueryImHints_data()
{
QTest::addColumn<Qt::InputMethodHints>("hints");
QTest::newRow("None") << static_cast<Qt::InputMethodHints>(Qt::ImhNone);
QTest::newRow("Password") << static_cast<Qt::InputMethodHints>(Qt::ImhHiddenText);
QTest::newRow("Normal") << static_cast<Qt::InputMethodHints>(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData);
}
void tst_QTextEdit::inputMethodQueryImHints()
{
QFETCH(Qt::InputMethodHints, hints);
ed->setInputMethodHints(hints);
QVariant value = ed->inputMethodQuery(Qt::ImHints);
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
}
QTEST_MAIN(tst_QTextEdit)
#include "tst_qtextedit.moc"