From 4ee912a752a4b7f129e98e180328f1f46f053d4f Mon Sep 17 00:00:00 2001 From: axis Date: Fri, 1 Oct 2010 13:25:28 +0200 Subject: Added support for using inputMethodHints in QInputDialog edit widget. AutoTest: Included Task: QTBUG-13200 RevBy: Denis Dzyubenko --- src/gui/dialogs/qinputdialog.cpp | 6 ++++++ src/gui/kernel/qwidget.cpp | 11 +++++++++-- src/gui/kernel/qwidget_p.h | 3 +++ tests/auto/qinputdialog/tst_qinputdialog.cpp | 20 ++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/qinputdialog.cpp b/src/gui/dialogs/qinputdialog.cpp index e996ee9..700b234 100644 --- a/src/gui/dialogs/qinputdialog.cpp +++ b/src/gui/dialogs/qinputdialog.cpp @@ -244,6 +244,9 @@ void QInputDialogPrivate::ensureLineEdit() Q_Q(QInputDialog); if (!lineEdit) { lineEdit = new QLineEdit(q); +#ifndef QT_NO_IM + qt_widget_private(lineEdit)->inheritsInputMethodHints = 1; +#endif lineEdit->hide(); QObject::connect(lineEdit, SIGNAL(textChanged(QString)), q, SLOT(_q_textChanged(QString))); @@ -255,6 +258,9 @@ void QInputDialogPrivate::ensureComboBox() Q_Q(QInputDialog); if (!comboBox) { comboBox = new QComboBox(q); +#ifndef QT_NO_IM + qt_widget_private(comboBox)->inheritsInputMethodHints = 1; +#endif comboBox->hide(); QObject::connect(comboBox, SIGNAL(editTextChanged(QString)), q, SLOT(_q_textChanged(QString))); diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index dc0dbf4..330d699 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -273,6 +273,9 @@ QWidgetPrivate::QWidgetPrivate(int version) , isMoved(0) , isGLWidget(0) , usesDoubleBufferedGLContext(0) +#ifndef QT_NO_IM + , inheritsInputMethodHints(0) +#endif #if defined(Q_WS_X11) , picture(0) #elif defined(Q_WS_WIN) @@ -9228,9 +9231,13 @@ QVariant QWidget::inputMethodQuery(Qt::InputMethodQuery query) const */ Qt::InputMethodHints QWidget::inputMethodHints() const { - Q_D(const QWidget); #ifndef QT_NO_IM - return d->imHints; + const QWidgetPrivate *priv = d_func(); + while (priv->inheritsInputMethodHints) { + priv = priv->q_func()->parentWidget()->d_func(); + Q_ASSERT(priv); + } + return priv->imHints; #else //QT_NO_IM return 0; #endif //QT_NO_IM diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 4a79dc7..6c89659 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -748,6 +748,9 @@ public: uint isMoved : 1; uint isGLWidget : 1; uint usesDoubleBufferedGLContext : 1; +#ifndef QT_NO_IM + uint inheritsInputMethodHints : 1; +#endif // *************************** Platform specific ************************************ #if defined(Q_WS_X11) // <----------------------------------------------------------- X11 diff --git a/tests/auto/qinputdialog/tst_qinputdialog.cpp b/tests/auto/qinputdialog/tst_qinputdialog.cpp index 0d6644a..5d03142 100644 --- a/tests/auto/qinputdialog/tst_qinputdialog.cpp +++ b/tests/auto/qinputdialog/tst_qinputdialog.cpp @@ -74,6 +74,7 @@ private slots: void getItem_data(); void getItem(); void task256299_getTextReturnNullStringOnRejected(); + void inputMethodHintsOfChildWidget(); }; QString stripFraction(const QString &s) @@ -404,5 +405,24 @@ void tst_QInputDialog::getItem() delete parent; } +void tst_QInputDialog::inputMethodHintsOfChildWidget() +{ + QInputDialog dialog; + dialog.setInputMode(QInputDialog::TextInput); + QList children = dialog.children(); + QLineEdit *editWidget = 0; + for (int c = 0; c < children.size(); c++) { + editWidget = qobject_cast(children.at(c)); + if (editWidget) + break; + } + QVERIFY(editWidget); + QCOMPARE(editWidget->inputMethodHints(), dialog.inputMethodHints()); + QCOMPARE(editWidget->inputMethodHints(), Qt::ImhNone); + dialog.setInputMethodHints(Qt::ImhDigitsOnly); + QCOMPARE(editWidget->inputMethodHints(), dialog.inputMethodHints()); + QCOMPARE(editWidget->inputMethodHints(), Qt::ImhDigitsOnly); +} + QTEST_MAIN(tst_QInputDialog) #include "tst_qinputdialog.moc" -- cgit v0.12