mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Text of conductor can be placed at top/bottom/left/right of conductor, and text never overlaps the conductor.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5342 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
a975915428
commit
d53f830ad9
@ -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<Qt::Alignment>();
|
||||
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);
|
||||
@ -316,6 +320,10 @@ void ConductorProperties::fromXml(QDomElement &e)
|
||||
verti_rotate_text = e.attribute("vertirotatetext").toDouble();
|
||||
horiz_rotate_text = e.attribute("horizrotatetext").toDouble();
|
||||
|
||||
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
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.
|
||||
//@TODO remove this code for qet 0.6 or later
|
||||
@ -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<Qt::Alignment>();
|
||||
settings.setValue(prefix + "horizontal-alignment", me.valueToKey(m_horizontal_alignment));
|
||||
settings.setValue(prefix + "vertical-alignment", me.valueToKey(m_vertical_alignment));
|
||||
|
||||
singleLineProperties.toSettings(settings, prefix);
|
||||
}
|
||||
|
||||
@ -378,6 +391,10 @@ void ConductorProperties::fromSettings(QSettings &settings, const QString &prefi
|
||||
verti_rotate_text = settings.value((prefix + "vertirotatetext"), "270").toDouble();
|
||||
horiz_rotate_text = settings.value((prefix + "horizrotatetext"), "0").toDouble();
|
||||
|
||||
QMetaEnum me = QMetaEnum::fromType<Qt::Alignment>();
|
||||
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<ConductorProperties> 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<ConductorProperties> 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<ConductorProperties> 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
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -1181,7 +1181,8 @@ 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;
|
||||
@ -1196,14 +1197,19 @@ QPointF Conductor::posForText(Qt::Orientations &flag) {
|
||||
QPointF p1 = segment -> firstPoint(); //<First point of conductor
|
||||
ConductorSegment *biggest_segment = segment; //<biggest segment: contain the longest segment of conductor.
|
||||
|
||||
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;
|
||||
|
||||
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.
|
||||
@ -1246,17 +1252,21 @@ 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) {
|
||||
if(longuest_conductor != this)
|
||||
{
|
||||
longuest_conductor -> calculateTextItemPosition();
|
||||
return;
|
||||
}
|
||||
@ -1270,7 +1280,8 @@ void Conductor::calculateTextItemPosition() {
|
||||
}
|
||||
|
||||
//position
|
||||
if (m_text_item -> wasMovedByUser()) {
|
||||
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();
|
||||
@ -1278,12 +1289,15 @@ void Conductor::calculateTextItemPosition() {
|
||||
if (!near_shape.contains(text_item_pos)) {
|
||||
m_text_item -> setPos(movePointIntoPolygon(text_item_pos, near_shape));
|
||||
}
|
||||
} else {
|
||||
}
|
||||
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);
|
||||
}
|
||||
@ -1291,12 +1305,43 @@ void Conductor::calculateTextItemPosition() {
|
||||
//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;
|
||||
if(m_properties.m_vertical_alignment == Qt::AlignLeft)
|
||||
text_pos.rx() -= m_text_item->boundingRect().height();
|
||||
}
|
||||
|
||||
//Finaly set the position of text
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>504</width>
|
||||
<height>566</height>
|
||||
<width>716</width>
|
||||
<height>825</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -176,33 +176,41 @@
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="m_text_angle_gl">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="m_horiz_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Vertical</string>
|
||||
<string>Horizontal en haut</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Horizontal en bas</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<item row="1" column="0">
|
||||
<widget class="QComboBox" name="m_verti_cb">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Horizontal</string>
|
||||
<string>Vertical à gauche</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Vertical à droite</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Rotation du texte de conducteur :</string>
|
||||
<string>Position et rotation du texte de conducteur :</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
<set>Qt::AlignHCenter|Qt::AlignTop</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -344,88 +352,6 @@
|
||||
<string>Apparence</string>
|
||||
</attribute>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="toolTip">
|
||||
<string>Couleur du conducteur</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Couleur :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="toolTip">
|
||||
<string>Style du conducteur</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Style :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="m_line_style_cb">
|
||||
<property name="toolTip">
|
||||
<string>Style du conducteur</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="m_color_pb">
|
||||
<property name="toolTip">
|
||||
<string>Couleur du conducteur</string>
|
||||
</property>
|
||||
<property name="accessibleName">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</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="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="m_cond_size_sb">
|
||||
<property name="minimum">
|
||||
<double>0.400000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.200000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="m_color_2_gb">
|
||||
<property name="title">
|
||||
@ -475,6 +401,88 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="toolTip">
|
||||
<string>Couleur du conducteur</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Couleur :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="m_color_pb">
|
||||
<property name="toolTip">
|
||||
<string>Couleur du conducteur</string>
|
||||
</property>
|
||||
<property name="accessibleName">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_10">
|
||||
<property name="text">
|
||||
<string>size:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="toolTip">
|
||||
<string>Style du conducteur</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Style :</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="m_line_style_cb">
|
||||
<property name="toolTip">
|
||||
<string>Style du conducteur</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="m_cond_size_sb">
|
||||
<property name="minimum">
|
||||
<double>0.400000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>10.000000000000000</double>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<double>0.200000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>1.000000000000000</double>
|
||||
</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>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
|
Loading…
x
Reference in New Issue
Block a user