summaryrefslogtreecommitdiff
path: root/src/data
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2018-04-21 22:53:05 +0200
committerAleks Kissinger <aleks0@gmail.com>2018-04-21 22:53:05 +0200
commitb00c5250d7a56b6d20980d89cf331a114fdfdee0 (patch)
tree5fef5c2a534cf150f9ae57cd20a90d6789bd3789 /src/data
parent9dd19037afd93d879ec32c5191314196f7f50592 (diff)
edge styles 90 percent
Diffstat (limited to 'src/data')
-rw-r--r--src/data/edge.cpp68
-rw-r--r--src/data/edge.h16
-rw-r--r--src/data/edgestyle.cpp6
3 files changed, 79 insertions, 11 deletions
diff --git a/src/data/edge.cpp b/src/data/edge.cpp
index d0f0deb..a18c8ea 100644
--- a/src/data/edge.cpp
+++ b/src/data/edge.cpp
@@ -16,6 +16,7 @@ Edge::Edge(Node *s, Node *t, QObject *parent) :
_inAngle = 0;
_outAngle = 0;
_weight = 0.4f;
+ _style = noneEdgeStyle;
updateControls();
}
@@ -43,6 +44,7 @@ Edge *Edge::copy(QMap<Node*,Node*> *nodeTable)
e->setInAngle(_inAngle);
e->setOutAngle(_outAngle);
e->setWeight(_weight);
+ e->attachStyle();
e->updateControls();
return e;
}
@@ -79,6 +81,19 @@ void Edge::setData(GraphElementData *data)
setAttributesFromData();
}
+QString Edge::styleName() const
+{
+ QString nm = _data->property("style");
+ if (nm.isNull()) return "none";
+ else return nm;
+}
+
+void Edge::setStyleName(const QString &styleName)
+{
+ if (!styleName.isNull() && styleName != "none") _data->setProperty("style", styleName);
+ else _data->unsetProperty("style");
+}
+
QString Edge::sourceAnchor() const
{
return _sourceAnchor;
@@ -142,15 +157,15 @@ void Edge::updateControls() {
if (_source->style()->isNone()) {
_tail = src;
} else {
- _tail = QPointF(src.x() + std::cos(outAngleR) * 0.1,
- src.y() + std::sin(outAngleR) * 0.1);
+ _tail = QPointF(src.x() + std::cos(outAngleR) * 0.2,
+ src.y() + std::sin(outAngleR) * 0.2);
}
if (_target->style()->isNone()) {
_head = targ;
} else {
- _head = QPointF(targ.x() + std::cos(inAngleR) * 0.1,
- targ.y() + std::sin(inAngleR) * 0.1);
+ _head = QPointF(targ.x() + std::cos(inAngleR) * 0.2,
+ targ.y() + std::sin(inAngleR) * 0.2);
}
// give a default distance for self-loops
@@ -163,12 +178,8 @@ void Edge::updateControls() {
targ.y() + (_cpDist * std::sin(inAngleR)));
_mid = bezierInterpolateFull (0.5f, _tail, _cp1, _cp2, _head);
-// midTan = [self _findTanFor:mid usingSpanFrom:0.4f to:0.6f];
-
-// tailTan = [self _findTanFor:tail usingSpanFrom:0.0f to:0.1f];
-// headTan = [self _findTanFor:head usingSpanFrom:1.0f to:0.9f];
- //_dirty = false;
- //}
+ _tailTangent = bezierTangent(0.0f, 0.1f);
+ _headTangent = bezierTangent(1.0f, 0.9f);
}
void Edge::setAttributesFromData()
@@ -344,4 +355,41 @@ QPointF Edge::mid() const
return _mid;
}
+QPointF Edge::headTangent() const
+{
+ return _headTangent;
+}
+
+QPointF Edge::tailTangent() const
+{
+ return _tailTangent;
+}
+
+void Edge::attachStyle()
+{
+ QString nm = styleName();
+ if (nm.isNull()) _style = noneEdgeStyle;
+ else _style = tikzit->styles()->edgeStyle(nm);
+}
+EdgeStyle * Edge::style() const
+{
+ return _style;
+}
+
+QPointF Edge::bezierTangent(float start, float end) const
+{
+ float dx = bezierInterpolate(end, _tail.x(), _cp1.x(), _cp2.x(), _head.x()) -
+ bezierInterpolate(start, _tail.x(), _cp1.x(), _cp2.x(), _head.x());
+ float dy = bezierInterpolate(end, _tail.y(), _cp1.y(), _cp2.y(), _head.y()) -
+ bezierInterpolate(start, _tail.y(), _cp1.y(), _cp2.y(), _head.y());
+
+ // normalise
+ float len = sqrt(dx*dx + dy * dy);
+ if (len != 0) {
+ dx = (dx / len) * 0.1f;
+ dy = (dy / len) * 0.1f;
+ }
+
+ return QPointF(dx, dy);
+}
diff --git a/src/data/edge.h b/src/data/edge.h
index 7df899f..3dc0211 100644
--- a/src/data/edge.h
+++ b/src/data/edge.h
@@ -3,6 +3,7 @@
#include "graphelementdata.h"
#include "node.h"
+#include "edgestyle.h"
#include <QObject>
#include <QPointF>
@@ -43,6 +44,8 @@ public:
QPointF cp1() const;
QPointF cp2() const;
QPointF mid() const;
+ QPointF headTangent() const;
+ QPointF tailTangent() const;
int bend() const;
int inAngle() const;
@@ -60,11 +63,18 @@ public:
int tikzLine() const;
void setTikzLine(int tikzLine);
+
+ void attachStyle();
+ QString styleName() const;
+ void setStyleName(const QString & styleName);
+ EdgeStyle *style() const;
+
signals:
public slots:
private:
+ QPointF bezierTangent(float start, float end) const;
QString _sourceAnchor;
QString _targetAnchor;
@@ -76,6 +86,9 @@ private:
Node *_source;
Node *_target;
+
+ EdgeStyle *_style;
+
bool _dirty;
bool _basicBendMode;
int _bend;
@@ -90,6 +103,9 @@ private:
QPointF _cp2;
QPointF _mid;
+ QPointF _headTangent;
+ QPointF _tailTangent;
+
int _tikzLine;
};
diff --git a/src/data/edgestyle.cpp b/src/data/edgestyle.cpp
index d366946..9fb2638 100644
--- a/src/data/edgestyle.cpp
+++ b/src/data/edgestyle.cpp
@@ -41,7 +41,7 @@ EdgeStyle::DrawStyle EdgeStyle::drawStyle() const
QPen EdgeStyle::pen() const
{
QPen p(strokeColor());
- p.setWidthF((float)strokeThickness() * 3.0f);
+ p.setWidthF((float)strokeThickness() * 2.0f);
QVector<qreal> pat;
switch (drawStyle()) {
@@ -84,6 +84,10 @@ QIcon EdgeStyle::icon() const
painter.drawLine(10, 50, 90, 50);
+ QPen pn = pen();
+ pn.setStyle(Qt::SolidLine);
+ painter.setPen(pn);
+
switch (arrowHead()) {
case Pointer:
painter.drawLine(90,50,80,40);