Password editor mask delay stylable by platform plugin
Replaced hard coding as QT_GUI_PASSWORD_ECHO_DELAY with a style hint. Change-Id: I0b78ebad723dbe19d9b9496583203e31545874e2 Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
083052933f
commit
bc0b37d6b6
@ -291,6 +291,8 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
|
||||
return 500;
|
||||
case ShowIsFullScreen:
|
||||
return false;
|
||||
case PasswordMaskDelay:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -121,7 +121,8 @@ public:
|
||||
StartDragDistance,
|
||||
StartDragTime,
|
||||
KeyboardAutoRepeatRate,
|
||||
ShowIsFullScreen
|
||||
ShowIsFullScreen,
|
||||
PasswordMaskDelay
|
||||
};
|
||||
|
||||
virtual QVariant styleHint(StyleHint hint) const;
|
||||
|
@ -96,4 +96,9 @@ bool QStyleHints::showIsFullScreen() const
|
||||
return hint(QPlatformIntegration::ShowIsFullScreen).toBool();
|
||||
}
|
||||
|
||||
int QStyleHints::passwordMaskDelay() const
|
||||
{
|
||||
return hint(QPlatformIntegration::PasswordMaskDelay).toInt();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -62,6 +62,8 @@ public:
|
||||
int keyboardAutoRepeatRate() const;
|
||||
int cursorFlashTime() const;
|
||||
bool showIsFullScreen() const;
|
||||
int passwordMaskDelay() const;
|
||||
|
||||
private:
|
||||
friend class QGuiApplication;
|
||||
QStyleHints();
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "qclipboard.h"
|
||||
#include <private/qguiapplication_p.h>
|
||||
#include <qplatformtheme_qpa.h>
|
||||
#include <qstylehints.h>
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
#include "qaccessible.h"
|
||||
#endif
|
||||
@ -58,21 +59,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
static const int qt_passwordEchoDelay = QT_GUI_PASSWORD_ECHO_DELAY;
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\macro QT_GUI_PASSWORD_ECHO_DELAY
|
||||
|
||||
\internal
|
||||
|
||||
Defines the amount of time in milliseconds the last entered character
|
||||
should be displayed unmasked in the Password echo mode.
|
||||
|
||||
If not defined in qplatformdefs.h there will be no delay in masking
|
||||
password characters.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\internal
|
||||
@ -113,7 +99,6 @@ void QWidgetLineControl::updateDisplayText(bool forceUpdate)
|
||||
|
||||
if (m_echoMode == QLineEdit::Password) {
|
||||
str.fill(m_passwordCharacter);
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
if (m_passwordEchoTimer != 0 && m_cursor > 0 && m_cursor <= m_text.length()) {
|
||||
int cursor = m_cursor - 1;
|
||||
QChar uc = m_text.at(cursor);
|
||||
@ -126,7 +111,6 @@ void QWidgetLineControl::updateDisplayText(bool forceUpdate)
|
||||
str[cursor - 1] = uc;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else if (m_echoMode == QLineEdit::PasswordEchoOnEdit && !m_passwordEchoEditing) {
|
||||
str.fill(m_passwordCharacter);
|
||||
}
|
||||
@ -818,13 +802,13 @@ void QWidgetLineControl::addCommand(const Command &cmd)
|
||||
*/
|
||||
void QWidgetLineControl::internalInsert(const QString &s)
|
||||
{
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
if (m_echoMode == QLineEdit::Password) {
|
||||
if (m_passwordEchoTimer != 0)
|
||||
killTimer(m_passwordEchoTimer);
|
||||
m_passwordEchoTimer = startTimer(qt_passwordEchoDelay);
|
||||
int delay = qGuiApp->styleHints()->passwordMaskDelay();
|
||||
if (delay > 0)
|
||||
m_passwordEchoTimer = startTimer(delay);
|
||||
}
|
||||
#endif
|
||||
if (hasSelectedText())
|
||||
addCommand(Command(SetSelection, m_cursor, 0, m_selstart, m_selend));
|
||||
if (m_maskData) {
|
||||
@ -1517,12 +1501,10 @@ void QWidgetLineControl::timerEvent(QTimerEvent *event)
|
||||
} else if (event->timerId() == m_tripleClickTimer) {
|
||||
killTimer(m_tripleClickTimer);
|
||||
m_tripleClickTimer = 0;
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
} else if (event->timerId() == m_passwordEchoTimer) {
|
||||
killTimer(m_passwordEchoTimer);
|
||||
m_passwordEchoTimer = 0;
|
||||
updateDisplayText();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,9 +93,7 @@ public:
|
||||
m_ascent(0), m_maxLength(32767), m_lastCursorPos(-1),
|
||||
m_tripleClickTimer(0), m_maskData(0), m_modifiedState(0), m_undoState(0),
|
||||
m_selstart(0), m_selend(0), m_passwordEchoEditing(false)
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
, m_passwordEchoTimer(0)
|
||||
#endif
|
||||
#if defined(Q_WS_MAC)
|
||||
, m_threadChecks(false)
|
||||
, m_textLayoutThread(0)
|
||||
@ -306,10 +304,8 @@ public:
|
||||
|
||||
void updatePasswordEchoEditing(bool editing);
|
||||
bool passwordEchoEditing() const {
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
if (m_passwordEchoTimer != 0)
|
||||
return true;
|
||||
#endif
|
||||
return m_passwordEchoEditing ;
|
||||
}
|
||||
|
||||
@ -484,17 +480,13 @@ private:
|
||||
|
||||
bool m_passwordEchoEditing;
|
||||
QChar m_passwordCharacter;
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
int m_passwordEchoTimer;
|
||||
#endif
|
||||
void cancelPasswordEchoTimer()
|
||||
{
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
if (m_passwordEchoTimer != 0) {
|
||||
killTimer(m_passwordEchoTimer);
|
||||
m_passwordEchoTimer = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int redoTextLayout() const;
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "qcompleter.h"
|
||||
#include "qstandarditemmodel.h"
|
||||
#include "qplatformtheme_qpa.h"
|
||||
#include "qstylehints.h"
|
||||
#include <private/qguiapplication_p.h>
|
||||
|
||||
#ifndef QT_NO_CLIPBOARD
|
||||
@ -174,10 +175,7 @@ private slots:
|
||||
void displayText_data();
|
||||
void displayText();
|
||||
void passwordEchoOnEdit();
|
||||
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
void passwordEchoDelay();
|
||||
#endif
|
||||
|
||||
void maxLength_mask_data();
|
||||
void maxLength_mask();
|
||||
@ -1664,9 +1662,10 @@ void tst_QLineEdit::passwordEchoOnEdit()
|
||||
testWidget->setEchoMode(QLineEdit::Normal);
|
||||
}
|
||||
|
||||
#ifdef QT_GUI_PASSWORD_ECHO_DELAY
|
||||
void tst_QLineEdit::passwordEchoDelay()
|
||||
{
|
||||
if (qGuiApp->styleHints()->passwordMaskDelay() <= 0)
|
||||
QSKIP("No mask delay in use");
|
||||
QStyleOptionFrameV2 opt;
|
||||
QChar fillChar = testWidget->style()->styleHint(QStyle::SH_LineEdit_PasswordCharacter, &opt, testWidget);
|
||||
|
||||
@ -1686,7 +1685,7 @@ void tst_QLineEdit::passwordEchoDelay()
|
||||
QCOMPARE(testWidget->displayText(), QString(4, fillChar));
|
||||
QTest::keyPress(testWidget, '4');
|
||||
QCOMPARE(testWidget->displayText(), QString(4, fillChar) + QLatin1Char('4'));
|
||||
QTest::qWait(QT_GUI_PASSWORD_ECHO_DELAY);
|
||||
QTest::qWait(qGuiApp->styleHints()->passwordMaskDelay());
|
||||
QTRY_COMPARE(testWidget->displayText(), QString(5, fillChar));
|
||||
QTest::keyPress(testWidget, '5');
|
||||
QCOMPARE(testWidget->displayText(), QString(5, fillChar) + QLatin1Char('5'));
|
||||
@ -1714,7 +1713,6 @@ void tst_QLineEdit::passwordEchoDelay()
|
||||
// restore clean state
|
||||
testWidget->setEchoMode(QLineEdit::Normal);
|
||||
}
|
||||
#endif
|
||||
|
||||
void tst_QLineEdit::maxLength_mask_data()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user