3662 } |
3662 } |
3663 QTRY_VERIFY(!viewPrivate->fullUpdatePending); |
3663 QTRY_VERIFY(!viewPrivate->fullUpdatePending); |
3664 #endif |
3664 #endif |
3665 } |
3665 } |
3666 |
3666 |
|
3667 class FocusItem : public QGraphicsRectItem |
|
3668 { |
|
3669 public: |
|
3670 FocusItem() : QGraphicsRectItem(0, 0, 20, 20) { |
|
3671 m_viewHasIMEnabledInFocusInEvent = false; |
|
3672 } |
|
3673 |
|
3674 void focusInEvent(QFocusEvent *event) |
|
3675 { |
|
3676 QGraphicsView *view = scene()->views().first(); |
|
3677 m_viewHasIMEnabledInFocusInEvent = view->testAttribute(Qt::WA_InputMethodEnabled); |
|
3678 } |
|
3679 |
|
3680 bool m_viewHasIMEnabledInFocusInEvent; |
|
3681 }; |
|
3682 |
3667 void tst_QGraphicsView::inputMethodSensitivity() |
3683 void tst_QGraphicsView::inputMethodSensitivity() |
3668 { |
3684 { |
3669 QGraphicsScene scene; |
3685 QGraphicsScene scene; |
3670 QGraphicsView view(&scene); |
3686 QGraphicsView view(&scene); |
3671 view.show(); |
3687 view.show(); |
3672 QTest::qWaitForWindowShown(&view); |
3688 QTest::qWaitForWindowShown(&view); |
3673 QApplication::setActiveWindow(&view); |
3689 QApplication::setActiveWindow(&view); |
3674 QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
3690 QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
3675 |
3691 |
3676 QGraphicsRectItem *item = new QGraphicsRectItem; |
3692 FocusItem *item = new FocusItem; |
3677 |
3693 |
3678 view.setAttribute(Qt::WA_InputMethodEnabled, true); |
3694 view.setAttribute(Qt::WA_InputMethodEnabled, true); |
3679 |
3695 |
3680 scene.addItem(item); |
3696 scene.addItem(item); |
3681 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3697 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3700 item->setFlag(QGraphicsItem::ItemIsFocusable); |
3716 item->setFlag(QGraphicsItem::ItemIsFocusable); |
3701 scene.addItem(item); |
3717 scene.addItem(item); |
3702 scene.setFocusItem(item); |
3718 scene.setFocusItem(item); |
3703 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3719 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3704 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
3720 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3721 QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); |
3705 |
3722 |
3706 item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false); |
3723 item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false); |
3707 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3724 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3708 |
3725 |
3709 item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); |
3726 item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); |
3710 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
3727 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
3711 |
3728 |
3712 // introduce another item that is focusable but does not accept input methods |
3729 // introduce another item that is focusable but does not accept input methods |
3713 QGraphicsRectItem *item2 = new QGraphicsRectItem; |
3730 FocusItem *item2 = new FocusItem; |
3714 item2->setFlag(QGraphicsItem::ItemIsFocusable); |
3731 item2->setFlag(QGraphicsItem::ItemIsFocusable); |
3715 scene.addItem(item2); |
3732 scene.addItem(item2); |
3716 scene.setFocusItem(item2); |
3733 scene.setFocusItem(item2); |
3717 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3734 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3735 QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false); |
3718 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
3736 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
3719 |
3737 |
3720 scene.setFocusItem(item); |
3738 scene.setFocusItem(item); |
3721 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
3739 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3740 QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); |
3722 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3741 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3723 |
3742 |
3724 view.setScene(0); |
3743 view.setScene(0); |
3725 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3744 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3726 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3745 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3727 |
3746 |
3728 view.setScene(&scene); |
3747 view.setScene(&scene); |
3729 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
3748 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3749 QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); |
3730 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3750 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3731 |
3751 |
3732 scene.setFocusItem(item2); |
3752 scene.setFocusItem(item2); |
3733 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3753 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
|
3754 QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false); |
3734 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
3755 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
3735 |
3756 |
3736 view.setScene(0); |
3757 view.setScene(0); |
3737 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3758 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3738 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
3759 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item2)); |
3741 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3762 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); |
3742 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3763 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3743 |
3764 |
3744 view.setScene(&scene); |
3765 view.setScene(&scene); |
3745 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
3766 QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); |
|
3767 QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); |
3746 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3768 QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); |
3747 } |
3769 } |
3748 |
3770 |
3749 class InputContextTester : public QInputContext |
3771 class InputContextTester : public QInputContext |
3750 { |
3772 { |