2014-02-23 18:55:26 +00:00
|
|
|
#include "qetshapeitem.h"
|
|
|
|
|
|
|
|
QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) :
|
|
|
|
QetGraphicsItem(parent),
|
|
|
|
_shapeStyle(Qt::DashLine),
|
2014-02-27 09:55:54 +00:00
|
|
|
_lineAngle(lineAngle),
|
|
|
|
_isFullyBuilt(false)
|
2014-02-23 18:55:26 +00:00
|
|
|
{
|
|
|
|
_shapeType = type;
|
|
|
|
_boundingRect = QRectF(p1, p2);
|
|
|
|
}
|
|
|
|
|
|
|
|
QetShapeItem::~QetShapeItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void QetShapeItem::setStyle(Qt::PenStyle newStyle)
|
|
|
|
{
|
|
|
|
_shapeStyle = newStyle;
|
|
|
|
}
|
|
|
|
|
2014-02-27 09:55:54 +00:00
|
|
|
void QetShapeItem::setFullyBuilt(bool isBuilt)
|
|
|
|
{
|
|
|
|
_isFullyBuilt = isBuilt;
|
|
|
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
|
|
|
|
}
|
|
|
|
|
2014-02-23 18:55:26 +00:00
|
|
|
QRectF QetShapeItem::boundingRect() const
|
|
|
|
{
|
|
|
|
return _boundingRect;
|
|
|
|
}
|
|
|
|
|
2014-02-27 09:55:54 +00:00
|
|
|
QPainterPath QetShapeItem::shape() const
|
|
|
|
{
|
|
|
|
QPainterPath path;
|
|
|
|
QPainterPathStroker pps;
|
|
|
|
QRectF rect = boundingRect();
|
|
|
|
|
|
|
|
switch (_shapeType) {
|
|
|
|
case Line:
|
|
|
|
if (_lineAngle) {
|
|
|
|
path.moveTo(rect.topRight());
|
|
|
|
path.lineTo(rect.bottomLeft());
|
|
|
|
} else {
|
|
|
|
path.moveTo(rect.topLeft());
|
|
|
|
path.lineTo(rect.bottomRight());
|
|
|
|
}
|
|
|
|
//use @pps for grab line with bigger outerline
|
|
|
|
//more usefull
|
|
|
|
pps.setWidth(10);
|
|
|
|
path= pps.createStroke(path);
|
|
|
|
break;
|
|
|
|
case Rectangle:
|
|
|
|
path = QetGraphicsItem::shape();
|
|
|
|
break;
|
|
|
|
case Ellipse:
|
|
|
|
path.addEllipse(rect);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
path = QetGraphicsItem::shape();
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2014-02-23 18:55:26 +00:00
|
|
|
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
2014-02-27 12:54:09 +00:00
|
|
|
painter -> setRenderHint(QPainter::Antialiasing, false);
|
2014-02-23 18:55:26 +00:00
|
|
|
QRectF rec = boundingRect();
|
|
|
|
QPen pen(Qt::black);
|
2014-02-27 09:55:54 +00:00
|
|
|
if (isSelected())
|
|
|
|
pen.setColor(Qt::red);
|
2014-02-23 18:55:26 +00:00
|
|
|
pen.setStyle(_shapeStyle);
|
|
|
|
painter->setPen(pen);
|
|
|
|
switch(_shapeType) {
|
|
|
|
case Line:
|
|
|
|
if (_lineAngle)
|
|
|
|
painter -> drawLine(rec.topRight(), rec.bottomLeft());
|
|
|
|
else
|
|
|
|
painter -> drawLine(rec.topLeft(), rec.bottomRight());
|
|
|
|
break;
|
|
|
|
case Rectangle:
|
|
|
|
painter -> drawRect(rec);
|
|
|
|
break;
|
|
|
|
default: //(case Ellipse:)
|
|
|
|
painter ->drawEllipse(rec);
|
|
|
|
}
|
|
|
|
}
|