diff options
author | axis <qt-info@nokia.com> | 2009-04-07 14:28:57 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2009-05-04 13:24:07 (GMT) |
commit | 0bc0c1c9b09cda459dbfdc16cb4089297160ce85 (patch) | |
tree | 9b619fc14285c3fd1b7dd7598c7f4b4301cc7f33 | |
parent | 8d08c42c6a5478e8890d59f58483f4eff3d286ca (diff) | |
download | Qt-0bc0c1c9b09cda459dbfdc16cb4089297160ce85.zip Qt-0bc0c1c9b09cda459dbfdc16cb4089297160ce85.tar.gz Qt-0bc0c1c9b09cda459dbfdc16cb4089297160ce85.tar.bz2 |
Implemented RequestSoftwareInputPanel events in QLineEdit.
AutoTest: Included
RevBy: denis
-rw-r--r-- | src/gui/widgets/qlineedit.cpp | 9 | ||||
-rw-r--r-- | src/gui/widgets/qlineedit_p.h | 4 | ||||
-rw-r--r-- | tests/auto/qinputcontext/tst_qinputcontext.cpp | 49 |
3 files changed, 57 insertions, 5 deletions
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp index 8b553f9..d03cd3e 100644 --- a/src/gui/widgets/qlineedit.cpp +++ b/src/gui/widgets/qlineedit.cpp @@ -1768,6 +1768,13 @@ void QLineEdit::mouseReleaseEvent(QMouseEvent* e) } } #endif + + if (e->button() == Qt::LeftButton && (!d->clickCausedFocus + || QApplication::autoSipOnMouseFocus())) { + QEvent event(QEvent::RequestSoftwareInputPanel); + QApplication::sendEvent(this, &event); + } + d->clickCausedFocus = 0; } /*! \reimp @@ -2350,6 +2357,8 @@ void QLineEdit::focusInEvent(QFocusEvent *e) d->moveCursor(d->nextMaskBlank(0)); else if (!d->hasSelectedText()) selectAll(); + } else if (e->reason() == Qt::MouseFocusReason) { + d->clickCausedFocus = 1; } #ifdef QT_KEYPAD_NAVIGATION if (!QApplication::keypadNavigationEnabled() || (hasEditFocus() && e->reason() == Qt::PopupFocusReason)) diff --git a/src/gui/widgets/qlineedit_p.h b/src/gui/widgets/qlineedit_p.h index 532528b..3db903f 100644 --- a/src/gui/widgets/qlineedit_p.h +++ b/src/gui/widgets/qlineedit_p.h @@ -76,7 +76,8 @@ public: : cursor(0), preeditCursor(0), cursorTimer(0), frame(1), cursorVisible(0), hideCursor(false), separator(0), readOnly(0), dragEnabled(0), contextMenuEnabled(1), echoMode(0), textDirty(0), - selDirty(0), validInput(1), alignment(Qt::AlignLeading | Qt::AlignVCenter), ascent(0), + selDirty(0), validInput(1), clickCausedFocus(0), + alignment(Qt::AlignLeading | Qt::AlignVCenter), ascent(0), maxLength(32767), hscroll(0), vscroll(0), lastCursorPos(-1), maskData(0), modifiedState(0), undoState(0), selstart(0), selend(0), userInput(false), emitingEditingFinished(false), passwordEchoEditing(false) @@ -110,6 +111,7 @@ public: uint textDirty : 1; uint selDirty : 1; uint validInput : 1; + uint clickCausedFocus : 1; uint alignment; int ascent; int maxLength; diff --git a/tests/auto/qinputcontext/tst_qinputcontext.cpp b/tests/auto/qinputcontext/tst_qinputcontext.cpp index 08bf614..5fdd931 100644 --- a/tests/auto/qinputcontext/tst_qinputcontext.cpp +++ b/tests/auto/qinputcontext/tst_qinputcontext.cpp @@ -45,6 +45,7 @@ #include <qinputcontext.h> #include <qlineedit.h> #include <qplaintextedit.h> +#include <qlayout.h> class tst_QInputContext : public QObject { @@ -62,6 +63,7 @@ public slots: private slots: void maximumTextLength(); void filterMouseEvents(); + void requestSoftwareInputPanel(); }; void tst_QInputContext::maximumTextLength() @@ -82,7 +84,7 @@ void tst_QInputContext::maximumTextLength() class QFilterInputContext : public QInputContext { public: - QFilterInputContext() : successful(false) {} + QFilterInputContext() : lastType(QEvent::None) {} ~QFilterInputContext() {} QString identifierName() { return QString(); } @@ -94,26 +96,65 @@ public: bool filterEvent( const QEvent *event ) { - successful = event->type() == QEvent::MouseButtonRelease; + lastType = event->type(); + return false; } public: - bool successful; + QEvent::Type lastType; }; void tst_QInputContext::filterMouseEvents() { QLineEdit le; le.show(); + QApplication::setActiveWindow(&le); QFilterInputContext *ic = new QFilterInputContext; le.setInputContext(ic); QTest::mouseClick(&le, Qt::LeftButton); - QVERIFY(ic->successful); + QCOMPARE(ic->lastType, QEvent::MouseButtonRelease); le.setInputContext(0); } +void tst_QInputContext::requestSoftwareInputPanel() +{ + QWidget w; + QLayout *layout = new QVBoxLayout; + QLineEdit *le1, *le2; + le1 = new QLineEdit; + le2 = new QLineEdit; + layout->addWidget(le1); + layout->addWidget(le2); + w.setLayout(layout); + + QFilterInputContext *ic1, *ic2; + ic1 = new QFilterInputContext; + ic2 = new QFilterInputContext; + le1->setInputContext(ic1); + le2->setInputContext(ic2); + + w.show(); + QApplication::setActiveWindow(&w); + + // Testing single click panel activation. + QApplication::setTwoClicksToRequestSIP(false); + QTest::mouseClick(le2, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); + QCOMPARE(ic2->lastType, QEvent::RequestSoftwareInputPanel); + + // Testing double click panel activation. + QApplication::setTwoClicksToRequestSIP(true); + QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); + QVERIFY(ic1->lastType != QEvent::RequestSoftwareInputPanel); + QTest::mouseClick(le1, Qt::LeftButton, Qt::NoModifier, QPoint(5, 5)); + QCOMPARE(ic1->lastType, QEvent::RequestSoftwareInputPanel); + + // Testing right mouse button + QTest::mouseClick(le1, Qt::RightButton, Qt::NoModifier, QPoint(5, 5)); + QVERIFY(ic1->lastType != QEvent::RequestSoftwareInputPanel); +} + QTEST_MAIN(tst_QInputContext) #include "tst_qinputcontext.moc" |