summaryrefslogtreecommitdiff
path: root/src/gui/pathitem.cpp
diff options
context:
space:
mode:
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;
+}