add multiedit feature also for dynamic text

This commit is contained in:
Martin Marmsoler
2020-06-01 19:38:07 +02:00
committed by Laurent Trinques
parent a8c62b8257
commit 1ccffda93b
3 changed files with 160 additions and 81 deletions

View File

@@ -647,7 +647,9 @@ void QETElementEditor::slot_updateInformations()
// if(editor->currentPart() == cep_list.first()) // if(editor->currentPart() == cep_list.first())
// return; // return;
if (selection_xml_name == "terminal" || selection_xml_name == "text") { if (selection_xml_name == "terminal" ||
selection_xml_name == "text" ||
selection_xml_name == "dynamic_text") {
clearToolsDock(); clearToolsDock();
//We add the editor widget //We add the editor widget
ElementItemEditor *editor = static_cast<ElementItemEditor*>(m_editors[selection_xml_name]); ElementItemEditor *editor = static_cast<ElementItemEditor*>(m_editors[selection_xml_name]);

View File

@@ -57,10 +57,7 @@ DynamicTextFieldEditor::~DynamicTextFieldEditor()
*/ */
bool DynamicTextFieldEditor::setPart(CustomElementPart *part) bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
{ {
//Remove previous connection disconnectConnections();
if(!m_connection_list.isEmpty())
for(const QMetaObject::Connection& con : m_connection_list)
disconnect(con);
QGraphicsItem *qgi = part->toItem(); QGraphicsItem *qgi = part->toItem();
if(!qgi) if(!qgi)
@@ -71,21 +68,42 @@ bool DynamicTextFieldEditor::setPart(CustomElementPart *part)
m_text_field = static_cast<PartDynamicTextField *>(qgi); m_text_field = static_cast<PartDynamicTextField *>(qgi);
updateForm(); updateForm();
//Setup the connection setUpConnections();
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::frameChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textWidthChanged,[this]() {this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();});
return true; return true;
} }
bool DynamicTextFieldEditor::setParts(QList <CustomElementPart *> parts) {
if (parts.isEmpty())
{
m_parts.clear();
if (m_text_field) {
disconnectConnections();
}
m_text_field = nullptr;
return true;
}
if (PartDynamicTextField *part= static_cast<PartDynamicTextField *>(parts.first()))
{
if (m_text_field) {
disconnectConnections();
}
m_text_field = part;
m_parts.clear();
m_parts.append(part);
for (int i=1; i < parts.length(); i++)
m_parts.append(static_cast<PartDynamicTextField*>(parts[i]));
setUpConnections();
updateForm();
return true;
}
return(false);
}
/** /**
* @brief DynamicTextFieldEditor::currentPart * @brief DynamicTextFieldEditor::currentPart
* @return The current edited part, note they can return nullptr if * @return The current edited part, note they can return nullptr if
@@ -128,6 +146,29 @@ void DynamicTextFieldEditor::updateForm()
} }
} }
void DynamicTextFieldEditor::setUpConnections() {
assert(m_connection_list.isEmpty());
//Setup the connection
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::colorChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::fontChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::taggChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textFromChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::infoNameChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::frameChanged, [this](){this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::textWidthChanged,[this]() {this->updateForm();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::compositeTextChanged, [this]() {this->updateForm();});
}
void DynamicTextFieldEditor::disconnectConnections() {
//Remove previous connection
if(!m_connection_list.isEmpty())
for(const QMetaObject::Connection& con : m_connection_list)
disconnect(con);
m_connection_list.clear();
}
/** /**
* @brief DynamicTextFieldEditor::fillInfoComboBox * @brief DynamicTextFieldEditor::fillInfoComboBox
* Fill the combo box "element information" * Fill the combo box "element information"
@@ -156,66 +197,84 @@ void DynamicTextFieldEditor::fillInfoComboBox()
void DynamicTextFieldEditor::on_m_x_sb_editingFinished() void DynamicTextFieldEditor::on_m_x_sb_editingFinished()
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "x", m_text_field.data()->x(), ui->m_x_sb->value()); double value = ui->m_x_sb->value();
undo->setText(tr("Déplacer un champ texte")); for (int i = 0; i < m_parts.length(); i++) {
undo->enableAnimation(true); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "x", m_parts[i]->x(), value);
undoStack().push(undo); undo->setText(tr("Déplacer un champ texte"));
undo->enableAnimation(true);
undoStack().push(undo);
}
} }
void DynamicTextFieldEditor::on_m_y_sb_editingFinished() void DynamicTextFieldEditor::on_m_y_sb_editingFinished()
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "y", m_text_field.data()->y(), ui->m_y_sb->value()); double value = ui->m_y_sb->value();
undo->setText(tr("Déplacer un champ texte")); for (int i = 0; i < m_parts.length(); i++) {
undo->enableAnimation(true); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "y", m_parts[i]->y(), value);
undoStack().push(undo); undo->setText(tr("Déplacer un champ texte"));
undo->enableAnimation(true);
undoStack().push(undo);
}
} }
void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished() void DynamicTextFieldEditor::on_m_rotation_sb_editingFinished()
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "rotation", m_text_field.data()->rotation(), ui->m_rotation_sb->value()); int value = ui->m_rotation_sb->value();
undo->setText(tr("Pivoter un champ texte")); for (int i = 0; i < m_parts.length(); i++) {
undo->enableAnimation(true); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "rotation", m_parts[i]->rotation(), value);
undoStack().push(undo); undo->setText(tr("Pivoter un champ texte"));
undo->enableAnimation(true);
undoStack().push(undo);
}
} }
void DynamicTextFieldEditor::on_m_user_text_le_editingFinished() void DynamicTextFieldEditor::on_m_user_text_le_editingFinished()
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "text", m_text_field.data()->text(), ui->m_user_text_le->text()); QString text = ui->m_user_text_le->text();
undo->setText(tr("Modifier le texte d'un champ texte")); for (int i = 0; i < m_parts.length(); i++) {
undoStack().push(undo); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "text", m_parts[i]->text(), text);
undo->setText(tr("Modifier le texte d'un champ texte"));
undoStack().push(undo);
}
} }
void DynamicTextFieldEditor::on_m_size_sb_editingFinished() void DynamicTextFieldEditor::on_m_size_sb_editingFinished()
{ {
QFont font_ = m_text_field->font(); QFont font_ = m_text_field->font();
font_.setPointSize(ui->m_size_sb->value()); font_.setPointSize(ui->m_size_sb->value());
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "font", m_text_field.data()->font(), font_); for (int i = 0; i < m_parts.length(); i++) {
undo->setText(tr("Modifier la police d'un champ texte")); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_);
undoStack().push(undo); undo->setText(tr("Modifier la police d'un champ texte"));
undoStack().push(undo);
}
} }
void DynamicTextFieldEditor::on_m_frame_cb_clicked() void DynamicTextFieldEditor::on_m_frame_cb_clicked()
{ {
bool frame = ui->m_frame_cb->isChecked(); bool frame = ui->m_frame_cb->isChecked();
if(frame != m_text_field.data()->frame()) for (int i = 0; i < m_parts.length(); i++) {
{ if(frame != m_parts[i]->frame())
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "frame", m_text_field.data()->frame(), frame); {
undo->setText(tr("Modifier le cadre d'un champ texte")); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "frame", m_parts[i]->frame(), frame);
undoStack().push(undo); undo->setText(tr("Modifier le cadre d'un champ texte"));
} undoStack().push(undo);
}
}
} }
void DynamicTextFieldEditor::on_m_width_sb_editingFinished() void DynamicTextFieldEditor::on_m_width_sb_editingFinished()
{ {
qreal width = (qreal)ui->m_width_sb->value(); qreal width = (qreal)ui->m_width_sb->value();
if(width != m_text_field.data()->textWidth()) for (int i = 0; i < m_parts.length(); i++) {
{ if(width != m_parts[i]->textWidth())
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "textWidth", m_text_field.data()->textWidth(), width); {
undo->setText(tr("Modifier la largeur d'un texte")); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textWidth", m_parts[i]->textWidth(), width);
undoStack().push(undo); undo->setText(tr("Modifier la largeur d'un texte"));
} undoStack().push(undo);
}
}
} }
void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1) void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1)
@@ -223,15 +282,16 @@ void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1)
Q_UNUSED(arg1) Q_UNUSED(arg1)
QString info = ui->m_elmt_info_cb->currentData().toString(); QString info = ui->m_elmt_info_cb->currentData().toString();
for (int i = 0; i < m_parts.length(); i++) {
if(info != m_text_field.data()->infoName()) if(info != m_parts[i]->infoName())
{ {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "infoName", m_text_field.data()->infoName(), info); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "infoName", m_parts[i]->infoName(), info);
undo->setText(tr("Modifier l'information d'un texte")); undo->setText(tr("Modifier l'information d'un texte"));
undoStack().push(undo); undoStack().push(undo);
m_text_field.data()->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_text_field.data()->infoName()).toString()); m_parts[i]->setPlainText(elementEditor()->elementScene()->elementInformation().value(m_parts[i]->infoName()).toString());
} }
}
} }
void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index) void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index)
@@ -252,12 +312,14 @@ void DynamicTextFieldEditor::on_m_text_from_cb_activated(int index)
else if(index == 1) tf = DynamicElementTextItem::ElementInfo; else if(index == 1) tf = DynamicElementTextItem::ElementInfo;
else tf = DynamicElementTextItem::CompositeText; else tf = DynamicElementTextItem::CompositeText;
if(tf != m_text_field.data()->textFrom()) for (int i = 0; i < m_parts.length(); i++) {
{ if(tf != m_parts[i]->textFrom())
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "textFrom", m_text_field.data()->textFrom(), tf); {
undo->setText(tr("Modifier la source de texte, d'un texte")); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "textFrom", m_parts[i]->textFrom(), tf);
undoStack().push(undo); undo->setText(tr("Modifier la source de texte, d'un texte"));
} undoStack().push(undo);
}
}
} }
void DynamicTextFieldEditor::on_m_composite_text_pb_clicked() void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
@@ -266,11 +328,13 @@ void DynamicTextFieldEditor::on_m_composite_text_pb_clicked()
if(ctd.exec()) if(ctd.exec())
{ {
QString ct = ctd.plainText(); QString ct = ctd.plainText();
if(ct != m_text_field.data()->compositeText()) for (int i = 0; i < m_parts.length(); i++) {
{ if(ct != m_parts[i]->compositeText())
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "compositeText", m_text_field.data()->compositeText(), ctd.plainText()); {
undoStack().push(undo); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "compositeText", m_parts[i]->compositeText(), ctd.plainText());
} undoStack().push(undo);
}
}
} }
} }
@@ -279,12 +343,14 @@ void DynamicTextFieldEditor::on_m_alignment_pb_clicked()
AlignmentTextDialog atd(m_text_field.data()->alignment(), this); AlignmentTextDialog atd(m_text_field.data()->alignment(), this);
atd.exec(); atd.exec();
if(atd.alignment() != m_text_field.data()->alignment()) for (int i = 0; i < m_parts.length(); i++) {
{ if(atd.alignment() != m_parts[i]->alignment())
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "alignment", QVariant(m_text_field.data()->alignment()), QVariant(atd.alignment())); {
undo->setText(tr("Modifier l'alignement d'un champ texte")); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "alignment", QVariant(m_parts[i]->alignment()), QVariant(atd.alignment()));
undoStack().push(undo); undo->setText(tr("Modifier l'alignement d'un champ texte"));
} undoStack().push(undo);
}
}
} }
void DynamicTextFieldEditor::on_m_font_pb_clicked() void DynamicTextFieldEditor::on_m_font_pb_clicked()
@@ -296,18 +362,25 @@ void DynamicTextFieldEditor::on_m_font_pb_clicked()
ui->m_font_pb->setText(font_.family()); ui->m_font_pb->setText(font_.family());
ui->m_size_sb->setValue(font_.pointSize()); ui->m_size_sb->setValue(font_.pointSize());
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field.data(), "font", m_text_field->font(), font_); for (int i = 0; i < m_parts.length(); i++) {
undo->setText(tr("Modifier la police d'un champ texte")); QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "font", m_parts[i]->font(), font_);
undoStack().push(undo); undo->setText(tr("Modifier la police d'un champ texte"));
undoStack().push(undo);
}
} }
} }
void DynamicTextFieldEditor::on_m_color_kpb_changed(const QColor &newColor) void DynamicTextFieldEditor::on_m_color_kpb_changed(const QColor &newColor)
{ {
if(newColor.isValid() && newColor != m_text_field.data()->color()) if (!newColor.isValid())
{ return;
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text_field, "color", m_text_field.data()->color(), newColor);
undo->setText(tr("Modifier la couleur d'un champ texte")); for (int i = 0; i < m_parts.length(); i++) {
undoStack().push(undo); if(newColor != m_parts[i]->color())
} {
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "color", m_parts[i]->color(), newColor);
undo->setText(tr("Modifier la couleur d'un champ texte"));
undoStack().push(undo);
}
}
} }

View File

@@ -38,11 +38,14 @@ class DynamicTextFieldEditor : public ElementItemEditor
~DynamicTextFieldEditor() override; ~DynamicTextFieldEditor() override;
bool setPart(CustomElementPart *part) override; bool setPart(CustomElementPart *part) override;
bool setParts(QList <CustomElementPart *>) override;
CustomElementPart *currentPart() const override; CustomElementPart *currentPart() const override;
void updateForm() override; void updateForm() override;
private: private:
void fillInfoComboBox(); void fillInfoComboBox();
void setUpConnections();
void disconnectConnections();
private slots: private slots:
void on_m_x_sb_editingFinished(); void on_m_x_sb_editingFinished();
@@ -63,6 +66,7 @@ class DynamicTextFieldEditor : public ElementItemEditor
private: private:
Ui::DynamicTextFieldEditor *ui; Ui::DynamicTextFieldEditor *ui;
QPointer<PartDynamicTextField> m_text_field; QPointer<PartDynamicTextField> m_text_field;
QList<PartDynamicTextField*> m_parts;
QList<QMetaObject::Connection> m_connection_list; QList<QMetaObject::Connection> m_connection_list;
}; };