summaryrefslogtreecommitdiff
path: root/src/gui/pathitem.cpp
diff options
context:
space:
mode:
authorGard Spreemann <gspr@nonempty.org>2020-08-20 09:03:17 +0200
committerGard Spreemann <gspr@nonempty.org>2020-08-20 09:03:17 +0200
commit4e1b4e9877732d1e1887674e48312902437f08c5 (patch)
tree7993cbc3ad71eed10da830aca85ef0b99d163bac /src/gui/pathitem.cpp
parent99f00a3ef9d1bd2d686b1521d25c9afedb880b34 (diff)
parent300267089b80785551c4721684280efe654ec834 (diff)
Merge tag 'v2.1.6' into debian/sid
Diffstat (limited to 'src/gui/pathitem.cpp')
-rw-r--r--src/gui/pathitem.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/gui/pathitem.cpp b/src/gui/pathitem.cpp
new file mode 100644
index 0000000..b45c0a5
--- /dev/null
+++ b/src/gui/pathitem.cpp
@@ -0,0 +1,68 @@
+#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();
+ QBrush brush = st->brush();
+ QColor c = brush.color();
+ brush.setColor(QColor(c.red(),c.green(),c.blue(),200));
+ painter->setPen(pen);
+ painter->setBrush(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;
+}