[qet] qet/qet: [5738] Independent text editor can now edit several texts. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 5738
Author: blacksun
Date: 2019-02-20 21:36:56 +0100 (Wed, 20 Feb 2019)
Log Message:
-----------
Independent text editor can now edit several texts.
Modified Paths:
--------------
trunk/sources/ui/diagrampropertieseditordockwidget.cpp
trunk/sources/ui/inditextpropertieswidget.cpp
trunk/sources/ui/inditextpropertieswidget.h
trunk/sources/ui/inditextpropertieswidget.ui
Modified: trunk/sources/ui/diagrampropertieseditordockwidget.cpp
===================================================================
--- trunk/sources/ui/diagrampropertieseditordockwidget.cpp 2019-02-19 16:42:07 UTC (rev 5737)
+++ trunk/sources/ui/diagrampropertieseditordockwidget.cpp 2019-02-20 20:36:56 UTC (rev 5738)
@@ -1,4 +1,4 @@
-/*
+/*
Copyright 2006-2017 The QElectroTech Team
This file is part of QElectroTech.
@@ -80,12 +80,30 @@
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<QGraphicsItem *> 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 @@
{
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 @@
}
case IndependentTextItem::Type: //1005
{
+ QList<IndependentTextItem *> text_list;
+ for (QGraphicsItem *qgi : m_diagram->selectedItems()) {
+ text_list.append(static_cast<IndependentTextItem*>(qgi));
+ }
+
if (m_edited_qgi_type == type_)
{
- static_cast<IndiTextPropertiesWidget*>(editors().first())->setText(static_cast<IndependentTextItem*>(item));
+ static_cast<IndiTextPropertiesWidget*>(editors().first())->setText(text_list);
return;
}
clear();
m_edited_qgi_type = type_;
- addEditor(new IndiTextPropertiesWidget(static_cast<IndependentTextItem*>(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<DiagramImageItem*>(item), this));
@@ -129,6 +165,13 @@
}
case QetShapeItem::Type: //1008
{
+ if (count_ > 1)
+ {
+ clear();
+ m_edited_qgi_type = -1;
+ return;
+ }
+
if (m_edited_qgi_type == type_)
{
static_cast<ShapeGraphicsItemPropertiesWidget*>(editors().first())->setItem(static_cast<QetShapeItem*>(item));
@@ -142,6 +185,13 @@
}
case DynamicElementTextItem::Type: //1010
{
+ if (count_ > 1)
+ {
+ clear();
+ m_edited_qgi_type = -1;
+ return;
+ }
+
DynamicElementTextItem *deti = static_cast<DynamicElementTextItem *>(item);
//For dynamic element text, we open the element editor to edit it
@@ -159,6 +209,13 @@
}
case QGraphicsItemGroup::Type:
{
+ if (count_ > 1)
+ {
+ clear();
+ m_edited_qgi_type = -1;
+ return;
+ }
+
if(ElementTextItemGroup *group = dynamic_cast<ElementTextItemGroup *>(item))
{
//For element text item group, we open the element editor to edit it
@@ -180,8 +237,9 @@
clear();
}
- foreach (PropertiesEditorWidget *pew, editors())
+ for (PropertiesEditorWidget *pew : editors()) {
pew->setLiveEdit(true);
+ }
}
/**
Modified: trunk/sources/ui/inditextpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/inditextpropertieswidget.cpp 2019-02-19 16:42:07 UTC (rev 5737)
+++ trunk/sources/ui/inditextpropertieswidget.cpp 2019-02-20 20:36:56 UTC (rev 5738)
@@ -40,6 +40,19 @@
}
/**
+ * @brief IndiTextPropertiesWidget::IndiTextPropertiesWidget
+ * @param text_list : a list of texts to edit
+ * @param parent : the parent widget of this widget
+ */
+IndiTextPropertiesWidget::IndiTextPropertiesWidget(QList<IndependentTextItem *> text_list, QWidget *parent) :
+ PropertiesEditorWidget (parent),
+ ui(new Ui::IndiTextPropertiesWidget)
+{
+ ui->setupUi(this);
+ setText(text_list);
+}
+
+/**
* @brief IndiTextPropertiesWidget::~IndiTextPropertiesWidget
*/
IndiTextPropertiesWidget::~IndiTextPropertiesWidget() {
@@ -69,6 +82,32 @@
updateUi();
}
+void IndiTextPropertiesWidget::setText(QList<IndependentTextItem *> 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<IndependentTextItem>(iti));
+ }
+ updateUi();
+ }
+}
+
/**
* @brief IndiTextPropertiesWidget::apply
* Apply the current edition through a QUndoCommand pushed
@@ -76,11 +115,24 @@
*/
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<IndependentTextItem> 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 @@
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<IndependentTextItem> 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<IndependentTextItem> 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<IndependentTextItem> 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 @@
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 @@
disconnect(c);
}
m_edit_connection.clear();
- m_edit_connection << connect(ui->m_x_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
- m_edit_connection << connect(ui->m_y_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
+
+ if (m_text_list.isEmpty())
+ {
+ m_edit_connection << connect(ui->m_x_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
+ m_edit_connection << connect(ui->m_y_sb, QOverload<double>::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<double>::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<int>::of(&QSpinBox::valueChanged), this, &IndiTextPropertiesWidget::apply);
}
@@ -194,7 +307,7 @@
*/
void IndiTextPropertiesWidget::updateUi()
{
- if (!m_text) {
+ if (!m_text && m_text_list.isEmpty()) {
return;
}
@@ -205,14 +318,45 @@
}
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<IndependentTextItem> 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 @@
m_text->edit();
}
}
+
+void IndiTextPropertiesWidget::on_m_break_html_pb_clicked()
+{
+ if (m_text)
+ {
+ m_text->setPlainText(m_text->toPlainText());
+ updateUi();
+ }
+}
Modified: trunk/sources/ui/inditextpropertieswidget.h
===================================================================
--- trunk/sources/ui/inditextpropertieswidget.h 2019-02-19 16:42:07 UTC (rev 5737)
+++ trunk/sources/ui/inditextpropertieswidget.h 2019-02-20 20:36:56 UTC (rev 5738)
@@ -1,4 +1,4 @@
-/*
+/*
Copyright 2006-2019 The QElectroTech Team
This file is part of QElectroTech.
@@ -28,7 +28,7 @@
/**
* @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,8 +36,10 @@
public:
IndiTextPropertiesWidget(IndependentTextItem *text = nullptr, QWidget *parent = nullptr);
+ IndiTextPropertiesWidget(QList <IndependentTextItem *> text_list, QWidget *parent = nullptr);
~IndiTextPropertiesWidget() override;
void setText (IndependentTextItem *text);
+ void setText (QList<IndependentTextItem *> text_list);
void apply() override;
bool setLiveEdit(bool live_edit) override;
@@ -44,7 +46,8 @@
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 @@
private:
Ui::IndiTextPropertiesWidget *ui;
QPointer <IndependentTextItem> m_text;
+ QList <QPointer<IndependentTextItem>> m_text_list;
QList <QMetaObject::Connection> m_connect_list,
m_edit_connection;
};
Modified: trunk/sources/ui/inditextpropertieswidget.ui
===================================================================
--- trunk/sources/ui/inditextpropertieswidget.ui 2019-02-19 16:42:07 UTC (rev 5737)
+++ trunk/sources/ui/inditextpropertieswidget.ui 2019-02-20 20:36:56 UTC (rev 5738)
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>299</width>
- <height>237</height>
+ <width>288</width>
+ <height>251</height>
</rect>
</property>
<property name="windowTitle">
@@ -14,17 +14,14 @@
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="2" column="1">
- <widget class="QDoubleSpinBox" name="m_x_sb">
- <property name="suffix">
- <string>px</string>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>X :</string>
</property>
- <property name="decimals">
- <number>0</number>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
- <property name="maximum">
- <double>10000.000000000000000</double>
- </property>
</widget>
</item>
<item row="1" column="0" colspan="4">
@@ -34,6 +31,16 @@
</property>
</widget>
</item>
+ <item row="3" column="2">
+ <widget class="QLabel" name="label_4">
+ <property name="text">
+ <string>Taille :</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
@@ -44,30 +51,20 @@
</property>
</widget>
</item>
- <item row="3" column="1">
- <widget class="QDoubleSpinBox" name="m_angle_sb">
- <property name="wrapping">
- <bool>true</bool>
- </property>
+ <item row="2" column="1">
+ <widget class="QDoubleSpinBox" name="m_x_sb">
<property name="suffix">
- <string>°</string>
+ <string>px</string>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
- <double>359.000000000000000</double>
+ <double>10000.000000000000000</double>
</property>
</widget>
</item>
- <item row="0" column="0" colspan="4">
- <widget class="QLineEdit" name="m_line_edit">
- <property name="placeholderText">
- <string>Texte</string>
- </property>
- </widget>
- </item>
- <item row="4" column="0">
+ <item row="6" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -80,6 +77,16 @@
</property>
</spacer>
</item>
+ <item row="3" column="3">
+ <widget class="QSpinBox" name="m_size_sb">
+ <property name="minimum">
+ <number>4</number>
+ </property>
+ <property name="maximum">
+ <number>50</number>
+ </property>
+ </widget>
+ </item>
<item row="2" column="3">
<widget class="QDoubleSpinBox" name="m_y_sb">
<property name="suffix">
@@ -93,14 +100,20 @@
</property>
</widget>
</item>
- <item row="2" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>X :</string>
+ <item row="3" column="1">
+ <widget class="QDoubleSpinBox" name="m_angle_sb">
+ <property name="wrapping">
+ <bool>true</bool>
</property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ <property name="suffix">
+ <string>°</string>
</property>
+ <property name="decimals">
+ <number>0</number>
+ </property>
+ <property name="maximum">
+ <double>359.000000000000000</double>
+ </property>
</widget>
</item>
<item row="2" column="2">
@@ -113,26 +126,34 @@
</property>
</widget>
</item>
- <item row="3" column="3">
- <widget class="QSpinBox" name="m_size_sb">
- <property name="minimum">
- <number>4</number>
+ <item row="0" column="0" colspan="4">
+ <widget class="QLineEdit" name="m_line_edit">
+ <property name="placeholderText">
+ <string>Texte</string>
</property>
- <property name="maximum">
- <number>50</number>
- </property>
</widget>
</item>
- <item row="3" column="2">
- <widget class="QLabel" name="label_4">
+ <item row="4" column="0" colspan="4">
+ <widget class="QLabel" name="m_label">
<property name="text">
- <string>Taille :</string>
+ <string>Le contenu et la taille du texte ne peuvent être modifié car formaté en html.
+Veuillez utiliser l'éditeur avancé pour cela.</string>
</property>
- <property name="alignment">
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ <property name="scaledContents">
+ <bool>false</bool>
</property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
</widget>
</item>
+ <item row="5" column="0" colspan="4">
+ <widget class="QPushButton" name="m_break_html_pb">
+ <property name="text">
+ <string>Cliquez ici pour annuler le formatage html</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>