summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsproxywidget
diff options
context:
space:
mode:
authorjasplin <qt-info@nokia.com>2009-07-03 15:40:20 +0200
committerjasplin <qt-info@nokia.com>2009-07-03 16:04:04 +0200
commit7bc98d7bd7aabc6086e5cd27a167769d7aa71d83 (patch)
treed90f7a01a905212f9e96fbb14b41322172100548 /tests/auto/qgraphicsproxywidget
parentccdf924d01cbcb716ed25862561bb94d53ffed1f (diff)
Improved the support for input methods in Graphics View.
This patch improves the graphics view support for input methods in several ways: * A new ItemAcceptsInputMethod flag is introduced to serve the same purpose for graphics items as WA_InputMethodEnabled does for widgets: Input method support can be controlled individually for each item. * The input method sensitivity of a view (i.e. the value of the WA_InputMethodEnabled flag) is updated dynamically whenever the input method support of the current focus item may change. * Input contexts are reset whenever an item that supports input methods loses focus. Reviewed-by: janarve Task-number: 254492
Diffstat (limited to 'tests/auto/qgraphicsproxywidget')
-rw-r--r--tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index 0b1d5cf9d2..dbc433914d 100644
--- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -178,6 +178,7 @@ private slots:
void windowFlags_data();
void windowFlags();
void comboboxWindowFlags();
+ void inputMethod();
};
// Subclass that exposes the protected functions.
@@ -1572,7 +1573,7 @@ void tst_QGraphicsProxyWidget::resize_simple()
QGraphicsProxyWidget proxy;
QWidget *widget = new QWidget;
- widget->setGeometry(0, 0, size.width(), size.height());
+ widget->setGeometry(0, 0, (int)size.width(), (int)size.height());
proxy.setWidget(widget);
widget->show();
QCOMPARE(widget->pos(), QPoint());
@@ -3217,10 +3218,51 @@ void tst_QGraphicsProxyWidget::comboboxWindowFlags()
QVERIFY((static_cast<QGraphicsWidget *>(popupProxy)->windowFlags() & Qt::Popup) == Qt::Popup);
}
+class InputMethod_LineEdit : public QLineEdit
+{
+ bool event(QEvent *e)
+ {
+ if (e->type() == QEvent::InputMethod)
+ ++inputMethodEvents;
+ return QLineEdit::event(e);
+ }
+public:
+ int inputMethodEvents;
+};
+
+void tst_QGraphicsProxyWidget::inputMethod()
+{
+ QGraphicsScene scene;
+
+ // check that the proxy is initialized with the correct input method sensitivity
+ for (int i = 0; i < 2; ++i)
+ {
+ QLineEdit *lineEdit = new QLineEdit;
+ lineEdit->setAttribute(Qt::WA_InputMethodEnabled, !!i);
+ QGraphicsProxyWidget *proxy = scene.addWidget(lineEdit);
+ QCOMPARE(!!(proxy->flags() & QGraphicsItem::ItemAcceptsInputMethod), !!i);
+ }
+
+ // check that input method events are only forwarded to widgets with focus
+ for (int i = 0; i < 2; ++i)
+ {
+ InputMethod_LineEdit *lineEdit = new InputMethod_LineEdit;
+ lineEdit->setAttribute(Qt::WA_InputMethodEnabled, true);
+ QGraphicsProxyWidget *proxy = scene.addWidget(lineEdit);
+
+ if (i)
+ lineEdit->setFocus();
+
+ lineEdit->inputMethodEvents = 0;
+ QInputMethodEvent event;
+ qApp->sendEvent(proxy, &event);
+ QCOMPARE(lineEdit->inputMethodEvents, i);
+ }
+}
+
QTEST_MAIN(tst_QGraphicsProxyWidget)
#include "tst_qgraphicsproxywidget.moc"
#else // QT_NO_STYLE_CLEANLOOKS
QTEST_NOOP_MAIN
#endif
-