QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
secretlineedit.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
8#ifndef SRC_SECRETLINEEDIT_H_
9#define SRC_SECRETLINEEDIT_H_
10
11#include <QClipboard>
12#include <QLineEdit>
13#include <functional>
14
15class QMenu;
16
44class SecretLineEdit : public QLineEdit {
45 Q_OBJECT
46
47public:
60 static constexpr int kMaxLength = 1 << 20;
61
66 explicit SecretLineEdit(QWidget *parent = nullptr);
76 explicit SecretLineEdit(const QString &text, QWidget *parent = nullptr);
77
83 [[nodiscard]] auto createSecretContextMenu() -> QMenu *;
84
91 [[nodiscard]] static auto isLineBreak(QChar ch) -> bool;
92
99 [[nodiscard]] static auto withoutLineBreaks(QString text) -> QString;
100
111 void setStoredText(const QString &text);
112
113signals:
118 void copied(const QString &text);
119
120protected:
127 void keyPressEvent(QKeyEvent *event) override;
128
134 void mouseReleaseEvent(QMouseEvent *event) override;
135
140 void contextMenuEvent(QContextMenuEvent *event) override;
141
142private:
150 void copySelection(QClipboard::Mode mode);
155 void cutSelection();
164 void withoutPlainSelectionCopy(const std::function<void()> &handler);
170 void publishSelection();
181 void pasteOneLine(QClipboard::Mode mode);
187 void markUndoBoundary();
188};
189
190#endif // SRC_SECRETLINEEDIT_H_
void mouseReleaseEvent(QMouseEvent *event) override
Fills the primary selection with the marked selection on a left-button release, instead of QLineEdit'...
void copied(const QString &text)
Selected text was copied out of the line edit.
void cutSelection()
Copies the selection through copySelection() and then deletes it. Does nothing when read-only or with...
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 re...
static auto withoutLineBreaks(QString text) -> QString
text with every line break (see isLineBreak()) removed: what a one-line field keeps of a paste.
auto createSecretContextMenu() -> QMenu *
The standard context menu, with Copy and Cut going through the secret copy.
void publishSelection()
Fills the X11 primary selection with the marked selection, on platforms that have one; called after a...
SecretLineEdit(QWidget *parent=nullptr)
Constructs the line edit.
void contextMenuEvent(QContextMenuEvent *event) override
Shows createSecretContextMenu().
static constexpr int kMaxLength
Most characters the line edit holds (1 MiB of them): its maxLength in place of QLineEdit's 32767.
void setStoredText(const QString &text)
Shows a value read from the entry exactly as it is stored.
static auto isLineBreak(QChar ch) -> bool
Whether ch breaks a line: LF, CR, NEL (U+0085), or the Unicode line and paragraph separators (U+2028,...
void markUndoBoundary()
Ends the current undo step, so that the next edit starts its own, as QLineEdit::paste() does around a...
void pasteOneLine(QClipboard::Mode mode)
Pastes the clipboard or the primary selection with its line breaks removed, as one undoable edit....
void copySelection(QClipboard::Mode mode)
Puts the selection on the clipboard or in the primary selection as secret-marked MIME data and emits ...
void keyPressEvent(QKeyEvent *event) override
Ctrl+C copies with the hints, Ctrl+X as well before it deletes; after any other key the primary selec...