[qet] qet/qet: [5342] Text of conductor can be placed at top/bottom/left/ right of conductor, and text never overlaps the conductor. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
- To: qet@xxxxxxxxxxxxxxxxxxx
- Subject: [qet] qet/qet: [5342] Text of conductor can be placed at top/bottom/left/ right of conductor, and text never overlaps the conductor.
- From: subversion@xxxxxxxxxxxxx
- Date: Sat, 28 Apr 2018 15:35:24 +0200
Revision: 5342
Author: blacksun
Date: 2018-04-28 15:35:23 +0200 (Sat, 28 Apr 2018)
Log Message:
-----------
Text of conductor can be placed at top/bottom/left/right of conductor, and text never overlaps the conductor.
Modified Paths:
--------------
trunk/sources/conductorproperties.cpp
trunk/sources/conductorproperties.h
trunk/sources/qetgraphicsitem/conductor.cpp
trunk/sources/ui/conductorpropertieswidget.cpp
trunk/sources/ui/conductorpropertieswidget.ui
Modified: trunk/sources/conductorproperties.cpp
===================================================================
--- trunk/sources/conductorproperties.cpp 2018-04-24 17:25:42 UTC (rev 5341)
+++ trunk/sources/conductorproperties.cpp 2018-04-28 13:35:23 UTC (rev 5342)
@@ -268,6 +268,10 @@
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);
@@ -315,6 +319,10 @@
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<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.
@@ -344,6 +352,11 @@
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);
}
@@ -377,7 +390,11 @@
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<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 @@
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 @@
QString s_value;
int i_value;
double d_value;
+ Qt::Alignment align_value;
//Color
c_value = clist.first().color;
@@ -595,6 +615,28 @@
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 @@
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
);
}
Modified: trunk/sources/conductorproperties.h
===================================================================
--- trunk/sources/conductorproperties.h 2018-04-24 17:25:42 UTC (rev 5341)
+++ trunk/sources/conductorproperties.h 2018-04-28 13:35:23 UTC (rev 5342)
@@ -97,6 +97,9 @@
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;
Modified: trunk/sources/qetgraphicsitem/conductor.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/conductor.cpp 2018-04-24 17:25:42 UTC (rev 5341)
+++ trunk/sources/qetgraphicsitem/conductor.cpp 2018-04-28 13:35:23 UTC (rev 5342)
@@ -1181,13 +1181,14 @@
* @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 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.
+ //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 @@
* 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
+ }
+ }
}
}
Modified: trunk/sources/ui/conductorpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/conductorpropertieswidget.cpp 2018-04-24 17:25:42 UTC (rev 5341)
+++ trunk/sources/ui/conductorpropertieswidget.cpp 2018-04-28 13:35:23 UTC (rev 5342)
@@ -94,6 +94,8 @@
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 @@
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 @@
*/
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));
Modified: trunk/sources/ui/conductorpropertieswidget.ui
===================================================================
--- trunk/sources/ui/conductorpropertieswidget.ui 2018-04-24 17:25:42 UTC (rev 5341)
+++ trunk/sources/ui/conductorpropertieswidget.ui 2018-04-28 13:35:23 UTC (rev 5342)
@@ -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">
- <property name="text">
- <string>Vertical</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
+ <item row="1" column="1">
+ <widget class="QComboBox" name="m_horiz_cb">
+ <item>
+ <property name="text">
+ <string>Horizontal en haut</string>
+ </property>
+ </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">
- <property name="text">
- <string>Horizontal</string>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
+ <item row="1" column="0">
+ <widget class="QComboBox" name="m_verti_cb">
+ <item>
+ <property name="text">
+ <string>Vertical à gauche</string>
+ </property>
+ </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,6 +352,55 @@
<string>Apparence</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
+ <item row="3" column="0" colspan="2">
+ <widget class="QGroupBox" name="m_color_2_gb">
+ <property name="title">
+ <string>Couleur secondaire :</string>
+ </property>
+ <property name="flat">
+ <bool>true</bool>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="1" column="1">
+ <widget class="QSpinBox" name="m_dash_size_sb">
+ <property name="suffix">
+ <string>px</string>
+ </property>
+ <property name="minimum">
+ <number>2</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QPushButton" name="m_color_2_pb">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_12">
+ <property name="text">
+ <string>Couleur :</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_13">
+ <property name="text">
+ <string>Taille de trait :</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="toolTip">
@@ -354,23 +411,6 @@
</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">
@@ -390,19 +430,6 @@
</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">
@@ -410,6 +437,23 @@
</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">
@@ -426,54 +470,18 @@
</property>
</widget>
</item>
- <item row="3" column="0" colspan="2">
- <widget class="QGroupBox" name="m_color_2_gb">
- <property name="title">
- <string>Couleur secondaire :</string>
+ <item row="4" column="0">
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
</property>
- <property name="flat">
- <bool>true</bool>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
</property>
- <property name="checkable">
- <bool>true</bool>
- </property>
- <property name="checked">
- <bool>false</bool>
- </property>
- <layout class="QGridLayout" name="gridLayout_2">
- <item row="1" column="1">
- <widget class="QSpinBox" name="m_dash_size_sb">
- <property name="suffix">
- <string>px</string>
- </property>
- <property name="minimum">
- <number>2</number>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QPushButton" name="m_color_2_pb">
- <property name="text">
- <string/>
- </property>
- </widget>
- </item>
- <item row="0" column="0">
- <widget class="QLabel" name="label_12">
- <property name="text">
- <string>Couleur :</string>
- </property>
- </widget>
- </item>
- <item row="1" column="0">
- <widget class="QLabel" name="label_13">
- <property name="text">
- <string>Taille de trait :</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
+ </spacer>
</item>
</layout>
</widget>