Mailinglist Archive: yast-commit (819 mails)

< Previous Next >
[yast-commit] r54868 - in /trunk/qt-graph: examples/shapes.dot src/QGraph.cc src/QGraph.h
  • From: aschnell@xxxxxxxxxxxxxxxx
  • Date: Wed, 21 Jan 2009 17:10:38 -0000
  • Message-id: <E1LPgb8-0006ep-AH@xxxxxxxxxxxxxxxx>
Author: aschnell
Date: Wed Jan 21 18:10:38 2009
New Revision: 54868

URL: http://svn.opensuse.org/viewcvs/yast?rev=54868&view=rev
Log:
- work on shapes

Added:
trunk/qt-graph/examples/shapes.dot
Modified:
trunk/qt-graph/src/QGraph.cc
trunk/qt-graph/src/QGraph.h

Added: trunk/qt-graph/examples/shapes.dot
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/examples/shapes.dot?rev=54868&view=auto
==============================================================================
--- trunk/qt-graph/examples/shapes.dot (added)
+++ trunk/qt-graph/examples/shapes.dot Wed Jan 21 18:10:38 2009
@@ -0,0 +1,10 @@
+digraph
+{
+ node [style="filled"];
+
+ rectangle [shape="rectangle"];
+ diamond [shape="diamond"];
+ triangle [shape="triangle"];
+ circle [shape="circle"];
+ ellipse [shape="ellipse"];
+}

Modified: trunk/qt-graph/src/QGraph.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QGraph.cc?rev=54868&r1=54867&r2=54868&view=diff
==============================================================================
--- trunk/qt-graph/src/QGraph.cc (original)
+++ trunk/qt-graph/src/QGraph.cc Wed Jan 21 18:10:38 2009
@@ -97,10 +97,18 @@


QPointF
-QGraph::gToQ(const point& p) const
+QGraph::gToQ(const point& p, bool trans) const
{
QPointF tmp(p.x, p.y);
- return QPointF(tmp.x(), size.height() - tmp.y());
+ return trans ? QPointF(tmp.x(), size.height() - tmp.y()) :
QPointF(tmp.x(), -tmp.y());
+}
+
+
+QPointF
+QGraph::gToQ(const pointf& p, bool trans) const
+{
+ QPointF tmp(p.x, p.y);
+ return trans ? QPointF(tmp.x(), size.height() - tmp.y()) :
QPointF(tmp.x(), -tmp.y());
}


@@ -192,6 +200,60 @@
}


