From f711f9387544aabf21ec19a7dd1dcb91f3d947fc Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 13 Mar 2013 14:34:51 +0100 Subject: [PATCH] Use the platform theme's password mask character for text input fields. Task-number: QTBUG-29871 Change-Id: I3b15dfab5ca6455df465c502c93aac7b85a64531 Reviewed-by: Jerome Pasion Reviewed-by: Caroline Chao --- src/quick/items/qquicktextinput.cpp | 8 +++++--- src/quick/items/qquicktextinput_p_p.h | 2 +- .../quick/qquicktextinput/tst_qquicktextinput.cpp | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 65a0d62..30be926 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -1229,10 +1229,11 @@ Qt::InputMethodHints QQuickTextInputPrivate::effectiveInputMethodHints() const Specifies how the text should be displayed in the TextInput. \list \li TextInput.Normal - Displays the text as it is. (Default) - \li TextInput.Password - Displays asterisks instead of characters. + \li TextInput.Password - Displays platform-dependent password mask + characters instead of the actual characters. \li TextInput.NoEcho - Displays nothing. \li TextInput.PasswordEchoOnEdit - Displays characters as they are entered - while editing, otherwise displays asterisks. + while editing, otherwise identical to \c TextInput.Password. \endlist */ QQuickTextInput::EchoMode QQuickTextInput::echoMode() const @@ -2199,7 +2200,8 @@ void QQuickTextInput::selectWord() \qmlproperty string QtQuick2::TextInput::passwordCharacter This is the character displayed when echoMode is set to Password or - PasswordEchoOnEdit. By default it is an asterisk. + PasswordEchoOnEdit. By default it is the password character used by + the platform theme. If this property is set to a string with more than one character, the first character is used. If the string is empty, the value diff --git a/src/quick/items/qquicktextinput_p_p.h b/src/quick/items/qquicktextinput_p_p.h index 57eff17..11096cf 100644 --- a/src/quick/items/qquicktextinput_p_p.h +++ b/src/quick/items/qquicktextinput_p_p.h @@ -110,7 +110,7 @@ public: , updateType(UpdatePaintNode) , mouseSelectionMode(QQuickTextInput::SelectCharacters) , m_layoutDirection(Qt::LayoutDirectionAuto) - , m_passwordCharacter(QLatin1Char('*')) + , m_passwordCharacter(qApp->styleHints()->passwordMaskCharacter()) , focusOnPress(true) , cursorVisible(false) , cursorPending(false) diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 4ffbe9c..8c72be5 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -3148,6 +3148,7 @@ void tst_qquicktextinput::echoMode() QCOMPARE(initial, QLatin1String("ABCDefgh")); QCOMPARE(input->echoMode(), QQuickTextInput::Normal); QCOMPARE(input->displayText(), input->text()); + const QString passwordMaskCharacter = qApp->styleHints()->passwordMaskCharacter(); //Normal ref &= ~Qt::ImhHiddenText; ref &= ~(Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); @@ -3155,7 +3156,7 @@ void tst_qquicktextinput::echoMode() input->setEchoMode(QQuickTextInput::NoEcho); QCOMPARE(input->text(), initial); QCOMPARE(input->displayText(), QLatin1String("")); - QCOMPARE(input->passwordCharacter(), QLatin1String("*")); + QCOMPARE(input->passwordCharacter(), passwordMaskCharacter); //NoEcho ref |= Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); @@ -3165,7 +3166,7 @@ void tst_qquicktextinput::echoMode() ref |= Qt::ImhHiddenText; ref |= (Qt::ImhNoAutoUppercase | Qt::ImhNoPredictiveText | Qt::ImhSensitiveData); QCOMPARE(input->text(), initial); - QCOMPARE(input->displayText(), QLatin1String("********")); + QCOMPARE(input->displayText(), QString(8, passwordMaskCharacter.at(0))); QCOMPARE((Qt::InputMethodHints) input->inputMethodQuery(Qt::ImHints).toInt(), ref); // clearing input hints do not clear bits set by echo mode input->setInputMethodHints(Qt::ImhNone); @@ -3220,7 +3221,7 @@ void tst_qquicktextinput::passwordEchoDelay() QQuickItem *cursor = input->findChild("cursor"); QVERIFY(cursor); - QChar fillChar = QLatin1Char('*'); + QChar fillChar = qApp->styleHints()->passwordMaskCharacter(); input->setEchoMode(QQuickTextInput::Password); QCOMPARE(input->displayText(), QString(8, fillChar)); -- 1.7.2.5