mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 05:00:33 +01:00
Basic shapes: Items can be selected and moved (thanks joshua)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2879 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -524,6 +524,7 @@ void DiagramView::mouseReleaseEvent(QMouseEvent *e) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (current_behavior == addingLine || current_behavior == addingRectangle || current_behavior == addingEllipse) {
|
if (current_behavior == addingLine || current_behavior == addingRectangle || current_behavior == addingEllipse) {
|
||||||
|
newItem -> setFullyBuilt(true);
|
||||||
if (current_behavior == addingLine)
|
if (current_behavior == addingLine)
|
||||||
emit(LineAdded(false));
|
emit(LineAdded(false));
|
||||||
else if (current_behavior == addingRectangle)
|
else if (current_behavior == addingRectangle)
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) :
|
QetShapeItem::QetShapeItem(QPointF p1, QPointF p2, ShapeType type, bool lineAngle,QGraphicsItem *parent) :
|
||||||
QetGraphicsItem(parent),
|
QetGraphicsItem(parent),
|
||||||
_shapeStyle(Qt::DashLine),
|
_shapeStyle(Qt::DashLine),
|
||||||
_lineAngle(lineAngle)
|
_lineAngle(lineAngle),
|
||||||
|
_isFullyBuilt(false)
|
||||||
{
|
{
|
||||||
_shapeType = type;
|
_shapeType = type;
|
||||||
_boundingRect = QRectF(p1, p2);
|
_boundingRect = QRectF(p1, p2);
|
||||||
@@ -18,15 +19,56 @@ void QetShapeItem::setStyle(Qt::PenStyle newStyle)
|
|||||||
_shapeStyle = newStyle;
|
_shapeStyle = newStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QetShapeItem::setFullyBuilt(bool isBuilt)
|
||||||
|
{
|
||||||
|
_isFullyBuilt = isBuilt;
|
||||||
|
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
|
||||||
|
}
|
||||||
|
|
||||||
QRectF QetShapeItem::boundingRect() const
|
QRectF QetShapeItem::boundingRect() const
|
||||||
{
|
{
|
||||||
return _boundingRect;
|
return _boundingRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void QetShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
{
|
||||||
QRectF rec = boundingRect();
|
QRectF rec = boundingRect();
|
||||||
QPen pen(Qt::black);
|
QPen pen(Qt::black);
|
||||||
|
if (isSelected())
|
||||||
|
pen.setColor(Qt::red);
|
||||||
pen.setStyle(_shapeStyle);
|
pen.setStyle(_shapeStyle);
|
||||||
painter->setPen(pen);
|
painter->setPen(pen);
|
||||||
switch(_shapeType) {
|
switch(_shapeType) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class QetShapeItem : public QetGraphicsItem
|
|||||||
ShapeType getType() const { return _shapeType; }
|
ShapeType getType() const { return _shapeType; }
|
||||||
void setBoundingRect(QRectF rec) { _boundingRect = rec; }
|
void setBoundingRect(QRectF rec) { _boundingRect = rec; }
|
||||||
void setLineAngle(bool lineAngle){ _lineAngle = lineAngle; }
|
void setLineAngle(bool lineAngle){ _lineAngle = lineAngle; }
|
||||||
|
void setFullyBuilt(bool isBuilt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ShapeType _shapeType;
|
ShapeType _shapeType;
|
||||||
@@ -28,12 +29,14 @@ class QetShapeItem : public QetGraphicsItem
|
|||||||
QRectF _boundingRect;
|
QRectF _boundingRect;
|
||||||
bool _lineAngle; // false if line from topleft corner to bottomright corner
|
bool _lineAngle; // false if line from topleft corner to bottomright corner
|
||||||
// and true if line from topright corner to bottomleft corner
|
// and true if line from topright corner to bottomleft corner
|
||||||
|
bool _isFullyBuilt;
|
||||||
|
|
||||||
virtual void editProperty() {}
|
virtual void editProperty() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
|
QPainterPath shape() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user