+QPolygonF
+QGraph::haha1(node_t* node) const
+{
+ const polygon_t* poly = (polygon_t*) ND_shape_info(node);
+
+ const int sides = poly->sides;
+ const pointf* vertices = poly->vertices;
+
+ QPolygonF polygon;
+ for (int side = 0; side < sides; side++)
+ polygon.append(gToQ(vertices[side], false));
+ return polygon;
+}
+
+
+
+QPainterPath
+QGraph::haha2(node_t* node) const
+{
+ QPainterPath path;
+
+ const char* name = ND_shape(node)->name;
+
+ if ((strcmp(name, "rectangle") == 0) ||
+ (strcmp(name, "diamond") == 0) ||
+ (strcmp(name, "triangle") == 0))
+ {
+ QPolygonF polygon = haha1(node);
+ polygon.append(polygon[0]);
+ path.addPolygon(polygon);
+ }
+
+ if ((strcmp(name, "ellipse") == 0) ||
+ (strcmp(name, "circle") == 0))
+ {
+ QPolygonF polygon = haha1(node);
+ path.addEllipse(QRectF(polygon[0], polygon[1]));
+ }
+
+ return path;
+}
+
+
+void
+QGraph::drawLabel(const textlabel_t* textlabel, QPainter* painter)
+{
+ painter->setPen(textlabel->fontcolor);
+
+ QRectF rect(-100, -100, 100, 100); // TODO
+ rect.moveCenter(gToQ(textlabel->p, false));
+ painter->drawText(rect, Qt::AlignCenter | Qt::AlignHCenter,
textlabel->text);
+}
+
+
void
QGraph::renderGraph(graph_t* graph)
{
@@ -213,34 +275,22 @@

for (node_t* node = agfstnode(graph); node != NULL; node =
agnxtnode(graph, node))
{
- QRectF rect(0.0, 0.0, 72.0*ND_width(node), 72.0*ND_height(node));
- rect.moveCenter(gToQ(ND_coord_i(node)));
+ Node* shape = new Node(haha2(node));

- Node* shape = NULL;
+ scene->addItem(shape);

- if (strcmp(ND_shape(node)->name, "ellipse") == 0)
- {
- shape = new Node(rect);
- scene->addItem(shape);
- shape->setPen(pen1);
- shape->setBrush(brush1);
- }
- else
- {
- shape = new Node(rect);
- scene->addItem(shape);
- shape->setPen(pen1);
- shape->setBrush(brush1);
- }
+ shape->setPos(gToQ(ND_coord_i(node), true));
+
+ shape->setPen(pen1);
+ shape->setBrush(brush1);

QPainter painter;
painter.begin(&shape->picture);
- painter.setPen(Qt::black);
- painter.drawText(rect, Qt::AlignCenter | Qt::AlignHCenter,
ND_label(node)->text);
+ drawLabel(ND_label(node), &painter);
painter.end();

const char* tooltip = agget(node, "tooltip");
- if (tooltip && tooltip[0] != '\0')
+ if (tooltip && strlen(tooltip) > 0)
shape->setToolTip(tooltip);

for (edge_t* edge = agfstout(graph, node); edge != NULL; edge =
agnxtout(graph, edge))
@@ -254,14 +304,14 @@
QPainterPath path;

if (bz.sflag)
- arrow(path, QLineF(gToQ(bz.list[0]), gToQ(bz.sp)),
aggetToQ(edge, "arrowhead", "normal"));
+ arrow(path, QLineF(gToQ(bz.list[0], true), gToQ(bz.sp,
true)), aggetToQ(edge, "arrowhead", "normal"));

- path.moveTo(gToQ(bz.list[0]));
+ path.moveTo(gToQ(bz.list[0], true));
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]));
+ path.cubicTo(gToQ(bz.list[j], true), gToQ(bz.list[j+1],
true), gToQ(bz.list[j+2], true));

if (bz.eflag)
- arrow(path, QLineF(gToQ(bz.list[bz.size-1]), gToQ(bz.ep)),
aggetToQ(edge, "arrowtail", "normal"));
+ arrow(path, QLineF(gToQ(bz.list[bz.size-1], true),
gToQ(bz.ep, true)), aggetToQ(edge, "arrowtail", "normal"));

QGraphicsPathItem* shape = scene->addPath(path);

@@ -273,9 +323,10 @@
}


-Node::Node(const QRectF& rect)
- : QGraphicsRectItem(rect)
+Node::Node(const QPainterPath& path)
+ : QGraphicsPathItem(path)
{
+ // setFlag(ItemIsMovable);
}


@@ -285,7 +336,7 @@
// TODO: rethink painter state handling, see also
QGraphicsView::DontSavePainterState

painter->save();
- QGraphicsRectItem::paint(painter, option, widget);
+ QGraphicsPathItem::paint(painter, option, widget);
painter->restore();

picture.play(painter);

Modified: trunk/qt-graph/src/QGraph.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QGraph.h?rev=54868&r1=54867&r2=54868&view=diff
==============================================================================
--- trunk/qt-graph/src/QGraph.h (original)
+++ trunk/qt-graph/src/QGraph.h Wed Jan 21 18:10:38 2009
@@ -55,7 +55,12 @@
/**
* Transform graphviz point into Qt QPointF.
*/
- QPointF gToQ(const point& p) const;
+ QPointF gToQ(const point& p, bool trans) const;
+
+ /**
+ * Transform graphviz pointf into Qt QPointF.
+ */
+ QPointF gToQ(const pointf& p, bool trans) const;

private:

@@ -67,15 +72,21 @@

void arrow(QPainterPath& path, const QLineF& line, const QString& type);

+ QPolygonF haha1(node_t* node) const;
+
+ QPainterPath haha2(node_t* node) const;
+
+ void drawLabel(const textlabel_t* textlabel, QPainter* painter);
+
};


-class Node : public QGraphicsRectItem
+class Node : public QGraphicsPathItem
{

public:

- Node(const QRectF& rect);
+ Node(const QPainterPath& path);

void paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
QWidget* widget);


--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages