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
This commit is contained in:
blacksun
2015-01-18 11:28:56 +00:00
parent 6ac8a3f610
commit 21a62066a2
4 changed files with 81 additions and 39 deletions

View File

@@ -94,20 +94,20 @@ bool Qet::isOpposed(Qet::Orientation a, Qet::Orientation b)
} }
/** /**
Indique si une orientation de borne est horizontale (Est / Ouest). * @brief Qet::isHorizontal
@param a L'orientation de borne * @param a
@return True si l'orientation de borne est horizontale, false sinon * @return true if @a is horizontal, else false.
*/ */
bool Qet::estHorizontale(Qet::Orientation a) { bool Qet::isHorizontal(Qet::Orientation a) {
return(a == Qet::East || a == Qet::West); return(a == Qet::East || a == Qet::West);
} }
/** /**
Indique si une orientation de borne est verticale (Nord / Sud). * @brief Qet::isVertical
@param a L'orientation de borne * @param a
@return True si l'orientation de borne est verticale, false sinon * @return true if @a is vertical, else false.
*/ */
bool Qet::estVerticale(Qet::Orientation a) { bool Qet::isVertical(Qet::Orientation a) {
return(a == Qet::North || a == Qet::South); return(a == Qet::North || a == Qet::South);
} }

View File

@@ -186,8 +186,8 @@ class Qet : public QObject {
static bool surLeMemeAxe (Qet::Orientation, Qet::Orientation); static bool surLeMemeAxe (Qet::Orientation, Qet::Orientation);
static bool isOpposed (Qet::Orientation a, Qet::Orientation b); static bool isOpposed (Qet::Orientation a, Qet::Orientation b);
static bool estHorizontale (Qet::Orientation); static bool isHorizontal (Qet::Orientation);
static bool estVerticale (Qet::Orientation); static bool isVertical (Qet::Orientation);
}; };
#endif #endif

View File

@@ -81,6 +81,7 @@ Terminal::Terminal(QPointF pf, Qet::Orientation o, Element *e) :
QGraphicsItem(e), QGraphicsItem(e),
m_draw_help_line(false), m_draw_help_line(false),
m_help_line (nullptr), m_help_line (nullptr),
m_help_line_a (nullptr),
parent_element_ (e), parent_element_ (e),
hovered_color_ (Terminal::neutralColor) hovered_color_ (Terminal::neutralColor)
{ {
@@ -99,6 +100,7 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
QGraphicsItem(e), QGraphicsItem(e),
m_draw_help_line (false), m_draw_help_line (false),
m_help_line (nullptr), m_help_line (nullptr),
m_help_line_a (nullptr),
parent_element_ (e), parent_element_ (e),
hovered_color_ (Terminal::neutralColor) hovered_color_ (Terminal::neutralColor)
{ {
@@ -117,6 +119,9 @@ Terminal::Terminal(qreal pf_x, qreal pf_y, Qet::Orientation o, Element *e) :
*/ */
Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) : Terminal::Terminal(QPointF pf, Qet::Orientation o, QString num, QString name, bool hiddenName, Element *e) :
QGraphicsItem (e), QGraphicsItem (e),
m_draw_help_line (false),
m_help_line (nullptr),
m_help_line_a (nullptr),
parent_element_ (e), parent_element_ (e),
hovered_color_ (Terminal::neutralColor) hovered_color_ (Terminal::neutralColor)
{ {
@@ -273,36 +278,66 @@ void Terminal::paint(QPainter *p, const QStyleOptionGraphicsItem *options, QWidg
p -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0)); p -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0));
} else p -> drawPoint(c); } else p -> drawPoint(c);
//Draw help line if needed,
//Draw help line if needed, only if there isn't conductor if (diagram() && m_draw_help_line)
//docked to this terminal {
if (m_draw_help_line && conductors().isEmpty()) //Draw the help line with same orientation of terminal
//Only if there isn't docked conductor
if (conductors().isEmpty())
{ {
if (!m_help_line) if (!m_help_line)
m_help_line = new QGraphicsLineItem(this); m_help_line = new QGraphicsLineItem(this);
m_help_line -> setPen(QPen (Qt::darkBlue)); QPen pen(Qt::darkBlue);
QLineF line(HelpLine()); QLineF line(HelpLine());
if (Diagram *dia = diagram()) if (diagram() -> project() -> autoConductor())
{
if (dia -> project() -> autoConductor())
{ {
Terminal *t = alignedWithTerminal(); Terminal *t = alignedWithTerminal();
if (t) if (t)
{ {
line.setP2(t -> dockConductor()); line.setP2(t -> dockConductor());
m_help_line -> setPen(QPen (Qt::darkGreen)); pen.setColor(Qt::darkGreen);
}
} }
} }
//Map the line (in scene coordinate) to help_line coordinate //Map the line (in scene coordinate) to m_help_line coordinate
line.setP1(m_help_line -> mapFromScene(line.p1())); line.setP1(m_help_line -> mapFromScene(line.p1()));
line.setP2(m_help_line -> mapFromScene(line.p2())); line.setP2(m_help_line -> mapFromScene(line.p2()));
m_help_line -> setPen(pen);
m_help_line -> setLine(line); 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(); p -> restore();
} }
@@ -317,13 +352,19 @@ void Terminal::drawHelpLine(bool draw)
m_draw_help_line = draw; m_draw_help_line = draw;
if (!draw && m_help_line) if (!draw)
{
if (m_help_line)
{ {
delete m_help_line; delete m_help_line;
m_help_line = nullptr; m_help_line = nullptr;
} }
if (m_help_line_a)
//update(); {
delete m_help_line_a;
m_help_line_a = nullptr;
}
}
} }
/** /**

View File

@@ -102,6 +102,7 @@ class Terminal : public QGraphicsItem {
private: private:
bool m_draw_help_line; bool m_draw_help_line;
QGraphicsLineItem *m_help_line; QGraphicsLineItem *m_help_line;
QGraphicsLineItem *m_help_line_a;
/// Parent electrical element /// Parent electrical element
Element *parent_element_; Element *parent_element_;