From 1ec083a313e69cb0bfd3b4f7622f4fefc22f060b Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 20 Feb 2019 20:36:56 +0000 Subject: [PATCH] Independent text editor can now edit several texts. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5738 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- .../ui/diagrampropertieseditordockwidget.cpp | 76 +++++- sources/ui/inditextpropertieswidget.cpp | 231 +++++++++++++++--- sources/ui/inditextpropertieswidget.h | 10 +- sources/ui/inditextpropertieswidget.ui | 155 +++++++----- 4 files changed, 354 insertions(+), 118 deletions(-) diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp index 6d8691410..226f9dc3b 100644 --- a/sources/ui/diagrampropertieseditordockwidget.cpp +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2017 The QElectroTech Team This file is part of QElectroTech. @@ -80,12 +80,30 @@ void DiagramPropertiesEditorDockWidget::setDiagram(Diagram *diagram) void DiagramPropertiesEditorDockWidget::selectionChanged() { if (!m_diagram) return; - //This editor can edit only one item. - if (m_diagram->selectedItems().size() != 1) + + int count_ = m_diagram->selectedItems().size(); + + //The editor widget can only edit one item + //or several items of the same type + if (count_ != 1) { - clear(); - m_edited_qgi_type = -1; - return; + if (count_ == 0) { + clear(); + m_edited_qgi_type = -1; + return; + } + + const QList list_ = m_diagram->selectedItems(); + int type_ = list_.first()->type(); + for (QGraphicsItem *qgi : list_) + { + if (qgi->type() != type_) + { + clear(); + m_edited_qgi_type = -1; + return; + } + } } QGraphicsItem *item = m_diagram->selectedItems().first(); @@ -95,6 +113,12 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() { case Element::Type: //1000 { + if (count_ > 1) + { + clear(); + m_edited_qgi_type = -1; + return; + } //We already edit an element, just update the editor with a new element if (m_edited_qgi_type == type_) { @@ -109,19 +133,31 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() } case IndependentTextItem::Type: //1005 { + QList text_list; + for (QGraphicsItem *qgi : m_diagram->selectedItems()) { + text_list.append(static_cast(qgi)); + } + if (m_edited_qgi_type == type_) { - static_cast(editors().first())->setText(static_cast(item)); + static_cast(editors().first())->setText(text_list); return; } clear(); m_edited_qgi_type = type_; - addEditor(new IndiTextPropertiesWidget(static_cast(item), this)); + addEditor(new IndiTextPropertiesWidget(text_list, this)); break; } case DiagramImageItem::Type: //1007 { + if (count_ > 1) + { + clear(); + m_edited_qgi_type = -1; + return; + } + clear(); m_edited_qgi_type = type_; addEditor(new ImagePropertiesWidget(static_cast(item), this)); @@ -129,6 +165,13 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() } case QetShapeItem::Type: //1008 { + if (count_ > 1) + { + clear(); + m_edited_qgi_type = -1; + return; + } + if (m_edited_qgi_type == type_) { static_cast(editors().first())->setItem(static_cast(item)); @@ -142,6 +185,13 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() } case DynamicElementTextItem::Type: //1010 { + if (count_ > 1) + { + clear(); + m_edited_qgi_type = -1; + return; + } + DynamicElementTextItem *deti = static_cast(item); //For dynamic element text, we open the element editor to edit it @@ -159,6 +209,13 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() } case QGraphicsItemGroup::Type: { + if (count_ > 1) + { + clear(); + m_edited_qgi_type = -1; + return; + } + if(ElementTextItemGroup *group = dynamic_cast(item)) { //For element text item group, we open the element editor to edit it @@ -180,8 +237,9 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() clear(); } - foreach (PropertiesEditorWidget *pew, editors()) + for (PropertiesEditorWidget *pew : editors()) { pew->setLiveEdit(true); + } } /** diff --git a/sources/ui/inditextpropertieswidget.cpp b/sources/ui/inditextpropertieswidget.cpp index c0c81ace8..db3830d9e 100644 --- a/sources/ui/inditextpropertieswidget.cpp +++ b/sources/ui/inditextpropertieswidget.cpp @@ -39,6 +39,19 @@ IndiTextPropertiesWidget::IndiTextPropertiesWidget(IndependentTextItem *text, QW } } +/** + * @brief IndiTextPropertiesWidget::IndiTextPropertiesWidget + * @param text_list : a list of texts to edit + * @param parent : the parent widget of this widget + */ +IndiTextPropertiesWidget::IndiTextPropertiesWidget(QList text_list, QWidget *parent) : + PropertiesEditorWidget (parent), + ui(new Ui::IndiTextPropertiesWidget) +{ + ui->setupUi(this); + setText(text_list); +} + /** * @brief IndiTextPropertiesWidget::~IndiTextPropertiesWidget */ @@ -69,6 +82,32 @@ void IndiTextPropertiesWidget::setText(IndependentTextItem *text) updateUi(); } +void IndiTextPropertiesWidget::setText(QList text_list) +{ + for (QMetaObject::Connection c : m_connect_list) { + disconnect(c); + } + m_connect_list.clear(); + m_text_list.clear(); + m_text = nullptr; + + if (text_list.size() == 0) { + updateUi(); + } + else if (text_list.size() == 1) + { + setText(text_list.first()); + m_text_list.clear(); + } + else + { + for (IndependentTextItem *iti : text_list) { + m_text_list.append(QPointer(iti)); + } + updateUi(); + } +} + /** * @brief IndiTextPropertiesWidget::apply * Apply the current edition through a QUndoCommand pushed @@ -76,11 +115,24 @@ void IndiTextPropertiesWidget::setText(IndependentTextItem *text) */ void IndiTextPropertiesWidget::apply() { - if (m_text && m_text->diagram()) + Diagram *d = nullptr; + + if (m_text && m_text->diagram()) { + d = m_text->diagram(); + } else if (!m_text_list.isEmpty()) { + for (QPointer piti : m_text_list) { + if (piti->diagram()) { + d = piti->diagram(); + break; + } + } + } + + if (d) { QUndoCommand *undo = associatedUndo(); if (undo) { - m_text->diagram()->undoStack().push(undo); + d->undoStack().push(undo); } } } @@ -118,34 +170,88 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const if (m_live_edit) { QPropertyUndoCommand *undo = nullptr; - if(ui->m_x_sb->value() != m_text->pos().x()) { - undo = new QPropertyUndoCommand(m_text.data(), "x", QVariant(m_text->pos().x()), QVariant(ui->m_x_sb->value())); - undo->setAnimated(true, false); - undo->setText(tr("Déplacer un champ texte")); + //One text is edited + if (m_text_list.isEmpty()) + { + if(ui->m_x_sb->value() != m_text->pos().x()) { + undo = new QPropertyUndoCommand(m_text.data(), "x", QVariant(m_text->pos().x()), QVariant(ui->m_x_sb->value())); + undo->setAnimated(true, false); + undo->setText(tr("Déplacer un champ texte")); + } + if(ui->m_y_sb->value() != m_text->pos().y()) { + undo = new QPropertyUndoCommand(m_text.data(), "y", QVariant(m_text->pos().y()), QVariant(ui->m_y_sb->value())); + undo->setAnimated(true, false); + undo->setText(tr("Déplacer un champ texte")); + } + if(ui->m_angle_sb->value() != m_text->rotation()) { + undo = new QPropertyUndoCommand(m_text.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value())); + undo->setAnimated(true, false); + undo->setText(tr("Pivoter un champ texte")); + } + if (ui->m_line_edit->text() != m_text->toPlainText()) { + undo = new QPropertyUndoCommand(m_text.data(), "plainText", m_text->toPlainText(), ui->m_line_edit->text()); + undo->setText(tr("Modifier un champ texte")); + } + if (ui->m_size_sb->value() != m_text->fontSize()) { + undo = new QPropertyUndoCommand(m_text.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value()); + undo->setAnimated(true, false); + undo->setText(tr("Modifier la taille d'un champ texte")); + } + + return undo; } - if(ui->m_y_sb->value() != m_text->pos().y()) { - undo = new QPropertyUndoCommand(m_text.data(), "y", QVariant(m_text->pos().y()), QVariant(ui->m_y_sb->value())); - undo->setAnimated(true, false); - undo->setText(tr("Déplacer un champ texte")); + else //several text are edited, only size and rotation is available for edition + { + QUndoCommand *parent_undo = nullptr; + bool size_equal = true; + bool angle_equal = true; + qreal rotation_ = m_text_list.first()->rotation(); + int size_ = m_text_list.first()->fontSize(); + for (QPointer piti : m_text_list) + { + if (piti->rotation() != rotation_) { + angle_equal = false; + } + if (piti->fontSize() != size_) { + size_equal = false; + } + } + + if ((angle_equal && (ui->m_angle_sb->value() != rotation_)) || + (!angle_equal && (ui->m_angle_sb->value() != ui->m_angle_sb->minimum()))) + { + for (QPointer piti : m_text_list) + { + if (piti) + { + if (!parent_undo) { + parent_undo = new QUndoCommand(tr("Pivoter plusieurs champs texte")); + } + QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(piti.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value()), parent_undo); + qpuc->setAnimated(true, false); + } + } + } + else if ((size_equal && (ui->m_size_sb->value() != size_)) || + (!size_equal && (ui->m_size_sb->value() != ui->m_size_sb->minimum()))) + { + for (QPointer piti : m_text_list) + { + if (piti) + { + if (!parent_undo) { + parent_undo = new QUndoCommand(tr("Modifier la taille de plusieurs champs texte")); + } + QPropertyUndoCommand *qpuc = new QPropertyUndoCommand(piti.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value(), parent_undo); + qpuc->setAnimated(true, false); + } + } + } + return parent_undo; } - if(ui->m_angle_sb->value() != m_text->rotation()) { - undo = new QPropertyUndoCommand(m_text.data(), "rotation", QVariant(m_text->rotation()), QVariant(ui->m_angle_sb->value())); - undo->setAnimated(true, false); - undo->setText(tr("Pivoter un champ texte")); - } - if (ui->m_line_edit->text() != m_text->toPlainText()) { - undo = new QPropertyUndoCommand(m_text.data(), "plainText", m_text->toPlainText(), ui->m_line_edit->text()); - undo->setText(tr("Modifier un champ texte")); - } - if (ui->m_size_sb->value() != m_text->fontSize()) { - undo = new QPropertyUndoCommand(m_text.data(), "fontSize", m_text->fontSize(), ui->m_size_sb->value()); - undo->setAnimated(true, false); - undo->setText(tr("Modifier la taille d'un champ texte")); - } - - return undo; } - else + //In mode not live edit, only one text can be edited + else if (m_text_list.isEmpty()) { QUndoCommand *undo = new QUndoCommand(tr("Modifier les propriétées d'un texte")); if(ui->m_x_sb->value() != m_text->pos().x()) { @@ -170,11 +276,14 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const return nullptr; } } + else { + return nullptr; + } } /** * @brief IndiTextPropertiesWidget::setUpEditConnection - * Disconnect the previous connection, and reconnect the connection between the editors widgets and apply function + * Disconnect the previous connection, and reconnect the connection between the editors widgets and void IndiTextPropertiesWidget::apply function */ void IndiTextPropertiesWidget::setUpEditConnection() { @@ -182,10 +291,14 @@ void IndiTextPropertiesWidget::setUpEditConnection() disconnect(c); } m_edit_connection.clear(); - m_edit_connection << connect(ui->m_x_sb, QOverload::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); - m_edit_connection << connect(ui->m_y_sb, QOverload::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); + + if (m_text_list.isEmpty()) + { + m_edit_connection << connect(ui->m_x_sb, QOverload::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); + m_edit_connection << connect(ui->m_y_sb, QOverload::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); + m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, this, &IndiTextPropertiesWidget::apply); + } m_edit_connection << connect(ui->m_angle_sb, QOverload::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); - m_edit_connection << connect(ui->m_line_edit, &QLineEdit::textEdited, this, &IndiTextPropertiesWidget::apply); m_edit_connection << connect(ui->m_size_sb, QOverload::of(&QSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply); } @@ -194,7 +307,7 @@ void IndiTextPropertiesWidget::setUpEditConnection() */ void IndiTextPropertiesWidget::updateUi() { - if (!m_text) { + if (!m_text && m_text_list.isEmpty()) { return; } @@ -205,14 +318,45 @@ void IndiTextPropertiesWidget::updateUi() } m_edit_connection.clear(); - ui->m_x_sb->setValue(m_text->pos().x()); - ui->m_y_sb->setValue(m_text->pos().y()); - ui->m_angle_sb->setValue(m_text->rotation()); - ui->m_line_edit->setText(m_text->toPlainText()); - ui->m_size_sb->setValue(m_text->fontSize()); + ui->m_x_sb->setEnabled(m_text_list.isEmpty() ? true : false); + ui->m_y_sb->setEnabled(m_text_list.isEmpty() ? true : false); + ui->m_line_edit->setEnabled(m_text_list.isEmpty() ? true : false); + ui->m_advanced_editor_pb->setEnabled(m_text_list.isEmpty() ? true : false); - ui->m_line_edit->setDisabled(m_text->isHtml() ? true : false); - ui->m_size_sb->setDisabled(m_text->isHtml() ? true : false); + if (m_text_list.isEmpty()) + { + ui->m_x_sb->setValue(m_text->pos().x()); + ui->m_y_sb->setValue(m_text->pos().y()); + ui->m_line_edit->setText(m_text->toPlainText()); + ui->m_angle_sb->setValue(m_text->rotation()); + ui->m_size_sb->setValue(m_text->fontSize()); + + ui->m_line_edit->setDisabled(m_text->isHtml() ? true : false); + ui->m_size_sb->setDisabled(m_text->isHtml() ? true : false); + ui->m_label->setVisible(m_text->isHtml() ? true : false); + ui->m_break_html_pb->setVisible(m_text->isHtml() ? true : false); + } + else + { + bool size_equal = true; + bool angle_equal = true; + qreal rotation_ = m_text_list.first()->rotation(); + int size_ = m_text_list.first()->fontSize(); + for (QPointer piti : m_text_list) + { + if (piti->rotation() != rotation_) { + angle_equal = false; + } + if (piti->fontSize() != size_) { + size_equal = false; + } + } + ui->m_angle_sb->setValue(angle_equal ? rotation_ : 0); + ui->m_size_sb->setValue(size_equal ? size_ : 0); + ui->m_label->setVisible(false); + ui->m_break_html_pb->setVisible(false); + } + //Set the connection now setUpEditConnection(); @@ -226,3 +370,12 @@ void IndiTextPropertiesWidget::on_m_advanced_editor_pb_clicked() { m_text->edit(); } } + +void IndiTextPropertiesWidget::on_m_break_html_pb_clicked() +{ + if (m_text) + { + m_text->setPlainText(m_text->toPlainText()); + updateUi(); + } +} diff --git a/sources/ui/inditextpropertieswidget.h b/sources/ui/inditextpropertieswidget.h index cfd21a01b..6ead20174 100644 --- a/sources/ui/inditextpropertieswidget.h +++ b/sources/ui/inditextpropertieswidget.h @@ -1,4 +1,4 @@ -/* +/* Copyright 2006-2019 The QElectroTech Team This file is part of QElectroTech. @@ -28,7 +28,7 @@ namespace Ui { /** * @brief The IndiTextPropertiesWidget class - * This widget is used to edit the properties of an independent text item + * This widget is used to edit the properties of one or several independent text item */ class IndiTextPropertiesWidget : public PropertiesEditorWidget { @@ -36,15 +36,18 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget public: IndiTextPropertiesWidget(IndependentTextItem *text = nullptr, QWidget *parent = nullptr); + IndiTextPropertiesWidget(QList text_list, QWidget *parent = nullptr); ~IndiTextPropertiesWidget() override; void setText (IndependentTextItem *text); + void setText (QList text_list); void apply() override; bool setLiveEdit(bool live_edit) override; QUndoCommand* associatedUndo() const override; private slots: - void on_m_advanced_editor_pb_clicked(); + void on_m_advanced_editor_pb_clicked(); + void on_m_break_html_pb_clicked(); private: void setUpEditConnection(); @@ -53,6 +56,7 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget private: Ui::IndiTextPropertiesWidget *ui; QPointer m_text; + QList > m_text_list; QList m_connect_list, m_edit_connection; }; diff --git a/sources/ui/inditextpropertieswidget.ui b/sources/ui/inditextpropertieswidget.ui index 1df9d84e2..2b72a9945 100644 --- a/sources/ui/inditextpropertieswidget.ui +++ b/sources/ui/inditextpropertieswidget.ui @@ -6,14 +6,51 @@ 0 0 - 299 - 237 + 288 + 251 Form + + + + X : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Éditeur avancé + + + + + + + Taille : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Angle : + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + @@ -27,20 +64,39 @@ - - - - Éditeur avancé + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + 4 + + + 50 - - - - Angle : + + + + px - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + 0 + + + 10000.000000000000000 @@ -60,49 +116,6 @@ - - - - Texte - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - px - - - 0 - - - 10000.000000000000000 - - - - - - - X : - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - @@ -113,23 +126,31 @@ - - - - 4 - - - 50 + + + + Texte - - + + - Taille : + Le contenu et la taille du texte ne peuvent être modifié car formaté en html. +Veuillez utiliser l'éditeur avancé pour cela. - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + false + + + true + + + + + + + Cliquez ici pour annuler le formatage html