From 732499eead71b23a7ba551fe788b47a4cf45124e Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Mon, 13 Apr 2020 16:21:39 +0100 Subject: adding and drawing paths works --- src/gui/pathitem.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/gui/pathitem.cpp (limited to 'src/gui/pathitem.cpp') 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; +} -- cgit v1.2.3