From 21a62066a2a8ad84b1beb2bc971d4c66eeef166e Mon Sep 17 00:00:00 2001 From: blacksun Date: Sun, 18 Jan 2015 11:28:56 +0000 Subject: [PATCH] Element : add new help line (perpendicular to terminal) git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3615 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/qet.cpp | 20 +++--- sources/qet.h | 8 +-- sources/qetgraphicsitem/terminal.cpp | 91 ++++++++++++++++++++-------- sources/qetgraphicsitem/terminal.h | 1 + 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/sources/qet.cpp b/sources/qet.cpp index 661b3e7d3..7482be56c 100644 --- a/sources/qet.cpp +++ b/sources/qet.cpp @@ -94,20 +94,20 @@ bool Qet::isOpposed(Qet::Orientation a, Qet::Orientation b) } /** - 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); } diff --git a/sources/qet.h b/sources/qet.h index bee7c31fb..bb9352edd 100644 --- a/sources/qet.h +++ b/sources/qet.h @@ -184,10 +184,10 @@ class Qet : public QObject { 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 diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index e68de0420..d2e63d5af 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -81,6 +81,7 @@ Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) : 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 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) : 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 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) : @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 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg 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)); - - QLineF line(HelpLine()); - - if (Diagram *dia = diagram()) + //Draw the help line with same orientation of terminal + //Only if there isn't docked conductor + if (conductors().isEmpty()) { - if (dia -> project() -> autoConductor()) + if (!m_help_line) + m_help_line = new QGraphicsLineItem(this); + QPen pen(Qt::darkBlue); + + QLineF line(HelpLine()); + + 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 @@ void Terminal::drawHelpLine(bool draw) 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(); } /** diff --git a/sources/qetgraphicsitem/terminal.h b/sources/qetgraphicsitem/terminal.h index 279dd0369..3fdf76af0 100644 --- a/sources/qetgraphicsitem/terminal.h +++ b/sources/qetgraphicsitem/terminal.h @@ -102,6 +102,7 @@ class Terminal : public QGraphicsItem { private: bool m_draw_help_line; QGraphicsLineItem *m_help_line; + QGraphicsLineItem *m_help_line_a; /// Parent electrical element Element *parent_element_;