QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgspasswordlineedit.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspasswordlineedit.cpp
3 ------------------------
4 begin : March 13, 2017
5 copyright : (C) 2017 by Alexander Bruy
6 email : alexander dot bruy at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgspasswordlineedit.h"
19#include "moc_qgspasswordlineedit.cpp"
20#include "qgsapplication.h"
21
22QgsPasswordLineEdit::QgsPasswordLineEdit( QWidget *parent, bool passwordVisible )
23 : QLineEdit( parent )
24{
25 mShowPasswordIcon = QgsApplication::getThemeIcon( QStringLiteral( "/mActionShowAllLayers.svg" ) );
26 mHidePasswordIcon = QgsApplication::getThemeIcon( QStringLiteral( "/mActionHideAllLayers.svg" ) );
27
28 mActionShowHidePassword = addAction( mShowPasswordIcon, QLineEdit::TrailingPosition );
29 mActionShowHidePassword->setCheckable( true );
30
31 if ( mLockIconVisible )
32 {
33 mActionLock = addAction( QgsApplication::getThemeIcon( QStringLiteral( "/lockedGray.svg" ) ), QLineEdit::LeadingPosition );
34 }
35
36 setPasswordVisibility( passwordVisible );
37 connect( mActionShowHidePassword, &QAction::triggered, this, &QgsPasswordLineEdit::togglePasswordVisibility );
38}
39
41{
42 togglePasswordVisibility( visible );
43}
44
45void QgsPasswordLineEdit::togglePasswordVisibility( bool toggled )
46{
47 if ( toggled )
48 {
49 setEchoMode( QLineEdit::Normal );
50 mActionShowHidePassword->setIcon( mHidePasswordIcon );
51 mActionShowHidePassword->setToolTip( tr( "Hide text" ) );
52 }
53 else
54 {
55 setEchoMode( QLineEdit::Password );
56 mActionShowHidePassword->setIcon( mShowPasswordIcon );
57 mActionShowHidePassword->setToolTip( tr( "Show text" ) );
58 }
59}
60
62{
63 mLockIconVisible = visible;
64 if ( mLockIconVisible )
65 {
66 if ( !mActionLock )
67 {
68 mActionLock = addAction( QgsApplication::getThemeIcon( QStringLiteral( "/lockedGray.svg" ) ), QLineEdit::LeadingPosition );
69 }
70 }
71 else
72 {
73 if ( mActionLock )
74 {
75 removeAction( mActionLock );
76 mActionLock = nullptr;
77 }
78 }
79}
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
void setPasswordVisibility(bool visible)
Set state of the password's visibility.
QgsPasswordLineEdit(QWidget *parent=nullptr, bool passwordVisible=false)
Constructor for QgsPasswordLineEdit.
void setShowLockIcon(bool visible)
Define if a lock icon shall be shown on the left of the widget.