aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-12-16 13:57:54 +1000
committerQt by Nokia <qt-info@nokia.com>2011-12-20 07:33:37 +0100
commit657f6d7111a4ee6f3e8ef0919956990fc8abbf3d (patch)
treec0707088f5bdae59523a35226eb1a8d499d1a1e8 /src
parent59e607a2ce1e1fbb5324040c26554ecc22d8b1fd (diff)
Delay masking the last character in Password echo mode.
If QT_GUI_PASSWORD_ECHO_DELAY is defined in qplatformdefs.h with an integer value in milliseconds, QLineEdit and TextInput will display the last character entered unmasked for that delay period and then mask the character as normal. If QT_GUI_PASSWORD_ECHO_DELAY is not defined then the behaviour is unchanged. Task-number: QTBUG-17003 Task-number: QTBUG-20719 (cherry picked from commit f9e7aee2019d321edd655bfde7de43f20a106971) Change-Id: I9a8647a0adeb94fc6beea949cdce7336671c898e Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquicktextinput.cpp46
-rw-r--r--src/quick/items/qquicktextinput_p_p.h11
2 files changed, 54 insertions, 3 deletions
diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp
index b6bc33c767..903769ba0d 100644
--- a/src/quick/items/qquicktextinput.cpp
+++ b/src/quick/items/qquicktextinput.cpp
@@ -62,6 +62,10 @@ QT_BEGIN_NAMESPACE
DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD)
+#ifdef QT_GUI_PASSWORD_ECHO_DELAY
+static const int qt_passwordEchoDelay = QT_GUI_PASSWORD_ECHO_DELAY;
+#endif
+
/*!
\qmlclass TextInput QQuickTextInput
\inqmlmodule QtQuick 2
@@ -976,6 +980,7 @@ void QQuickTextInput::setEchoMode(QQuickTextInput::EchoMode echo)
Q_D(QQuickTextInput);
if (echoMode() == echo)
return;
+ d->cancelPasswordEchoTimer();
d->m_echoMode = echo;
d->m_passwordEchoEditing = false;
d->updateInputMethodHints();
@@ -1992,8 +1997,13 @@ void QQuickTextInput::itemChange(ItemChange change, const ItemChangeData &value)
bool hasFocus = value.boolValue;
d->focused = hasFocus;
setCursorVisible(hasFocus); // ### refactor: && d->canvas && d->canvas->hasFocus()
- if (echoMode() == QQuickTextInput::PasswordEchoOnEdit && !hasFocus)
+#ifdef QT_GUI_PASSWORD_ECHO_DELAY
+ if (!hasFocus && (d->m_passwordEchoEditing || d->m_passwordEchoTimer.isActive())) {
+#else
+ if (!hasFocus && d->m_passwordEchoEditing) {
+#endif
d->updatePasswordEchoEditing(false);//QQuickTextInputPrivate sets it on key events, but doesn't deal with focus events
+ }
if (!hasFocus)
d->deselect();
}
@@ -2158,9 +2168,25 @@ void QQuickTextInputPrivate::updateDisplayText(bool forceUpdate)
else
str = m_text;
- if (m_echoMode == QQuickTextInput::Password
- || (m_echoMode == QQuickTextInput::PasswordEchoOnEdit && !m_passwordEchoEditing))
+ if (m_echoMode == QQuickTextInput::Password) {
+ str.fill(m_passwordCharacter);
+#ifdef QT_GUI_PASSWORD_ECHO_DELAY
+ if (m_passwordEchoTimer.isActive() && m_cursor > 0 && m_cursor <= m_text.length()) {
+ int cursor = m_cursor - 1;
+ QChar uc = m_text.at(cursor);
+ str[cursor] = uc;
+ if (cursor > 0 && uc.unicode() >= 0xdc00 && uc.unicode() < 0xe000) {
+ // second half of a surrogate, check if we have the first half as well,
+ // if yes restore both at once
+ uc = m_text.at(cursor - 1);
+ if (uc.unicode() >= 0xd800 && uc.unicode() < 0xdc00)
+ str[cursor - 1] = uc;
+ }
+ }
+#endif
+ } else if (m_echoMode == QQuickTextInput::PasswordEchoOnEdit && !m_passwordEchoEditing) {
str.fill(m_passwordCharacter);
+ }
// replace certain non-printable characters with spaces (to avoid
// drawing boxes when using fonts that don't have glyphs for such
@@ -2437,6 +2463,7 @@ void QQuickTextInputPrivate::init(const QString &txt)
*/
void QQuickTextInputPrivate::updatePasswordEchoEditing(bool editing)
{
+ cancelPasswordEchoTimer();
m_passwordEchoEditing = editing;
updateDisplayText();
}
@@ -2775,6 +2802,11 @@ void QQuickTextInputPrivate::addCommand(const Command &cmd)
*/
void QQuickTextInputPrivate::internalInsert(const QString &s)
{
+#ifdef QT_GUI_PASSWORD_ECHO_DELAY
+ Q_Q(QQuickTextInput);
+ if (m_echoMode == QQuickTextInput::Password)
+ m_passwordEchoTimer.start(qt_passwordEchoDelay, q);
+#endif
if (hasSelectedText())
addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend));
if (m_maskData) {
@@ -2812,6 +2844,7 @@ void QQuickTextInputPrivate::internalInsert(const QString &s)
void QQuickTextInputPrivate::internalDelete(bool wasBackspace)
{
if (m_cursor < (int) m_text.length()) {
+ cancelPasswordEchoTimer();
if (hasSelectedText())
addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend));
addCommand(Command((CommandType)((m_maskData ? 2 : 0) + (wasBackspace ? Remove : Delete)),
@@ -2838,6 +2871,7 @@ void QQuickTextInputPrivate::internalDelete(bool wasBackspace)
void QQuickTextInputPrivate::removeSelectedText()
{
if (m_selstart < m_selend && m_selend <= (int) m_text.length()) {
+ cancelPasswordEchoTimer();
separate();
int i ;
addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend));
@@ -3236,6 +3270,7 @@ void QQuickTextInputPrivate::internalUndo(int until)
{
if (!isUndoAvailable())
return;
+ cancelPasswordEchoTimer();
internalDeselect();
while (m_undoState && m_undoState > until) {
Command& cmd = m_history[--m_undoState];
@@ -3392,6 +3427,11 @@ void QQuickTextInput::timerEvent(QTimerEvent *event)
killTimer(d->m_deleteAllTimer);
d->m_deleteAllTimer = 0;
d->clear();
+#ifdef QT_GUI_PASSWORD_ECHO_DELAY
+ } else if (event->timerId() == d->m_passwordEchoTimer.timerId()) {
+ d->m_passwordEchoTimer.stop();
+ d->updateDisplayText();
+#endif
}
}
diff --git a/src/quick/items/qquicktextinput_p_p.h b/src/quick/items/qquicktextinput_p_p.h
index a5fa6d58b8..804adf4e62 100644
--- a/src/quick/items/qquicktextinput_p_p.h
+++ b/src/quick/items/qquicktextinput_p_p.h
@@ -50,12 +50,14 @@
#include <QtDeclarative/qdeclarative.h>
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qpointer.h>
+#include <QtCore/qbasictimer.h>
#include <QtGui/qclipboard.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qpalette.h>
#include <QtGui/qtextlayout.h>
#include <QtGui/qstylehints.h>
+#include "qplatformdefs.h"
//
// W A R N I N G
@@ -204,6 +206,9 @@ public:
int m_blinkPeriod; // 0 for non-blinking cursor
int m_blinkTimer;
int m_deleteAllTimer;
+#ifdef QT_GUI_PASSWORD_ECHO_DELAY
+ QBasicTimer m_passwordEchoTimer;
+#endif
int m_ascent;
int m_maxLength;
int m_lastCursorPos;
@@ -367,6 +372,12 @@ public:
void updatePasswordEchoEditing(bool editing);
+ void cancelPasswordEchoTimer() {
+#ifdef QT_GUI_PASSWORD_ECHO_DELAY
+ m_passwordEchoTimer.stop();
+#endif
+ }
+
Qt::LayoutDirection layoutDirection() const {
if (m_layoutDirection == Qt::LayoutDirectionAuto) {
if (m_text.isEmpty())