diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2018-04-09 13:22:47 +0200 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2018-04-09 13:22:47 +0200 |
commit | 72433d3354ce4cdfad8c88f993364a76b192e3e5 (patch) | |
tree | 614121d671c7b15e34a9397aa2f059eaabcc4cf5 /src | |
parent | 4271b6364f581b37f5fe125c1992e1420b3e51d1 (diff) |
major speed boost
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/edgeitem.cpp | 40 | ||||
-rw-r--r-- | src/gui/edgeitem.h | 9 | ||||
-rw-r--r-- | src/gui/tikzscene.cpp | 1 |
3 files changed, 36 insertions, 14 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(); +} diff --git a/src/gui/edgeitem.h b/src/gui/edgeitem.h index 3701372..5641912 100644 --- a/src/gui/edgeitem.h +++ b/src/gui/edgeitem.h @@ -14,7 +14,7 @@ #include <QWidget> #include <QGraphicsEllipseItem> -class EdgeItem : public QGraphicsPathItem +class EdgeItem : public QGraphicsItem { public: EdgeItem(Edge *edge); @@ -26,8 +26,15 @@ public: QGraphicsEllipseItem *cp1Item() const; QGraphicsEllipseItem *cp2Item() const; + + QPainterPath path() const; + void setPath(const QPainterPath &path); + private: Edge *_edge; + QPainterPath _path; + QPainterPath _expPath; + QRectF _boundingRect; QGraphicsEllipseItem *_cp1Item; QGraphicsEllipseItem *_cp2Item; }; diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index b26c4ba..927809e 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -84,6 +84,7 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) { if (!_enabled) return; + // current mouse position, in scene coordinates _mouseDownPos = event->scenePos(); |