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
This commit is contained in:
blacksun
2019-02-20 20:36:56 +00:00
parent 33d757e0d8
commit 1ec083a313
4 changed files with 354 additions and 118 deletions

View File

@@ -1,4 +1,4 @@
/*
/*
Copyright 2006-2017 The QElectroTech Team
This file is part of QElectroTech.
@@ -80,13 +80,31 @@ 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)
{
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();
const int type_ = item->type();
@@ -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<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 @@ 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<ShapeGraphicsItemPropertiesWidget*>(editors().first())->setItem(static_cast<QetShapeItem*>(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<DynamicElementTextItem *>(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<ElementTextItemGroup *>(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);
}
}
/**

View File

@@ -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<IndependentTextItem *> 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<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::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<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,6 +170,9 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
if (m_live_edit)
{
QPropertyUndoCommand *undo = nullptr;
//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);
@@ -145,7 +200,58 @@ QUndoCommand *IndiTextPropertiesWidget::associatedUndo() const
return undo;
}
else
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;
}
}
//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();
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_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_angle_sb, QOverload<double>::of(&QDoubleSpinBox::valueChanged), 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::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->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);
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_angle_sb->setValue(m_text->rotation());
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 @@ 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();
}
}

View File

@@ -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,8 +36,10 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget
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;
@@ -45,6 +47,7 @@ class IndiTextPropertiesWidget : public PropertiesEditorWidget
private slots:
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 <IndependentTextItem> m_text;
QList <QPointer<IndependentTextItem>> m_text_list;
QList <QMetaObject::Connection> m_connect_list,
m_edit_connection;
};

View File

@@ -6,14 +6,51 @@
<rect>
<x>0</x>
<y>0</y>
<width>299</width>
<height>237</height>
<width>288</width>
<height>251</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QPushButton" name="m_advanced_editor_pb">
<property name="text">
<string>Éditeur avancé</string>
</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">
<string>Angle :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="m_x_sb">
<property name="suffix">
@@ -27,20 +64,39 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QPushButton" name="m_advanced_editor_pb">
<property name="text">
<string>Éditeur avancé</string>
<item row="6" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</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="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Angle :</string>
<item row="2" column="3">
<widget class="QDoubleSpinBox" name="m_y_sb">
<property name="suffix">
<string>px</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
</property>
</widget>
</item>
@@ -60,49 +116,6 @@
</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">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="3">
<widget class="QDoubleSpinBox" name="m_y_sb">
<property name="suffix">
<string>px</string>
</property>
<property name="decimals">
<number>0</number>
</property>
<property name="maximum">
<double>10000.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>X :</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label">
<property name="text">
@@ -113,23 +126,31 @@
</property>
</widget>
</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>
<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="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>