mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
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:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -184,10 +184,10 @@ class Qet : public QObject {
|
|||||||
static Qet::Orientation orientationFromString (const QString &);
|
static Qet::Orientation orientationFromString (const QString &);
|
||||||
static QString orientationToString (Qet::Orientation);
|
static QString orientationToString (Qet::Orientation);
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -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
|
@param s Scene sur laquelle figure cette borne
|
||||||
*/
|
*/
|
||||||
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),
|
||||||
parent_element_(e),
|
m_draw_help_line (false),
|
||||||
hovered_color_(Terminal::neutralColor)
|
m_help_line (nullptr),
|
||||||
|
m_help_line_a (nullptr),
|
||||||
|
parent_element_ (e),
|
||||||
|
hovered_color_ (Terminal::neutralColor)
|
||||||
{
|
{
|
||||||
init(pf, o, num, name, hiddenName);
|
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));
|
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())
|
|
||||||
{
|
{
|
||||||
if (!m_help_line)
|
//Draw the help line with same orientation of terminal
|
||||||
m_help_line = new QGraphicsLineItem(this);
|
//Only if there isn't docked conductor
|
||||||
m_help_line -> setPen(QPen (Qt::darkBlue));
|
if (conductors().isEmpty())
|
||||||
|
|
||||||
QLineF line(HelpLine());
|
|
||||||
|
|
||||||
if (Diagram *dia = diagram())
|
|
||||||
{
|
{
|
||||||
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();
|
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 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
|
//Draw the help line perpendicular to the terminal
|
||||||
line.setP1(m_help_line -> mapFromScene(line.p1()));
|
if (!m_help_line_a)
|
||||||
line.setP2(m_help_line -> mapFromScene(line.p2()));
|
{
|
||||||
m_help_line -> setLine(line);
|
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)
|
||||||
{
|
{
|
||||||
delete m_help_line;
|
if (m_help_line)
|
||||||
m_help_line = nullptr;
|
{
|
||||||
|
delete m_help_line;
|
||||||
|
m_help_line = nullptr;
|
||||||
|
}
|
||||||
|
if (m_help_line_a)
|
||||||
|
{
|
||||||
|
delete m_help_line_a;
|
||||||
|
m_help_line_a = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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_;
|
||||||
|
|||||||
Reference in New Issue
Block a user