mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-01-08 14:49:58 +01:00
QetShapeItem : shapes can be filled with some patterns and colors
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4315 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -63,6 +63,19 @@ void QetShapeItem::setPen(const QPen &pen)
|
||||
emit penChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetShapeItem::setBrush
|
||||
* Set the brush to use for the fill the shape
|
||||
* @param brush
|
||||
*/
|
||||
void QetShapeItem::setBrush(const QBrush &brush)
|
||||
{
|
||||
if (m_brush == brush) return;
|
||||
m_brush = brush;
|
||||
update();
|
||||
emit brushChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetShapeItem::setP2
|
||||
* Set the second point of this item.
|
||||
@@ -132,6 +145,21 @@ bool QetShapeItem::setPolygon(const QPolygonF &polygon)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetShapeItem::setClosed
|
||||
* Close this item, have effect only if this item is a polygon.
|
||||
* @param close
|
||||
*/
|
||||
void QetShapeItem::setClosed(bool close)
|
||||
{
|
||||
if (m_shapeType == Polygon && close != m_close)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
m_close = close;
|
||||
emit closeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief QetShapeItem::pointCount
|
||||
* @return the number of point in the polygon
|
||||
@@ -196,7 +224,8 @@ QPainterPath QetShapeItem::shape() const
|
||||
path.lineTo(m_P2); break;
|
||||
case Rectangle: path.addRect(QRectF(m_P1, m_P2)); break;
|
||||
case Ellipse: path.addEllipse(QRectF(m_P1, m_P2)); break;
|
||||
case Polygon: path.addPolygon(m_polygon); break;
|
||||
case Polygon: path.addPolygon(m_polygon);
|
||||
if (m_close) path.closeSubpath(); break;
|
||||
default: Q_ASSERT(false); break;
|
||||
}
|
||||
|
||||
@@ -239,6 +268,7 @@ void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||
painter->setPen(m_pen);
|
||||
painter->setBrush(m_brush);
|
||||
|
||||
//Draw hovered shadow
|
||||
if (m_hovered)
|
||||
@@ -274,7 +304,7 @@ void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
break;
|
||||
|
||||
case Polygon:
|
||||
painter->drawPolyline(m_polygon);
|
||||
m_close ? painter->drawPolygon(m_polygon) : painter->drawPolyline(m_polygon);
|
||||
if (isSelected())
|
||||
m_handler.drawHandler(painter, m_polygon);
|
||||
break;
|
||||
@@ -457,7 +487,9 @@ bool QetShapeItem::fromXml(const QDomElement &e)
|
||||
if (e.tagName() != "shape") return (false);
|
||||
|
||||
is_movable_ = (e.attribute("is_movable").toInt());
|
||||
m_close = e.attribute("closed", "0").toInt();
|
||||
m_pen = QETXML::penFromXml(e.firstChildElement("pen"));
|
||||
m_brush = QETXML::brushFromXml(e.firstChildElement("brush"));
|
||||
|
||||
QString type = e.attribute("type");
|
||||
//@TODO Compatibility for version older than N°4075, shape type was stored with an int
|
||||
@@ -506,7 +538,10 @@ QDomElement QetShapeItem::toXml(QDomDocument &document) const
|
||||
QMetaEnum me = metaObject()->enumerator(metaObject()->indexOfEnumerator("ShapeType"));
|
||||
result.setAttribute("type", me.valueToKey(m_shapeType));
|
||||
result.appendChild(QETXML::penToXml(document, m_pen));
|
||||
result.appendChild(QETXML::brushToXml(document, m_brush));
|
||||
result.setAttribute("is_movable", bool(is_movable_));
|
||||
result.setAttribute("closed", bool(m_close));
|
||||
|
||||
if (m_shapeType != Polygon)
|
||||
{
|
||||
result.setAttribute("x1", QString::number(mapToScene(m_P1).x()));
|
||||
|
||||
@@ -35,12 +35,16 @@ class QetShapeItem : public QetGraphicsItem
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
|
||||
Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
|
||||
Q_PROPERTY(QRectF rect READ rect WRITE setRect)
|
||||
Q_PROPERTY(QLineF line READ line WRITE setLine)
|
||||
Q_PROPERTY(QPolygonF polygon READ polygon WRITE setPolygon)
|
||||
Q_PROPERTY(bool close READ isClosed WRITE setClosed NOTIFY closeChanged)
|
||||
|
||||
signals:
|
||||
void penChanged();
|
||||
void brushChanged();
|
||||
void closeChanged();
|
||||
|
||||
public:
|
||||
Q_ENUMS(ShapeType)
|
||||
@@ -60,6 +64,8 @@ class QetShapeItem : public QetGraphicsItem
|
||||
///METHODS
|
||||
QPen pen() const {return m_pen;}
|
||||
void setPen(const QPen &pen);
|
||||
QBrush brush() const {return m_brush;}
|
||||
void setBrush(const QBrush &brush);
|
||||
ShapeType shapeType() const {return m_shapeType;}
|
||||
|
||||
virtual bool fromXml (const QDomElement &);
|
||||
@@ -76,6 +82,8 @@ class QetShapeItem : public QetGraphicsItem
|
||||
bool setRect (const QRectF &rect);
|
||||
QPolygonF polygon() const {return m_polygon;}
|
||||
bool setPolygon (const QPolygonF &polygon);
|
||||
bool isClosed() const {return m_close;}
|
||||
void setClosed (bool close);
|
||||
|
||||
//Methods available for polygon shape
|
||||
int pointsCount () const;
|
||||
@@ -98,11 +106,13 @@ class QetShapeItem : public QetGraphicsItem
|
||||
private:
|
||||
ShapeType m_shapeType;
|
||||
QPen m_pen;
|
||||
QBrush m_brush;
|
||||
QPointF m_P1, m_P2, m_old_P1, m_old_P2;
|
||||
QPolygonF m_polygon, m_old_polygon;
|
||||
bool m_hovered,
|
||||
m_mouse_grab_handler;
|
||||
int m_vector_index;
|
||||
QetGraphicsHandlerUtility m_handler;
|
||||
bool m_close = false;
|
||||
};
|
||||
#endif // QETSHAPEITEM_H
|
||||
|
||||
Reference in New Issue
Block a user