[kgraphviewer-devel] extragear/graphics/kgraphviewer/src/part

Gaël de Chalendar kleag at free.fr
Sun Oct 10 14:17:46 CEST 2010


SVN commit 1184473 by kleag:

Correctly set line width and color for edges and width for nodes

 M  +13 -2     canvasedge.cpp  
 M  +23 -1     canvaselement.cpp  
 M  +1 -0      graphedge.cpp  


--- trunk/extragear/graphics/kgraphviewer/src/part/canvasedge.cpp #1184472:1184473
@@ -356,6 +356,17 @@
         lineWidth = edge()->style().mid(12, edge()->style().length()-1-12).toInt(&ok);
         pen.setWidth(int(lineWidth * widthScaleFactor));
       }
+      if (edge()->attributes().contains("penwidth"))
+      {
+        bool ok;
+        lineWidth = edge()->attributes()["penwidth"].toInt(&ok);
+        pen.setWidth(int(lineWidth * widthScaleFactor));
+      }
+      if (edge()->attributes().contains("color"))
+      {
+        kDebug() << "set edge color to " << QColor(edge()->attributes()["color"]).name();
+        lineColor = QColor(edge()->attributes()["color"]);
+      }
       for (int splineNum = 0; splineNum < edge()->colors().count() || (splineNum==0 && edge()->colors().count()==0); splineNum++)
       {
         QPolygonF points(dro.integers[0]);
@@ -398,10 +409,10 @@
 //           kDebug() << edge()->fromNode()->id() << "->" << edge()->toNode()->id()  << p;
           allPoints.append(p);
         }
-//         kDebug() << "Setting pen color to " << edge()->color(splineNum);
+        kDebug() << "Setting pen color to " << edge()->color(splineNum);
         if (splineNum != 0)
           lineColor = Dot2QtConsts::componentData().qtColor(edge()->color(splineNum));
-        pen.setColor(splineNum);
+        pen.setColor(lineColor);
         p->save();
 //         p->setBrush(Dot2QtConsts::componentData().qtColor(edge()->color(0)));
         p->setBrush(Qt::NoBrush);
--- trunk/extragear/graphics/kgraphviewer/src/part/canvaselement.cpp #1184472:1184473
@@ -211,6 +211,13 @@
 {
   Q_UNUSED(option)
   Q_UNUSED(widget)
+  /// computes the scaling of line width
+  qreal widthScaleFactor = (m_scaleX+m_scaleY)/2;
+  if (widthScaleFactor < 1)
+  {
+    widthScaleFactor = 1;
+  }
+  
   QString msg;
   QTextStream dd(&msg);
   foreach (const DotRenderOp &op, element()->renderOperations())
@@ -265,6 +272,7 @@
     }
     else if (dro.renderop == "e" || dro.renderop == "E")
     {
+      QPen pen = p->pen();
       qreal w = m_scaleX * dro.integers[2] * 2;
       qreal h = m_scaleY * dro.integers[3] * 2;
       qreal x = m_xMargin + ((dro.integers[0]/*%m_wdhcf*/)*m_scaleX) - w/2;
@@ -272,7 +280,15 @@
       QRectF rect(x,y,w,h);
       p->save();
       p->setBrush(backColor);
-      p->setPen(lineColor);
+      pen.setColor(lineColor);
+      if (element()->attributes().contains("penwidth"))
+      {
+        bool ok;
+        int lineWidth = element()->attributes()["penwidth"].toInt(&ok);
+        pen.setWidth(int(lineWidth * widthScaleFactor));
+      }
+      p->setPen(pen);
+      
 //       kDebug() << element()->id() << "drawEllipse" << lineColor << backColor << rect;
 //       rect = QRectF(0,0,100,100);
       p->drawEllipse(rect);
@@ -304,6 +320,12 @@
         pen.setStyle(Qt::SolidLine);
         pen.setWidth(2);
       }
+      if (element()->attributes().contains("penwidth"))
+      {
+        bool ok;
+        int lineWidth = element()->attributes()["penwidth"].toInt(&ok);
+        pen.setWidth(int(lineWidth * widthScaleFactor));
+      }
       else if (element()->style() != "filled")
       {
         pen.setStyle(Dot2QtConsts::componentData().qtPenStyle(element()->style()));
--- trunk/extragear/graphics/kgraphviewer/src/part/graphedge.cpp #1184472:1184473
@@ -140,6 +140,7 @@
   Agsym_t *attr = agfstattr(edge);
   while(attr)
   {
+    kDebug() /*<< edge->name*/ << ":" << attr->name << agxget(edge,attr->index);
     m_attributes[attr->name] = agxget(edge,attr->index);
     attr = agnxtattr(edge,attr);
   }


More information about the kgraphviewer-devel mailing list