From 8cd3439154037f7df9e0986e426e929384518939 Mon Sep 17 00:00:00 2001 From: gdd Date: Tue, 25 Jan 2011 18:30:03 +0000 Subject: [PATCH] Added the possibility to set the echo mode of a preference line edit field. The available names for the option are: "echo", "echo_mode", "echomode" Usage: Add a preference option for passwords --- src/Qtx/QtxPagePrefMgr.cxx | 54 ++++++++++++++++++++++++++++++++++++-- src/Qtx/QtxPagePrefMgr.h | 4 +++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/Qtx/QtxPagePrefMgr.cxx b/src/Qtx/QtxPagePrefMgr.cxx index 938271307..e8b58835f 100644 --- a/src/Qtx/QtxPagePrefMgr.cxx +++ b/src/Qtx/QtxPagePrefMgr.cxx @@ -2097,7 +2097,8 @@ QtxPagePrefEditItem::QtxPagePrefEditItem( const QString& title, QtxPreferenceIte const QString& sect, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ), myType( String ), - myDecimals( 1000 ) + myDecimals( 1000 ), + myEchoMode( 0 ) { setControl( myEditor = new QLineEdit() ); updateEditor(); @@ -2120,7 +2121,8 @@ QtxPagePrefEditItem::QtxPagePrefEditItem( const int type, const QString& title, const QString& param ) : QtxPageNamedPrefItem( title, parent, sect, param ), myType( type ), - myDecimals( 1000 ) + myDecimals( 1000 ), + myEchoMode( 0 ) { setControl( myEditor = new QLineEdit() ); updateEditor(); @@ -2181,6 +2183,30 @@ void QtxPagePrefEditItem::setDecimals( const int dec ) updateEditor(); } +/*! + \brief Get the line edit's echo mode + \return preference item echo mode value + \sa setEchoMode() +*/ +int QtxPagePrefEditItem::echoMode() const +{ + return myEchoMode; +} + +/*! + \brief Set the line edit's echo mode + \param echo new preference item echo mode value + \sa echoMode() +*/ +void QtxPagePrefEditItem::setEchoMode( const int echo ) +{ + if ( myEchoMode == echo ) + return; + + myEchoMode = echo; + updateEditor(); +} + /*! \brief Store preference item to the resource manager. \sa retrieve() @@ -2212,6 +2238,8 @@ QVariant QtxPagePrefEditItem::optionValue( const QString& name ) const return inputType(); else if ( name == "precision" || name == "prec" || name == "decimals" ) return decimals(); + else if ( name == "echo" || name == "echo_mode" || name == "echomode") + return echoMode(); else return QtxPageNamedPrefItem::optionValue( name ); } @@ -2233,6 +2261,10 @@ void QtxPagePrefEditItem::setOptionValue( const QString& name, const QVariant& v if ( val.canConvert( QVariant::Int ) ) setDecimals( val.toInt() ); } + else if ( name == "echo" || name == "echo_mode" || name == "echomode") { + if ( val.canConvert( QVariant::Int ) ) + setEchoMode( val.toInt() ); + } else QtxPageNamedPrefItem::setOptionValue( name, val ); } @@ -2242,6 +2274,24 @@ void QtxPagePrefEditItem::setOptionValue( const QString& name, const QVariant& v */ void QtxPagePrefEditItem::updateEditor() { + switch (myEchoMode) + { + case 0: + myEditor->setEchoMode(QLineEdit::Normal); + break; + case 1: + myEditor->setEchoMode(QLineEdit::NoEcho); + break; + case 2: + myEditor->setEchoMode(QLineEdit::Password); + break; + case 3: + myEditor->setEchoMode(QLineEdit::PasswordEchoOnEdit); + break; + default: + myEditor->setEchoMode(QLineEdit::Normal); + } + QValidator* val = 0; switch ( inputType() ) { diff --git a/src/Qtx/QtxPagePrefMgr.h b/src/Qtx/QtxPagePrefMgr.h index 592e8da35..92f0b4a8c 100644 --- a/src/Qtx/QtxPagePrefMgr.h +++ b/src/Qtx/QtxPagePrefMgr.h @@ -407,6 +407,9 @@ public: int decimals() const; void setDecimals( const int ); + + int echoMode() const; + void setEchoMode( const int ); virtual void store(); virtual void retrieve(); @@ -421,6 +424,7 @@ private: private: int myType; int myDecimals; + int myEchoMode; QLineEdit* myEditor; }; -- 2.39.2