[Kst] branches/work/kst/portto4/kst/src/libkstapp

Mike Fenton mike at staikos.net
Mon Aug 11 20:22:42 CEST 2008


SVN commit 845465 by fenton:

Fix for saving of backgrounds for viewitems.


 M  +30 -6     viewitem.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #845464:845465
@@ -111,6 +111,19 @@
   xml.writeStartElement("brush");
   xml.writeAttribute("color", brush().color().name());
   xml.writeAttribute("style", QVariant(brush().style()).toString());
+  if (brush().gradient()) {
+    QString stopList;
+    foreach(QGradientStop stop, brush().gradient()->stops()) {
+      qreal point = (qreal)stop.first;
+      QColor color = (QColor)stop.second;
+
+      stopList += QString::number(point);
+      stopList += ",";
+      stopList += color.name();
+      stopList += ",";
+    }
+    xml.writeAttribute("gradient", stopList);
+  }
   xml.writeEndElement();
 }
 
@@ -143,14 +156,25 @@
     } else if (xml.name().toString() == "brush") {
       knownTag = true;
       QBrush brush;
-      av = attrs.value("color");
+      av = attrs.value("gradient");
       if (!av.isNull()) {
-          brush.setColor(QColor(av.toString()));
+        QStringList stopInfo = av.toString().split(',', QString::SkipEmptyParts);
+        QLinearGradient gradient(1,0,0,0);
+        gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
+        for (int i = 0; i < stopInfo.size(); i+=2) {
+          gradient.setColorAt(stopInfo.at(i).toDouble(), QColor(stopInfo.at(i+1)));
+        }
+        brush = QBrush(gradient);
+      } else {
+        av = attrs.value("color");
+        if (!av.isNull()) {
+            brush.setColor(QColor(av.toString()));
+        }
+        av = attrs.value("style");
+        if (!av.isNull()) {
+          brush.setStyle((Qt::BrushStyle)av.toString().toInt());
+        }
       }
-      av = attrs.value("style");
-      if (!av.isNull()) {
-        brush.setStyle((Qt::BrushStyle)av.toString().toInt());
-      }
       setBrush(brush);
     } else if (xml.name().toString() == "pen") {
       knownTag = true;


More information about the Kst mailing list