Revert Martin pull request for now, and return to last 7e9fd8df9 commit

This commit is contained in:
Laurent Trinques
2020-06-11 13:19:30 +02:00
parent bf2e02273e
commit 3e1740cee0
33 changed files with 473 additions and 1026 deletions

View File

@@ -28,7 +28,7 @@
* @param parent : the parent widget
*/
TextEditor::TextEditor(QETElementEditor *editor, PartText *text, QWidget *parent) :
ElementItemEditor(editor, parent),
ElementItemEditor(editor, parent),
ui(new Ui::TextEditor)
{
ui->setupUi(this);
@@ -57,7 +57,10 @@ void TextEditor::updateForm()
return;
}
disconnectEditConnection();
for (QMetaObject::Connection c : m_edit_connection) {
disconnect(c);
}
m_edit_connection.clear();
ui->m_line_edit->setText(m_text->toPlainText());
ui->m_x_sb->setValue(m_text->pos().x());
@@ -70,30 +73,6 @@ void TextEditor::updateForm()
setUpEditConnection();
}
void TextEditor::setUpChangeConnection(QPointer<PartText> part) {
assert(m_change_connection.isEmpty());
m_change_connection << connect(part, &PartText::plainTextChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part, &PartText::xChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part, &PartText::yChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part, &PartText::rotationChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part, &PartText::fontChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part, &PartText::colorChanged, this, &TextEditor::updateForm);
}
void TextEditor::disconnectChangeConnection() {
for (QMetaObject::Connection c : m_change_connection) {
disconnect(c);
}
m_change_connection.clear();
}
void TextEditor::disconnectEditConnection() {
for (QMetaObject::Connection c : m_edit_connection) {
disconnect(c);
}
m_edit_connection.clear();
}
/**
* @brief TextEditor::setPart
* Set the current text to edit.
@@ -106,18 +85,27 @@ bool TextEditor::setPart(CustomElementPart *part)
if (!part)
{
m_text = nullptr;
disconnectChangeConnection();
for (QMetaObject::Connection c : m_change_connection) {
disconnect(c);
}
m_change_connection.clear();
return true;
}
if (PartText *part_text = static_cast<PartText *>(part))
if (PartText *part_text = dynamic_cast<PartText *>(part))
{
if (part_text == m_text) {
return true;
}
m_text = part_text;
setUpChangeConnection(m_text);
m_change_connection.clear();
m_change_connection << connect(part_text, &PartText::plainTextChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part_text, &PartText::xChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part_text, &PartText::yChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part_text, &PartText::rotationChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part_text, &PartText::fontChanged, this, &TextEditor::updateForm);
m_change_connection << connect(part_text, &PartText::colorChanged, this, &TextEditor::updateForm);
updateForm();
return true;
@@ -125,37 +113,6 @@ bool TextEditor::setPart(CustomElementPart *part)
return false;
}
bool TextEditor::setParts(QList <CustomElementPart *> parts) {
if (parts.isEmpty())
{
m_parts.clear();
if (m_text) {
disconnectChangeConnection();
}
m_text = nullptr;
return true;
}
if (PartText *part= static_cast<PartText *>(parts.first()))
{
if (m_text) {
disconnectChangeConnection();
}
m_text = part;
m_parts.clear();
m_parts.append(part);
for (int i=1; i < parts.length(); i++)
m_parts.append(static_cast<PartText*>(parts[i]));
setUpChangeConnection(m_text);
updateForm();
return true;
}
return(false);
}
/**
* @brief TextEditor::currentPart
* @return The current part
@@ -164,14 +121,6 @@ CustomElementPart *TextEditor::currentPart() const {
return m_text;
}
QList<CustomElementPart*> TextEditor::currentParts() const {
QList<CustomElementPart*> parts;
for (auto part: m_parts) {
parts.append(static_cast<CustomElementPart*>(part));
}
return parts;
}
/**
* @brief TextEditor::setUpEditConnection
* Setup the connection between the widgets of this editor and the undo command
@@ -179,77 +128,63 @@ QList<CustomElementPart*> TextEditor::currentParts() const {
*/
void TextEditor::setUpEditConnection()
{
disconnectEditConnection();
for (QMetaObject::Connection c : m_edit_connection) {
disconnect(c);
}
m_edit_connection.clear();
m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, [this]()
{
QString text_ = ui->m_line_edit->text();
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (text_ != partText->toPlainText())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "text", partText->toPlainText(), text_);
undo->setText(tr("Modifier le contenu d'un champ texte"));
undoStack().push(undo);
}
}
if (text_ != m_text->toPlainText())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "text", m_text->toPlainText(), text_);
undo->setText(tr("Modifier le contenu d'un champ texte"));
undoStack().push(undo);
}
});
m_edit_connection << connect(ui->m_x_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
{
QPointF pos(ui->m_x_sb->value(), 0);
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
pos.setY(partText->pos().y());
if (pos != partText->pos())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos);
undo->setText(tr("Déplacer un champ texte"));
undo->setAnimated(true, false);
undoStack().push(undo);
}
}
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
if (pos != m_text->pos())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
undo->setText(tr("Déplacer un champ texte"));
undo->setAnimated(true, false);
undoStack().push(undo);
}
});
m_edit_connection << connect(ui->m_y_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
{
QPointF pos(0, ui->m_y_sb->value());
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
pos.setX(partText->pos().x());
if (pos != partText->pos())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "pos", partText->pos(), pos);
undo->setText(tr("Déplacer un champ texte"));
undo->setAnimated(true, false);
undoStack().push(undo);
}
}
QPointF pos(ui->m_x_sb->value(), ui->m_y_sb->value());
if (pos != m_text->pos())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "pos", m_text->pos(), pos);
undo->setText(tr("Déplacer un champ texte"));
undo->setAnimated(true, false);
undoStack().push(undo);
}
});
m_edit_connection << connect(ui->m_rotation_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
{
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (ui->m_rotation_sb->value() != partText->rotation())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "rotation", partText->rotation(), ui->m_rotation_sb->value());
undo->setText(tr("Pivoter un champ texte"));
undo->setAnimated(true, false);
undoStack().push(undo);
}
}
if (ui->m_rotation_sb->value() != m_text->rotation())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "rotation", m_text->rotation(), ui->m_rotation_sb->value());
undo->setText(tr("Pivoter un champ texte"));
undo->setAnimated(true, false);
undoStack().push(undo);
}
});
m_edit_connection << connect(ui->m_size_sb, QOverload<int>::of(&QSpinBox::valueChanged), [this]()
{
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (partText->font().pointSize() != ui->m_size_sb->value())
{
QFont font_ = partText->font();
font_.setPointSize(ui->m_size_sb->value());
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_);
undo->setText(tr("Modifier la police d'un texte"));
undoStack().push(undo);
}
}
if (m_text->font().pointSize() != ui->m_size_sb->value())
{
QFont font_ = m_text->font();
font_.setPointSize(ui->m_size_sb->value());
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
undo->setText(tr("Modifier la police d'un texte"));
undoStack().push(undo);
}
});
}
@@ -261,23 +196,17 @@ void TextEditor::on_m_font_pb_clicked()
bool ok;
QFont font_ = QFontDialog::getFont(&ok, m_text->font(), this);
if (ok && font_ != m_text->font()) {
ui->m_size_sb->blockSignals(true);
ui->m_size_sb->setValue(font_.pointSize());
ui->m_size_sb->blockSignals(false);
if (ok && font_ != m_text->font())
{
ui->m_size_sb->blockSignals(true);
ui->m_size_sb->setValue(font_.pointSize());
ui->m_size_sb->blockSignals(false);
ui->m_font_pb->setText(font_.family());
}
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (ok && font_ != partText->font())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "font", partText->font(), font_);
undo->setText(tr("Modifier la police d'un texte"));
undoStack().push(undo);
}
}
ui->m_font_pb->setText(font_.family());
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "font", m_text->font(), font_);
undo->setText(tr("Modifier la police d'un texte"));
undoStack().push(undo);
}
}
/**
@@ -286,13 +215,10 @@ void TextEditor::on_m_font_pb_clicked()
*/
void TextEditor::on_m_color_pb_changed(const QColor &newColor)
{
for (int i=0; i < m_parts.length(); i++) {
PartText* partText = m_parts[i];
if (newColor != partText->defaultTextColor())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(partText, "color", partText->defaultTextColor(), newColor);
undo->setText(tr("Modifier la couleur d'un texte"));
undoStack().push(undo);
}
}
if (newColor != m_text->defaultTextColor())
{
QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_text, "color", m_text->defaultTextColor(), newColor);
undo->setText(tr("Modifier la couleur d'un texte"));
undoStack().push(undo);
}
}