70 setAcceptHoverEvents(
true);
71 setAcceptedMouseButtons(Qt::LeftButton);
86 m_draw_help_line(false),
87 m_help_line (nullptr),
88 m_help_line_a (nullptr),
90 hovered_color_ (
Terminal::neutralColor)
92 init(pf, o,
"_",
"_",
false);
105 m_draw_help_line (false),
106 m_help_line (nullptr),
107 m_help_line_a (nullptr),
109 hovered_color_ (
Terminal::neutralColor)
111 init(QPointF(pf_x, pf_y), o,
"_",
"_",
false);
126 m_draw_help_line (false),
127 m_help_line (nullptr),
128 m_help_line_a (nullptr),
130 hovered_color_ (
Terminal::neutralColor)
132 init(pf, o, std::move(num), std::move(
name), hiddenName);
153 if (
Element *elt = qgraphicsitem_cast<Element *>(parentItem())) {
156 if (ori_cur == 0)
return(
ori_);
160 int angle = ori_cur +
ori_;
161 while (angle >= 4) angle -= 4;
193 if (!conductor)
return(
false);
195 Q_ASSERT_X(((conductor -> terminal1 ==
this) ^ (conductor -> terminal2 ==
this)),
"Terminal::addConductor",
"The conductor must be linked exactly once to this terminal");
202 if (cond -> terminal1 == other_terminal || cond -> terminal2 == other_terminal)
218 if (index == -1)
return;
229 void Terminal::paint(QPainter *p,
const QStyleOptionGraphicsItem *options, QWidget *) {
231 if (options && options -> levelOfDetail < 0.5)
return;
236 p -> setRenderHint(QPainter::Antialiasing,
false);
237 p -> setRenderHint(QPainter::TextAntialiasing,
false);
238 p -> setRenderHint(QPainter::SmoothPixmapTransform,
false);
247 if (options && options -> levelOfDetail < 1.0) {
261 p -> setRenderHint(QPainter::Antialiasing,
true);
262 p -> drawEllipse(QRectF(c.x() - 2.5, c.y() - 2.5, 5.0, 5.0));
263 }
else p -> drawPoint(c);
275 pen.setColor(Qt::darkBlue);
279 if (
diagram() -> project() -> autoConductor())
285 pen.setColor(Qt::darkGreen);
290 line.setP1(
m_help_line -> mapFromScene(line.p1()));
291 line.setP2(
m_help_line -> mapFromScene(line.p2()));
305 QRectF rect =
diagram() -> border_and_titleblock.insideBorderRect();
310 line.setP1(QPointF(
dockConductor().x(), rect.topLeft().y()));
311 line.setP2(QPointF(
dockConductor().x(), rect.bottomLeft().y()));
315 line.setP1(QPointF(rect.topLeft().x(),
dockConductor().y()));
316 line.setP2(QPointF(rect.topRight().x(),
dockConductor().y()));
363 QRectF rect =
diagram() -> border_and_titleblock.insideBorderRect();
365 QLineF line(scene_dock , QPointF());
372 line.setP2(QPointF(scene_dock.x(), rect.top()));
375 line.setP2(QPointF(rect.right() , scene_dock.y()));
378 line.setP2(QPointF(scene_dock.x(), rect.bottom()));
381 line.setP2(QPointF(rect.left(), scene_dock.y()));
392 if (
br_ -> isNull()) {
398 origin += QPointF(-3.0, -3.0);
399 qreal w = qAbs((
int)(dcx - dex)) + 7;
400 qreal h = qAbs((
int)(dcy - dey)) + 7;
401 *
br_ = QRectF(origin, QSizeF(w, h));
418 path.moveTo(line.p1());
419 path.lineTo(line.p2());
422 QList <QGraphicsItem *> qgi_list =
diagram() -> items(path);
426 qgi_list.removeAll(t);
428 if (qgi_list.isEmpty())
return nullptr;
431 QList <Terminal *> available_terminals;
432 foreach (QGraphicsItem *qgi, qgi_list)
434 if (
Terminal *tt = qgraphicsitem_cast <Terminal *> (qgi))
441 available_terminals << tt;
446 if (available_terminals.isEmpty())
return nullptr;
447 if (available_terminals.size() == 1)
return (available_terminals.first());
451 qreal current_lenght = line.length();
452 Terminal *nearest_terminal = available_terminals.takeFirst();
455 foreach (
Terminal *terminal, available_terminals)
458 if (line.length() < current_lenght)
460 current_lenght = line.length();
461 nearest_terminal = terminal;
465 return nearest_terminal;
497 d -> setConductorStop(e -> scenePos());
498 d -> setConductor(
true);
523 d -> setConductorStop(e -> scenePos());
526 QList<QGraphicsItem *> qgis = d -> items(e -> scenePos());
534 Q_ASSERT_X(!(qgis.isEmpty()),
"Terminal::mouseMoveEvent",
"La liste d'items ne devrait pas etre vide");
537 if (qgis.size() <= 1)
return;
540 QGraphicsItem *qgi = qgis.at(1);
543 if (!other_terminal)
return;
556 other_terminal -> update();
572 diagram() -> setConductor(
false);
575 QGraphicsItem *qgi =
diagram() -> itemAt(e -> scenePos(), QTransform());
580 if (!other_terminal)
return;
597 bool use_properties =
false;
598 if (!conductors_list.isEmpty())
600 use_properties =
true;
601 others_properties = (*conductors_list.begin())->properties();
602 foreach (
Conductor *conductor, conductors_list) {
603 if (conductor->
properties() != others_properties)
604 use_properties =
false;
609 QUndoCommand *undo =
new QUndoCommand();
611 undo->setText(aic->text());
615 Conductor *other = conductors_list.toList().first();
616 new_conductor->rSequenceNum() = other->
sequenceNum();
617 new_conductor->setProperties(others_properties);
626 diagram() -> undoStack().push(undo);
629 Conductor *other = conductors_list.toList().first();
630 new_conductor->setProperties(other->
properties());
648 if (other_terminal ==
this)
return(
false);
650 bool already_linked =
false;
652 if (c -> terminal1 == other_terminal || c -> terminal2 == other_terminal) {
653 already_linked =
true;
657 return(already_linked);
668 if (other_terminal ==
this ||
isLinkedTo(other_terminal))
687 QDomElement qdo = doc.createElement(
"terminal");
688 qdo.setAttribute(
"x", QString(
"%1").arg(
dock_elmt_.x()));
689 qdo.setAttribute(
"y", QString(
"%1").arg(
dock_elmt_.y()));
690 qdo.setAttribute(
"orientation",
ori_);
704 if (terminal.tagName() !=
"terminal")
return(
false);
707 if (!terminal.hasAttribute(
"x"))
return(
false);
708 if (!terminal.hasAttribute(
"y"))
return(
false);
709 if (!terminal.hasAttribute(
"orientation"))
return(
false);
713 terminal.attribute(
"x").toDouble(&conv_ok);
714 if (!conv_ok)
return(
false);
717 terminal.attribute(
"y").toDouble(&conv_ok);
718 if (!conv_ok)
return(
false);
721 terminal.attribute(
"id").toInt(&conv_ok);
722 if (!conv_ok)
return(
false);
725 int terminal_or = terminal.attribute(
"orientation").toInt(&conv_ok);
726 if (!conv_ok)
return(
false);
743 qFuzzyCompare(terminal.attribute(
"x").toDouble(),
dock_elmt_.x()) &&
744 qFuzzyCompare(terminal.attribute(
"y").toDouble(),
dock_elmt_.y()) &&
745 (terminal.attribute(
"orientation").toInt() ==
ori_)
753 return(qobject_cast<Diagram *>(scene()));
779 QList <Element *> elmt_list = terminal -> parentElement() -> linkedElements();
780 if (!elmt_list.isEmpty())
782 return (elmt_list.first()->terminals());
789 terminals.removeAll(const_cast<Terminal *>(terminal));
793 return QList<Terminal *>();
static QColor forbiddenColor
color for forbidden actions
QList< Conductor * > conductors() const
ConductorProperties properties
Conductor::properties.
static QColor allowedColor
color for legal actions
QPointF dock_elmt_
docking point for parent element
bool addConductor(Conductor *conductor)
Terminal::addConductor Add a conductor to this terminal.
bool isLinkedTo(Terminal *)
QColor hovered_color_
Color used for the hover effect.
int conductorsCount() const
Terminal(QPointF, Qet::Orientation, Element *=nullptr)
static bool isHorizontal(Qet::Orientation)
Qet::isHorizontal.
QSet< Conductor * > relatedPotentialConductors(const bool all_diagram=true, QList< Terminal *> *t_list=nullptr)
Conductor::relatedPotentialConductors Return all conductors at the same potential of this conductor...
void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override
Terminal::mouseReleaseEvent.
void mousePressEvent(QGraphicsSceneMouseEvent *) override
void hoverEnterEvent(QGraphicsSceneHoverEvent *) override
static const qreal terminalSize
Terminal * alignedWithTerminal() const
Terminal::alignedWithTerminal If this terminal is aligned with an other terminal and is orientation i...
void init(QPointF, Qet::Orientation, QString number, QString name, bool hiddenName)
QList< Terminal * > relatedPotentialTerminal(const Terminal *terminal, const bool all_diagram)
Conductor::relatedPotentialTerminal Return terminal at the same potential from the same parent elemen...
autonum::sequentialNumbers sequenceNum
The AddItemCommand class This command add an item in a diagram The item to add is template...
void conductorWasAdded(Conductor *conductor)
QDomElement toXml(QDomDocument &) const
QString number_terminal_
Number of Terminal.
static bool valideXml(QDomElement &)
Element * parentElement() const
bool hovered_
Whether the mouse pointer is hovering the terminal.
QRectF boundingRect() const override
void setNumber(QString number)
Terminal::setNumber.
QList< Terminal * > terminals() const
Element::terminals.
QLineF HelpLine() const
Terminal::HelpLine.
Terminal * previous_terminal_
Last terminal seen through an attached conductor.
static bool isOpposed(Qet::Orientation a, Qet::Orientation b)
Qet::isOpposed.
QPointF dockConductor() const
void numerate()
ConductorAutoNumerotation::numerate execute the automatic numerotation.
Qet::Orientation ori_
terminal orientation
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override
bool canBeLinkedTo(Terminal *)
Terminal::canBeLinkedTo.
bool name_terminal_hidden
QGraphicsLineItem * m_help_line_a
static QColor neutralColor
default color
QGraphicsLineItem * m_help_line
static QColor background_color
background color of diagram
QList< Conductor * > conductors_
List of conductors attached to the terminal.
void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override
void updateConductor()
Terminal::updateConductor Update the path of conductor docked to this terminal.
bool fromXml(QDomElement &)
void removeConductor(Conductor *conductor)
Terminal::removeConductor Remove a conductor from this terminal.
Element * parent_element_
Parent electrical element.
bool lineContainsPoint(const QLineF &, const QPointF &)
void conductorWasRemoved(Conductor *conductor)
QPointF dock_conductor_
docking point for conductors
QString name_terminal_
Name of Terminal.
Qet::Orientation orientation() const
static QColor warningColor
color for allowed but fuzzy or not recommended actions
void mouseMoveEvent(QGraphicsSceneMouseEvent *) override
void setName(QString name, bool hiddenName)
Terminal::setName.
void updatePath(const QRectF &=QRectF())
Diagram * diagram() const
void drawHelpLine(bool draw=true)
Terminal::drawHelpLine.
void hoverMoveEvent(QGraphicsSceneHoverEvent *) override
Orientation
Orientation (used for electrical elements and their terminals)