diff --git a/sources/conductorproperties.cpp b/sources/conductorproperties.cpp index c3a4013c8..805d47086 100644 --- a/sources/conductorproperties.cpp +++ b/sources/conductorproperties.cpp @@ -268,6 +268,10 @@ void ConductorProperties::toXml(QDomElement &e) const e.setAttribute("vertirotatetext", QString::number(verti_rotate_text)); e.setAttribute("horizrotatetext", QString::number(horiz_rotate_text)); + QMetaEnum me = QMetaEnum::fromType(); + e.setAttribute("horizontal-alignment", me.valueToKey(m_horizontal_alignment)); + e.setAttribute("vertical-alignment", me.valueToKey(m_vertical_alignment)); + QString conductor_style = writeStyle(); if (!conductor_style.isEmpty()) e.setAttribute("style", conductor_style); @@ -315,6 +319,10 @@ void ConductorProperties::fromXml(QDomElement &e) m_one_text_per_folio = e.attribute("onetextperfolio", QString::number(0)).toInt(); verti_rotate_text = e.attribute("vertirotatetext").toDouble(); horiz_rotate_text = e.attribute("horizrotatetext").toDouble(); + + QMetaEnum me = QMetaEnum::fromType(); + m_horizontal_alignment = Qt::Alignment(me.keyToValue(e.attribute("horizontal-alignment", "AlignBottom").toStdString().data())); + m_vertical_alignment = Qt::Alignment(me.keyToValue(e.attribute("vertical-alignment", "AlignRight").toStdString().data())); //Keep retrocompatible with version older than 0,4 //If the propertie @type is simple (removed since QET 0,4), we set text no visible. @@ -344,6 +352,11 @@ void ConductorProperties::toSettings(QSettings &settings, const QString &prefix) settings.setValue(prefix + "onetextperfolio", m_one_text_per_folio); settings.setValue(prefix + "vertirotatetext", QString::number(verti_rotate_text)); settings.setValue(prefix + "horizrotatetext", QString::number(horiz_rotate_text)); + + QMetaEnum me = QMetaEnum::fromType(); + settings.setValue(prefix + "horizontal-alignment", me.valueToKey(m_horizontal_alignment)); + settings.setValue(prefix + "vertical-alignment", me.valueToKey(m_vertical_alignment)); + singleLineProperties.toSettings(settings, prefix); } @@ -377,7 +390,11 @@ void ConductorProperties::fromSettings(QSettings &settings, const QString &prefi m_one_text_per_folio = settings.value(prefix + "onetextperfolio", false).toBool(); verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble(); horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble(); - + + QMetaEnum me = QMetaEnum::fromType(); + m_horizontal_alignment = Qt::Alignment(me.keyToValue(settings.value((prefix + "horizontal-alignment", "AlignBottom")).toString().toStdString().data())); + m_vertical_alignment = Qt::Alignment(me.keyToValue(settings.value((prefix + "vertical-alignment", "AlignRight")).toString().toStdString().data())); + readStyle(settings.value(prefix + "style").toString()); } @@ -431,6 +448,8 @@ void ConductorProperties::applyForEqualAttributes(QList lis m_one_text_per_folio = cp.m_one_text_per_folio; verti_rotate_text = cp.verti_rotate_text; horiz_rotate_text = cp.horiz_rotate_text; + m_vertical_alignment = cp.m_vertical_alignment; + m_horizontal_alignment = cp.m_horizontal_alignment; return; } @@ -441,6 +460,7 @@ void ConductorProperties::applyForEqualAttributes(QList lis QString s_value; int i_value; double d_value; + Qt::Alignment align_value; //Color c_value = clist.first().color; @@ -595,6 +615,28 @@ void ConductorProperties::applyForEqualAttributes(QList lis if (equal) horiz_rotate_text = d_value; equal = true; + + //Text alignment for horizontal conducor + align_value = clist.first().m_horizontal_alignment; + for(ConductorProperties cp : clist) + { + if (cp.m_horizontal_alignment != align_value) + equal = false; + } + if (equal) + m_horizontal_alignment = align_value; + equal = true; + + //Text alignment for vertical conducor + align_value = clist.first().m_vertical_alignment; + for(ConductorProperties cp : clist) + { + if (cp.m_vertical_alignment != align_value) + equal = false; + } + if (equal) + m_vertical_alignment = align_value; + equal = true; } /** @@ -635,7 +677,9 @@ bool ConductorProperties::operator==(const ConductorProperties &other) const other.verti_rotate_text == verti_rotate_text &&\ other.horiz_rotate_text == horiz_rotate_text &&\ other.singleLineProperties == singleLineProperties &&\ - other.m_one_text_per_folio == m_one_text_per_folio + other.m_one_text_per_folio == m_one_text_per_folio &&\ + other.m_horizontal_alignment == m_horizontal_alignment &&\ + other.m_vertical_alignment == m_vertical_alignment ); } diff --git a/sources/conductorproperties.h b/sources/conductorproperties.h index db5cdd829..085e099aa 100644 --- a/sources/conductorproperties.h +++ b/sources/conductorproperties.h @@ -97,6 +97,9 @@ class ConductorProperties m_one_text_per_folio, m_bicolor = false; + Qt::Alignment m_horizontal_alignment = Qt::AlignBottom, + m_vertical_alignment = Qt::AlignRight; + Qt::PenStyle style; SingleLineProperties singleLineProperties; diff --git a/sources/qetgraphicsitem/conductor.cpp b/sources/qetgraphicsitem/conductor.cpp index 21855b5d1..bc66def2e 100644 --- a/sources/qetgraphicsitem/conductor.cpp +++ b/sources/qetgraphicsitem/conductor.cpp @@ -1181,13 +1181,14 @@ ConductorSegment *Conductor::middleSegment() { * @param flag : flag is used to know if text pos is near of * a vertical or horizontal conductor segment. */ -QPointF Conductor::posForText(Qt::Orientations &flag) { +QPointF Conductor::posForText(Qt::Orientations &flag) +{ ConductorSegment *segment = segments; bool all_segment_is_vertical = true; bool all_segment_is_horizontal = true; - //Go to first segement + //Go to first segement while (!segment->isFirstSegment()) { segment = segment->previousSegment(); } @@ -1196,17 +1197,22 @@ QPointF Conductor::posForText(Qt::Orientations &flag) { QPointF p1 = segment -> firstPoint(); // firstPoint().x() != segment -> secondPoint().x()) all_segment_is_vertical = false; - if (segment -> firstPoint().y() != segment -> secondPoint().y()) all_segment_is_horizontal = false; + if (segment -> firstPoint().x() != segment -> secondPoint().x()) + all_segment_is_vertical = false; + if (segment -> firstPoint().y() != segment -> secondPoint().y()) + all_segment_is_horizontal = false; - while (segment -> hasNextSegment()) { + while (segment -> hasNextSegment()) + { segment = segment -> nextSegment(); - if (segment -> firstPoint().x() != segment -> secondPoint().x()) all_segment_is_vertical = false; - if (segment -> firstPoint().y() != segment -> secondPoint().y()) all_segment_is_horizontal = false; + if (segment -> firstPoint().x() != segment -> secondPoint().x()) + all_segment_is_vertical = false; + if (segment -> firstPoint().y() != segment -> secondPoint().y()) + all_segment_is_horizontal = false; - //We must to compare length segment, but they can be negative - //so we multiply by -1 to make it positive. + //We must to compare length segment, but they can be negative + //so we multiply by -1 to make it positive. int saved = biggest_segment -> length(); if (saved < 0) saved *= -1; int curent = segment->length(); @@ -1246,57 +1252,96 @@ QPointF Conductor::posForText(Qt::Orientations &flag) { * otherwise, move conductor at the middle of the longest segment of conductor. * If text was moved by user, this function do nothing, except check if text is near conductor. */ -void Conductor::calculateTextItemPosition() { - if (!m_text_item || !diagram() || m_properties.type != ConductorProperties::Multi) return; +void Conductor::calculateTextItemPosition() +{ + if (!m_text_item || !diagram() || m_properties.type != ConductorProperties::Multi) + return; if (diagram() -> defaultConductorProperties.m_one_text_per_folio == true && - relatedPotentialConductors(false).size() > 0) { + relatedPotentialConductors(false).size() > 0) + { Conductor *longuest_conductor = longuestConductorInPotential(this); - //The longuest conductor isn't this conductor - //we call calculateTextItemPosition of the longuest conductor - if(longuest_conductor != this) { + //The longuest conductor isn't this conductor + //we call calculateTextItemPosition of the longuest conductor + if(longuest_conductor != this) + { longuest_conductor -> calculateTextItemPosition(); return; } - //At this point this conductor is the longuest conductor we hide all text of conductor_list + //At this point this conductor is the longuest conductor we hide all text of conductor_list foreach (Conductor *c, relatedPotentialConductors(false)) { c -> textItem() -> setVisible(false); - } - //Make sure text item is visible + } + //Make sure text item is visible m_text_item -> setVisible(true); } - //position - if (m_text_item -> wasMovedByUser()) { - //Text field was moved by user : - //we check if text field is yet near the conductor + //position + if (m_text_item -> wasMovedByUser()) + { + //Text field was moved by user : + //we check if text field is yet near the conductor QPointF text_item_pos = m_text_item -> pos(); QPainterPath near_shape = nearShape(); if (!near_shape.contains(text_item_pos)) { m_text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape)); } - } else { - //Position and rotation of text is calculated. + } + else + { + //Position and rotation of text is calculated. Qt::Orientations rotation; QPointF text_pos = posForText(rotation); - if (!m_text_item -> wasRotateByUser()) { + if (!m_text_item -> wasRotateByUser()) + { rotation == Qt::Vertical ? m_text_item -> setRotation(m_properties.verti_rotate_text): m_text_item -> setRotation(m_properties.horiz_rotate_text); } - - //Adjust the position of text if his rotation - //is 0° or 270°, to be exactly centered to the conductor + + //Adjust the position of text if his rotation + //is 0° or 270°, to be exactly centered to the conductor if (m_text_item -> rotation() == 0) + { text_pos.rx() -= m_text_item -> boundingRect().width()/2; + if(m_properties.m_horizontal_alignment == Qt::AlignTop) + text_pos.ry() -= m_text_item->boundingRect().height(); + } else if (m_text_item -> rotation() == 270) + { text_pos.ry() += m_text_item -> boundingRect().width()/2; - - //Finaly set the position of text + if(m_properties.m_vertical_alignment == Qt::AlignLeft) + text_pos.rx() -= m_text_item->boundingRect().height(); + } + m_text_item -> setPos(text_pos); + + //Ensure text item don't collide with this conductor + while (m_text_item->collidesWithItem(this)) + { + if(rotation == Qt::Vertical) + { + qWarning() << "v"; + if(m_properties.m_vertical_alignment == Qt::AlignRight) + m_text_item->setX(m_text_item->x()+1); + else if (m_properties.m_vertical_alignment == Qt::AlignLeft) + m_text_item->setX(m_text_item->x()-1); + else + return; //avoid infinite loop + } + else if (rotation == Qt::Horizontal) + { + if(m_properties.m_horizontal_alignment == Qt::AlignTop) + m_text_item->setY(m_text_item->y()-1); + else if (m_properties.m_horizontal_alignment == Qt::AlignBottom) + m_text_item->setY(m_text_item->y()+1); + else + return; //avoid infinite loop + } + } } } diff --git a/sources/ui/conductorpropertieswidget.cpp b/sources/ui/conductorpropertieswidget.cpp index 0613fd8a9..c092a11c4 100644 --- a/sources/ui/conductorpropertieswidget.cpp +++ b/sources/ui/conductorpropertieswidget.cpp @@ -94,6 +94,8 @@ void ConductorPropertiesWidget::setProperties(const ConductorProperties &propert ui->m_phase_cb -> setChecked (m_properties.singleLineProperties.phasesCount()); ui->m_phase_slider -> setValue (m_properties.singleLineProperties.phasesCount()); + ui->m_horiz_cb->setCurrentIndex(m_properties.m_horizontal_alignment == Qt::AlignTop? 0 : 1); + ui->m_verti_cb->setCurrentIndex(m_properties.m_vertical_alignment == Qt::AlignLeft? 0 : 1); m_verti_select -> setValue (m_properties.verti_rotate_text); m_horiz_select -> setValue (m_properties.horiz_rotate_text); @@ -126,6 +128,8 @@ ConductorProperties ConductorPropertiesWidget::properties() const properties_.m_one_text_per_folio = ui -> m_one_text_per_folio_cb -> isChecked(); properties_.verti_rotate_text = m_verti_select -> value(); properties_.horiz_rotate_text = m_horiz_select -> value(); + properties_.m_vertical_alignment = ui->m_verti_cb->currentIndex() == 0? Qt::AlignLeft : Qt::AlignRight; + properties_.m_horizontal_alignment = ui->m_horiz_cb->currentIndex() == 0? Qt::AlignTop : Qt::AlignBottom; properties_.singleLineProperties.hasGround = ui -> m_earth_cb -> isChecked(); properties_.singleLineProperties.hasNeutral = ui -> m_neutral_cb -> isChecked(); @@ -208,9 +212,9 @@ QPushButton *ConductorPropertiesWidget::editAutonumPushButton() const */ void ConductorPropertiesWidget::initWidget() { m_verti_select = QETApp::createTextOrientationSpinBoxWidget(); - ui -> m_text_angle_gl -> addWidget(m_verti_select, 2, 0, Qt::AlignHCenter); + ui -> m_text_angle_gl -> addWidget(m_verti_select, 2, 0, Qt::AlignHCenter); m_horiz_select = QETApp::createTextOrientationSpinBoxWidget(); - ui -> m_text_angle_gl -> addWidget(m_horiz_select, 2, 1, Qt::AlignHCenter); + ui -> m_text_angle_gl -> addWidget(m_horiz_select, 2, 1, Qt::AlignHCenter); ui -> m_line_style_cb -> addItem(tr("Trait plein", "conductor style: solid line"), QPen(Qt::SolidLine)); ui -> m_line_style_cb -> addItem(tr("Trait en pointillés", "conductor style: dashed line"), QPen(Qt::DashLine)); diff --git a/sources/ui/conductorpropertieswidget.ui b/sources/ui/conductorpropertieswidget.ui index 920fc9f5d..387bfd2de 100644 --- a/sources/ui/conductorpropertieswidget.ui +++ b/sources/ui/conductorpropertieswidget.ui @@ -6,8 +6,8 @@ 0 0 - 504 - 566 + 716 + 825 @@ -176,33 +176,41 @@ - - - - Vertical - - - Qt::AlignCenter - + + + + + Horizontal en haut + + + + + Horizontal en bas + + - - - - Horizontal - - - Qt::AlignCenter - + + + + + Vertical à gauche + + + + + Vertical à droite + + - Rotation du texte de conducteur : + Position et rotation du texte de conducteur : - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + Qt::AlignHCenter|Qt::AlignTop @@ -344,88 +352,6 @@ Apparence - - - - Couleur du conducteur - - - Couleur : - - - - - - - Style du conducteur - - - Style : - - - - - - - Style du conducteur - - - - - - - Couleur du conducteur - - - - - - false - - - - - - false - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - size: - - - - - - - 0.400000000000000 - - - 10.000000000000000 - - - 0.200000000000000 - - - 1.000000000000000 - - - @@ -475,6 +401,88 @@ + + + + Couleur du conducteur + + + Couleur : + + + + + + + Couleur du conducteur + + + + + + false + + + + + + false + + + + + + + size: + + + + + + + Style du conducteur + + + Style : + + + + + + + Style du conducteur + + + + + + + 0.400000000000000 + + + 10.000000000000000 + + + 0.200000000000000 + + + 1.000000000000000 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + +