Mailinglist Archive: yast-commit (819 mails)

< Previous Next >
[yast-commit] r54884 - in /trunk/qt-graph: examples/colors.dot src/QGraph.cc src/QGraph.h
  • From: aschnell@xxxxxxxxxxxxxxxx
  • Date: Thu, 22 Jan 2009 11:07:48 -0000
  • Message-id: <E1LPxPY-0008Hw-RK@xxxxxxxxxxxxxxxx>
Author: aschnell
Date: Thu Jan 22 12:07:48 2009
New Revision: 54884

URL: http://svn.opensuse.org/viewcvs/yast?rev=54884&view=rev
Log:
- added basic color support

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

Added: trunk/qt-graph/examples/colors.dot
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/examples/colors.dot?rev=54884&view=auto
==============================================================================
--- trunk/qt-graph/examples/colors.dot (added)
+++ trunk/qt-graph/examples/colors.dot Thu Jan 22 12:07:48 2009
@@ -0,0 +1,8 @@
+digraph
+{
+ node [style="filled"];
+
+ A;
+ B [color="red", fillcolor="yellow", fontcolor="red"];
+ C [color="#0000ff", fillcolor="#ccccff", fontcolor="#000000"];
+}

Modified: trunk/qt-graph/src/QGraph.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QGraph.cc?rev=54884&r1=54883&r2=54884&view=diff
==============================================================================
--- trunk/qt-graph/src/QGraph.cc (original)
+++ trunk/qt-graph/src/QGraph.cc Thu Jan 22 12:07:48 2009
@@ -113,18 +113,27 @@


QString
-aggetToQ(void* obj, char* name, const char* fallback)
+QGraph::aggetToQString(void* obj, const char* name, const char* fallback) const
{
- const char* tmp = agget(obj, name);
- if (tmp == NULL || tmp[0] == '\0')
- return fallback;
- else
- return QString(tmp);
+ const char* tmp = agget(obj, const_cast<char*>(name));
+ if (tmp == NULL || strlen(tmp) == 0)
+ return QString(fallback);
+ return QString(tmp);
+}
+
+
+QColor
+QGraph::aggetToQColor(void* obj, const char* name, const char* fallback) const
+{
+ const char* tmp = agget(obj, const_cast<char*>(name));
+ if (tmp == NULL || strlen(tmp) == 0)
+ return QColor(fallback);
+ return QColor(tmp);
}


void
-QGraph::arrow(QPainterPath& path, const QLineF& line, const QString& type)
+QGraph::arrow(QPainterPath& path, const QLineF& line, const QString& type)
const
{
if (type == "normal")
{
@@ -215,7 +224,6 @@
}


-
QPainterPath
QGraph::haha2(node_t* node) const
{
@@ -244,7 +252,7 @@


void
-QGraph::drawLabel(const textlabel_t* textlabel, QPainter* painter)
+QGraph::drawLabel(const textlabel_t* textlabel, QPainter* painter) const
{
painter->setPen(textlabel->fontcolor);

@@ -271,10 +279,6 @@
size = rect.size();


- QPen pen1("#0000ff");
- pen1.setWidthF(1);
- QBrush brush1("#bbbbff");
-
QPen pen2(Qt::black);
pen2.setWidthF(1);

@@ -287,16 +291,20 @@

shape->setPos(gToQ(ND_coord_i(node), true));

- shape->setPen(pen1);
- shape->setBrush(brush1);
+ QPen pen(aggetToQColor(node, "color", "black"));
+ pen.setWidthF(1.0);
+ shape->setPen(pen);
+
+ QBrush brush(aggetToQColor(node, "fillcolor", "gray"));
+ shape->setBrush(brush);

QPainter painter;
painter.begin(&shape->picture);
drawLabel(ND_label(node), &painter);
painter.end();

- const char* tooltip = agget(node, "tooltip");
- if (tooltip && strlen(tooltip) > 0)
+ QString tooltip = aggetToQString(node, "tooltip", "");
+ if (!tooltip.isEmpty())
shape->setToolTip(tooltip);

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

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

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));

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

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


Modified: trunk/qt-graph/src/QGraph.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/qt-graph/src/QGraph.h?rev=54884&r1=54883&r2=54884&view=diff
==============================================================================
--- trunk/qt-graph/src/QGraph.h (original)
+++ trunk/qt-graph/src/QGraph.h Thu Jan 22 12:07:48 2009
@@ -52,6 +52,14 @@
void wheelEvent(QWheelEvent* event);
void scaleView(qreal scaleFactor);

+private:
+
+ void init();
+
+ QGraphicsScene* scene;
+
+ QSizeF size;
+
/**
* Transform graphviz point into Qt QPointF.
*/
@@ -62,21 +70,17 @@
*/
QPointF gToQ(const pointf& p, bool trans) const;

-private:
-
- void init();
+ QString aggetToQString(void* obj, const char* name, const char* fallback)
const;

- QGraphicsScene* scene;
-
- QSizeF size;
+ QColor aggetToQColor(void* obj, const char* name, const char* fallback)
const;

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

QPolygonF haha1(node_t* node) const;

QPainterPath haha2(node_t* node) const;

- void drawLabel(const textlabel_t* textlabel, QPainter* painter);
+ void drawLabel(const textlabel_t* textlabel, QPainter* painter) const;

};


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

< Previous Next >
This Thread
  • No further messages