[Kst] [Bug 129399] Legends and labels do not print properly

Andrew Walker arwalker at sumusltd.com
Fri Jan 5 23:37:40 CET 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=129399         
arwalker sumusltd com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From arwalker sumusltd com  2007-01-05 23:37 -------
SVN commit 620401 by arwalker:

BUG:129399 Correctly handle the printing of legends and labels. This wasn't working properly as the lineWidthAdjustmentFactor() for the border wasn't taken into account when printing.

 M  +9 -0      kstborderedviewobject.cpp  
 M  +2 -1      kstborderedviewobject.h  
 M  +21 -14    kstviewlabel.cpp  
 M  +1 -0      kstviewlabel.h  
 M  +16 -6     kstviewlegend.cpp  
 M  +1 -0      kstviewlegend.h  


--- trunk/extragear/graphics/kst/src/libkstapp/kstborderedviewobject.cpp #620400:620401
 @ -186,6 +186,15  @
 }
 
 
+void KstBorderedViewObject::setContentsRectForDevice(const KstPainter& painter, QRect& rect) {
+  const int mpb = (_margin + _padding + _borderWidth) * painter.lineWidthAdjustmentFactor();
+  _geom.setX(rect.left() - mpb);
+  _geom.setY(rect.top() - mpb);
+  _geom.setWidth(rect.width() + 2 * mpb);
+  _geom.setHeight(rect.height() + 2 * mpb);
+}
+
+
 void KstBorderedViewObject::setContentsRect(QRect& rect) {
   const int mpb = _margin + _padding + _borderWidth;
   _geom.setX(rect.left() - mpb);
--- trunk/extragear/graphics/kst/src/libkstapp/kstborderedviewobject.h #620400:620401
 @ -104,7 +104,8  @
     virtual void paintSelf(KstPainter& p, const QRegion& bounds);
 
     QRect contentsRectForDevice(const KstPainter& painter) const;
-
+    virtual void setContentsRectForDevice(const KstPainter& painter, QRect& rect);
+  
   protected:
     virtual void readBinary(QDataStream& str);
     virtual void writeBinary(QDataStream& str);
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlabel.cpp #620400:620401
 @ -382,16 +382,15  @
   if (p.type() == KstPainter::P_PRINT || p.type() == KstPainter::P_EXPORT) {
     int absFontSizeOld = _absFontSize;
     
-    adjustSizeForText(_parent->geometry());
+    QRect cr(contentsRectForDevice(p));
+    cr.setSize(sizeForText(_parent->geometry()));
+    setContentsRectForDevice(p, cr);    
     KstBorderedViewObject::paintSelf(p, bounds);
-    const QRect geom(contentsRectForDevice(p));
-    p.setViewport(geom);
-    p.setWindow(0, 0, geom.width(), geom.height());
-
+    
+    p.translate(cr.left(), cr.top());
     if (!_transparent) {
-      p.fillRect(0, 0, geom.width(), geom.height(), backgroundColor());
+      p.fillRect(0, 0, cr.width(), cr.height(), backgroundColor());
     }
-
     drawToPainter(_parsed, p);
     
     _absFontSize = absFontSizeOld;
 @ -463,6 +462,13  @
 
 
 void KstViewLabel::adjustSizeForText(QRect w) {
+  QRect cr(contentsRect());
+  cr.setSize(sizeForText(w));
+  setContentsRect(cr);
+}
+
+
+QSize KstViewLabel::sizeForText(QRect w) {
   double x_s, y_s;
   
   x_s = y_s = _fontSize + (double)KstSettings::globalSettings()->plotFontSize;
 @ -492,12 +498,13  @
   }
  
   QSize sz(kMax(1, _textWidth), kMax(1, _textHeight));
+
   if (int(_rotation) != 0 && int(_rotation) != 180) {
     QPointArray pts(4);
     pts[0] = QPoint(0, 0);
     pts[1] = QPoint(0, _textHeight);
-    pts[2] = QPoint(_textWidth, 0);
-    pts[3] = QPoint(_textWidth, _textHeight);
+    pts[2] = QPoint(_textWidth, _textHeight);
+    pts[3] = QPoint(_textWidth, 0);
     double theta = M_PI * (int(_rotation) % 360) / 180;
     double sina = sin(theta);
     double cosa = cos(theta);
 @ -507,26 +514,26  @
 
     if (_parent) {
       QRect r(position(), pts.boundingRect().size());
+      r.setSize(r.size() + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10));
       sz = r.intersect(_parent->geometry()).size();
     } else {
       sz = pts.boundingRect().size();
+      sz += QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10);
     }
   } else {
     if (_parent) {
       QRect r(position(), sz);
+      r.setSize(r.size() + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10));
       sz = r.intersect(_parent->geometry()).size();
     }
   }
