Element editor : minor improvement

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4061 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun 2015-07-21 12:29:43 +00:00
parent 012ba2ccd7
commit 50c61b4e03
13 changed files with 126 additions and 1 deletions

View File

@ -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 ();
}

View File

@ -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 &);

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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;
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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;