Author: aschnell Date: Fri Jan 23 20:27:10 2009 New Revision: 54965 URL: http://svn.opensuse.org/viewcvs/yast?rev=54965&view=rev Log: - improved renderer Modified: trunk/qt-graph/examples/arrows.dot trunk/qt-graph/examples/shapes.dot trunk/qt-graph/examples/simple.dot trunk/qt-graph/src/QGraph.cc trunk/qt-graph/src/QGraph.h Modified: trunk/qt-graph/examples/arrows.dot URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/examples/arrows.dot?rev=54965&r1=54964&r2=54965&view=diff ============================================================================== --- trunk/qt-graph/examples/arrows.dot (original) +++ trunk/qt-graph/examples/arrows.dot Fri Jan 23 20:27:10 2009 @@ -3,9 +3,12 @@ node [style="filled"]; edge [style="dotted"]; - A -> B [arrowhead="normal", arrowtail="normal"]; - A -> B [arrowhead="none", arrowtail="none"]; + A -> B; + B -> A; - C -> D [arrowhead="open"]; - C -> D [arrowhead="empty"]; + C -> D [arrowhead="normal", arrowtail="normal"]; + C -> D [arrowhead="none", arrowtail="none"]; + + E -> F [dir="both"]; + E -> F [dir="none"]; } Modified: trunk/qt-graph/examples/shapes.dot URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/examples/shapes.dot?rev=54965&r1=54964&r2=54965&view=diff ============================================================================== --- trunk/qt-graph/examples/shapes.dot (original) +++ trunk/qt-graph/examples/shapes.dot Fri Jan 23 20:27:10 2009 @@ -1,6 +1,6 @@ digraph { - node [style="filled"]; + node [style="filled", fontname="Helvetica"]; rectangle [shape="rectangle"]; diamond [shape="diamond"]; Modified: trunk/qt-graph/examples/simple.dot URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/examples/simple.dot?rev=54965&r1=54964&r2=54965&view=diff ============================================================================== --- trunk/qt-graph/examples/simple.dot (original) +++ trunk/qt-graph/examples/simple.dot Fri Jan 23 20:27:10 2009 @@ -1,5 +1,7 @@ -digraph test +digraph simple { + node [style="filled", fontname="Times"]; + 1; 2; Modified: trunk/qt-graph/src/QGraph.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QGraph.cc?rev=54965&r1=54964&r2=54965&view=diff ============================================================================== --- trunk/qt-graph/src/QGraph.cc (original) +++ trunk/qt-graph/src/QGraph.cc Fri Jan 23 20:27:10 2009 @@ -146,52 +146,36 @@ } -void -QGraph::arrow(QPainterPath& path, const QLineF& line, const QString& type) const +QPainterPath +QGraph::haha3(const bezier& bezier) const { - if (type == "normal") - { - QLineF n(line.normalVector()); - QPointF o(n.dx() / 2.0, n.dy() / 2.0); + QPainterPath path; + path.moveTo(gToQ(bezier.list[0])); + for (int i = 1; i < bezier.size - 1; i += 3) + path.cubicTo(gToQ(bezier.list[i]), gToQ(bezier.list[i+1]), gToQ(bezier.list[i+2])); + return path; +} - 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); +void +QGraph::drawArrow(const QLineF& line, const QColor& color, QPainter* painter) const +{ + QLineF n(line.normalVector()); + QPointF o(n.dx() / 2.0, n.dy() / 2.0); - path.moveTo(line.p1()); - path.lineTo(line.p2()); + QPolygonF polygon; + polygon.append(line.p1() + o); + polygon.append(line.p2()); + polygon.append(line.p1() - o); + + QPen pen(color); + pen.setWidthF(1.0); + painter->setPen(pen); - 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; - } + QBrush brush(color); + painter->setBrush(brush); + + painter->drawPolygon(polygon); } @@ -294,77 +278,83 @@ size = rect.size(); - for (node_t* node = agfstnode(graph); node != NULL; node = agnxtnode(graph, node)) { - Node* shape = new Node(haha2(node)); + QPicture picture; + QPainter painter; - scene->addItem(shape); + painter.begin(&picture); + drawLabel(ND_label(node), &painter); + painter.end(); + + Node* item = new Node(haha2(node), picture); - shape->setPos(gToQ(ND_coord_i(node), true)); + item->setPos(gToQ(ND_coord_i(node))); QPen pen(aggetToQColor(node, "color", Qt::black)); pen.setWidthF(1.0); - shape->setPen(pen); + item->setPen(pen); QBrush brush(aggetToQColor(node, "fillcolor", Qt::gray)); - shape->setBrush(brush); - - QPainter painter; - painter.begin(&shape->picture); - drawLabel(ND_label(node), &painter); - painter.end(); + item->setBrush(brush); QString tooltip = aggetToQString(node, "tooltip", ""); if (!tooltip.isEmpty()) - shape->setToolTip(tooltip); + item->setToolTip(tooltip); + + scene->addItem(item); for (edge_t* edge = agfstout(graph, node); edge != NULL; edge = agnxtout(graph, edge)) { const splines* spl = ED_spl(edge); + const bezier& bz = spl->list[0]; - for (int i = 0; i < spl->size; i++) - { - const bezier& bz = spl->list[i]; + QColor color(aggetToQColor(edge, "color", Qt::black)); - QPainterPath path; + QPainterPath path(haha3(bz)); - if (bz.sflag) - arrow(path, QLineF(gToQ(bz.list[0], true), gToQ(bz.sp, true)), aggetToQString(edge, "arrowhead", "normal")); + QPicture picture; + QPainter painter; - path.moveTo(gToQ(bz.list[0], true)); - for (int j = 1; j < bz.size-1; j += 3) - path.cubicTo(gToQ(bz.list[j], true), gToQ(bz.list[j+1], true), gToQ(bz.list[j+2], true)); + painter.begin(&picture); + if (bz.sflag) + drawArrow(QLineF(gToQ(bz.list[0]), gToQ(bz.sp)), color, &painter); + if (bz.eflag) + drawArrow(QLineF(gToQ(bz.list[bz.size-1]), gToQ(bz.ep)), color, &painter); + painter.end(); - if (bz.eflag) - arrow(path, QLineF(gToQ(bz.list[bz.size-1], true), gToQ(bz.ep, true)), aggetToQString(edge, "arrowtail", "normal")); + Edge* item = new Edge(path, picture); - QGraphicsPathItem* shape = scene->addPath(path); + QPen pen(color); + pen.setStyle(aggetToQPenStyle(edge, "style", Qt::SolidLine)); + pen.setWidthF(1.0); + item->setPen(pen); - QPen pen(aggetToQColor(edge, "color", Qt::black)); - pen.setStyle(aggetToQPenStyle(edge, "style", Qt::SolidLine)); - pen.setWidthF(1.0); - shape->setPen(pen); + item->setZValue(-1.0); - shape->setZValue(-1.0); - } + scene->addItem(item); } } } -Node::Node(const QPainterPath& path) - : QGraphicsPathItem(path) +Node::Node(const QPainterPath& path, const QPicture& picture) + : QGraphicsPathItem(path), + picture(picture) +{ +} + + +QRectF +Node::boundingRect() const { - // setFlag(ItemIsMovable); + return QGraphicsPathItem::boundingRect().united(picture.boundingRect()); } void Node::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - // TODO: rethink painter state handling, see also QGraphicsView::DontSavePainterState - painter->save(); QGraphicsPathItem::paint(painter, option, widget); painter->restore(); Modified: trunk/qt-graph/src/QGraph.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QGraph.h?rev=54965&r1=54964&r2=54965&view=diff ============================================================================== --- trunk/qt-graph/src/QGraph.h (original) +++ trunk/qt-graph/src/QGraph.h Fri Jan 23 20:27:10 2009 @@ -63,12 +63,12 @@ /** * Transform graphviz point into Qt QPointF. */ - QPointF gToQ(const point& p, bool trans) const; + QPointF gToQ(const point& p, bool trans = true) const; /** * Transform graphviz pointf into Qt QPointF. */ - QPointF gToQ(const pointf& p, bool trans) const; + QPointF gToQ(const pointf& p, bool trans = true) const; QString aggetToQString(void* obj, const char* name, const char* fallback) const; @@ -76,12 +76,14 @@ Qt::PenStyle aggetToQPenStyle(void* obj, const char* name, const Qt::PenStyle fallback) const; - void arrow(QPainterPath& path, const QLineF& line, const QString& type) const; + void drawArrow(const QLineF& line, const QColor& color, QPainter* painter) const; QPolygonF haha1(node_t* node) const; QPainterPath haha2(node_t* node) const; + QPainterPath haha3(const bezier& bezier) const; + void drawLabel(const textlabel_t* textlabel, QPainter* painter) const; }; @@ -92,13 +94,20 @@ public: - Node(const QPainterPath& path); + Node(const QPainterPath& path, const QPicture& picture); + + QRectF boundingRect() const; void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); +private: + QPicture picture; }; +typedef Node Edge; + + #endif // QGraph_h -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org