-
-  QRect cr(contentsRect());
-  cr.setSize(sz + QSize(2 * _labelMargin * _ascent / 10, 2 * _labelMargin * _ascent / 10));
-  setContentsRect(cr);
+    
+  return sz;
 }
 
 
 bool KstViewLabel::layoutPopupMenu(KPopupMenu *menu, const QPoint& pos, KstViewObjectPtr topLevelParent) {
   KstViewObject::layoutPopupMenu(menu, pos, topLevelParent);
-  //menu->insertItem(i18n("&Adjust Size"), this, SLOT(adjustSizeForText()));
   return true;
 }
 
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlabel.h #620400:620401
 @ -102,6 +102,7  @
 
   public slots:
     void adjustSizeForText(QRect w);
+    QSize sizeForText(QRect w);
     void reparse();
 
   protected:
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlegend.cpp #620400:620401
 @ -363,14 +363,17  @
 void KstViewLegend::paintSelf(KstPainter& p, const QRegion& bounds) {
   if (p.type() == KstPainter::P_PRINT || p.type() == KstPainter::P_EXPORT) {
     p.save();
-    adjustSizeForText(_parent->geometry());
+    QRect cr(contentsRectForDevice(p));
+    cr.setSize(sizeForText(_parent->geometry()));
+    setContentsRectForDevice(p, cr);    
     KstBorderedViewObject::paintSelf(p, bounds);
-    const QRect cr(contentsRectForDevice(p));
+    
     p.translate(cr.left(), cr.top());
     if (!_transparent) {
       p.fillRect(0, 0, cr.width(), cr.height(), _backgroundColor);
     }
     drawToPainter(p);
+    
     p.restore();
   } else {
     const QRect cr(contentsRect());
 @ -440,6 +443,13  @
 
 
 void KstViewLegend::adjustSizeForText(QRect w) {
+  QRect cr(contentsRect());
+  cr.setSize(sizeForText(w));
+  setContentsRect(cr);
+}
+
+
+QSize KstViewLegend::sizeForText(QRect w) {
   double x_s, y_s;
 
   x_s = y_s = _fontSize + (double)KstSettings::globalSettings()->plotFontSize;
 @ -480,15 +490,15  @
   }
 
   QSize sz(width, height);
+  
+  sz += QSize(2 * _legendMargin * _ascent / 10, 2 * _legendMargin * _ascent / 10);
 
   if (_parent) {
     QRect r(position(), sz);
     sz = r.intersect(_parent->geometry()).size();
   }
-
-  QRect cr(contentsRect());
-  cr.setSize(sz + QSize(2 * _legendMargin * _ascent / 10, 2 * _legendMargin * _ascent / 10));
-  setContentsRect(cr);
+    
+  return sz;
 }
 
 void KstViewLegend::modifiedLegendEntry() {
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewlegend.h #620400:620401
 @ -101,6 +101,7  @
 
   public slots:
     void adjustSizeForText(QRect w);
+    QSize sizeForText(QRect w);
     void modifiedLegendEntry(void);
 
   protected:


More information about the Kst mailing list