1/*
2 SPDX-FileCopyrightText: 2017 Montel Laurent <montel@kde.org>
3 SPDX-FileCopyrightText: 2015 Elvis Angelaccio <elvis.angelaccio@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#ifndef KPASSWORDLINEEDIT_H
9#define KPASSWORDLINEEDIT_H
10
11#include <KPassword>
12#include <QLineEdit>
13#include <QWidget>
14#include <kwidgetsaddons_export.h>
15#include <memory>
16class QAction;
17
18/*!
19 * \class KPasswordLineEdit
20 * \inmodule KWidgetsAddons
21 *
22 * \brief A lineedit which allows to display password
23 *
24 * Usage Example:
25 *
26 * Get password
27 *
28 * \code
29 * KPasswordLineEdit *passwordLineEdit = new KPasswordLineEdit(parent);
30 * QString password = passwordLineEdit->password();
31 * \endcode
32 *
33 * \since 5.37
34 */
35class KWIDGETSADDONS_EXPORT KPasswordLineEdit : public QWidget
36{
37 Q_OBJECT
38
39 /*!
40 * \property KPasswordLineEdit::password
41 */
42 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
43
44 /*!
45 * \property KPasswordLineEdit::clearButtonEnabled
46 */
47 Q_PROPERTY(bool clearButtonEnabled READ isClearButtonEnabled WRITE setClearButtonEnabled)
48
49 /*!
50 * \property KPasswordLineEdit::echoMode
51 */
52 Q_PROPERTY(QLineEdit::EchoMode echoMode READ echoMode WRITE setEchoMode NOTIFY echoModeChanged)
53public:
54 /*!
55 * Constructs a lineedit password widget.
56 * \since 5.37
57 *
58 * \a parent Passed to lower level constructor.
59 */
60 explicit KPasswordLineEdit(QWidget *parent = nullptr);
61
62 ~KPasswordLineEdit() override;
63
64 /*!
65 * Assign password
66 */
67 void setPassword(const QString &password);
68
69 /*!
70 * Returns the password entered.
71 */
72 QString password() const;
73
74 /*!
75 * Clear text
76 */
77 void clear();
78
79 /*!
80 * Show/hide clear button (false by default)
81 */
82 void setClearButtonEnabled(bool clear);
83
84 /*!
85 * Inform if we show or not clear button
86 */
87 bool isClearButtonEnabled() const;
88
89 /*!
90 * Change echo mode (QLineEdit::Password by default)
91 */
92 void setEchoMode(QLineEdit::EchoMode mode);
93
94 /*!
95 * Return echo mode
96 */
97 QLineEdit::EchoMode echoMode() const;
98
99 /*!
100 * Set whether the line edit is read only.
101 * \since 6.0
102 */
103 void setReadOnly(bool readOnly);
104
105 /*!
106 * Return whether the line edit is read only.
107 * \since 6.0
108 */
109 bool isReadOnly() const;
110
111 /*!
112 * Return when the reveal password button is visible.
113 * \since 6.0
114 */
115 KPassword::RevealMode revealPasswordMode() const;
116
117 /*!
118 * Set when the reveal password button will be visible.
119 *
120 * The default is RevealPasswordMode::OnlyNew and the reveal password button will
121 * only be visible when entering a new password.
122 *
123 * This can be used to honor the lineedit_reveal_password kiosk key, for example:
124 *
125 * \code
126 * if (KAuthorized::authorize(QStringLiteral("lineedit_reveal_password"))) {
127 * passwordLineEdit.setRevealPasswordMode(KPasswordLineEdit::RevealPasswordMode::OnlyNew);
128 * } else {
129 * passwordLineEdit.setRevealPasswordMode(KPasswordLineEdit::RevealPasswordMode::Never);
130 * }
131 * \endcode
132 * \since 6.0
133 */
134 void setRevealPasswordMode(KPassword::RevealMode revealPasswordMode);
135
136#if KWIDGETSADDONS_ENABLE_DEPRECATED_SINCE(6, 0)
137 /*!
138 * Whether to show the visibility trailing action in the line edit.
139 * Default is true. This can be used to honor the lineedit_reveal_password
140 * kiosk key, for example:
141 * \code
142 * passwordLineEdit.setRevealPasswordAvailable(KAuthorized::authorize(QStringLiteral("lineedit_reveal_password")));
143 * \endcode
144 * \deprecated[6.0]
145 */
146 [[deprecated("Use setRevealPasswordMode")]] void setRevealPasswordAvailable(bool reveal);
147
148 /*!
149 * Whether the visibility trailing action in the line edit is visible.
150 * \deprecated[6.0]
151 */
152 [[deprecated("Use revealPasswordMode instead.")]] bool isRevealPasswordAvailable() const;
153#endif
154
155 /*!
156 * \internal
157 * Returns the QAction
158 */
159 QAction *toggleEchoModeAction() const;
160
161 /*!
162 * Returns the lineedit widget.
163 */
164 QLineEdit *lineEdit() const;
165
166Q_SIGNALS:
167 /*!
168 * When we click on visibility icon echo mode is switched between Normal echo mode and Password echo mode
169 */
170 void echoModeChanged(QLineEdit::EchoMode echoMode);
171
172 /*!
173 *
174 */
175 void passwordChanged(const QString &password);
176
177private:
178 std::unique_ptr<class KPasswordLineEditPrivate> const d;
179};
180
181#endif
182

source code of kwidgetsaddons/src/kpasswordlineedit.h