[Kst] extragear/graphics/kst/kst

Barth Netterfield netterfield at astro.utoronto.ca
Sun Oct 23 08:17:04 CEST 2005


SVN commit 473277 by netterfield:

size() for plot labels now returns the rotated dimensions.
PlotLabel rotation now works (could use some tweaking).



 M  +5 -10     kst2dplot.cpp  
 M  +2 -1      kstplotlabel.cpp  
 M  +1 -0      kstplotlabel.h  


--- trunk/extragear/graphics/kst/kst/kst2dplot.cpp #473276:473277
@@ -5710,16 +5710,13 @@
         p.restore();
       } else if (_xTickLabel->rotation() > 0) {
         p.save();
-        p.translate(d2i(xTickPos-_xTickLabel->lineSpacing()*(0.25 + 0.25*sin(_xTickLabel->rotation()*M_PI/180.0))), yTickPos);
+        p.translate(xTickPos-0.5*_xTickLabel->lineSpacing()*sin(_xTickLabel->rotation()*M_PI/180.0), yTickPos);
         _xTickLabel->paint(p);
         p.restore();
       } else if (_xTickLabel->rotation() < 0) {
         p.save();
-        p.translate(d2i(xTickPos - _xTickLabel->size().width()*cos(_xTickLabel->rotation()*M_PI/180.0)+
-            _xTickLabel->lineSpacing()*(0.25 + 0.5*sin(_xTickLabel->rotation()*M_PI/180.0)))
-            , yTickPos);
+        p.translate(xTickPos - _xTickLabel->size().width()-0.5*_xTickLabel->lineSpacing()*sin(_xTickLabel->rotation()*M_PI/180.0), yTickPos);
         _xTickLabel->paint(p);
-        printf("%g %g\n", double(_xTickLabel->rotation()), double(_xTickLabel->size().width()));
         p.restore();
       }
     }
@@ -5771,18 +5768,16 @@
       _yTickLabel->setText(tpy.labels[i - tpy.iLo]);
       p.save();
       
-      if (_yTickLabel->rotation() == 0) {
+      if (_yTickLabel->rotation() == 0 || _yTickLabel->rotation() <-89 || _yTickLabel->rotation() > 89) {
         p.translate(xTickPos - _yTickLabel->size().width(), d2i(yTickPos) - _yTickLabel->size().height() / 2);
         _yTickLabel->paint(p);
         p.restore();
       } else if (_yTickLabel->rotation() < 0) {
-        p.translate(xTickPos - _yTickLabel->size().width()*cos(_yTickLabel->rotation()*M_PI/180.0) + _yTickLabel->size().height()*sin(_yTickLabel->rotation()*M_PI/180.0),
-                    d2i(yTickPos));
+        p.translate(xTickPos - _yTickLabel->size().width(), d2i(yTickPos)-_yTickLabel->lineSpacing()/2);
         _yTickLabel->paint(p);
         p.restore();
       } else if (_yTickLabel->rotation() > 0) {
-        p.translate(xTickPos - _yTickLabel->size().width()*cos(_yTickLabel->rotation()*M_PI/180.0) - _yTickLabel->size().height()*sin(_yTickLabel->rotation()*M_PI/180.0),
-                    d2i(yTickPos));
+        p.translate(xTickPos - _yTickLabel->size().width(), d2i(yTickPos) - _yTickLabel->size().height()+_yTickLabel->lineSpacing()/2);
         _yTickLabel->paint(p);
         p.restore();
       }
--- trunk/extragear/graphics/kst/kst/kstplotlabel.cpp #473276:473277
@@ -179,7 +179,8 @@
 
 
 QSize KstPlotLabel::size() const {
-  return QSize(_textWidth, _textHeight);
+  double r = fabs(_rotation*M_PI/180.0);
+  return QSize(_textWidth*cos(r) + _textHeight*sin(r), _textHeight*cos(r) + _textWidth*sin(r));
 }
 
 void KstPlotLabel::load(const QDomElement& e) {
--- trunk/extragear/graphics/kst/kst/kstplotlabel.h #473276:473277
@@ -78,6 +78,7 @@
     int _fontSize;
     int _absFontSize;
     int _textWidth, _textHeight, _ascent;
+    
     KstLJustifyType _justify;
     Label::Parsed *_parsed;
     int _lineSpacing;


More information about the Kst mailing list