[qet] [3615] Element : add new help line (perpendicular to terminal)

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


Revision: 3615
Author:   blacksun
Date:     2015-01-18 12:28:56 +0100 (Sun, 18 Jan 2015)
Log Message:
-----------
Element : add new help line (perpendicular to terminal)

Modified Paths:
--------------
    trunk/sources/qet.cpp
    trunk/sources/qet.h
    trunk/sources/qetgraphicsitem/terminal.cpp
    trunk/sources/qetgraphicsitem/terminal.h

Modified: trunk/sources/qet.cpp
===================================================================
--- trunk/sources/qet.cpp	2015-01-18 10:27:36 UTC (rev 3614)
+++ trunk/sources/qet.cpp	2015-01-18 11:28:56 UTC (rev 3615)
@@ -94,20 +94,20 @@
 }
 
 /**
-	Indique si une orientation de borne est horizontale (Est / Ouest).
-	@param a L'orientation de borne
-	@return True si l'orientation de borne est horizontale, false sinon
-*/
-bool Qet::estHorizontale(Qet::Orientation a) {
+ * @brief Qet::isHorizontal
+ * @param a
+ * @return true if @a is horizontal, else false.
+ */
+bool Qet::isHorizontal(Qet::Orientation a) {
 	return(a == Qet::East || a == Qet::West);
 }
 
 /**
-	Indique si une orientation de borne est verticale (Nord / Sud).
-	@param a L'orientation de borne
-	@return True si l'orientation de borne est verticale, false sinon
-*/
-bool Qet::estVerticale(Qet::Orientation a) {
+ * @brief Qet::isVertical
+ * @param a
+ * @return true if @a is vertical, else false.
+ */
+bool Qet::isVertical(Qet::Orientation a) {
 	return(a == Qet::North || a == Qet::South);
 }
 

Modified: trunk/sources/qet.h
===================================================================
--- trunk/sources/qet.h	2015-01-18 10:27:36 UTC (rev 3614)
+++ trunk/sources/qet.h	2015-01-18 11:28:56 UTC (rev 3615)
@@ -184,10 +184,10 @@
 	static Qet::Orientation orientationFromString (const QString &);
 	static QString          orientationToString   (Qet::Orientation);
 
-	static bool surLeMemeAxe   (Qet::Orientation, Qet::Orientation);
-	static bool isOpposed      (Qet::Orientation a, Qet::Orientation b);
-	static bool estHorizontale (Qet::Orientation);
-	static bool estVerticale   (Qet::Orientation);
+	static bool surLeMemeAxe (Qet::Orientation, Qet::Orientation);
+	static bool isOpposed    (Qet::Orientation a, Qet::Orientation b);
+	static bool isHorizontal (Qet::Orientation);
+	static bool isVertical   (Qet::Orientation);
 };
 
 #endif

Modified: trunk/sources/qetgraphicsitem/terminal.cpp
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.cpp	2015-01-18 10:27:36 UTC (rev 3614)
+++ trunk/sources/qetgraphicsitem/terminal.cpp	2015-01-18 11:28:56 UTC (rev 3615)
@@ -81,6 +81,7 @@
 	QGraphicsItem(e),
 	m_draw_help_line(false),
 	m_help_line     (nullptr),
+	m_help_line_a   (nullptr),
 	parent_element_ (e),
 	hovered_color_  (Terminal::neutralColor)
 {
@@ -99,6 +100,7 @@
 	QGraphicsItem(e),
 	m_draw_help_line (false),
 	m_help_line      (nullptr),
+	m_help_line_a    (nullptr),
 	parent_element_  (e),
 	hovered_color_   (Terminal::neutralColor)
 {
@@ -116,9 +118,12 @@
 	@param s   Scene sur laquelle figure cette borne
 */
 Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
-	QGraphicsItem(e),
-	parent_element_(e),
-	hovered_color_(Terminal::neutralColor)
+	QGraphicsItem    (e),
+	m_draw_help_line (false),
+	m_help_line      (nullptr),
+	m_help_line_a    (nullptr),
+	parent_element_  (e),
+	hovered_color_   (Terminal::neutralColor)
 {
 	init(pf, o, num, name, hiddenName);
 }
@@ -273,34 +278,64 @@
 		p -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0));
 	} else p -> drawPoint(c);
 
