diff options
author | Aleks Kissinger <aleks0@gmail.com> | 2020-04-13 16:21:39 +0100 |
---|---|---|
committer | Aleks Kissinger <aleks0@gmail.com> | 2020-04-13 16:21:39 +0100 |
commit | 732499eead71b23a7ba551fe788b47a4cf45124e (patch) | |
tree | ac3a770f742a2ebc749afd273037ee60a326ed61 /src/gui/pathitem.cpp | |
parent | 6dda16a24dfe7cbd0d90b77c57f1cf789210feb5 (diff) |
adding and drawing paths works
Diffstat (limited to 'src/gui/pathitem.cpp')
-rw-r--r-- | src/gui/pathitem.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/gui/pathitem.cpp b/src/gui/pathitem.cpp new file mode 100644 index 0000000..107281f --- /dev/null +++ b/src/gui/pathitem.cpp @@ -0,0 +1,65 @@ +#include "pathitem.h" +#include "tikzit.h" + +PathItem::PathItem(Path *path) +{ + _path = path; + readPos(); +} + +void PathItem::readPos() +{ + QPainterPath painterPath; + + foreach (Edge *e, _path->edges()) { + e->updateControls(); + + if (e == _path->edges().first()) + painterPath.moveTo (toScreen(e->tail())); + + if (e->bend() != 0 || !e->basicBendMode()) { + painterPath.cubicTo(toScreen(e->cp1()), + toScreen(e->cp2()), + toScreen(e->head())); + } else { + painterPath.lineTo(toScreen(e->head())); + } + } + + setPainterPath(painterPath); +} + +void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) +{ + Style *st = _path->edges().first()->style(); + QPen pen = st->pen(); + painter->setPen(st->pen()); + painter->setBrush(st->brush()); + painter->drawPath(painterPath()); +} + +Path *PathItem::path() const +{ + return _path; +} + +QPainterPath PathItem::painterPath() const +{ + return _painterPath; +} + +void PathItem::setPainterPath(const QPainterPath &painterPath) +{ + prepareGeometryChange(); + + _painterPath = painterPath; + float r = GLOBAL_SCALEF * 0.1; + _boundingRect = _painterPath.boundingRect().adjusted(-r,-r,r,r); + + update(); +} + +QRectF PathItem::boundingRect() const +{ + return _boundingRect; +} |