Author: aschnell Date: Tue Jan 20 12:49:30 2009 New Revision: 54792 URL: http://svn.opensuse.org/viewcvs/yast?rev=54792&view=rev Log: - using QPicture for nodes Modified: trunk/qt-graph/src/QGraph.cc trunk/qt-graph/src/QGraph.h Modified: trunk/qt-graph/src/QGraph.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QGraph.cc?rev=54792&r1=54791&r2=54792&view=diff ============================================================================== --- trunk/qt-graph/src/QGraph.cc (original) +++ trunk/qt-graph/src/QGraph.cc Tue Jan 20 12:49:30 2009 @@ -220,30 +220,32 @@ QRectF rect(0.0, 0.0, 72.0*ND_width(node), 72.0*ND_height(node)); rect.moveCenter(gToQ(ND_coord_i(node))); - QGraphicsItem* item = NULL; + Node* shape = NULL; if (strcmp(ND_shape(node)->name, "ellipse") == 0) { - Node* shape = new Node(rect, ND_label(node)->text); + shape = new Node(rect); scene->addItem(shape); shape->setPen(pen1); shape->setBrush(brush1); - shape->setLabelPen(QPen(Qt::blue)); - item = shape; } else { - Node* shape = new Node(rect, ND_label(node)->text); + shape = new Node(rect); scene->addItem(shape); shape->setPen(pen1); shape->setBrush(brush1); - shape->setLabelPen(QPen(Qt::black)); - item = shape; } + QPainter painter; + painter.begin(&shape->picture); + painter.setPen(Qt::black); + painter.drawText(rect, Qt::AlignCenter | Qt::AlignHCenter, ND_label(node)->text); + painter.end(); + const char* tooltip = agget(node, "tooltip"); if (tooltip && tooltip[0] != '\0') - item->setToolTip(tooltip); + shape->setToolTip(tooltip); for (edge_t* edge = agfstout(graph, node); edge != NULL; edge = agnxtout(graph, edge)) { @@ -275,26 +277,22 @@ } -Node::Node(const QRectF& rect, const QString& label) - : QGraphicsRectItem(rect), - label(label) -{ -} - - -void -Node::setLabelPen(const QPen& tmp) +Node::Node(const QRectF& rect) + : QGraphicsRectItem(rect) { - labelPen = tmp; } void Node::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { + // TODO: rethink painter state handling, see also QGraphicsView::DontSavePainterState + + painter->save(); QGraphicsRectItem::paint(painter, option, widget); - painter->setPen(labelPen); - painter->drawText(rect(), Qt::AlignCenter | Qt::AlignHCenter, label); + 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=54792&r1=54791&r2=54792&view=diff ============================================================================== --- trunk/qt-graph/src/QGraph.h (original) +++ trunk/qt-graph/src/QGraph.h Tue Jan 20 12:49:30 2009 @@ -29,6 +29,7 @@ #include <QGraphicsScene> #include <QGraphicsRectItem> #include <QToolButton> +#include <QPicture> class QGraph : public QGraphicsView @@ -76,16 +77,11 @@ public: - Node(const QRectF& rect, const QString& label); - - void setLabelPen(const QPen& labelPen); + Node(const QRectF& rect); void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); -private: - - QString label; - QPen labelPen; + QPicture picture; }; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org