diff options
author | Timothy Pearson <[email protected]> | 2013-03-21 16:20:15 -0500 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-03-21 16:20:15 -0500 |
commit | d09860faff8dac4c63db6e22eeb556a15c2ffaeb (patch) | |
tree | ab7c58168fe33d8af1b9c04284cf38cb6a346139 /src/widgets | |
parent | ed9739fcff88bdf26974f4a80cd8df6de410d01a (diff) | |
download | qt3-d09860faff8dac4c63db6e22eeb556a15c2ffaeb.tar.gz qt3-d09860faff8dac4c63db6e22eeb556a15c2ffaeb.zip |
Add unpaged memory mode to TQString and TQLineEdit
Fix designer build warnings
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/qlineedit.cpp | 46 | ||||
-rw-r--r-- | src/widgets/qlineedit.h | 2 |
2 files changed, 40 insertions, 8 deletions
diff --git a/src/widgets/qlineedit.cpp b/src/widgets/qlineedit.cpp index d786829..2a71656 100644 --- a/src/widgets/qlineedit.cpp +++ b/src/widgets/qlineedit.cpp @@ -63,6 +63,9 @@ #include "../kernel/qinternal_p.h" #include "private/qtextlayout_p.h" #include "qvaluevector.h" +#if defined(Q_OS_LINUX) +#include <sys/mman.h> +#endif #if defined(QT_ACCESSIBILITY_SUPPORT) #include "qaccessible.h" #endif @@ -74,6 +77,11 @@ #define ACCEL_KEY(k) "\t" + QString("Ctrl+" #k) #endif +#if defined(Q_OS_LINUX) +#define LINUX_MEMLOCK_LIMIT_BYTES 16384 +#define LINUX_MEMLOCK_LIMIT_CHARACTERS LINUX_MEMLOCK_LIMIT_BYTES/sizeof(QChar) +#endif + #define innerMargin 1 struct QLineEditPrivate : public Qt @@ -451,6 +459,10 @@ QLineEdit::QLineEdit( const QString& contents, const QString &inputMask, QWidget QLineEdit::~QLineEdit() { + if ((d->echoMode == NoEcho) || (d->echoMode == Password) || (d->echoMode == PasswordThreeStars)) { + d->text.fill(QChar(0)); + munlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); + } delete [] d->maskData; delete d; } @@ -500,11 +512,16 @@ void QLineEdit::setText( const QString& text) QString QLineEdit::displayText() const { - if ( d->echoMode == NoEcho ) + if ( d->echoMode == NoEcho ) { return QString::fromLatin1(""); + } QString res = d->text; - if ( d->echoMode == Password ) + if ( d->echoMode == Password ) { res.fill( passwordChar() ); + } + else if ( d->echoMode == PasswordThreeStars ) { + res.fill( passwordChar(), res.length()*3 ); + } return ( res.isNull() ? QString::fromLatin1("") : res ); } @@ -598,11 +615,26 @@ QLineEdit::EchoMode QLineEdit::echoMode() const void QLineEdit::setEchoMode( EchoMode mode ) { - if (mode == (EchoMode)d->echoMode) + if (mode == (EchoMode)d->echoMode) { return; + } +#if defined(Q_OS_LINUX) + if (((mode == NoEcho) || (mode == Password) || (mode == PasswordThreeStars)) && ((EchoMode)d->echoMode == Normal)) { + if ((uint)d->maxLength > (LINUX_MEMLOCK_LIMIT_CHARACTERS-1)) { + d->maxLength = LINUX_MEMLOCK_LIMIT_CHARACTERS-1; + } + d->text.reserve(LINUX_MEMLOCK_LIMIT_CHARACTERS); + mlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); + d->text.setSecurityUnPaged(true); + } + else { + d->text.setSecurityUnPaged(false); + munlock(d->text.d->unicode, LINUX_MEMLOCK_LIMIT_BYTES); + } +#endif d->echoMode = mode; d->updateTextLayout(); - setInputMethodEnabled( mode == Normal ); + setInputMethodEnabled( ( mode == Normal ) || ( mode == Password) ); update(); } @@ -1688,12 +1720,12 @@ void QLineEdit::keyPressEvent( QKeyEvent * e ) case Key_Right: case Key_Left: if ( d->isRightToLeft() == (e->key() == Key_Right) ) { - if ( echoMode() == Normal ) + if (( echoMode() == Normal ) || ( echoMode() == Password )) cursorWordBackward( e->state() & ShiftButton ); else home( e->state() & ShiftButton ); } else { - if ( echoMode() == Normal ) + if (( echoMode() == Normal ) || ( echoMode() == Password )) cursorWordForward( e->state() & ShiftButton ); else end( e->state() & ShiftButton ); @@ -2069,7 +2101,7 @@ void QLineEdit::drawContents( QPainter *p ) // Asian users regard IM selection text as cursor on candidate // selection phase of input method, so ordinary cursor should be // invisible if IM selection text exists. - if ( d->cursorVisible && !supressCursor && !d->hasIMSelection() ) { + if ( d->cursorVisible && !supressCursor && !d->hasIMSelection() && (d->echoMode != PasswordThreeStars) ) { QPoint from( topLeft.x() + cix, lineRect.top() ); QPoint to = from + QPoint( 0, lineRect.height() ); p->drawLine( from, to ); diff --git a/src/widgets/qlineedit.h b/src/widgets/qlineedit.h index 3778e2a..b7e0fb8 100644 --- a/src/widgets/qlineedit.h +++ b/src/widgets/qlineedit.h @@ -94,7 +94,7 @@ public: bool frame() const; - enum EchoMode { Normal, NoEcho, Password }; + enum EchoMode { Normal, NoEcho, Password, PasswordThreeStars }; EchoMode echoMode() const; bool isReadOnly() const; |