[Kst] extragear/graphics/kst/kst

Barth Netterfield netterfield at astro.utoronto.ca
Sat Nov 5 18:04:52 CET 2005


SVN commit 478013 by netterfield:

Make view legend rendering work.


 M  +1 -1      kst2dplot.cpp  
 M  +1 -1      kstbasecurve.h  
 M  +2 -0      kstvcurve.cpp  
 M  +31 -7     kstviewlegend.cpp  


--- trunk/extragear/graphics/kst/kst/kst2dplot.cpp #478012:478013
@@ -579,7 +579,7 @@
   Legend = new KstLegend;
   Legend->setJustification(CxBy);
 
-#if 1
+#if 0
   KstViewLegendPtr vlp = new KstViewLegend();
   appendChild(KstViewObjectPtr(vlp), true);
   
--- trunk/extragear/graphics/kst/kst/kstbasecurve.h #478012:478013
@@ -103,7 +103,7 @@
     virtual Label::Parsed *parsedLegendTag() {return NULL;}
     
     // just store the size of the legend tag here.  The viewLegend actually uses and calculates it.
-    virtual QSize legendLabeSize() const {return _legendLabelSize;}
+    virtual QSize legendLabelSize() const {return _legendLabelSize;}
     virtual void setLegendLabelSize(QSize ls) {_legendLabelSize = ls;}
   protected:
  
--- trunk/extragear/graphics/kst/kst/kstvcurve.cpp #478012:478013
@@ -1535,6 +1535,7 @@
 }
 
 void KstVCurve::paintLegendSymbol(QPainter *p, const QRect& bound) {
+  p->save();
   if (hasLines()) {
     // draw a line from left to right centered vertically
     p->setPen(QPen(color(), lineWidth(), KstLineStyle[lineStyle()]));
@@ -1548,6 +1549,7 @@
     tmppoint.setType(Point.type());
     tmppoint.draw(p, bound.left() + bound.width()/2, bound.top() + bound.height()/2, lineWidth(), 600);
   }
+  p->restore();
 }
 
 Label::Parsed *KstVCurve::parsedLegendTag(){
--- trunk/extragear/graphics/kst/kst/kstviewlegend.cpp #478012:478013
@@ -52,7 +52,7 @@
 : KstBorderedViewObject("Label") {
   _rotation = 0;
   _justify = 0L;
-  _vertical = true;
+  _vertical = false;
   _fontName = KstApp::inst()->defaultFont();
   _symbolFontName = "Symbol";
   _fontSize = 0;
@@ -163,11 +163,36 @@
     for (int i=0; i<Curves.count(); i++) {
       p.save();
       if (Curves[i]->parsedLegendTag()) {
-        p.translate(6*_ascent, i*(rc.fontHeight()+_ascent));
+        p.translate(_ascent/2, _ascent/4 + (i)*(rc.fontHeight()+_ascent/4));
+        QRect symbolBound(QPoint(0,0), 
+                          QSize(16*_ascent/4, rc.fontHeight()));
+
+        Curves[i]->paintLegendSymbol(&p, symbolBound);
+        p.translate(9*_ascent/2, 0);
+        rc.x = 0;//Curves[i]->legendLabelSize().width() / 2;
+        rc.y = _ascent;
+        rc.xStart = rc.x;
         renderLabel(rc, Curves[i]->parsedLegendTag()->chunk);
       }
       p.restore();
     }
+  } else {
+    p.save();
+    p.translate(_ascent/2, _ascent/4);
+    for (int i=0; i<Curves.count(); i++) {
+      if (Curves[i]->parsedLegendTag()) {
+        QRect symbolBound(QPoint(0,0), 
+                          QSize(16*_ascent/4, rc.fontHeight()));
+        Curves[i]->paintLegendSymbol(&p, symbolBound);
+        p.translate(9*_ascent/2, 0);
+        rc.x = 0;//Curves[i]->legendLabelSize().width() / 2;
+        rc.y = _ascent;
+        rc.xStart = rc.x;
+        renderLabel(rc, Curves[i]->parsedLegendTag()->chunk);
+        p.translate(Curves[i]->legendLabelSize().width() + _ascent,0);
+      }
+    }
+    p.restore();
   }
   
   QApplication::syncX();
@@ -259,7 +284,7 @@
   RenderContext rc(_fontName, _symbolFontName, _absFontSize, 0L);
   _ascent = rc.fontAscent();
   if (_vertical) {
-    _textHeight = Curves.count()*rc.fontHeight() + (Curves.count()-1)*_ascent;
+    _textHeight = Curves.count()*rc.fontHeight() + (Curves.count()-1)*_ascent/4;
   } else {
     _textWidth += Curves.count()*_ascent;
   }
@@ -360,12 +385,11 @@
   computeTextSize();
   
   if (_vertical) {
-    width = _textWidth + 2*_ascent + 5*_ascent;
-    height = _textHeight + 2*_ascent;
+    width = _textWidth + _ascent/2 + 5*_ascent;
   } else {
-    width = _textWidth + 2*_ascent + 5*_ascent*Curves.count();
+    width = _textWidth + _ascent/2 + 9*_ascent*Curves.count()/2;
   }
-  height = _textHeight + 2*_ascent;
+  height = _textHeight + _ascent/2;
   
   QSize sz(width, height);
   if (_parent) {


More information about the Kst mailing list