Author: aschnell
Date: Wed Jan 14 16:17:27 2009
New Revision: 54625
URL: http://svn.opensuse.org/viewcvs/yast?rev=54625&view=rev
Log:
- backup
Modified:
branches/tmp/aschnell/graph/qt-graph/src/CMakeLists.txt
branches/tmp/aschnell/graph/qt-graph/src/YQGraph.cc
branches/tmp/aschnell/graph/qt-graph/src/YQGraph.h
Modified: branches/tmp/aschnell/graph/qt-graph/src/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/graph/qt-graph/src/CMakeLists.txt?rev=54625&r1=54624&r2=54625&view=diff
==============================================================================
--- branches/tmp/aschnell/graph/qt-graph/src/CMakeLists.txt (original)
+++ branches/tmp/aschnell/graph/qt-graph/src/CMakeLists.txt Wed Jan 14 16:17:27 2009
@@ -10,7 +10,7 @@
)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-nonliteral -fmessage-length=0" )
-SET(qt_yast_graph_plugin_SRCS
+SET(qt_yast_graph_plugin_SRCS
YQGraph.cc
YQGraphPlugin.cc
@@ -24,12 +24,14 @@
INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} )
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} )
INCLUDE_DIRECTORIES( ${CMAKE_INSTALL_PREFIX}/include/YaST2/yast2-qt )
+INCLUDE_DIRECTORIES( "/usr/include/graphviz" )
ADD_LIBRARY( py2qt_graph SHARED ${qt_yast_graph_plugin_SRCS} )
TARGET_LINK_LIBRARIES( py2qt_graph ${UI_PLUGIN_DIR}/libpy2qt.so )
TARGET_LINK_LIBRARIES( py2qt_graph ${LIBYUI_LIBRARY} )
TARGET_LINK_LIBRARIES( py2qt_graph ${QT_QTCORE_LIBRARY} )
TARGET_LINK_LIBRARIES( py2qt_graph ${QT_QTGUI_LIBRARY} )
+TARGET_LINK_LIBRARIES( py2qt_graph "-lgvc -lgraph -lcdt" )
SET_TARGET_PROPERTIES( py2qt_graph PROPERTIES SOVERSION 2 )
SET_TARGET_PROPERTIES( py2qt_graph PROPERTIES LINK_FLAGS "-Wl,--no-undefined -Wl,-rpath -Wl,${UI_PLUGIN_DIR}" )
Modified: branches/tmp/aschnell/graph/qt-graph/src/YQGraph.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/graph/qt-graph/src/YQGraph.cc?rev=54625&r1=54624&r2=54625&view=diff
==============================================================================
--- branches/tmp/aschnell/graph/qt-graph/src/YQGraph.cc (original)
+++ branches/tmp/aschnell/graph/qt-graph/src/YQGraph.cc Wed Jan 14 16:17:27 2009
@@ -39,6 +39,8 @@
#include <QTabWidget>
#include <QTimer>
#include <QMenu>
+#include <QGraphicsScene>
+#include <QGraphicsPathItem>
#define YUILogComponent "qt-graph"
#include "YUILog.h"
@@ -54,17 +56,187 @@
YQGraph::YQGraph( YWidget * parent )
- : QWidget( (QWidget *) parent->widgetRep() ),
+ : QGraphicsView( (QWidget *) parent->widgetRep() ),
YGraph( parent )
-{
+{
setWidgetRep( this );
- button = new QPushButton((QWidget *) parent->widgetRep() );
+ setRenderHint(QPainter::Antialiasing);
+ setRenderHint(QPainter::TextAntialiasing);
+ setTransformationAnchor(AnchorUnderMouse);
+ setResizeAnchor(AnchorUnderMouse);
+ setDragMode(ScrollHandDrag);
+
+ QGraphicsScene* scene = new QGraphicsScene(this);
+ populateScene(scene);
+ setScene(scene);
yuiMilestone() << "Graph init done" << endl;
}
+// transform graphviz point into Qt QPointF
+QPointF
+gToQ(const point& p)
+{
+ return QPointF(p.x, p.y);
+}
+
+
+QString
+aggetToQ(void* obj, char* name, const char* fallback)
+{
+ const char* tmp = agget(obj, name);
+ if (tmp == NULL || tmp[0] == '\0')
+ return fallback;
+ else
+ return QString(tmp);
+}
+
+
+void
+YQGraph::arrow(QPainterPath& path, const QLineF& line, const QString& type)
+{
+ if (type == "normal")
+ {
+ QLineF n(line.normalVector());
+ QPointF o(n.dx() / 2.0, n.dy() / 2.0);
+
+ path.moveTo(line.p1());
+ path.moveTo(line.p1() + o);
+ path.lineTo(line.p2());
+ path.lineTo(line.p1() - o);
+ path.closeSubpath();
+ }
+ else if (type == "empty")
+ {
+ QLineF n(line.normalVector());
+ QPointF o(n.dx() / 2.0, n.dy() / 2.0);
+
+ path.moveTo(line.p1());
+ path.moveTo(line.p1() + o);
+ path.lineTo(line.p2());
+ path.lineTo(line.p1() - o);
+ path.closeSubpath();
+ }
+ else if (type == "open")
+ {
+ QLineF n(line.normalVector());
+ QPointF o(n.dx() / 2.0, n.dy() / 2.0);
+
+ path.moveTo(line.p1());
+ path.lineTo(line.p2());
+
+ path.moveTo(line.p1() + o);
+ path.lineTo(line.p2());
+ path.lineTo(line.p1() - o);
+ }
+ else if (type == "none")
+ {
+ path.moveTo(line.p1());
+ path.lineTo(line.p2());
+ }
+ else
+ {
+ yuiError() << "unknown arrow type " << type.toStdString() << endl;
+ }
+}
+
+
+void
+YQGraph::populateScene(QGraphicsScene* scene)
+{
+ GVC_t* gvc = gvContext();
+
+ FILE* fp = fopen("example.dot", "r");
+ graph_t* g = agread(fp);
+
+ gvLayout(gvc, g, "dot");
+
+ const int border = 20;
+ QRectF size(gToQ(GD_bb(g).LL), gToQ(GD_bb(g).UR));
+ size.adjust(-border, -border, border, border);
+
+ scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
+ scene->setSceneRect(size);
+
+
+ QPen pen1("red");
+ pen1.setWidthF(1);
+ QBrush brush1("yellow");
+ QPen pen2("blue");
+ pen2.setWidthF(1);
+
+
+ for (Agnode_t* node = agfstnode(g); node != NULL; node = agnxtnode(g, node))
+ {
+ qreal w = 72*ND_width(node);
+ qreal h = 72*ND_height(node);
+
+ qreal x = ND_coord_i(node).x - w/2;
+ qreal y = ND_coord_i(node).y - h/2;
+
+ QRectF rect(x, y, w, h);
+
+ QGraphicsItem* item = NULL;
+
+ if (strcmp(ND_shape(node)->name, "ellipse") == 0)
+ {
+ QGraphicsEllipseItem* shape = scene->addEllipse(rect);
+ shape->setPen(pen1);
+ shape->setBrush(brush1);
+ item = shape;
+ }
+ else
+ {
+ QGraphicsRectItem* shape = scene->addRect(rect);
+ shape->setPen(pen1);
+ shape->setBrush(brush1);
+ item = shape;
+ }
+
+ const char* tooltip = agget(node, "tooltip");
+ if (tooltip && tooltip[0] != '\0')
+ item->setToolTip(tooltip);
+
+ QGraphicsSimpleTextItem* text = new QGraphicsSimpleTextItem(ND_label(node)->text, item);
+ text->translate(x, y); // ???
+
+ for (Agedge_t* edge = agfstedge(g, node); edge != NULL; edge = agnxtedge(g, edge, node))
+ {
+ const splines* spl = ED_spl(edge);
+
+ for (int i = 0; i < spl->size; i++)
+ {
+ const bezier& bz = spl->list[i];
+
+ QPainterPath path;
+
+ if (bz.sflag)
+ arrow(path, QLineF(gToQ(bz.list[0]), gToQ(bz.sp)), aggetToQ(edge, "arrowhead", "normal"));
+
+ path.moveTo(gToQ(bz.list[0]));
+ for (int j = 1; j < bz.size-1; j += 3)
+ path.cubicTo(gToQ(bz.list[j]), gToQ(bz.list[j+1]), gToQ(bz.list[j+2]));
+
+ if (bz.eflag)
+ arrow(path, QLineF(gToQ(bz.list[bz.size-1]), gToQ(bz.ep)), aggetToQ(edge, "arrowtail", "normal"));
+
+ QGraphicsPathItem* shape = scene->addPath(path);
+
+ shape->setPen(pen2);
+ shape->setZValue(-1.0);
+ }
+ }
+ }
+
+
+ gvFreeLayout(gvc, g);
+ agclose(g);
+ gvFreeContext(gvc);
+}
+
+
int
YQGraph::preferredWidth()
{
Modified: branches/tmp/aschnell/graph/qt-graph/src/YQGraph.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/aschnell/graph/qt-graph/src/YQGraph.h?rev=54625&r1=54624&r2=54625&view=diff
==============================================================================
--- branches/tmp/aschnell/graph/qt-graph/src/YQGraph.h (original)
+++ branches/tmp/aschnell/graph/qt-graph/src/YQGraph.h Wed Jan 14 16:17:27 2009
@@ -20,6 +20,8 @@
#ifndef YQGraph_h
#define YQGraph_h
+#include