[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Mon Aug 9 22:55:47 CEST 2004


CVS commit by arwalker: 

Added ability to display rotated labels on the x-axis and y-axis. This feature is not accessible through the UI interface, so can not be used. If the feature is considered desirable the UI can be simply added.


  M +19 -6     kst2dplot.cpp   1.215
  M +18 -0     kstlabel.cpp   1.40
  M +3 -1      kstlabel.h   1.27


--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.214:1.215
@@ -1087,6 +1087,6 @@ void Kst2DPlot::genAxisTickLabels(QPaint
     dMaxWidth = Label->rotation();
     Label->setText(strTmp);
-    dWidth  = Label->width(p);
-    dHeight = Label->lineSpacing(p);
+    dWidth  = Label->rotatedWidth(p);
+    dHeight = Label->rotatedHeight(p);
     if (dWidth > dMaxWidth) {
       dMaxWidth = dWidth;
@@ -1128,6 +1128,6 @@ void Kst2DPlot::genAxisTickLabels(QPaint
       labelList.append(strTmp);
       Label->setText(strTmp);
-      dWidth  = Label->width(p);
-      dHeight = Label->lineSpacing(p);
+      dWidth  = Label->rotatedWidth(p);
+      dHeight = Label->rotatedHeight(p);
       if (dWidth > dMaxWidth) {
         dMaxWidth = dWidth;
@@ -4468,5 +4468,11 @@ void Kst2DPlot::plotAxes(QPainter& p, do
   for (i=iLoLabelIndex; i<iHiLabelIndex; i++) {
     XTickLabel->setText(labelList[i-iLoLabelIndex]);
+    if (XTickLabel->rotation() == 0) {
     XTickLabel->draw(p, d2i(x_orig_px + (double)i * xtick_px), yTickPos);
+    } else if (XTickLabel->rotation() > 0) {
+      XTickLabel->draw(p, d2i(x_orig_px + (double)i * xtick_px + (0.5 * XTickLabel->rotatedWidth(p))), yTickPos + d2i(0.25 * XTickLabel->rotatedHeight(p)));
+    } else if (XTickLabel->rotation() < 0) {
+      XTickLabel->draw(p, d2i(x_orig_px + (double)i * xtick_px - (0.5 * XTickLabel->rotatedWidth(p))), yTickPos + d2i(0.25 * XTickLabel->rotatedHeight(p)));
+    }
   }
 
@@ -4484,6 +4490,12 @@ void Kst2DPlot::plotAxes(QPainter& p, do
   for (i=iLoLabelIndex; i<iHiLabelIndex; i++) {
     YTickLabel->setText(labelList[i-iLoLabelIndex]);
+    if (YTickLabel->rotation() == 0) {
+      YTickLabel->draw(p, xTickPos, d2i(y_orig_px - (double)i * ytick_px));
+    } else if (YTickLabel->rotation() > 0) {
+      YTickLabel->draw(p, xTickPos, d2i(y_orig_px - (double)i * ytick_px));
+    } else if (YTickLabel->rotation() < 0) {
     YTickLabel->draw(p, xTickPos, d2i(y_orig_px - (double)i * ytick_px));
   }
+  }
 }
 

--- kdeextragear-2/kst/kst/kstlabel.cpp  #1.39:1.40
@@ -172,4 +172,22 @@ int KstLabel::ascent(QPainter &p) {
 }
 
+int KstLabel::rotatedWidth(QPainter &p) {
+  double  dWidth;
+
+  dWidth  = fabs((double)width(p) * cos(rotationRadians()));
+  dWidth += fabs((double)lineSpacing(p) * sin(rotationRadians()));
+
+  return (int)dWidth;
+}
+
+int KstLabel::rotatedHeight(QPainter &p) {
+  double  dHeight;
+
+  dHeight  = fabs((double)width(p) * sin(rotationRadians()));
+  dHeight += fabs((double)lineSpacing(p) * cos(rotationRadians()));
+
+  return (int)dHeight;
+}
+
 // FIXME: expensive - cache it?
 int KstLabel::lineSpacing(QPainter &p) {

--- kdeextragear-2/kst/kst/kstlabel.h  #1.26:1.27
@@ -55,9 +55,11 @@ public:
   int width(QPainter &p);
   int ascent(QPainter &p);
+  int rotatedWidth(QPainter &p);
+  int rotatedHeight(QPainter &p);
   int lineSpacing(QPainter &p);
 
   const QString& text() const;
   float rotation() const {return Rotation;}
-  float rotationRadians() const {return 3.1415926535897932333796 * Rotation / 180.0;}
+  double rotationRadians() const {return 3.1415926535897932333796 * (double)Rotation / 180.0;}
   
   const QColor& color() const;





More information about the Kst mailing list