12#include <QContextMenuEvent>
22 setTextFormat(Qt::PlainText);
24 setToolTip(tr(
"Double-click to rename this field"));
34 if (event->button() == Qt::LeftButton) {
38 QLabel::mouseDoubleClickEvent(event);
45 menu.exec(event->globalPos());
61 m_editor->setObjectName(QStringLiteral(
"fieldNameEditor"));
63 connect(
m_editor, &QLineEdit::editingFinished,
this,
67 auto *form = qobject_cast<QFormLayout *>(parentWidget()->layout());
69 QFormLayout::ItemRole role{};
70 if (form !=
nullptr) {
71 form->getWidgetPosition(
this, &row, &role);
74 form->removeWidget(
this);
76 form->setWidget(row, role,
m_editor);
83 if (QWidget *value = buddy()) {
84 QWidget *before = value->previousInFocusChain();
85 if (before !=
nullptr && before !=
m_editor) {
86 QWidget::setTabOrder(before,
m_editor);
88 QWidget::setTabOrder(
m_editor, value);
99 if (event->type() != QEvent::KeyPress || watched !=
m_editor) {
100 return QLabel::eventFilter(watched, event);
102 switch (
static_cast<QKeyEvent *
>(event)->key()) {
113 return QLabel::eventFilter(watched, event);
129 auto *form = qobject_cast<QFormLayout *>(parentWidget()->layout());
131 QFormLayout::ItemRole role{};
132 if (form !=
nullptr) {
133 form->getWidgetPosition(editor, &row, &role);
138 if (editor->hasFocus()) {
139 if (QWidget *value = buddy()) {
140 value->setFocus(Qt::OtherFocusReason);
145 form->removeWidget(editor);
146 form->setWidget(row, role,
this);
149 editor->deleteLater();
153 const QString from =
m_name;
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...
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.
~FieldLabel() override
Takes an open editor with it: the editor is a sibling, not a child, so it would otherwise stay behind...
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().
QString m_name
The field's key, whole (the text shown may be cut).
void copied(const QString &text)
Selected text was copied out of the line edit.
static auto withoutLineBreaks(QString text) -> QString
text with every line break (see isLineBreak()) removed: what a one-line field keeps of a paste.
SecretLineEdit(QWidget *parent=nullptr)
Constructs the line edit.
static auto shownName(const QString &name, qsizetype max=kMaxShownName) -> QString
A name or path from the store, as a label or list shows it: one line, at most max characters.
FieldLabel: the in-place renamable, removable name label of a key: value field in PasswordDialog.
QLineEdit whose copies, cuts and primary-selection fills carry the secret clipboard hints and are rep...
Util: static helpers for the process environment, binary discovery, store paths, URL safety and the l...