diff --git a/sources/editor/graphicspart/partdynamictextfield.cpp b/sources/editor/graphicspart/partdynamictextfield.cpp
index f8dece784..d04ac6f5b 100644
--- a/sources/editor/graphicspart/partdynamictextfield.cpp
+++ b/sources/editor/graphicspart/partdynamictextfield.cpp
@@ -148,6 +148,7 @@ const QDomElement PartDynamicTextField::toXml(QDomDocument &dom_doc) const
root_element.setAttribute("frame", m_frame? "true" : "false");
root_element.setAttribute("text_width", QString::number(m_text_width));
root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false");
+ root_element.setAttribute("rotation_point_center", m_rotation_point_center ? "true" : "false");
QMetaEnum me = DynamicElementTextItem::textFromMetaEnum();
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
@@ -212,6 +213,7 @@ void PartDynamicTextField::fromXml(const QDomElement &dom_elmt) {
setZValue(dom_elmt.attribute("z", QString::number(zValue())).toDouble());
QGraphicsObject::setRotation(QET::correctAngle(dom_elmt.attribute("rotation", QString::number(0)).toDouble()));
setKeepVisualRotation(dom_elmt.attribute("keep_visual_rotation", "true") == "true"? true : false);
+ setRotationPointCenter(dom_elmt.attribute("rotation_point_center", "false") == "true"? true : false);
if (dom_elmt.hasAttribute("font")) {
QFont font_;
@@ -492,6 +494,20 @@ bool PartDynamicTextField::keepVisualRotation() const {
return m_keep_visual_rotation;
}
+void PartDynamicTextField::setRotationPointCenter(const bool ¢er)
+{
+ if (center == this->m_rotation_point_center) {
+ return;
+ }
+
+ m_rotation_point_center = center;
+ emit rotationPointCenterChanged(center);
+}
+
+bool PartDynamicTextField::rotationPointCenter() const {
+ return m_rotation_point_center;
+}
+
/**
@brief PartDynamicTextField::mouseMoveEvent
@param event
diff --git a/sources/editor/graphicspart/partdynamictextfield.h b/sources/editor/graphicspart/partdynamictextfield.h
index 218a8379e..4fdf0d700 100644
--- a/sources/editor/graphicspart/partdynamictextfield.h
+++ b/sources/editor/graphicspart/partdynamictextfield.h
@@ -44,6 +44,7 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
Q_PROPERTY(bool keepVisualRotation READ keepVisualRotation WRITE setKeepVisualRotation NOTIFY keepVisualRotationChanged)
+ Q_PROPERTY(bool rotationPointCenter READ rotationPointCenter WRITE setRotationPointCenter NOTIFY rotationPointCenterChanged)
public:
///PROPERTY
@@ -62,6 +63,7 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
void alignmentChanged(Qt::Alignment alignment);
void fontChanged(QFont font);
void keepVisualRotationChanged(bool keep);
+ void rotationPointCenterChanged(bool center);
public:
PartDynamicTextField(QETElementEditor *editor, QGraphicsItem *parent = nullptr);
@@ -100,6 +102,8 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
void setFont(const QFont &font);
void setKeepVisualRotation(const bool &keep);
bool keepVisualRotation() const;
+ void setRotationPointCenter(const bool ¢er);
+ bool rotationPointCenter() const;
void setRotation(qreal angle);
void mirror();
@@ -129,7 +133,8 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
bool m_frame = false,
m_first_add = true,
m_block_alignment = false,
- m_keep_visual_rotation = false;
+ m_keep_visual_rotation = false,
+ m_rotation_point_center = false;
qreal m_text_width = -1;
Qt::Alignment m_alignment = Qt::AlignTop|Qt::AlignLeft;
QRectF m_alignment_rect;
diff --git a/sources/editor/ui/dynamictextfieldeditor.cpp b/sources/editor/ui/dynamictextfieldeditor.cpp
index fb23c8141..145dd959a 100644
--- a/sources/editor/ui/dynamictextfieldeditor.cpp
+++ b/sources/editor/ui/dynamictextfieldeditor.cpp
@@ -140,6 +140,7 @@ void DynamicTextFieldEditor::updateForm()
ui -> m_user_text_le -> setText(m_text_field.data() -> text());
ui -> m_size_sb -> setValue(m_text_field.data() -> font().pointSize());
ui->m_keep_visual_rotation_cb->setChecked(m_text_field.data()->keepVisualRotation());
+ ui->m_rotation_point_center_cb->setChecked(m_text_field.data()->rotationPointCenter());
#ifdef BUILD_WITHOUT_KF5
#else
m_color_kpb -> setColor(m_text_field.data() -> color());
@@ -197,6 +198,7 @@ void DynamicTextFieldEditor::setUpConnections()
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();});
m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::keepVisualRotationChanged, this, [=](){this -> updateForm();});
+ m_connection_list << connect(m_text_field.data(), &PartDynamicTextField::rotationPointCenterChanged, this, [=](){this -> updateForm();});
// Refresh info combo when element data changes (e.g. type switched to PLC-Slave)
m_connection_list << connect(elementEditor()->elementScene(), &ElementScene::elementInfoChanged,
@@ -347,8 +349,8 @@ void DynamicTextFieldEditor::on_m_width_sb_editingFinished()
}
}
-void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(const QString &arg1) {
- Q_UNUSED(arg1)
+void DynamicTextFieldEditor::on_m_elmt_info_cb_activated(int index) {
+ Q_UNUSED(index)
QString info = ui -> m_elmt_info_cb -> currentData().toString();
for (int i = 0; i < m_parts.length(); i++) {
@@ -489,3 +491,16 @@ void DynamicTextFieldEditor::on_m_keep_visual_rotation_cb_clicked()
}
}
}
+
+void DynamicTextFieldEditor::on_m_rotation_point_center_cb_clicked()
+{
+ bool center = ui->m_rotation_point_center_cb->isChecked();
+
+ for (int i = 0; i < m_parts.length(); i++) {
+ if (center != m_parts[i]->rotationPointCenter()) {
+ QPropertyUndoCommand *undo = new QPropertyUndoCommand(m_parts[i], "rotationPointCenter", m_parts[i]->rotationPointCenter(), center);
+ undo->setText(tr("Modifier le point de rotation d'un champ texte"));
+ undoStack().push(undo);
+ }
+ }
+}
\ No newline at end of file
diff --git a/sources/editor/ui/dynamictextfieldeditor.h b/sources/editor/ui/dynamictextfieldeditor.h
index 5e5464222..e2f4662e3 100644
--- a/sources/editor/ui/dynamictextfieldeditor.h
+++ b/sources/editor/ui/dynamictextfieldeditor.h
@@ -62,7 +62,7 @@ class DynamicTextFieldEditor : public ElementItemEditor {
void on_m_size_sb_editingFinished();
void on_m_frame_cb_clicked();
void on_m_width_sb_editingFinished();
- void on_m_elmt_info_cb_activated(const QString &arg1);
+ void on_m_elmt_info_cb_activated(int index);
void on_m_text_from_cb_activated(int index);
void on_m_composite_text_pb_clicked();
void on_m_alignment_pb_clicked();
@@ -71,6 +71,7 @@ class DynamicTextFieldEditor : public ElementItemEditor {
void m_color_kpb_changed(QColor newColor);
void on_m_keep_visual_rotation_cb_clicked();
+ void on_m_rotation_point_center_cb_clicked();
private:
Ui::DynamicTextFieldEditor *ui;
diff --git a/sources/editor/ui/dynamictextfieldeditor.ui b/sources/editor/ui/dynamictextfieldeditor.ui
index 91836342b..516b41853 100644
--- a/sources/editor/ui/dynamictextfieldeditor.ui
+++ b/sources/editor/ui/dynamictextfieldeditor.ui
@@ -37,7 +37,7 @@
- -
+
-
Largeur
@@ -73,6 +73,13 @@
+ -
+
+
+ Tourner autour de son propre centre
+
+
+
-
@@ -92,7 +99,7 @@
- -
+
-
-1
@@ -149,7 +156,7 @@
- -
+
-
Alignement
@@ -236,6 +243,7 @@
m_y_sb
m_rotation_sb
m_keep_visual_rotation_cb
+ m_rotation_point_center_cb
m_width_sb
m_alignment_pb
m_size_sb
diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.cpp b/sources/qetgraphicsitem/dynamicelementtextitem.cpp
index 8f6359e97..28fc9ab56 100644
--- a/sources/qetgraphicsitem/dynamicelementtextitem.cpp
+++ b/sources/qetgraphicsitem/dynamicelementtextitem.cpp
@@ -99,7 +99,8 @@ QDomElement DynamicElementTextItem::toXml(QDomDocument &dom_doc) const
root_element.setAttribute("text_width", QString::number(m_text_width));
root_element.setAttribute("font", QETUtils::fontToString(font()));
root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false");
-
+ root_element.setAttribute("rotation_point_center", m_rotation_point_center ? "true" : "false");
+
QMetaEnum me = textFromMetaEnum();
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
@@ -164,6 +165,7 @@ void DynamicElementTextItem::fromXml(const QDomElement &dom_elmt)
QGraphicsTextItem::setRotation(dom_elmt.attribute("rotation", QString::number(0)).toDouble());
setKeepVisualRotation(dom_elmt.attribute("keep_visual_rotation", "true") == "true"? true : false);
+ setRotationPointCenter(dom_elmt.attribute("rotation_point_center", "false") == "true"? true : false);
if (dom_elmt.hasAttribute("font"))
{
@@ -1311,6 +1313,7 @@ void DynamicElementTextItem::parentElementRotationChanged()
//We temporally disconnect for not change m_visual_rotation value.
//We don't use block signal, because rotationChanged signal is used in other place.
disconnect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
+ setTransformOriginPoint(m_rotation_point_center ? boundingRect().center() : QPointF(0, 0));
this->setRotation(QET::correctAngle(m_visual_rotation_ref - m_parent_element->rotation(), true));
connect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
}
@@ -1526,3 +1529,13 @@ bool DynamicElementTextItem::keepVisualRotation() const {
return m_keep_visual_rotation;
}
+void DynamicElementTextItem::setRotationPointCenter(bool center)
+{
+ if (m_rotation_point_center == center) return;
+ m_rotation_point_center = center;
+ emit rotationPointCenterChanged(center);
+}
+
+bool DynamicElementTextItem::rotationPointCenter() const {
+ return m_rotation_point_center;
+}
\ No newline at end of file
diff --git a/sources/qetgraphicsitem/dynamicelementtextitem.h b/sources/qetgraphicsitem/dynamicelementtextitem.h
index f31096b53..85826eb8f 100644
--- a/sources/qetgraphicsitem/dynamicelementtextitem.h
+++ b/sources/qetgraphicsitem/dynamicelementtextitem.h
@@ -51,7 +51,7 @@ class DynamicElementTextItem : public DiagramTextItem
Q_PROPERTY(bool frame READ frame WRITE setFrame NOTIFY frameChanged)
Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth NOTIFY textWidthChanged)
Q_PROPERTY(bool keepVisualRotation READ keepVisualRotation WRITE setKeepVisualRotation NOTIFY keepVisualRotationChanged)
-
+ Q_PROPERTY(bool rotationPointCenter READ rotationPointCenter WRITE setRotationPointCenter NOTIFY rotationPointCenterChanged)
public:
enum TextFrom {
@@ -72,6 +72,7 @@ class DynamicElementTextItem : public DiagramTextItem
void plainTextChanged();
void textWidthChanged(qreal width);
void keepVisualRotationChanged(bool keep);
+ void rotationPointCenterChanged(bool center);
public:
DynamicElementTextItem(Element *parent_element);
@@ -113,6 +114,9 @@ class DynamicElementTextItem : public DiagramTextItem
void setKeepVisualRotation(bool set);
bool keepVisualRotation() const;
+ void setRotationPointCenter(bool set);
+ bool rotationPointCenter() const;
+
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
@@ -172,6 +176,7 @@ class DynamicElementTextItem : public DiagramTextItem
qreal m_text_width = -1;
QPointF m_initial_position;
bool m_keep_visual_rotation = true;
+ bool m_rotation_point_center = false;
qreal m_visual_rotation_ref = 0;
bool m_move_parent = true;
};