QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
fieldlabel.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 FIELDLABEL_H_
9#define FIELDLABEL_H_
10
11#include <QLabel>
12#include <QPointer>
13
14class QLineEdit;
15
26class FieldLabel : public QLabel {
27 Q_OBJECT
28
29public:
35 explicit FieldLabel(const QString &name, QWidget *parent = nullptr);
36
42 [[nodiscard]] auto name() const -> QString { return m_name; }
47 void setName(const QString &name);
53 ~FieldLabel() override;
54
55public slots:
59 void startEdit();
60
61signals:
68 void renamed(const QString &from, const QString &to);
77 void copied(const QString &text);
78
79protected:
84 void mouseDoubleClickEvent(QMouseEvent *event) override;
89 void contextMenuEvent(QContextMenuEvent *event) override;
96 auto eventFilter(QObject *watched, QEvent *event) -> bool override;
97
98private:
103 void finishEdit(bool commit);
104
110 QPointer<QLineEdit> m_editor;
112 QString m_name;
113};
114
115#endif // FIELDLABEL_H_
The name of a key: value field in PasswordDialog, editable in place: double-click or the context menu...
Definition fieldlabel.h:26
FieldLabel(const QString &name, QWidget *parent=nullptr)
Label for the field called name.
void contextMenuEvent(QContextMenuEvent *event) override
Menu with Rename field and Remove field.
QPointer< QLineEdit > m_editor
The line edit open over the label while a rename is in progress; null otherwise. A sibling in the par...
Definition fieldlabel.h:110
void copied(const QString &text)
Text was copied out of the name editor, marked as a secret.
void setName(const QString &name)
Name the field name and show it.
void removeRequested()
The user chose "Remove field".
void finishEdit(bool commit)
Close the editor, putting the label back in its place.
void renamed(const QString &from, const QString &to)
The user typed a different name and confirmed it.
void mouseDoubleClickEvent(QMouseEvent *event) override
A left double-click starts editing the name.
void startEdit()
Open the in-place editor over the label.
auto eventFilter(QObject *watched, QEvent *event) -> bool override
Escape in the editor cancels the edit.
auto name() const -> QString
The field's key, whole; the label shows it through Util::shownName().
Definition fieldlabel.h:42
QString m_name
The field's key, whole (the text shown may be cut).
Definition fieldlabel.h:112