[qet] [4547] Xref: Change Vertical Offset of Cross References

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 4547
Author:   dfochi
Date:     2016-06-07 19:01:59 +0200 (Tue, 07 Jun 2016)
Log Message:
-----------
Xref: Change Vertical Offset of Cross References

Modified Paths:
--------------
    trunk/sources/properties/xrefproperties.cpp
    trunk/sources/properties/xrefproperties.h
    trunk/sources/qetgraphicsitem/commentitem.cpp
    trunk/sources/qetgraphicsitem/crossrefitem.cpp
    trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp
    trunk/sources/qetgraphicsitem/qgraphicsitemutility.h
    trunk/sources/ui/xrefpropertieswidget.cpp
    trunk/sources/ui/xrefpropertieswidget.ui

Modified: trunk/sources/properties/xrefproperties.cpp
===================================================================
--- trunk/sources/properties/xrefproperties.cpp	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/properties/xrefproperties.cpp	2016-06-07 17:01:59 UTC (rev 4547)
@@ -30,6 +30,7 @@
 	m_prefix_keys << "power" << "delay" << "switch";
 	m_master_label = "%f-%l%c";
 	m_slave_label = "(%f-%l%c)";
+	m_offset = 0;
 }
 
 /**
@@ -44,6 +45,8 @@
 	settings.setValue(prefix + "displayhas", display);
 	QString snap = m_snap_to == Bottom? "bottom" : "label";
 	settings.setValue(prefix + "snapto", snap);
+	int offset = m_offset;
+	settings.setValue(prefix + "offset", offset);
 	QString master_label = m_master_label;
 	settings.setValue(prefix + "master_label", master_label);
 	QString slave_label = m_slave_label;
@@ -65,6 +68,7 @@
 	display == "cross"? m_display = Cross : m_display = Contacts;
 	QString snap = settings.value(prefix + "snapto", "label").toString();
 	snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
+	m_offset = settings.value(prefix + "offset", "0").toInt();
 	m_master_label = settings.value(prefix + "master_label", "%f-%l%c").toString();
 	m_slave_label = settings.value(prefix + "slave_label", "(%f-%l%c)").toString();
 	foreach (QString key, m_prefix_keys) {
@@ -83,6 +87,8 @@
 	xml_element.setAttribute("displayhas", display);
 	QString snap = m_snap_to == Bottom? "bottom" : "label";
 	xml_element.setAttribute("snapto", snap);
+	int offset = m_offset;
+	xml_element.setAttribute("offset", offset);
 	QString master_label = m_master_label;
 	xml_element.setAttribute("master_label", master_label);
 	QString slave_label = m_slave_label;
@@ -103,6 +109,7 @@
 	display == "cross"? m_display = Cross : m_display = Contacts;
 	QString snap = xml_element.attribute("snapto", "label");
 	snap == "bottom"? m_snap_to = Bottom : m_snap_to = Label;
+	m_offset = xml_element.attribute("offset", "0").toInt();
 	m_master_label = xml_element.attribute("master_label", "%f-%l%c");
 	m_slave_label = xml_element.attribute("slave_label","(%f-%l%c)");
 	foreach (QString key, m_prefix_keys) {
@@ -142,7 +149,8 @@
 			m_snap_to == xrp.m_snap_to &&
 			m_prefix == xrp.m_prefix &&
 			m_master_label == xrp.m_master_label &&
-			m_slave_label == xrp.m_slave_label);
+			m_slave_label == xrp.m_slave_label &&
+			m_offset == xrp.m_offset);
 }
 
 bool XRefProperties::operator !=(const XRefProperties &xrp) const {

Modified: trunk/sources/properties/xrefproperties.h
===================================================================
--- trunk/sources/properties/xrefproperties.h	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/properties/xrefproperties.h	2016-06-07 17:01:59 UTC (rev 4547)
@@ -68,6 +68,9 @@
 	void setSlaveLabel(const QString slave) {m_slave_label = slave;}
 	QString slaveLabel () const				{return m_slave_label;}
 
+	void setOffset(const int offset) {m_offset = offset;}
+	int offset() const				 {return m_offset;}
+
 	private:
 	bool m_show_power_ctc;
 	DisplayHas m_display;
@@ -76,6 +79,7 @@
 	QStringList m_prefix_keys;
 	QString m_master_label;
 	QString m_slave_label;
+	int     m_offset;
 };
 
 #endif // XREFPROPERTIES_H

Modified: trunk/sources/qetgraphicsitem/commentitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/commentitem.cpp	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/qetgraphicsitem/commentitem.cpp	2016-06-07 17:01:59 UTC (rev 4547)
@@ -57,8 +57,10 @@
 void CommentItem::autoPos() {
 	if (m_text_parent)
 		centerToParentBottom(this);
-	else
-		centerToBottomDiagram(this, m_element);
+	else {
+		XRefProperties xrp = m_element->diagram()->defaultXRefProperties(m_element->kindInformations()["type"].toString());
+		centerToBottomDiagram(this, m_element, xrp.offset());
+	}
 }
 
 /**

Modified: trunk/sources/qetgraphicsitem/crossrefitem.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/crossrefitem.cpp	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/qetgraphicsitem/crossrefitem.cpp	2016-06-07 17:01:59 UTC (rev 4547)
@@ -217,7 +217,7 @@
 void CrossRefItem::autoPos() {
 	//We calcul the position according to the @snapTo of the xrefproperties
 	if (m_properties.snapTo() == XRefProperties::Bottom)
-		centerToBottomDiagram(this, m_element);
+		centerToBottomDiagram(this, m_element, m_properties.offset());
 	else
 		centerToParentBottom(this);
 }

Modified: trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/qetgraphicsitem/qgraphicsitemutility.cpp	2016-06-07 17:01:59 UTC (rev 4547)
@@ -48,7 +48,7 @@
  * @param element_to_follow
  * @return true if element is centered else false (element_to_follow have not diagram)
  */
-bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow) {
+bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, int offset) {
 	if (! element_to_follow -> diagram()) {
 		qDebug() << "qgraphicsitemutility centerAtBottomDiagram : Element_to_follow have not diagram";
 		return false;
@@ -57,8 +57,10 @@
 	QRectF  border = element_to_follow -> diagram() -> border_and_titleblock.insideBorderRect();
 	QPointF point  = element_to_follow -> sceneBoundingRect().center();
 
+	if (offset >= 50) //applies offset
+	point.setY(border.bottom() - offset );
+	else //applies default
 	point.setY(border.bottom() - item_to_center -> boundingRect().height() - 5);
-
 	point.rx() -= (item_to_center -> boundingRect().width()/2 +
 				   item_to_center -> boundingRect().left()); //< we add boundingrect.left because this value can be négative
 

Modified: trunk/sources/qetgraphicsitem/qgraphicsitemutility.h
===================================================================
--- trunk/sources/qetgraphicsitem/qgraphicsitemutility.h	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/qetgraphicsitem/qgraphicsitemutility.h	2016-06-07 17:01:59 UTC (rev 4547)
@@ -22,6 +22,6 @@
 class Element;
 
 bool centerToParentBottom  (QGraphicsItem *item);
-bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow);
+bool centerToBottomDiagram (QGraphicsItem *item_to_center, Element *element_to_follow, int offset );
 
 #endif // QGRAPHICSITEMUTILITY_H

Modified: trunk/sources/ui/xrefpropertieswidget.cpp
===================================================================
--- trunk/sources/ui/xrefpropertieswidget.cpp	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/ui/xrefpropertieswidget.cpp	2016-06-07 17:01:59 UTC (rev 4547)
@@ -119,6 +119,7 @@
 	xrp.setPrefix("switch", ui->m_switch_prefix_le->text());
 	xrp.setMasterLabel(ui->m_master_le->text());
 	xrp.setSlaveLabel(ui->m_slave_le->text());
+	xrp.setOffset(ui->m_offset_sb->value());
 
 	m_properties.insert(type, xrp);
 }
@@ -145,6 +146,9 @@
 	QString slave = xrp.slaveLabel();
 	ui->m_slave_le->setText(slave);
 
+	int offset = xrp.offset();
+	ui->m_offset_sb->setValue(offset);
+
 	if (xrp.snapTo() == XRefProperties::Bottom)
 		 ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("bottom"));
 	else ui->m_snap_to_cb->setCurrentIndex(ui->m_snap_to_cb->findData("label"));

Modified: trunk/sources/ui/xrefpropertieswidget.ui
===================================================================
--- trunk/sources/ui/xrefpropertieswidget.ui	2016-06-07 12:55:05 UTC (rev 4546)
+++ trunk/sources/ui/xrefpropertieswidget.ui	2016-06-07 17:01:59 UTC (rev 4547)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>484</width>
+    <width>507</width>
     <height>649</height>
    </rect>
   </property>
@@ -49,6 +49,48 @@
        </layout>
       </item>
       <item>
+       <layout class="QHBoxLayout" name="horizontalLayout_7">
+        <item>
+         <widget class="QLabel" name="label_9">
+          <property name="text">
+           <string>XRef Vertical Offset:</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QSpinBox" name="m_offset_sb">
+          <property name="toolTip">
+           <string>10px corresponds to 1 tile displacement</string>
+          </property>
+          <property name="whatsThis">
+           <string>Set Vertical Offset for the Cross References. 10px corresponds to 1 tile displacement.</string>
+          </property>
+          <property name="specialValueText">
+           <string>Default - Fit to XRef height</string>
+          </property>
+          <property name="correctionMode">
+           <enum>QAbstractSpinBox::CorrectToNearestValue</enum>
+          </property>
+          <property name="suffix">
+           <string notr="true">px</string>
+          </property>
+          <property name="minimum">
+           <number>40</number>
+          </property>
+          <property name="maximum">
+           <number>300</number>
+          </property>
+          <property name="singleStep">
+           <number>10</number>
+          </property>
+          <property name="value">
+           <number>40</number>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item>
        <layout class="QHBoxLayout" name="horizontalLayout_3">
         <item>
          <layout class="QVBoxLayout" name="verticalLayout_2">


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/