Make password mask characters themeable.

Task-number: QTBUG-29871

Change-Id: I3cf739a321d7917f8f8431992e29bba0871b1934
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Mitch Curtis 2013-03-13 14:32:08 +01:00 committed by The Qt Project
parent 8597458ceb
commit f3612f39ff
12 changed files with 33 additions and 38 deletions

View File

@ -313,6 +313,8 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
return false;
case PasswordMaskDelay:
return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskDelay);
case PasswordMaskCharacter:
return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskCharacter);
case FontSmoothingGamma:
return qreal(1.7);
case StartDragVelocity:

View File

@ -140,7 +140,8 @@ public:
FontSmoothingGamma,
StartDragVelocity,
UseRtlExtensions,
SynthesizeMouseFromTouchEvents
SynthesizeMouseFromTouchEvents,
PasswordMaskCharacter
};
virtual QVariant styleHint(StyleHint hint) const;

View File

@ -238,6 +238,8 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
return QVariant(500);
case QPlatformTheme::PasswordMaskDelay:
return QVariant(int(0));
case QPlatformTheme::PasswordMaskCharacter:
return QVariant(QChar(0x25CF));
case QPlatformTheme::StartDragVelocity:
return QVariant(int(0)); // no limit
case QPlatformTheme::UseFullScreenForPopupMenu:

View File

@ -103,7 +103,8 @@ public:
UiEffects,
SpellCheckUnderlineStyle,
TabAllWidgets,
IconPixmapSizes
IconPixmapSizes,
PasswordMaskCharacter
};
enum DialogType {

View File

@ -192,6 +192,15 @@ int QStyleHints::passwordMaskDelay() const
return themeableHint(QPlatformTheme::PasswordMaskDelay, QPlatformIntegration::PasswordMaskDelay).toInt();
}
/*!
Returns the character used to mask the characters typed into text input
fields in password mode.
*/
QChar QStyleHints::passwordMaskCharacter() const
{
return themeableHint(QPlatformTheme::PasswordMaskCharacter, QPlatformIntegration::PasswordMaskCharacter).toChar();
}
/*!
Returns the gamma value used in font smoothing.
*/

View File

@ -62,6 +62,7 @@ public:
int cursorFlashTime() const;
bool showIsFullScreen() const;
int passwordMaskDelay() const;
QChar passwordMaskCharacter() const;
qreal fontSmoothingGamma() const;
bool useRtlExtensions() const;

View File

@ -448,6 +448,8 @@ QVariant QGnomeTheme::themeHint(QPlatformTheme::ThemeHint hint) const
}
case QPlatformTheme::KeyboardScheme:
return QVariant(int(GnomeKeyboardScheme));
case QPlatformTheme::PasswordMaskCharacter:
return QVariant(QChar(0x2022));
default:
break;
}

View File

@ -290,6 +290,8 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const
sizes << 16 << 32 << 64 << 128;
return QVariant::fromValue(sizes);
}
case QPlatformTheme::PasswordMaskDelay:
return QVariant(QChar(kBulletUnicode));
default:
break;
}

View File

@ -4905,20 +4905,12 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
ret = -1;
break;
case SH_LineEdit_PasswordCharacter: {
const QFontMetrics &fm = opt ? opt->fontMetrics
: (widget ? widget->fontMetrics() : QFontMetrics(QFont()));
ret = 0;
if (fm.inFont(QChar(0x25CF))) {
ret = 0x25CF;
} else if (fm.inFont(QChar(0x2022))) {
ret = 0x2022;
} else {
ret = '*';
}
const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme();
const QPlatformTheme::ThemeHint hintType = QPlatformTheme::PasswordMaskCharacter;
const QVariant hint = theme ? theme->themeHint(hintType) : QPlatformTheme::defaultThemeHint(hintType);
ret = hint.toChar().unicode();
break;
}
case SH_ToolBox_SelectedPageTitleBold:
ret = 1;
break;

View File

@ -2466,9 +2466,6 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
case SH_TabBar_PreferNoArrows:
ret = true;
break;
case SH_LineEdit_PasswordCharacter:
ret = kBulletUnicode;
break;
/*
case SH_DialogButtons_DefaultButton:
ret = QDialogButtons::Reject;

View File

@ -602,21 +602,6 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid
}
break;
#endif // QT_NO_RUBBERBAND
case SH_LineEdit_PasswordCharacter:
{
#ifdef Q_OS_WIN
if (widget && (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) {
const QFontMetrics &fm = widget->fontMetrics();
if (fm.inFont(QChar(0x25CF)))
ret = 0x25CF;
else if (fm.inFont(QChar(0x2022)))
ret = 0x2022;
}
#endif
if (!ret)
ret = '*';
}
break;
#ifndef QT_NO_WIZARD
case SH_WizardStyle:
ret = QWizard::ModernStyle;

View File

@ -360,9 +360,9 @@ void QLineEdit::setPlaceholderText(const QString& placeholderText)
\brief the displayed text
If \l echoMode is \l Normal this returns the same as text(); if
\l EchoMode is \l Password or \l PasswordEchoOnEdit it returns a string of asterisks
text().length() characters long, e.g. "******"; if \l EchoMode is
\l NoEcho returns an empty string, "".
\l EchoMode is \l Password or \l PasswordEchoOnEdit it returns a string of
platform-dependent password mask characters text().length() in size,
e.g. "******"; if \l EchoMode is \l NoEcho returns an empty string, "".
By default, this property contains an empty string.
@ -440,10 +440,11 @@ void QLineEdit::setFrame(bool enable)
\value NoEcho Do not display anything. This may be appropriate
for passwords where even the length of the
password should be kept secret.
\value Password Display asterisks instead of the characters
actually entered.
\value Password Display platform-dependent password mask characters instead
of the characters actually entered.
\value PasswordEchoOnEdit Display characters as they are entered
while editing otherwise display asterisks.
while editing otherwise display characters as with
\c Password.
\sa setEchoMode(), echoMode()
*/