diff --git a/src/widgets/widgets/qabstractspinbox.cpp b/src/widgets/widgets/qabstractspinbox.cpp index 6bcdc372ef..7ee53587e6 100644 --- a/src/widgets/widgets/qabstractspinbox.cpp +++ b/src/widgets/widgets/qabstractspinbox.cpp @@ -694,6 +694,10 @@ void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit) this, SLOT(_q_editorTextChanged(QString))); connect(d->edit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(_q_editorCursorPositionChanged(int,int))); + connect(d->edit, SIGNAL(cursorPositionChanged(int,int)), + this, SLOT(updateMicroFocus())); + connect(d->edit->d_func()->control, SIGNAL(updateMicroFocus()), + this, SLOT(updateMicroFocus())); } d->updateEditFieldGeometry(); d->edit->setContextMenuPolicy(Qt::NoContextMenu); diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 4519265fb8..f4e08dc670 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -65,6 +65,7 @@ #include #include #include +#include #include #if 0 /* Used to be included in Qt4 for Q_WS_MAC */ && !defined(QT_NO_EFFECTS) && QT_CONFIG(style_mac) #include @@ -1790,6 +1791,7 @@ void QComboBox::setLineEdit(QLineEdit *edit) connect(d->lineEdit, SIGNAL(textChanged(QString)), this, SIGNAL(currentTextChanged(QString))); connect(d->lineEdit, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(updateMicroFocus())); connect(d->lineEdit, SIGNAL(selectionChanged()), this, SLOT(updateMicroFocus())); + connect(d->lineEdit->d_func()->control, SIGNAL(updateMicroFocus()), this, SLOT(updateMicroFocus())); d->lineEdit->setFrame(false); d->lineEdit->setContextMenuPolicy(Qt::NoContextMenu); d->updateFocusPolicy(); diff --git a/src/widgets/widgets/qlineedit.h b/src/widgets/widgets/qlineedit.h index 1bdcfaf848..96dd64164f 100644 --- a/src/widgets/widgets/qlineedit.h +++ b/src/widgets/widgets/qlineedit.h @@ -239,6 +239,7 @@ public: private: friend class QAbstractSpinBox; friend class QAccessibleLineEdit; + friend class QComboBox; #ifdef QT_KEYPAD_NAVIGATION friend class QDateTimeEdit; #endif diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 9947d63279..13f18f66d2 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -196,6 +196,9 @@ void QLineEditPrivate::init(const QString& txt) QObject::connect(control, SIGNAL(textChanged(QString)), q, SLOT(updateMicroFocus())); + QObject::connect(control, SIGNAL(updateMicroFocus()), + q, SLOT(updateMicroFocus())); + // for now, going completely overboard with updates. QObject::connect(control, SIGNAL(selectionChanged()), q, SLOT(update())); diff --git a/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro b/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro index f9b601228e..be758a8bdd 100644 --- a/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro +++ b/tests/auto/widgets/widgets/qabstractspinbox/qabstractspinbox.pro @@ -4,7 +4,7 @@ CONFIG += testcase TARGET = tst_qabstractspinbox -QT += widgets testlib +QT += widgets gui-private core-private testlib SOURCES += tst_qabstractspinbox.cpp diff --git a/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp b/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp index 36f5df4649..3fb4863b0e 100644 --- a/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp +++ b/tests/auto/widgets/widgets/qabstractspinbox/tst_qabstractspinbox.cpp @@ -35,6 +35,20 @@ #include #include +#include "../../../shared/platforminputcontext.h" +#include + +static inline void centerOnScreen(QWidget *w, const QSize &size) +{ + const QPoint offset = QPoint(size.width() / 2, size.height() / 2); + w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); +} + +static inline void centerOnScreen(QWidget *w) +{ + centerOnScreen(w, w->geometry().size()); +} + class tst_QAbstractSpinBox : public QObject { Q_OBJECT @@ -44,11 +58,19 @@ public: virtual ~tst_QAbstractSpinBox(); private slots: + void initTestCase(); + void cleanupTestCase(); + void getSetCheck(); // task-specific tests below me: void task183108_clear(); void task228728_cssselector(); + + void inputMethodUpdate(); + +private: + PlatformInputContext m_platformInputContext; }; tst_QAbstractSpinBox::tst_QAbstractSpinBox() @@ -67,6 +89,18 @@ public: void setLineEdit(QLineEdit *le) { QAbstractSpinBox::setLineEdit(le); } }; +void tst_QAbstractSpinBox::initTestCase() +{ + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = &m_platformInputContext; +} + +void tst_QAbstractSpinBox::cleanupTestCase() +{ + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = 0; +} + // Testing get/set functions void tst_QAbstractSpinBox::getSetCheck() { @@ -141,6 +175,60 @@ void tst_QAbstractSpinBox::task228728_cssselector() QSpinBox box; } +void tst_QAbstractSpinBox::inputMethodUpdate() +{ + QSpinBox box; + + QSpinBox *testWidget = &box; + testWidget->setRange(0, 1); + + centerOnScreen(testWidget); + testWidget->clear(); + testWidget->show(); + QVERIFY(QTest::qWaitForWindowExposed(testWidget)); + + testWidget->activateWindow(); + testWidget->setFocus(); + QTRY_VERIFY(testWidget->hasFocus()); + QTRY_COMPARE(qApp->focusObject(), testWidget); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("1", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, 1, QVariant()); + QInputMethodEvent event("1", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("", attributes); + event.setCommitString("1"); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + QCOMPARE(testWidget->value(), 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant()); + QInputMethodEvent event("", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); +} + QTEST_MAIN(tst_QAbstractSpinBox) #include "tst_qabstractspinbox.moc" diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 3afdc0a12a..b882055888 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -64,6 +64,9 @@ #include #include +#include "../../../shared/platforminputcontext.h" +#include + static inline void setFrameless(QWidget *w) { Qt::WindowFlags flags = w->windowFlags(); @@ -80,6 +83,8 @@ public: tst_QComboBox() {} private slots: + void initTestCase(); + void cleanupTestCase(); void getSetCheck(); void ensureReturnIsIgnored(); void setEditable(); @@ -162,6 +167,10 @@ private slots: void task_QTBUG_39088_inputMethodHints(); void task_QTBUG_49831_scrollerNotActivated(); void task_QTBUG_56693_itemFontFromModel(); + void inputMethodUpdate(); + +private: + PlatformInputContext m_platformInputContext; }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -207,6 +216,18 @@ protected: QRegion visualRegionForSelection(const QItemSelection &) const { return QRegion(); } }; +void tst_QComboBox::initTestCase() +{ + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = &m_platformInputContext; +} + +void tst_QComboBox::cleanupTestCase() +{ + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = 0; +} + // Testing get/set functions void tst_QComboBox::getSetCheck() { @@ -3324,5 +3345,59 @@ void tst_QComboBox::task_QTBUG_56693_itemFontFromModel() box.hidePopup(); } +void tst_QComboBox::inputMethodUpdate() +{ + TestWidget topLevel; + topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QComboBox *testWidget = topLevel.comboBox(); + // make sure we have no lineedit + QVERIFY(!testWidget->lineEdit()); + // test setEditable(true) + testWidget->setEditable(true); + QVERIFY(testWidget->lineEdit()); + + testWidget->activateWindow(); + testWidget->setFocus(); + QTRY_VERIFY(testWidget->hasFocus()); + QTRY_COMPARE(qApp->focusObject(), testWidget); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("preedit text", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, 1, QVariant()); + QInputMethodEvent event("preedit text", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("", attributes); + event.setCommitString("preedit text"); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + QCOMPARE(testWidget->lineEdit()->text(), QString("preedit text")); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant()); + QInputMethodEvent event("", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index a4614d0a9d..4c0ffdc77c 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -294,6 +294,8 @@ private slots: void inputMethodQueryImHints_data(); void inputMethodQueryImHints(); + void inputMethodUpdate(); + void undoRedoAndEchoModes_data(); void undoRedoAndEchoModes(); @@ -4184,6 +4186,57 @@ void tst_QLineEdit::inputMethodQueryImHints() QCOMPARE(static_cast(value.toInt()), hints); } +void tst_QLineEdit::inputMethodUpdate() +{ + QLineEdit *testWidget = ensureTestWidget(); + + centerOnScreen(testWidget); + testWidget->show(); + QVERIFY(QTest::qWaitForWindowExposed(testWidget)); + + testWidget->setText(""); + testWidget->activateWindow(); + testWidget->setFocus(); + QTRY_VERIFY(testWidget->hasFocus()); + QTRY_COMPARE(qApp->focusObject(), testWidget); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("preedit text", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, 1, QVariant()); + QInputMethodEvent event("preedit text", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("", attributes); + event.setCommitString("preedit text"); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + QCOMPARE(testWidget->text(), QString("preedit text")); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant()); + QInputMethodEvent event("", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); +} + void tst_QLineEdit::undoRedoAndEchoModes_data() { QTest::addColumn("echoMode"); diff --git a/tests/auto/widgets/widgets/widgets.pro b/tests/auto/widgets/widgets/widgets.pro index a8e8f6d865..c098108edc 100644 --- a/tests/auto/widgets/widgets/widgets.pro +++ b/tests/auto/widgets/widgets/widgets.pro @@ -49,6 +49,7 @@ SUBDIRS=\ # The following tests depend on private API: !qtConfig(private_tests): SUBDIRS -= \ + qabstractspinbox \ qcombobox \ qmainwindow \ qtextedit \