summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-04-19 14:00:48 +1000
committerAndrew den Exter <andrew.den-exter@nokia.com>2011-04-21 15:22:56 +1000
commit2f173e4945dd8414636c1061acfaf9c2d8b718d8 (patch)
treef4e97364bea41b9459d9866a404481d48a66f3f2
parent6e5a642c9484536fc173714f560f739944368cf5 (diff)
Fix TextInput echoMode clearing inputMethodHints set by the user.
Changing to the Normal echo mode from another mode clears the NoPredictiveText and NoAutoUppercase flags, irrespective of who originally set them. Add separate accessors for the property value so echo mode can overwrite the authoritive value without losing the value set in QML. Change-Id: I6a9563057bb17796b17ac7c2a3c564bb5e886c4d Task-number: QTBUG-18735 Reviewed-by: Martin Jones
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput.cpp40
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p.h5
-rw-r--r--src/declarative/graphicsitems/qdeclarativetextinput_p_p.h4
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp42
4 files changed, 78 insertions, 13 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
index e1c210701a..ee241d614e 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp
@@ -862,6 +862,20 @@ bool QDeclarativeTextInput::hasAcceptableInput() const
state.
*/
+void QDeclarativeTextInputPrivate::updateInputMethodHints()
+{
+ Q_Q(QDeclarativeTextInput);
+ Qt::InputMethodHints hints = inputMethodHints;
+ uint echo = control->echoMode();
+ if (echo == QDeclarativeTextInput::Password || echo == QDeclarativeTextInput::NoEcho)
+ hints |= Qt::ImhHiddenText;
+ else if (echo == QDeclarativeTextInput::PasswordEchoOnEdit)
+ hints &= ~Qt::ImhHiddenText;
+ if (echo != QDeclarativeTextInput::Normal)
+ hints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+ q->setInputMethodHints(hints);
+}
+
/*!
\qmlproperty enumeration TextInput::echoMode
@@ -884,21 +898,27 @@ void QDeclarativeTextInput::setEchoMode(QDeclarativeTextInput::EchoMode echo)
Q_D(QDeclarativeTextInput);
if (echoMode() == echo)
return;
- Qt::InputMethodHints imHints = inputMethodHints();
- if (echo == Password || echo == NoEcho)
- imHints |= Qt::ImhHiddenText;
- else
- imHints &= ~Qt::ImhHiddenText;
- if (echo != Normal)
- imHints |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
- else
- imHints &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
- setInputMethodHints(imHints);
d->control->setEchoMode((uint)echo);
+ d->updateInputMethodHints();
q_textChanged();
emit echoModeChanged(echoMode());
}
+Qt::InputMethodHints QDeclarativeTextInput::imHints() const
+{
+ Q_D(const QDeclarativeTextInput);
+ return d->inputMethodHints;
+}
+
+void QDeclarativeTextInput::setIMHints(Qt::InputMethodHints hints)
+{
+ Q_D(QDeclarativeTextInput);
+ if (d->inputMethodHints == hints)
+ return;
+ d->inputMethodHints = hints;
+ d->updateInputMethodHints();
+}
+
/*!
\qmlproperty Component TextInput::cursorDelegate
The delegate for the cursor in the TextInput.
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
index 8c873b3329..ec70e43f68 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p.h
@@ -86,7 +86,7 @@ class Q_AUTOTEST_EXPORT QDeclarativeTextInput : public QDeclarativeImplicitSizeP
Q_PROPERTY(QValidator* validator READ validator WRITE setValidator NOTIFY validatorChanged)
#endif
Q_PROPERTY(QString inputMask READ inputMask WRITE setInputMask NOTIFY inputMaskChanged)
- Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ inputMethodHints WRITE setInputMethodHints)
+ Q_PROPERTY(Qt::InputMethodHints inputMethodHints READ imHints WRITE setIMHints)
Q_PROPERTY(bool acceptableInput READ hasAcceptableInput NOTIFY acceptableInputChanged)
Q_PROPERTY(EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
@@ -215,6 +215,9 @@ public:
bool isInputMethodComposing() const;
+ Qt::InputMethodHints imHints() const;
+ void setIMHints(Qt::InputMethodHints hints);
+
Q_SIGNALS:
void textChanged();
void cursorPositionChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
index fd4da2e134..ed53e8f89e 100644
--- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h
@@ -73,7 +73,7 @@ public:
QDeclarativeTextInputPrivate() : control(new QLineControl(QString())),
color((QRgb)0), style(QDeclarativeText::Normal),
styleColor((QRgb)0), hAlign(QDeclarativeTextInput::AlignLeft),
- mouseSelectionMode(QDeclarativeTextInput::SelectCharacters),
+ mouseSelectionMode(QDeclarativeTextInput::SelectCharacters), inputMethodHints(Qt::ImhNone),
hscroll(0), oldScroll(0), oldValidity(false), focused(false), focusOnPress(true),
showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false),
autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true)
@@ -108,6 +108,7 @@ public:
void mirrorChange();
int calculateTextWidth();
bool sendMouseEventToInputContext(QGraphicsSceneMouseEvent *event, QEvent::Type eventType);
+ void updateInputMethodHints();
QLineControl* control;
@@ -120,6 +121,7 @@ public:
QColor styleColor;
QDeclarativeTextInput::HAlignment hAlign;
QDeclarativeTextInput::SelectionMode mouseSelectionMode;
+ Qt::InputMethodHints inputMethodHints;
QPointer<QDeclarativeComponent> cursorComponent;
QPointer<QDeclarativeItem> cursorItem;
QPointF pressPos;
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index 943b1fa45f..79d95d3e7a 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -1364,8 +1364,10 @@ void tst_qdeclarativetextinput::inputMethods()
QVERIFY(canvas->rootObject() != 0);
QDeclarativeTextInput *input = qobject_cast<QDeclarativeTextInput *>(canvas->rootObject());
QVERIFY(input != 0);
+ QVERIFY(input->imHints() & Qt::ImhNoPredictiveText);
QVERIFY(input->inputMethodHints() & Qt::ImhNoPredictiveText);
- input->setInputMethodHints(Qt::ImhUppercaseOnly);
+ input->setIMHints(Qt::ImhUppercaseOnly);
+ QVERIFY(input->imHints() & Qt::ImhUppercaseOnly);
QVERIFY(input->inputMethodHints() & Qt::ImhUppercaseOnly);
QVERIFY(canvas->rootObject() != 0);
@@ -1805,6 +1807,7 @@ void tst_qdeclarativetextinput::echoMode()
ref &= ~Qt::ImhHiddenText;
ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhNone);
input->setEchoMode(QDeclarativeTextInput::NoEcho);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String(""));
@@ -1813,6 +1816,7 @@ void tst_qdeclarativetextinput::echoMode()
ref |= Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhNone);
input->setEchoMode(QDeclarativeTextInput::Password);
//Password
ref |= Qt::ImhHiddenText;
@@ -1820,6 +1824,7 @@ void tst_qdeclarativetextinput::echoMode()
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String("********"));
QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhNone);
input->setPasswordCharacter(QChar('Q'));
QCOMPARE(input->passwordCharacter(), QLatin1String("Q"));
QCOMPARE(input->text(), initial);
@@ -1829,6 +1834,7 @@ void tst_qdeclarativetextinput::echoMode()
ref &= ~Qt::ImhHiddenText;
ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhNone);
QCOMPARE(input->text(), initial);
QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ"));
QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), QLatin1String("QQQQQQQQ"));
@@ -1849,6 +1855,40 @@ void tst_qdeclarativetextinput::echoMode()
QCOMPARE(input->displayText(), initial);
QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), initial);
+ // Test echo mode doesn't override imHints.
+ input->setIMHints(Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
+ ref |= Qt::ImhDialableCharactersOnly;
+ //Normal
+ input->setEchoMode(QDeclarativeTextInput::Normal);
+ ref |= Qt::ImhHiddenText;
+ ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+ QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
+ //NoEcho
+ input->setEchoMode(QDeclarativeTextInput::NoEcho);
+ ref |= Qt::ImhHiddenText;
+ ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+ QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
+ //Password
+ input->setEchoMode(QDeclarativeTextInput::Password);
+ ref |= Qt::ImhHiddenText;
+ ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+ QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
+ //PasswordEchoOnEdit
+ input->setEchoMode(QDeclarativeTextInput::PasswordEchoOnEdit);
+ ref &= ~Qt::ImhHiddenText;
+ ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+ QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
+ //Normal
+ input->setEchoMode(QDeclarativeTextInput::Normal);
+ ref |= Qt::ImhHiddenText;
+ ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText);
+ QCOMPARE(input->inputMethodHints(), ref);
+ QCOMPARE(input->imHints(), Qt::ImhHiddenText | Qt::ImhDialableCharactersOnly);
+
delete canvas;
}