diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2010-03-31 04:28:59 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2010-03-31 07:04:43 (GMT) |
commit | 93ae014d7ee06a6ebb701420fffef5895cd731c4 (patch) | |
tree | 4fb5872be0d96587a009cd1bf3d2da35df407c9c /tests/auto/qgraphicsitem | |
parent | 525e6207b5e5c9cce82ed6e76a65571f56971f92 (diff) | |
download | Qt-93ae014d7ee06a6ebb701420fffef5895cd731c4.zip Qt-93ae014d7ee06a6ebb701420fffef5895cd731c4.tar.gz Qt-93ae014d7ee06a6ebb701420fffef5895cd731c4.tar.bz2 |
Add a QGraphicsItem::updateMicroFocus() to QGraphicsItem.
QGraphicsItem is no more lacking a way to notify the input method of a
changed micro focus.
Reviewed-by:denis
Reviewed-by:simon hausmann
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index be50182..3d86c48 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -61,6 +61,7 @@ #include <QScrollBar> #include <QVBoxLayout> #include <QGraphicsEffect> +#include <QInputContext> #include "../../shared/util.h" @@ -424,6 +425,7 @@ private slots: void modality_keyEvents(); void itemIsInFront(); void scenePosChange(); + void updateMicroFocus(); // task specific tests below me void task141694_textItemEnsureVisible(); @@ -9988,6 +9990,75 @@ void tst_QGraphicsItem::scenePosChange() QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); } +class MyInputContext : public QInputContext +{ +public: + MyInputContext() : nbUpdates(0) {} + ~MyInputContext() {} + + QString identifierName() { return QString(); } + QString language() { return QString(); } + + void reset() {} + + bool isComposing() const { return false; } + + void update() { nbUpdates++; } + + bool nbUpdates; +}; + +class MyInputWidget : public QGraphicsWidget +{ +public: + MyInputWidget() + { + setFlag(QGraphicsItem::ItemIsFocusable, true); + setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); + } + void mousePressEvent(QGraphicsSceneMouseEvent *event) + { + event->accept(); + } + + void doUpdateMicroFocus() + { + updateMicroFocus(); + } +}; + +void tst_QGraphicsItem::updateMicroFocus() +{ + QGraphicsScene scene; + QWidget parent; + QGridLayout layout; + parent.setLayout(&layout); + QGraphicsView view(&scene); + QGraphicsView view2(&scene); + layout.addWidget(&view, 0, 0); + layout.addWidget(&view2, 0, 1); + MyInputContext ic2; + view2.setInputContext(&ic2); + MyInputContext ic; + view.setInputContext(&ic); + MyInputWidget input; + input.setPos(0, 0); + input.resize(150, 150); + scene.addItem(&input); + input.setFocus(); + parent.show(); + view.setFocus(); + qApp->setAutoSipEnabled(true); + QApplication::setActiveWindow(&parent); + QTest::qWaitForWindowShown(&parent); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&parent)); + input.doUpdateMicroFocus(); + QApplication::processEvents(); + QCOMPARE(ic.nbUpdates, 1); + //No update since view2 does not have the focus. + QCOMPARE(ic2.nbUpdates, 0); +} + void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() { struct Item : public QGraphicsTextItem |