summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2010-04-22 04:55:07 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2010-04-27 03:43:49 (GMT)
commit8ed0a827298776ef2574b1298f24071c61dc8b07 (patch)
tree84fa0f30a6b15c3089d0c88c67234522fe569a68 /tests/auto/qgraphicsitem
parentb69864da59c42a09a3acc373eb77a85f8f8c93b2 (diff)
downloadQt-8ed0a827298776ef2574b1298f24071c61dc8b07.zip
Qt-8ed0a827298776ef2574b1298f24071c61dc8b07.tar.gz
Qt-8ed0a827298776ef2574b1298f24071c61dc8b07.tar.bz2
Fix QDeclarativeTextInput and QGraphicsView in regards of input methods hints.
When the echoMode changes for QDeclarativeTextInput we need to update the inputmethod hints. Also in QGraphicsView we need to update the input context installed on the view to make the former is aware of the change. For the input context framework the only way to deal with the current widget is focusWidget(). Unfortunately the widget that has the focus is the QGraphicsView so the input context don't know the real object QGraphicsView is actually focusing. We must keep in sync the inputMethodHints of QGV with the object QGraphicsView is focusing so the input context just called focusWidget()->inputMethodhints() to update itself. Task-number:QTBUG-9922 Reviewed-by:janarve Reviewed-by:bnilsen Reviewed-by:Michael Brasser
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp52
1 files changed, 50 insertions, 2 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index e2f7f18..e1c4791 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -63,6 +63,7 @@
#include <QGraphicsEffect>
#include <QInputContext>
#include <QPushButton>
+#include <QLineEdit>
#include "../../shared/util.h"
@@ -945,8 +946,52 @@ class ImhTester : public QGraphicsItem
void tst_QGraphicsItem::inputMethodHints()
{
- ImhTester item;
- QCOMPARE(item.inputMethodHints(), Qt::ImhNone);
+ ImhTester *item = new ImhTester;
+ item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true);
+ item->setFlag(QGraphicsItem::ItemIsFocusable, true);
+ QCOMPARE(item->inputMethodHints(), Qt::ImhNone);
+ ImhTester *item2 = new ImhTester;
+ item2->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true);
+ item2->setFlag(QGraphicsItem::ItemIsFocusable, true);
+ Qt::InputMethodHints imHints = item2->inputMethodHints();
+ imHints |= Qt::ImhHiddenText;
+ item2->setInputMethodHints(imHints);
+ QGraphicsScene scene;
+ scene.addItem(item);
+ scene.addItem(item2);
+ QGraphicsView view(&scene);
+ QApplication::setActiveWindow(&view);
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+ item->setFocus();
+ QTRY_VERIFY(item->hasFocus());
+ QCOMPARE(view.inputMethodHints(), item->inputMethodHints());
+ item2->setFocus();
+ QTRY_VERIFY(item2->hasFocus());
+ QCOMPARE(view.inputMethodHints(), item2->inputMethodHints());
+ item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false);
+ item->setFocus();
+ QTRY_VERIFY(item->hasFocus());
+ //Focus has changed but the new item doesn't accept input method, no hints.
+ QCOMPARE(view.inputMethodHints(), 0);
+ item2->setFocus();
+ QTRY_VERIFY(item2->hasFocus());
+ QCOMPARE(view.inputMethodHints(), item2->inputMethodHints());
+ imHints = item2->inputMethodHints();
+ imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+ item2->setInputMethodHints(imHints);
+ QCOMPARE(view.inputMethodHints(), item2->inputMethodHints());
+ QGraphicsProxyWidget *widget = new QGraphicsProxyWidget;
+ QLineEdit *edit = new QLineEdit;
+ edit->setEchoMode(QLineEdit::Password);
+ scene.addItem(widget);
+ widget->setFocus();
+ QTRY_VERIFY(widget->hasFocus());
+ //No widget on the proxy, so no hints
+ QCOMPARE(view.inputMethodHints(), 0);
+ widget->setWidget(edit);
+ //View should match with the line edit
+ QCOMPARE(view.inputMethodHints(), edit->inputMethodHints());
}
void tst_QGraphicsItem::toolTip()
@@ -10055,6 +10100,9 @@ void tst_QGraphicsItem::updateMicroFocus()
QApplication::setActiveWindow(&parent);
QTest::qWaitForWindowShown(&parent);
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&parent));
+ //We reset the number of updates that happened previously (initialisation)
+ ic.nbUpdates = 0;
+ ic2.nbUpdates = 0;
input.doUpdateMicroFocus();
QApplication::processEvents();
QTRY_COMPARE(ic.nbUpdates, 1);