summaryrefslogtreecommitdiff
path: root/src/gui/edgeitem.cpp
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-04-09 13:22:47 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-04-09 13:22:47 +0200
commit72433d3354ce4cdfad8c88f993364a76b192e3e5 (patch)
tree614121d671c7b15e34a9397aa2f059eaabcc4cf5 /src/gui/edgeitem.cpp
parent4271b6364f581b37f5fe125c1992e1420b3e51d1 (diff)
major speed boost
Diffstat (limited to 'src/gui/edgeitem.cpp')
-rw-r--r--src/gui/edgeitem.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/gui/edgeitem.cpp b/src/gui/edgeitem.cpp
index f174186..ec87815 100644
--- a/src/gui/edgeitem.cpp
+++ b/src/gui/edgeitem.cpp
@@ -9,9 +9,6 @@ EdgeItem::EdgeItem(Edge *edge)
_edge = edge;
setFlag(QGraphicsItem::ItemIsSelectable);
- QPen pen(Qt::black);
- pen.setWidth(2);
- setPen(pen);
_cp1Item = new QGraphicsEllipseItem(this);
_cp1Item->setParentItem(this);
_cp1Item->setRect(GLOBAL_SCALEF * (-0.05), GLOBAL_SCALEF * (-0.05),
@@ -53,7 +50,9 @@ void EdgeItem::readPos()
void EdgeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
//QGraphicsPathItem::paint(painter, option, widget);
- painter->setPen(pen());
+ QPen pen(Qt::black);
+ pen.setWidth(2);
+ painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->drawPath(path());
@@ -107,19 +106,12 @@ void EdgeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge
QRectF EdgeItem::boundingRect() const
{
- float r = GLOBAL_SCALEF * (_edge->cpDist() + 0.2);
- return shape().boundingRect().adjusted(-r,-r,r,r);
+ return _boundingRect;
}
QPainterPath EdgeItem::shape() const
{
- // get the shape of the edge, and expand a bit to make selection easier
- QPainterPath oldShape = QGraphicsPathItem::shape();
- QPainterPathStroker stroker;
- stroker.setWidth(5);
- stroker.setJoinStyle(Qt::MiterJoin);
- QPainterPath newShape = (stroker.createStroke(oldShape) + oldShape).simplified();
- return newShape;
+ return _expPath;
}
Edge *EdgeItem::edge() const
@@ -136,3 +128,25 @@ QGraphicsEllipseItem *EdgeItem::cp2Item() const
{
return _cp2Item;
}
+
+QPainterPath EdgeItem::path() const
+{
+ return _path;
+}
+
+void EdgeItem::setPath(const QPainterPath &path)
+{
+ _path = path;
+
+ // get the shape of the edge, and expand a bit to make selection easier
+ QPainterPathStroker stroker;
+ stroker.setWidth(5);
+ stroker.setJoinStyle(Qt::MiterJoin);
+ _expPath = (stroker.createStroke(_path) + _path).simplified();
+
+ float r = GLOBAL_SCALEF * (_edge->cpDist() + 0.2);
+ _boundingRect = _path.boundingRect().adjusted(-r,-r,r,r);
+
+ prepareGeometryChange();
+ update();
+}