diff --git a/sources/editor/graphicspart/customelementgraphicpart.cpp b/sources/editor/graphicspart/customelementgraphicpart.cpp index d87fcc1b4..6e684b640 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.cpp +++ b/sources/editor/graphicspart/customelementgraphicpart.cpp @@ -393,7 +393,7 @@ void CustomElementGraphicPart::drawShadowShape(QPainter *painter) color.setAlpha(50); painter -> setBrush (QBrush (color)); painter -> setPen (Qt::NoPen); - painter -> drawPath (strock.createStroke(shape())); + painter -> drawPath (strock.createStroke(shadowShape())); painter -> restore (); } diff --git a/sources/editor/graphicspart/customelementgraphicpart.h b/sources/editor/graphicspart/customelementgraphicpart.h index 0eb4aab70..33659fe2e 100644 --- a/sources/editor/graphicspart/customelementgraphicpart.h +++ b/sources/editor/graphicspart/customelementgraphicpart.h @@ -92,6 +92,8 @@ class CustomElementGraphicPart : public QGraphicsObject, public CustomElementPar virtual void setProperty (const char *name, const QVariant &value) {QObject::setProperty(name, value);} virtual QVariant property (const char *name) const {return QObject::property(name);} + virtual QPainterPath shadowShape ()const = 0; + protected: void stylesToXml (QDomElement &) const; void stylesFromXml(const QDomElement &); diff --git a/sources/editor/graphicspart/partarc.cpp b/sources/editor/graphicspart/partarc.cpp index f916cfd82..1f536f900 100644 --- a/sources/editor/graphicspart/partarc.cpp +++ b/sources/editor/graphicspart/partarc.cpp @@ -122,6 +122,16 @@ void PartArc::fromXml(const QDomElement &qde) { m_span_angle = qde.attribute("angle", "-1440").toInt() * 16; } +QRectF PartArc::boundingRect() const +{ + QRectF r = AbstractPartEllipse::boundingRect(); + + foreach(QRectF rect, m_handler.handlerRect(m_handler.pointsForRect(m_rect))) + r |= rect; + + return r; +} + /** * @brief PartArc::shape * @return the shape of this item @@ -143,6 +153,18 @@ QPainterPath PartArc::shape() const return shape; } +QPainterPath PartArc::shadowShape() const +{ + QPainterPath shape; + shape.arcMoveTo(m_rect, m_start_angle/16); + shape.arcTo(m_rect, m_start_angle/16, m_span_angle/16); + + QPainterPathStroker pps; + pps.setWidth(penWeight()); + + return (pps.createStroke(shape)); +} + /** * @brief PartArc::mousePressEvent * Handle mouse press event diff --git a/sources/editor/graphicspart/partarc.h b/sources/editor/graphicspart/partarc.h index e6df024ad..563314a37 100644 --- a/sources/editor/graphicspart/partarc.h +++ b/sources/editor/graphicspart/partarc.h @@ -55,7 +55,9 @@ class PartArc : public AbstractPartEllipse virtual const QDomElement toXml (QDomDocument &) const; virtual void fromXml (const QDomElement &); + virtual QRectF boundingRect() const; virtual QPainterPath shape() const; + virtual QPainterPath shadowShape() const; protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/sources/editor/graphicspart/partellipse.cpp b/sources/editor/graphicspart/partellipse.cpp index 4c58e8573..732b952a7 100644 --- a/sources/editor/graphicspart/partellipse.cpp +++ b/sources/editor/graphicspart/partellipse.cpp @@ -125,6 +125,16 @@ void PartEllipse::fromXml(const QDomElement &qde) QSizeF(width, height)); } +QRectF PartEllipse::boundingRect() const +{ + QRectF r = AbstractPartEllipse::boundingRect(); + + foreach(QRectF rect, m_handler.handlerRect(m_handler.pointsForRect(m_rect))) + r |= rect; + + return r; +} + /** * @brief PartEllipse::shape * @return the shape of this item @@ -145,6 +155,17 @@ QPainterPath PartEllipse::shape() const return shape; } +QPainterPath PartEllipse::shadowShape() const +{ + QPainterPath shape; + shape.addEllipse(m_rect); + + QPainterPathStroker pps; + pps.setWidth(penWeight()); + + return (pps.createStroke(shape)); +} + /** * @brief PartEllipse::mousePressEvent * Handle mouse press event diff --git a/sources/editor/graphicspart/partellipse.h b/sources/editor/graphicspart/partellipse.h index 15147fbf0..034f941e4 100644 --- a/sources/editor/graphicspart/partellipse.h +++ b/sources/editor/graphicspart/partellipse.h @@ -56,7 +56,9 @@ class PartEllipse : public AbstractPartEllipse virtual const QDomElement toXml (QDomDocument &) const; virtual void fromXml (const QDomElement &); + virtual QRectF boundingRect() const; virtual QPainterPath shape() const; + virtual QPainterPath shadowShape() const; protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/sources/editor/graphicspart/partline.cpp b/sources/editor/graphicspart/partline.cpp index ebd9cdd79..416fb8170 100644 --- a/sources/editor/graphicspart/partline.cpp +++ b/sources/editor/graphicspart/partline.cpp @@ -272,6 +272,31 @@ QPainterPath PartLine::shape() const shape.lineTo(m_line.p2()); } + QPainterPathStroker pps; + pps.setWidth(penWeight()); + shape = pps.createStroke(shape); + + if (isSelected()) + foreach(QRectF rect, m_handler.handlerRect(m_handler.pointsForLine(m_line))) + shape.addRect(rect); + + return shape; +} + +QPainterPath PartLine::shadowShape() const +{ + QPainterPath shape; + + //We calcul path only if there is an end type + //Else we just draw a line + if (first_end || second_end) + shape.addPath(path()); + else + { + shape.moveTo(m_line.p1()); + shape.lineTo(m_line.p2()); + } + QPainterPathStroker pps; pps.setWidth(penWeight()); @@ -409,6 +434,10 @@ QRectF PartLine::boundingRect() const bound = bound.normalized(); bound.adjust(-adjust, -adjust, adjust, adjust); + + foreach(QRectF rect, m_handler.handlerRect(m_handler.pointsForLine(m_line))) + bound |= rect; + return bound; } diff --git a/sources/editor/graphicspart/partline.h b/sources/editor/graphicspart/partline.h index 4413f73df..3fa4842f7 100644 --- a/sources/editor/graphicspart/partline.h +++ b/sources/editor/graphicspart/partline.h @@ -74,6 +74,7 @@ class PartLine : public CustomElementGraphicPart virtual QPointF sceneP1() const; virtual QPointF sceneP2() const; virtual QPainterPath shape() const; + virtual QPainterPath shadowShape() const; virtual QRectF boundingRect() const; virtual bool isUseless() const; virtual QRectF sceneGeometricRect() const; diff --git a/sources/editor/graphicspart/partpolygon.cpp b/sources/editor/graphicspart/partpolygon.cpp index d539e56c4..1450c82d6 100644 --- a/sources/editor/graphicspart/partpolygon.cpp +++ b/sources/editor/graphicspart/partpolygon.cpp @@ -306,6 +306,25 @@ QPainterPath PartPolygon::shape() const QPainterPath shape; shape.addPolygon(m_polygon); + if (m_closed) + shape.lineTo(m_polygon.first()); + + QPainterPathStroker pps; + pps.setWidth(penWeight()); + shape = pps.createStroke(shape); + + if (isSelected()) + foreach(QRectF rect, m_handler.handlerRect(m_polygon)) + shape.addRect(rect); + + return shape; +} + +QPainterPath PartPolygon::shadowShape() const +{ + QPainterPath shape; + shape.addPolygon(m_polygon); + if (m_closed) shape.lineTo(m_polygon.first()); @@ -329,5 +348,9 @@ QRectF PartPolygon::boundingRect() const if (penWeight() == 0) adjust += 0.5; r.adjust(-adjust, -adjust, adjust, adjust); + + foreach(QRectF rect, m_handler.handlerRect(m_polygon)) + r |=rect; + return(r); } diff --git a/sources/editor/graphicspart/partpolygon.h b/sources/editor/graphicspart/partpolygon.h index c7f73b26a..902ad4e48 100644 --- a/sources/editor/graphicspart/partpolygon.h +++ b/sources/editor/graphicspart/partpolygon.h @@ -61,6 +61,7 @@ class PartPolygon : public CustomElementGraphicPart const QDomElement toXml(QDomDocument &) const; virtual QPainterPath shape () const; + virtual QPainterPath shadowShape() const; virtual QRectF boundingRect() const; virtual bool isUseless() const; virtual QRectF sceneGeometricRect() const; diff --git a/sources/editor/graphicspart/partrectangle.cpp b/sources/editor/graphicspart/partrectangle.cpp index fee6a7b83..9ac978161 100644 --- a/sources/editor/graphicspart/partrectangle.cpp +++ b/sources/editor/graphicspart/partrectangle.cpp @@ -200,6 +200,22 @@ QPainterPath PartRectangle::shape() const QPainterPath shape; shape.addRect(m_rect); + QPainterPathStroker pps; + pps.setWidth(penWeight()); + shape = pps.createStroke(shape); + + if (isSelected()) + foreach(QRectF rect, m_handler.handlerRect(m_handler.pointsForRect(m_rect))) + shape.addRect(rect); + + return shape; +} + +QPainterPath PartRectangle::shadowShape() const +{ + QPainterPath shape; + shape.addRect(m_rect); + QPainterPathStroker pps; pps.setWidth(penWeight()); @@ -219,6 +235,10 @@ QRectF PartRectangle::boundingRect() const QRectF r = m_rect.normalized(); r.adjust(-adjust, -adjust, adjust, adjust); + + foreach(QRectF rect, m_handler.handlerRect(m_handler.pointsForRect(m_rect))) + r |= rect; + return(r); } diff --git a/sources/editor/graphicspart/partrectangle.h b/sources/editor/graphicspart/partrectangle.h index 9e0001e52..986a92c53 100644 --- a/sources/editor/graphicspart/partrectangle.h +++ b/sources/editor/graphicspart/partrectangle.h @@ -76,6 +76,7 @@ class PartRectangle : public CustomElementGraphicPart virtual QPointF sceneTopLeft() const; virtual QPainterPath shape () const; + virtual QPainterPath shadowShape() const; virtual QRectF boundingRect() const; virtual bool isUseless() const; diff --git a/sources/editor/graphicspart/partterminal.h b/sources/editor/graphicspart/partterminal.h index a18eb26fe..e1aaca8fb 100644 --- a/sources/editor/graphicspart/partterminal.h +++ b/sources/editor/graphicspart/partterminal.h @@ -57,6 +57,7 @@ class PartTerminal : public CustomElementGraphicPart virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); virtual QPainterPath shape() const; + virtual QPainterPath shadowShape() const {return shape();} virtual QRectF boundingRect() const; virtual bool isUseless() const; virtual QRectF sceneGeometricRect() const;