|
QtPass 2.0.0
Developer documentation
|
A QLineEdit for a password that can be shown: whatever is copied out of it is marked as a secret and reported for autoclear. More...
#include <secretlineedit.h>
Signals | |
| void | copied (const QString &text) |
| Selected text was copied out of the line edit. | |
Public Member Functions | |
| SecretLineEdit (QWidget *parent=nullptr) | |
| Constructs the line edit. | |
| auto | createSecretContextMenu () -> QMenu * |
| The standard context menu, with Copy and Cut going through the secret copy. | |
Protected Member Functions | |
| void | keyPressEvent (QKeyEvent *event) override |
| Ctrl+C copies with the hints, Ctrl+X as well before it deletes; after any other key the primary selection gets the marked selection, not QLineEdit's plain-text copy. | |
| void | mouseReleaseEvent (QMouseEvent *event) override |
| Fills the primary selection with the marked selection on a left-button release, instead of QLineEdit's plain-text copy. | |
| void | contextMenuEvent (QContextMenuEvent *event) override |
| Shows createSecretContextMenu(). | |
Private Member Functions | |
| void | copySelection (QClipboard::Mode mode) |
| Puts the selection on the clipboard or in the primary selection as secret-marked MIME data and emits copied(). Does nothing in Password echo mode or without a selection, as QLineEdit::copy() itself. | |
| void | cutSelection () |
| Copies the selection through copySelection() and then deletes it. Does nothing when read-only or without a selection, as QLineEdit::cut(). | |
| void | withoutPlainSelectionCopy (const std::function< void()> &handler) |
| Runs a base-class event handler so that it cannot fill the primary selection with plain text: in a read-only field in Normal echo mode the handler runs under Password mode, which makes QLineEdit skip the copy without moving cursor or selection. Editable fields run the handler as is and rely on publishSelection() replacing the plain copy at once. | |
| void | publishSelection () |
| Fills the X11 primary selection with the marked selection, on platforms that have one; called after a handled key or a left-button release, where QLineEdit would have copied plain text. | |
A QLineEdit for a password that can be shown: whatever is copied out of it is marked as a secret and reported for autoclear.
QLineEdit copies nothing in Password echo mode, but once a "show" button switches it to Normal it copies plain text, without the hints, on four paths: Ctrl+C, the context menu's Copy, and the X11 primary selection after a mouse selection or a key. Unlike QTextEdit it has no createMimeDataFromSelection() to hook. Here Ctrl+C and Copy put buildClipboardMimeData() on the clipboard instead, and the key and mouse handlers keep QLineEdit from filling the primary selection at all (it runs them in Password echo mode) and fill it with the marked data instead, so plain text never gets there, not even for a moment. Each copy emits copied() so the text is cleared with the rest when the autoclear timer runs. Dragging is off, as QLineEdit has it by default.
In an editable field (the password editor) Ctrl+X, Cut, and the keys that delete to the end of the line or the whole line copy the same way before they delete. Password mode would turn off undo, make Ctrl+arrow jump to the ends and change the input method hints there, so the base handlers run as they are and the marked selection replaces QLineEdit's plain one at once, in the same event: X11 and Wayland hand selection data over only when another program asks for it, which reaches QtPass through its event loop, after the replacement.
Definition at line 44 of file secretlineedit.h.
|
explicit |
Constructs the line edit.
| parent | Owner. |
Definition at line 17 of file secretlineedit.cpp.
|
overrideprotected |
Shows createSecretContextMenu().
| event | The context menu event. |
Definition at line 75 of file secretlineedit.cpp.
|
signal |
Selected text was copied out of the line edit.
| text | The text, as put on the clipboard or in the selection. |
|
private |
Puts the selection on the clipboard or in the primary selection as secret-marked MIME data and emits copied(). Does nothing in Password echo mode or without a selection, as QLineEdit::copy() itself.
| mode | Clipboard for Ctrl+C and Copy, Selection for the X11 primary selection. |
Definition at line 81 of file secretlineedit.cpp.
|
nodiscard |
The standard context menu, with Copy and Cut going through the secret copy.
Definition at line 19 of file secretlineedit.cpp.
|
private |
Copies the selection through copySelection() and then deletes it. Does nothing when read-only or without a selection, as QLineEdit::cut().
Definition at line 91 of file secretlineedit.cpp.
|
overrideprotected |
Ctrl+C copies with the hints, Ctrl+X as well before it deletes; after any other key the primary selection gets the marked selection, not QLineEdit's plain-text copy.
| event | The key event. |
Definition at line 36 of file secretlineedit.cpp.
|
overrideprotected |
Fills the primary selection with the marked selection on a left-button release, instead of QLineEdit's plain-text copy.
| event | The mouse event. |
Definition at line 67 of file secretlineedit.cpp.
|
private |
Fills the X11 primary selection with the marked selection, on platforms that have one; called after a handled key or a left-button release, where QLineEdit would have copied plain text.
Definition at line 119 of file secretlineedit.cpp.
|
private |
Runs a base-class event handler so that it cannot fill the primary selection with plain text: in a read-only field in Normal echo mode the handler runs under Password mode, which makes QLineEdit skip the copy without moving cursor or selection. Editable fields run the handler as is and rely on publishSelection() replacing the plain copy at once.
| handler | The base handler call, e.g. QLineEdit::keyPressEvent. |
Definition at line 100 of file secretlineedit.cpp.