35 second_end(
Qet::None),
37 m_undo_command(nullptr)
56 uint length_count_required = 0;
59 length_count_required = 2;
61 length_count_required = 1;
63 return(length_count_required);
73 void PartLine::paint(QPainter *painter,
const QStyleOptionGraphicsItem *options, QWidget *widget)
80 QPen t = painter -> pen();
81 t.setJoinStyle(Qt::MiterJoin);
82 t.setCosmetic(options && options -> levelOfDetail < 1.0);
84 if (isSelected()) t.setColor(Qt::red);
89 painter -> drawPath(
path());
91 painter -> drawLine(
m_line);
110 QDomElement xml_element = xml_document.createElement(
"line");
111 xml_element.setAttribute(
"x1", QString(
"%1").arg(p1.x()));
112 xml_element.setAttribute(
"y1", QString(
"%1").arg(p1.y()));
113 xml_element.setAttribute(
"x2", QString(
"%1").arg(p2.x()));
114 xml_element.setAttribute(
"y2", QString(
"%1").arg(p2.y()));
116 xml_element.setAttribute(
"length1", QString(
"%1").arg(
first_length));
118 xml_element.setAttribute(
"length2", QString(
"%1").arg(
second_length));
131 m_line = QLineF(mapFromScene(qde.attribute(
"x1",
"0").toDouble(),
132 qde.attribute(
"y1",
"0").toDouble()),
133 mapFromScene(qde.attribute(
"x2",
"0").toDouble(),
134 qde.attribute(
"y2",
"0").toDouble()));
137 first_length = qde.attribute(
"length1",
"1.5").toDouble();
150 if (change == ItemSelectedHasChanged && scene())
152 if (value.toBool() ==
true)
158 if (scene()->selectedItems().size() == 1)
167 else if (change == ItemPositionHasChanged)
171 else if (change == ItemSceneChange)
179 return QGraphicsItem::itemChange(change, value);
200 if(event->type() == QEvent::GraphicsSceneMousePress)
205 else if(event->type() == QEvent::GraphicsSceneMouseMove)
210 else if (event->type() == QEvent::GraphicsSceneMouseRelease)
231 QVector<QPointF> points_vector;
236 points_vector = mapToScene(points_vector);
237 for (
int i = 0 ; i < points_vector.size() ; ++i)
267 QPointF new_pos =
event->scenePos();
268 if (event->modifiers() != Qt::ControlModifier)
270 new_pos = mapFromScene(new_pos);
272 prepareGeometryChange();
303 if (this->isSelected() && scene()->selectedItems().size() == 1)
317 QVector<QPointF> points_vector;
324 handler->setColor(Qt::blue);
325 scene()->addItem(handler);
326 handler->installSceneEventFilter(
this);
327 handler->setZValue(this->zValue()+1);
350 return(mapToScene(
m_line.p1()));
358 return(mapToScene(
m_line.p2()));
379 QPainterPathStroker pps;
400 QPainterPathStroker pps;
403 return (pps.createStroke(
shape));
413 const qreal marge = 2.0;
418 QList<QPointF> result;
423 result << QPointF(a.x() - marge, a.y() - marge);
424 result << QPointF(a.x() - marge, a.y() + marge);
425 result << QPointF(a.x() + marge, a.y() + marge);
426 result << QPointF(a.x() + marge, a.y() - marge);
431 QPointF v_ab = b - a;
434 qreal ab = sqrt(pow(v_ab.x(), 2) + pow(v_ab.y(), 2));
438 QPointF u = v_ab / ab * marge;
441 QPointF v(-u.y(), u.x());
449 result << h << i << j << k;
500 painter -> setPen(Qt::gray);
503 painter -> setPen(Qt::green);
507 painter -> setPen(Qt::red);
510 painter -> drawEllipse(pointy, 0.1, 0.1);
513 painter -> drawEllipse(pointy, 0.1, 0.1);
515 painter -> restore();
526 bound =
path().boundingRect();
535 bound = bound.normalized();
536 bound.adjust(-adjust, -adjust, adjust, adjust);
569 Q_UNUSED(initial_selection_rect)
583 prepareGeometryChange();
584 m_line = QLineF(mapFromScene(mapped_points.at(0)), mapFromScene(mapped_points.at(1)));
604 QPointF line_vector = end_point - other_point;
605 qreal line_length = sqrt(pow(line_vector.x(), 2) + pow(line_vector.y(), 2));
608 QPointF u(line_vector / line_length * length);
609 QPointF v(-u.y(), u.x());
612 QPointF o(end_point - u);
617 return(QList<QPointF>() << o << a << b << c);
627 prepareGeometryChange();
636 prepareGeometryChange();
644 prepareGeometryChange();
651 qreal length = qMin(qAbs(l),
m_line.length());
653 prepareGeometryChange();
660 qreal length = qMin(qAbs(l),
m_line.length());
662 prepareGeometryChange();
678 QPointF point1(
m_line.p1());
679 QPointF point2(
m_line.p2());
681 qreal line_length(
m_line.length());
691 bool draw_1st_end =
first_end && reduced_line_length >= 0;
708 start_point = four_points1[1];
712 path.addPolygon(QPolygonF() << four_points1[1] << four_points1[2] << point1 << four_points1[3] << four_points1[1]);
713 start_point = four_points1[1];
717 path.addPolygon(QPolygonF() << four_points1[3] << point1 << four_points1[2]);
718 start_point = point1;
723 path.addPolygon(QPolygonF() << four_points1[0] << four_points1[2] << point1 << four_points1[3] << four_points1[0]);
724 start_point = four_points1[0];
729 start_point = QLineF(start_point, point2).pointAt(pen_width / 2.0 / line_length);
733 start_point = point1;
738 bool draw_2nd_end =
second_end && reduced_line_length >= 0;
746 stop_point = four_points2[1];
750 path.addPolygon(QPolygonF() << four_points2[2] << point2 << four_points2[3] << four_points2[1] << four_points2[2]);
751 stop_point = four_points2[1];
755 path.addPolygon(QPolygonF() << four_points2[3] << point2 << four_points2[2]);
764 path.addPolygon(QPolygonF() << four_points2[0] << four_points2[2] << point2 << four_points2[3] << four_points2[0]);
765 stop_point = four_points2[0];
770 stop_point = QLineF(point1, stop_point).pointAt((line_length - (pen_width / 2.0)) / line_length);
777 path.moveTo(start_point);
778 path.lineTo(stop_point);
EndType
This enum lists the various available endings for line primitives when drawing an electrical element...
QRectF sceneGeometricRect() const override
PartLine::sceneGeometricRect.
The QPropertyUndoCommand class This undo command manage QProperty of a QObject. This undo command can...
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override
PartLine::sceneEventFilter.
virtual QPointF sceneP2() const
PartLine::sceneP2.
void setSecondEndLength(const qreal &l)
The QetGraphicsHandlerItem class This graphics item represents a point, destined to be used as an han...
void setFirstEndType(const Qet::EndType &et)
virtual QPointF sceneP1() const
PartLine::sceneP1.
void sceneSelectionChanged()
PartLine::sceneSelectionChanged When the scene selection change, if there are several primitive selec...
QRectF firstEndCircleRect() const
PartLine::firstEndCircleRect.
void startUserTransformation(const QRectF &) override
PartLine::startUserTransformation Start the user-induced transformation, provided this primitive is c...
void enableAnimation(bool animate=true)
QPropertyUndoCommand::enableAnimation True to enable animation.
void setSecondEndType(const Qet::EndType &et)
void handlerMouseReleaseEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMouseReleaseEvent.
void handleUserTransformation(const QRectF &, const QRectF &) override
PartLine::handleUserTransformation Handle the user-induced transformation from initial_selection_rect...
QList< QPointF > mapPoints(const QRectF &, const QRectF &, const QList< QPointF > &)
The CustomElementGraphicPart class This class is the base for all home-made primitive like line...
void firstEndLengthChanged()
static QString endTypeToString(const Qet::EndType &)
QList< QPointF > saved_points_
void setLine(const QLineF &line)
void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *=nullptr) override
PartLine::paint Draw this line.
void secondEndTypeChanged()
void stylesToXml(QDomElement &) const
CustomElementGraphicPart::stylesToXml Write the curent style to xml element. The style are stored lik...
static uint requiredLengthForEndType(const Qet::EndType &)
PartLine::requiredLengthForEndType.
bool isUseless() const override
PartLine::isUseless.
QPainterPath path() const
PartLine::path.
void fromXml(const QDomElement &) override
PartLine::fromXml Import the properties of this line from a xml element.
QList< QPointF > fourShapePoints() const
PartLine::fourShapePoints.
void firstEndTypeChanged()
static Qet::EndType endTypeFromString(const QString &)
QRectF boundingRect() const override
PartLine::boundingRect.
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
PartLine::itemChange.
void handlerMousePressEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMousePressEvent.
void debugPaint(QPainter *)
PartLine::debugPaint Display several composante of the drawing -the bounding rect -special points at ...
void handlerMouseMoveEvent(QetGraphicsHandlerItem *qghi, QGraphicsSceneMouseEvent *event)
PartLine::handlerMouseMoveEvent.
QVector< QetGraphicsHandlerItem * > m_handler_vector
void secondEndLengthChanged()
void stylesFromXml(const QDomElement &)
CustomElementGraphicPart::stylesFromXml Read the style used by this, from a xml element.
const QDomElement toXml(QDomDocument &) const override
PartLine::toXml Export this line in xml.
static QList< QPointF > fourEndPoints(const QPointF &, const QPointF &, const qreal &)
PartLine::fourEndPoints Return the four interesting point needed to draw the shape at extremity of li...
void adjusteHandlerPos()
PartLine::adjusteHandlerPos Adjust the position of the handler item.
void removeHandler()
PartLine::removeHandler Remove the handlers of this item.
virtual ElementScene * elementScene() const
void addHandler()
PartLine::addHandler Add handlers for this item.
~PartLine() override
Destructeur.
static QVector< QetGraphicsHandlerItem * > handlerForPoint(const QVector< QPointF > &points, int size=10)
QetGraphicsHandlerItem::handlerForPoint.
qreal penWeight() const
CustomElementGraphicPart::penWeight.
QRectF secondEndCircleRect() const
PartLine::secondEndCircleRect.
void applyStylesToQPainter(QPainter &) const
CustomElementGraphicPart::applyStylesToQPainter Apply the current style to the QPainter.
QPointF snapToGrid(QPointF point)
PartLine(QETElementEditor *, QGraphicsItem *=nullptr)
PartLine::PartLine Constructor.
QPropertyUndoCommand * m_undo_command
void setNewValue(const QVariant &new_value)
QPropertyUndoCommand::setNewValue Set the new value of the property (set with redo) to ...
void drawShadowShape(QPainter *painter)
CustomElementGraphicPart::drawShadowShape Draw a transparent blue shadow arround the shape of this it...
QPainterPath shape() const override
PartLine::shape.
QPainterPath shadowShape() const override
void setFirstEndLength(const qreal &l)