8#include <QGraphicsProxyWidget>
22class InlineLabelLineEdit :
public QLineEdit
25 explicit InlineLabelLineEdit(InlineLabelEditor *owner)
31 void keyPressEvent(QKeyEvent *event)
override
33 if (event->key() == Qt::Key_Escape) {
38 QLineEdit::keyPressEvent(event);
42 InlineLabelEditor *m_owner;
70 auto *lineEdit =
new InlineLabelLineEdit(
this);
71 lineEdit->setText(element->
label());
73 QObject::connect(lineEdit, &QLineEdit::returnPressed, lineEdit, [
this] {
commit(); });
74 QObject::connect(lineEdit, &QLineEdit::editingFinished, lineEdit, [
this] {
commit(); });
76 m_proxy = m_scene->addWidget(lineEdit);
77 m_proxy->setZValue(1000);
80 if (targetRect.isEmpty()) {
81 targetRect = element->sceneBoundingRect();
83 const qreal width = std::max(targetRect.width(), 80.0);
84 lineEdit->resize(
static_cast<int>(width), lineEdit->sizeHint().height());
85 m_proxy->setPos(targetRect.topLeft());
88 lineEdit->selectAll();
97 auto *lineEdit = qobject_cast<QLineEdit *>(m_proxy->widget());
98 const QString newText = lineEdit ? lineEdit->text() : m_target->label();
100 if (newText != m_target->label()) {
102 QDataStream stream(&oldData, QIODevice::WriteOnly);
106 m_target->setLabel(newText);
107 m_scene->receiveCommand(
new UpdateCommand({m_target}, oldData, m_scene));
118void InlineLabelEditor::close()
122 m_proxy->deleteLater();
All QUndoCommand subclasses and the CommandUtils helper namespace.
Abstract base class for all graphical circuit elements.
InlineLabelEditor: on-canvas inline editing of an element's label.
Main circuit editing scene with undo/redo and user interaction.
Deserialization/serialization context structs passed through load()/save() call chains.
Circuit and waveform file serialization/deserialization utilities.
Abstract base class for all graphical circuit elements in wiRedPanda.
QString label() const
Returns the user-visible label text for this element.
QRectF labelSceneBoundingRect() const
void start(GraphicElement *element)
Starts inline-editing element's label, committing any already-in-progress edit first.
void cancel()
Discards the current edit (if any) and closes the editor without changing anything.
InlineLabelEditor(Scene *scene)
Main circuit editing scene.
static void writePandaHeader(QDataStream &stream)
Writes the .panda circuit file header to stream.
Undo command for property changes (label, color, frequency, appearance, etc.).