mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Dynamic element text item new feature
Add feature keep visual rotation. When parent is rotated, the text rotation is changed to keep the same visual rotation.
This commit is contained in:
@@ -570,10 +570,11 @@ qreal QET::round(qreal x, qreal epsilon) {
|
||||
@param angle Un angle quelconque
|
||||
@return l'angle passe en parametre, mais ramene entre -360.0 + 360.0 degres
|
||||
*/
|
||||
qreal QET::correctAngle(const qreal &angle) {
|
||||
qreal QET::correctAngle(const qreal &angle, const bool &positive) {
|
||||
// ramene l'angle demande entre -360.0 et +360.0 degres
|
||||
qreal corrected_angle = angle;
|
||||
while (corrected_angle <= -360.0) corrected_angle += 360.0;
|
||||
while (corrected_angle <= -360.0 ||
|
||||
(positive && corrected_angle < 0)) corrected_angle += 360.0;
|
||||
while (corrected_angle >= 360.0) corrected_angle -= 360.0;
|
||||
return(corrected_angle);
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace QET {
|
||||
QString diagramAreaToString(const QET::DiagramArea &);
|
||||
QET::DiagramArea diagramAreaFromString(const QString &);
|
||||
qreal round(qreal, qreal);
|
||||
qreal correctAngle(const qreal &);
|
||||
qreal correctAngle(const qreal &, const bool &positive = false);
|
||||
bool compareCanonicalFilePaths(const QString &, const QString &);
|
||||
bool writeXmlFile(QDomDocument &xml_doc, const QString &filepath, QString * error_message= nullptr);
|
||||
bool writeToFile (QDomDocument &xml_doc, QFile *file, QString *error_message = nullptr);
|
||||
|
||||
@@ -44,6 +44,7 @@ DynamicElementTextItem::DynamicElementTextItem(Element *parent_element) :
|
||||
setParentItem(parent_element);
|
||||
QSettings settings;
|
||||
setRotation(settings.value("dynamic_text_rotation", 0).toInt());
|
||||
setKeepVisualRotation(true);
|
||||
setTextWidth(settings.value("dynamic_text_widht", -1).toInt());
|
||||
connect(this, &DynamicElementTextItem::textEdited, [this](const QString &old_str, const QString &new_str)
|
||||
{
|
||||
@@ -95,6 +96,7 @@ QDomElement DynamicElementTextItem::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("font", font().toString());
|
||||
root_element.setAttribute("keep_visual_rotation", m_keep_visual_rotation ? "true" : "false");
|
||||
|
||||
QMetaEnum me = textFromMetaEnum();
|
||||
root_element.setAttribute("text_from", me.valueToKey(m_text_from));
|
||||
@@ -159,6 +161,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);
|
||||
|
||||
if (dom_elmt.hasAttribute("font"))
|
||||
{
|
||||
@@ -1248,6 +1251,32 @@ void DynamicElementTextItem::zoomToLinkedElement()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DynamicElementTextItem::parentElementRotationChanged
|
||||
* Called when the parent element is rotated
|
||||
*/
|
||||
void DynamicElementTextItem::parentElementRotationChanged()
|
||||
{
|
||||
if (m_parent_element && m_keep_visual_rotation)
|
||||
{
|
||||
//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);
|
||||
this->setRotation(QET::correctAngle(m_visual_rotation_ref - m_parent_element->rotation(), true));
|
||||
connect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DynamicElementTextItem::thisRotationChanged
|
||||
* This function is called when user change the rotation of the text
|
||||
* and "keep visual rotation" is to true
|
||||
* to keep in memory the visual rotation wanted by the user.
|
||||
*/
|
||||
void DynamicElementTextItem::thisRotationChanged() {
|
||||
m_visual_rotation_ref = this->rotation() + m_parent_element->rotation();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief DynamicElementTextItem::updateXref
|
||||
Create or delete the Xref according to the current properties of the project
|
||||
@@ -1422,3 +1451,22 @@ void DynamicElementTextItem::setXref_item(Qt::AlignmentFlag m_exHrefPos)
|
||||
return;
|
||||
}
|
||||
|
||||
void DynamicElementTextItem::setKeepVisualRotation(bool set)
|
||||
{
|
||||
m_keep_visual_rotation = set;
|
||||
emit keepVisualRotationChanged(set);
|
||||
if (set) {
|
||||
m_visual_rotation_ref = this->rotation() + m_parent_element->rotation();
|
||||
connect(m_parent_element, &Element::rotationChanged, this, &DynamicElementTextItem::parentElementRotationChanged);
|
||||
connect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
|
||||
}
|
||||
else {
|
||||
disconnect(m_parent_element, &Element::rotationChanged, this, &DynamicElementTextItem::parentElementRotationChanged);
|
||||
disconnect(this, &DynamicElementTextItem::rotationChanged, this, &DynamicElementTextItem::thisRotationChanged);
|
||||
}
|
||||
}
|
||||
|
||||
bool DynamicElementTextItem::keepVisualRotation() const {
|
||||
return m_keep_visual_rotation;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
Q_PROPERTY(QString compositeText READ compositeText WRITE setCompositeText NOTIFY compositeTextChanged)
|
||||
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)
|
||||
|
||||
public:
|
||||
|
||||
@@ -69,6 +70,7 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
void frameChanged(bool frame);
|
||||
void plainTextChanged();
|
||||
void textWidthChanged(qreal width);
|
||||
void keepVisualRotationChanged(bool keep);
|
||||
|
||||
public:
|
||||
DynamicElementTextItem(Element *parent_element);
|
||||
@@ -104,6 +106,9 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
void setTextWidth(qreal width);
|
||||
void setXref_item(Qt::AlignmentFlag m_exHrefPos);
|
||||
|
||||
void setKeepVisualRotation(bool set);
|
||||
bool keepVisualRotation() const;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||
@@ -133,6 +138,8 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
void conductorPropertiesChanged();
|
||||
QString reportReplacedCompositeText() const;
|
||||
void zoomToLinkedElement();
|
||||
void parentElementRotationChanged();
|
||||
void thisRotationChanged();
|
||||
|
||||
private:
|
||||
QPointer <Element>
|
||||
@@ -160,6 +167,8 @@ class DynamicElementTextItem : public DiagramTextItem
|
||||
QGraphicsTextItem *m_slave_Xref_item = nullptr;
|
||||
qreal m_text_width = -1;
|
||||
QPointF m_initial_position;
|
||||
bool m_keep_visual_rotation = true;
|
||||
qreal m_visual_rotation_ref = 0;
|
||||
};
|
||||
|
||||
#endif // DYNAMICELEMENTTEXTITEM_H
|
||||
|
||||
@@ -49,7 +49,8 @@ static int width_txt_row = 8;
|
||||
static int x_txt_row = 9;
|
||||
static int y_txt_row = 10;
|
||||
static int rot_txt_row = 11;
|
||||
static int align_txt_row = 12;
|
||||
static int keep_rot_row = 12;
|
||||
static int align_txt_row = 13;
|
||||
|
||||
static int align_grp_row = 0;
|
||||
static int x_grp_row = 1;
|
||||
@@ -335,8 +336,22 @@ QList<QStandardItem *> DynamicElementTextModel::itemsForText(
|
||||
| Qt::ItemIsEnabled
|
||||
| Qt::ItemIsEditable);
|
||||
|
||||
qsi_list.clear();;
|
||||
qsi_list.clear();
|
||||
qsi_list << rot << rot_a;
|
||||
qsi->appendRow(qsi_list);
|
||||
|
||||
//keep visual rotation
|
||||
auto keep_rotation = new QStandardItem(tr("Conserver la rotation visuel"));
|
||||
keep_rotation->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
auto keep_rotation_a = new QStandardItem;
|
||||
keep_rotation_a->setCheckable(true);
|
||||
keep_rotation_a->setCheckState(deti->keepVisualRotation() ? Qt::Checked : Qt::Unchecked);
|
||||
keep_rotation_a->setData(DynamicElementTextModel::keepVisualRotation, Qt::UserRole+1);
|
||||
keep_rotation_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
|
||||
|
||||
qsi_list.clear();
|
||||
qsi_list << keep_rotation << keep_rotation_a;
|
||||
qsi->appendRow(qsi_list);
|
||||
|
||||
//Alignment
|
||||
@@ -601,6 +616,16 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(
|
||||
}
|
||||
}
|
||||
|
||||
if (text_qsi->child(keep_rot_row,1))
|
||||
{
|
||||
bool keep_rot = text_qsi->child(keep_rot_row, 1)->checkState() == Qt::Checked? true : false;
|
||||
if (keep_rot != deti->keepVisualRotation())
|
||||
{
|
||||
auto qpuc = new QPropertyUndoCommand(deti, "keepVisualRotation", QVariant(deti->keepVisualRotation()), QVariant(keep_rot), undo);
|
||||
qpuc->setText(tr("Modifier le maintient de la rotation d'un texte d'élément"));
|
||||
}
|
||||
}
|
||||
|
||||
//When text is in a groupe, they're isn't item for alignment of the text
|
||||
if(text_qsi->child(align_txt_row, 1))
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@ class DynamicElementTextModel : public QStandardItemModel
|
||||
pos,
|
||||
frame,
|
||||
rotation,
|
||||
keepVisualRotation,
|
||||
textWidth,
|
||||
grpAlignment,
|
||||
grpPos,
|
||||
|
||||
Reference in New Issue
Block a user