summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2010-04-29 07:11:02 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2010-04-29 07:34:57 (GMT)
commite24b4b83fa4e71ab137ac254a9c69fec672d5e66 (patch)
tree744a4c062a643c4453267566675fc72504f2e8b5
parente393f03cb89c795e4a638f84b002cb16fd1613a7 (diff)
downloadQt-e24b4b83fa4e71ab137ac254a9c69fec672d5e66.zip
Qt-e24b4b83fa4e71ab137ac254a9c69fec672d5e66.tar.gz
Qt-e24b4b83fa4e71ab137ac254a9c69fec672d5e66.tar.bz2
Ensured that WA_InputMethodEnabled was set before FocusInEvent was sent.
When focusInEvent is called we need to ensure that WA_InputMethodEnabled is set, since FocusInEvent might lead to that QInputContext::setFocusWidget is called (with the QGraphicsView as the widget parameter). However, if the widget still does not have WA_InputMethodEnabled set yet it will assert in QInputContext::setFocusWidget (it requires that the widget has the flag set). This was a problem for the morbit bridge, where Dui requires the attribute to be set (while Orbit actually does not require) Task-number: QTBUG-10276 Reviewed-by: jasplin Reviewed-by: Alexis Menard
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp6
-rw-r--r--tests/auto/qgraphicsview/tst_qgraphicsview.cpp26
2 files changed, 27 insertions, 5 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index bd0f0d8..8cee021 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -820,13 +820,13 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item,
#endif //QT_NO_IM
}
- if (item) {
+ if (item)
focusItem = item;
+ updateInputMethodSensitivityInViews();
+ if (item) {
QFocusEvent event(QEvent::FocusIn, focusReason);
sendEvent(item, &event);
}
-
- updateInputMethodSensitivityInViews();
}
/*!
diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
index 5e889f4..d0752af 100644
--- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp
@@ -3665,6 +3665,22 @@ void tst_QGraphicsView::update()
#endif
}
+class FocusItem : public QGraphicsRectItem
+{
+public:
+ FocusItem() : QGraphicsRectItem(0, 0, 20, 20) {
+ m_viewHasIMEnabledInFocusInEvent = false;
+ }
+
+ void focusInEvent(QFocusEvent *event)
+ {
+ QGraphicsView *view = scene()->views().first();
+ m_viewHasIMEnabledInFocusInEvent = view->testAttribute(Qt::WA_InputMethodEnabled);
+ }
+
+ bool m_viewHasIMEnabledInFocusInEvent;
+};
+
void tst_QGraphicsView::inputMethodSensitivity()
{
QGraphicsScene scene;
@@ -3674,7 +3690,7 @@ void tst_QGraphicsView::inputMethodSensitivity()
QApplication::setActiveWindow(&view);
QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view));
- QGraphicsRectItem *item = new QGraphicsRectItem;
+ FocusItem *item = new FocusItem;
view.setAttribute(Qt::WA_InputMethodEnabled, true);
@@ -3703,6 +3719,7 @@ void tst_QGraphicsView::inputMethodSensitivity()
scene.setFocusItem(item);
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item));
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true);
+ QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true);
item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false);
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false);
@@ -3711,15 +3728,17 @@ void tst_QGraphicsView::inputMethodSensitivity()
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true);
// introduce another item that is focusable but does not accept input methods
- QGraphicsRectItem *item2 = new QGraphicsRectItem;
+ FocusItem *item2 = new FocusItem;
item2->setFlag(QGraphicsItem::ItemIsFocusable);
scene.addItem(item2);
scene.setFocusItem(item2);
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false);
+ QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false);
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2));
scene.setFocusItem(item);
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true);
+ QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true);
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item));
view.setScene(0);
@@ -3728,10 +3747,12 @@ void tst_QGraphicsView::inputMethodSensitivity()
view.setScene(&scene);
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true);
+ QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true);
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item));
scene.setFocusItem(item2);
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false);
+ QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false);
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2));
view.setScene(0);
@@ -3744,6 +3765,7 @@ void tst_QGraphicsView::inputMethodSensitivity()
view.setScene(&scene);
QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true);
+ QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true);
QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item));
}