-
-		//Draw help line if needed, only if there isn't conductor
-		//docked to this terminal
-	if (m_draw_help_line && conductors().isEmpty())
+		//Draw help line if needed,
+	if (diagram() && m_draw_help_line)
 	{
-		if (!m_help_line)
-			m_help_line = new QGraphicsLineItem(this);
-		m_help_line -> setPen(QPen (Qt::darkBlue));
+			//Draw the help line with same orientation of terminal
+			//Only if there isn't docked conductor
+		if (conductors().isEmpty())
+		{
+			if (!m_help_line)
+				m_help_line = new QGraphicsLineItem(this);
+			QPen pen(Qt::darkBlue);
 
-		QLineF line(HelpLine());
+			QLineF line(HelpLine());
 
-		if (Diagram *dia = diagram())
-		{
-			if (dia -> project() -> autoConductor())
+			if (diagram() -> project() -> autoConductor())
 			{
 				Terminal *t = alignedWithTerminal();
 				if (t)
 				{
 					line.setP2(t -> dockConductor());
-					m_help_line -> setPen(QPen (Qt::darkGreen));
+					pen.setColor(Qt::darkGreen);
 				}
 			}
+
+				//Map the line (in scene coordinate) to m_help_line coordinate
+			line.setP1(m_help_line -> mapFromScene(line.p1()));
+			line.setP2(m_help_line -> mapFromScene(line.p2()));
+			m_help_line -> setPen(pen);
+			m_help_line -> setLine(line);
 		}
 
-			//Map the line (in scene coordinate) to help_line coordinate
-		line.setP1(m_help_line -> mapFromScene(line.p1()));
-		line.setP2(m_help_line -> mapFromScene(line.p2()));
-		m_help_line -> setLine(line);
+			//Draw the help line perpendicular to the terminal
+		if (!m_help_line_a)
+		{
+			m_help_line_a = new QGraphicsLineItem(this);
+			QPen pen;
+			pen.setColor(Qt::darkGray);
+			pen.setStyle(Qt::DotLine);
+			m_help_line_a -> setPen(pen);
+		}
+
+		QRectF rect = diagram() -> drawingRect();
+		QLineF line;
+
+		if (Qet::isHorizontal(orientation()))
+		{
+			line.setP1(QPointF(dockConductor().x(), rect.topLeft().y()));
+			line.setP2(QPointF(dockConductor().x(), rect.bottomLeft().y()));
+		}
+		else
+		{
+			line.setP1(QPointF(rect.topLeft().x(), dockConductor().y()));
+			line.setP2(QPointF(rect.topRight().x(), dockConductor().y()));
+		}
+
+			//Map the line (in scene coordinate) to m_help_line_a coordinate
+		line.setP1(m_help_line_a -> mapFromScene(line.p1()));
+		line.setP2(m_help_line_a -> mapFromScene(line.p2()));
+		m_help_line_a -> setLine(line);
 	}
 	
 	p -> restore();
@@ -317,13 +352,19 @@
 
 	m_draw_help_line = draw;
 
-	if (!draw && m_help_line)
+	if (!draw)
 	{
-		delete m_help_line;
-		m_help_line = nullptr;
+		if (m_help_line)
+		{
+			delete m_help_line;
+			m_help_line = nullptr;
+		}
+		if (m_help_line_a)
+		{
+			delete m_help_line_a;
+			m_help_line_a = nullptr;
+		}
 	}
-
-	//update();
 }
 
 /**

Modified: trunk/sources/qetgraphicsitem/terminal.h
===================================================================
--- trunk/sources/qetgraphicsitem/terminal.h	2015-01-18 10:27:36 UTC (rev 3614)
+++ trunk/sources/qetgraphicsitem/terminal.h	2015-01-18 11:28:56 UTC (rev 3615)
@@ -102,6 +102,7 @@
 	private:
 		bool               m_draw_help_line;
 		QGraphicsLineItem *m_help_line;
+		QGraphicsLineItem *m_help_line_a;
 
 	/// Parent electrical element
 	Element *parent_element_;


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