draws tree
diff --git a/chatdialog.ui b/chatdialog.ui
index ed466e7..072d139 100644
--- a/chatdialog.ui
+++ b/chatdialog.ui
@@ -17,7 +17,7 @@
<number>6</number>
</property>
<item>
- <layout class="QHBoxLayout">
+ <layout class="QVBoxLayout">
<property name="margin">
<number>0</number>
</property>
@@ -25,6 +25,13 @@
<number>6</number>
</property>
<item>
+ <widget class="DigestTreeViewer" name="treeViewer">
+ <property name="focusPolicy">
+ <enum>Qt::NoFocus</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QTextEdit" name="textEdit">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
@@ -34,13 +41,6 @@
</property>
</widget>
</item>
- <item>
- <widget class="QListWidget" name="listWidget">
- <property name="focusPolicy">
- <enum>Qt::NoFocus</enum>
- </property>
- </widget>
- </item>
</layout>
</item>
<item>
diff --git a/digesttreescene.cpp b/digesttreescene.cpp
new file mode 100644
index 0000000..8d2d5c3
--- /dev/null
+++ b/digesttreescene.cpp
@@ -0,0 +1,97 @@
+#include "digesttreescene.h"
+#include <QtGui>
+#include "ogdf/basic/Array.h"
+#include "ogdf/basic/Graph_d.h"
+#include "ogdf/tree/TreeLayout.h"
+#include <vector>
+#include <iostream>
+#include <assert.h>
+
+static const double Pi = 3.14159265358979323846264338327950288419717;
+static double TwoPi = 2.0 * Pi;
+
+DigestTreeScene::DigestTreeScene(QWidget *parent)
+ : QGraphicsScene(parent)
+{
+ m_graph.clear();
+ std::vector<ogdf::node> v(5);
+ for (int i = 0; i < 5; i++)
+ v[i] = m_graph.newNode();
+
+ m_graph.newEdge(v[0], v[1]);
+ m_graph.newEdge(v[0], v[2]);
+ m_graph.newEdge(v[0], v[3]);
+ m_graph.newEdge(v[0], v[4]);
+
+ ogdf::GraphAttributes GA(m_graph);
+ GA.initAttributes(ogdf::GraphAttributes::nodeLabel);
+ int nodeWidth = 30, nodeHeight = 30, siblingDistance = 60;
+ ogdf::TreeLayout layout;
+ layout.siblingDistance(siblingDistance);
+ layout.rootSelection(ogdf::TreeLayout::rootIsSource);
+ //layout.call(GA);
+ layout.callSortByPositions(GA, m_graph);
+
+ int width = GA.boundingBox().width();
+ std::cout << "GA width " << width << std::endl;
+ int height = GA.boundingBox().height();
+ std::cout << "GA height " << height << std::endl;
+ setSceneRect(QRect(0, 0, width + nodeWidth, height + nodeHeight));
+ GA.setAllWidth(nodeWidth);
+ GA.setAllHeight(nodeHeight);
+
+ ogdf::edge e;
+ forall_edges(e, m_graph) {
+ ogdf::node source = e->source();
+ ogdf::node target = e->target();
+ int x1 = GA.x(source), y1 = -GA.y(source);
+ int x2 = GA.x(target), y2 = -GA.y(target);
+ // QPainterPath p;
+ QPointF src(x1 + nodeWidth/2, y1 + nodeHeight/2);
+ QPointF dest(x2 + nodeWidth/2, y2 + nodeHeight/2);
+ QLineF line(src, dest);
+ //p.moveTo(x1 + nodeWidth/2, y1 + nodeHeight/2);
+ //p.lineTo(x2 + nodeWidth/2, y2 + nodeHeight/2);
+ //addPath(p, QPen(Qt::black), QBrush(Qt::black));
+ addLine(line, QPen(Qt::black));
+
+ double angle = ::acos(line.dx() / line.length());
+
+ double arrowSize = 10;
+
+ QPointF sourceArrowP0 = src + QPointF(nodeWidth/2 * line.dx() / line.length(), nodeHeight/2 * line.dy() / line.length());
+ //QPointF sourceArrowP0 = src + QPointF(cos(angle) * nodeHeight/2, sin(angle) * nodeHeight/2);
+
+ std::cout << "src " << src.x() << ", " << src.y() << std::endl;
+ std::cout << "dest " << dest.x() << ", " << dest.y() << std::endl;
+ std::cout << "line dx " << line.dx() << ", dy " << line.dy() << ", lenght << " << line.length() << std::endl;
+ std::cout << "sap " << sourceArrowP0.x() << ", " << sourceArrowP0.y() << std::endl;
+
+ QPointF sourceArrowP1 = sourceArrowP0 + QPointF(cos(angle + Pi / 3 - Pi/2) * arrowSize,
+ sin(angle + Pi / 3 - Pi/2) * arrowSize);
+ QPointF sourceArrowP2 = sourceArrowP0 + QPointF(cos(angle + Pi - Pi / 3 - Pi/2) * arrowSize,
+ sin(angle + Pi - Pi / 3 - Pi/2) * arrowSize);
+ QLineF line1(sourceArrowP1, sourceArrowP2);
+ addLine(line1, QPen(Qt::black));
+
+ addPolygon(QPolygonF() << sourceArrowP0<< sourceArrowP1 << sourceArrowP2, QPen(Qt::black), QBrush(Qt::black));
+ }
+
+ /*
+ ogdf::node n;
+ forall_nodes(n, m_graph) {
+ double x = GA.x(n);
+
+ double y = -GA.y(n);
+ double w = GA.width(n);
+ double h = GA.height(n);
+ QRectF boundingRect(x, y, w, h);
+
+ addEllipse(boundingRect, QPen(Qt::black), QBrush(Qt::green));
+ QGraphicsTextItem *text = addText(QString(GA.labelNode(n).cstr()));
+ text->setPos(x, y);
+
+ }
+ */
+}
+
diff --git a/digesttreescene.h b/digesttreescene.h
new file mode 100644
index 0000000..0d98f7e
--- /dev/null
+++ b/digesttreescene.h
@@ -0,0 +1,17 @@
+#ifndef DIGESTTREESCENE_H
+#define DIGESTTREESCENE_H
+
+#include <QtGui/QGraphicsScene>
+#include "ogdf/basic/GraphAttributes.h"
+#include "ogdf/basic/Graph.h"
+
+class DigestTreeScene : public QGraphicsScene
+{
+ Q_OBJECT
+
+public:
+ DigestTreeScene(QWidget *parent = 0);
+private:
+ ogdf::Graph m_graph;
+};
+#endif
diff --git a/digesttreeviewer.cpp b/digesttreeviewer.cpp
new file mode 100644
index 0000000..cb52a9e
--- /dev/null
+++ b/digesttreeviewer.cpp
@@ -0,0 +1,10 @@
+#include "digesttreeviewer.h"
+#include "digesttreescene.h"
+#include <QtGui>
+
+DigestTreeViewer::DigestTreeViewer(QWidget *parent)
+ : QGraphicsView(parent)
+{
+ DigestTreeScene *scene = new DigestTreeScene(this);
+ setScene(scene);
+}
diff --git a/digesttreeviewer.h b/digesttreeviewer.h
new file mode 100644
index 0000000..0f09f67
--- /dev/null
+++ b/digesttreeviewer.h
@@ -0,0 +1,13 @@
+#ifndef DIGESTTREEVIEWER_H
+#define DIGESTTREEVIEWER_H
+#include <QtGui/QGraphicsView>
+
+class DigestTreeViewer : public QGraphicsView
+{
+ Q_OBJECT
+
+public:
+ DigestTreeViewer(QWidget *parent = 0);
+};
+
+#endif
diff --git a/sync-demo.pro b/sync-demo.pro
index e912e77..b201cb7 100644
--- a/sync-demo.pro
+++ b/sync-demo.pro
@@ -1,15 +1,20 @@
TEMPLATE = app
TARGET = sync-demo
-HEADERS = chatdialog.h
+HEADERS = chatdialog.h \
+ digesttreeviewer.h \
+ digesttreescene.h
SOURCES = main.cpp \
- chatdialog.cpp
+ chatdialog.cpp \
+ digesttreeviewer.cpp \
+ digesttreescene.cpp
FORMS = chatdialog.ui
+QMAKE_CXXFLAGS *= -g
-QMAKE_LIBDIR *= /opt/local/lib /usr/local/lib /usr/lib
-INCLUDEPATH *= /opt/local/include /usr/local/include
-LIBS *= -lccn -lssl -lcrypto
+QMAKE_LIBDIR *= /opt/local/lib /usr/local/lib /usr/lib ../../../third_party/OGDF/_release
+INCLUDEPATH *= /opt/local/include /usr/local/include ../../../third_party/OGDF
+LIBS *= -lccn -lssl -lcrypto -lpthread -lOGDF
CONFIG += console