[Kst] extragear/graphics/kst/src/libkstapp

Andrew Walker arwalker at sumusltd.com
Mon Feb 12 21:10:13 CET 2007


SVN commit 632968 by arwalker:

refactor code identified as soup

 M  +1 -57     kst.cpp  
 M  +66 -0     kstviewwindow.cpp  
 M  +1 -0      kstviewwindow.h  


--- trunk/extragear/graphics/kst/src/libkstapp/kst.cpp #632967:632968
@@ -1408,8 +1408,6 @@
 }
 
 
-// FIXME: this redefines soup.  It doesn't handle error conditions correctly
-//        and it's hard to understand (10 levels of nested braces!!).  Refator
 void KstApp::slotFilePrint() {
   KstViewWindow *currentWin = dynamic_cast<KstViewWindow*>(activeWindow());
   int currentPage = 0;
@@ -1580,63 +1578,9 @@
         if (!firstPage && !printer.newPage()) {
           break;
         }
-        if (lineAdjust != 0) {
-          tlv->forEachChild(&Kst2DPlot::pushAdjustLineWidth, lineAdjust, false);
-        }
-        if (monochrome) {
-          tlv->forEachChild2(&Kst2DPlot::pushPlotColors);
-          tlv->forEachChild<const QColor&>(&Kst2DPlot::pushCurveColor, Qt::black, false);
-          // additional pushes for enhanced readability
-          if (enhanceReadability) {
-            Kst2DPlotList plotList = tlv->findChildrenType<Kst2DPlot>(false);
-            for (Kst2DPlotList::Iterator it = plotList.begin(); it != plotList.end(); ++it ) {
-              (*it)->changeToMonochrome(pointStyleOrder, lineStyleOrder, lineWidthOrder, maxLineWidth, pointDensity);
-            }
-          }
-        }
 
-        if (datetimeFooter) {
-          QDateTime dateTime = QDateTime::currentDateTime();
-          QString title = i18n("Page: %1  Name: %2  Date: %3").arg(pages).arg(win->caption()).arg(dateTime.toString(Qt::ISODate));
-          QRect rect(0, 0, size.width(), size.height());
-          QRect rectBounding;
+        win->print(paint, size, pages, lineAdjust, monochrome, enhanceReadability, datetimeFooter,  maintainAspectRatio, pointStyleOrder, lineStyleOrder, lineWidthOrder, maxLineWidth, pointDensity);
 
-          rectBounding = paint.boundingRect(rect, Qt::AlignLeft | Qt::AlignVCenter, title);
-          rect.setTop(size.height() - (2 * rectBounding.height()));
-          paint.drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, title);
-          size.setHeight(rect.top());
-        }
-
-        if (maintainAspectRatio) {
-          const QRect geom(win->view()->geometry());
-          const double ratioWindow = double(geom.width()) / double(geom.height());
-          const double ratioPrinter = double(size.width()) / double(size.height());
-          if (ratioWindow > ratioPrinter) {
-            size.setHeight(int(double(size.width()) / ratioWindow));
-          } else if (ratioWindow < ratioPrinter) {
-            size.setWidth(int(ratioWindow * double(size.height())));
-          }
-        }
-
-        win->view()->resizeForPrint(size);
-        win->view()->paint(paint, QRegion());
-
-        if (lineAdjust != 0) {
-          tlv->forEachChild2(&Kst2DPlot::popLineWidth);
-        }
-        if (monochrome) {
-          tlv->forEachChild2(&Kst2DPlot::popPlotColors);
-          tlv->forEachChild2(&Kst2DPlot::popCurveColor);
-          // additional pops to undo enhanced readability
-          if (enhanceReadability) {
-            Kst2DPlotList plotList = tlv->findChildrenType<Kst2DPlot>(false);
-            for (Kst2DPlotList::Iterator it = plotList.begin(); it != plotList.end(); ++it ) {
-              (*it)->undoChangeToMonochrome(pointStyleOrder, lineStyleOrder, lineWidthOrder);
-            }
-          }
-        }
-        win->view()->revertForPrint();
-        
         firstPage = false;
       }
     }
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewwindow.cpp #632967:632968
@@ -26,6 +26,7 @@
 #include <kprinter.h>
 
 // application specific includes
+#include "kst2dplot.h"
 #include "kstdoc.h"
 #include "kstsettings.h"
 #include "kstviewwindow.h"
@@ -313,6 +314,71 @@
 }
 
 
+void KstViewWindow::print(KstPainter& paint, const QSize& size, int pages, int lineAdjust, bool monochrome, bool enhanceReadability, bool datetimeFooter, bool maintainAspectRatio, int pointStyleOrder, int lineStyleOrder, int lineWidthOrder, int maxLineWidth, int pointDensity) {
+  KstTopLevelViewPtr tlv = kst_cast<KstTopLevelView>(view());
+
+  if (tlv) {
+    if (lineAdjust != 0) {
+      tlv->forEachChild(&Kst2DPlot::pushAdjustLineWidth, lineAdjust, false);
+    }
+    if (monochrome) {
+      tlv->forEachChild2(&Kst2DPlot::pushPlotColors);
+      tlv->forEachChild<const QColor&>(&Kst2DPlot::pushCurveColor, Qt::black, false);
+      // additional pushes for enhanced readability
+      if (enhanceReadability) {
+        Kst2DPlotList plotList = tlv->findChildrenType<Kst2DPlot>(false);
+        for (Kst2DPlotList::Iterator it = plotList.begin(); it != plotList.end(); ++it ) {
+          (*it)->changeToMonochrome(pointStyleOrder, lineStyleOrder, lineWidthOrder, maxLineWidth, pointDensity);
+        }
+      }
+    }
+  
+    if (datetimeFooter) {
+      QDateTime dateTime = QDateTime::currentDateTime();
+      QString title = i18n("Page: %1  Name: %2  Date: %3").arg(pages).arg(caption()).arg(dateTime.toString(Qt::ISODate));
+      QRect rect(0, 0, size.width(), size.height());
+      QRect rectBounding;
+  
+      rectBounding = paint.boundingRect(rect, Qt::AlignLeft | Qt::AlignVCenter, title);
+      rect.setTop(size.height() - (2 * rectBounding.height()));
+      paint.drawText(rect, Qt::AlignLeft | Qt::AlignVCenter, title);
+      size.setHeight(rect.top());
+    }
+  
+    if (maintainAspectRatio) {
+      const QRect geom(view()->geometry());
+      const double ratioWindow = double(geom.width()) / double(geom.height());
+      const double ratioPrinter = double(size.width()) / double(size.height());
+      if (ratioWindow > ratioPrinter) {
+        size.setHeight(int(double(size.width()) / ratioWindow));
+      } else if (ratioWindow < ratioPrinter) {
+        size.setWidth(int(ratioWindow * double(size.height())));
+      }
+    }
+
+    view()->resizeForPrint(size);
+    view()->paint(paint, QRegion());
+
+    if (lineAdjust != 0) {
+      tlv->forEachChild2(&Kst2DPlot::popLineWidth);
+    }
+    if (monochrome) {
+      tlv->forEachChild2(&Kst2DPlot::popPlotColors);
+      tlv->forEachChild2(&Kst2DPlot::popCurveColor);
+      // additional pops to undo enhanced readability
+      if (enhanceReadability) {
+        Kst2DPlotList plotList = tlv->findChildrenType<Kst2DPlot>(false);
+        for (Kst2DPlotList::Iterator it = plotList.begin(); it != plotList.end(); ++it ) {
+          (*it)->undoChangeToMonochrome(pointStyleOrder, lineStyleOrder, lineWidthOrder);
+        }
+      }
+    }
+
+    view()->revertForPrint();
+  }
+}
+
+
 void KstViewWindow::save(QTextStream& ts, const QString& indent) {
   const QRect restoreGeom(restoreGeometry());
   const QRect internalGeom(internalGeometry());
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewwindow.h #632967:632968
@@ -50,6 +50,7 @@
     void setPaused(bool paused);
     void togglePaused();
     void save(QTextStream& ts, const QString& indent = QString::null);
+    void print( KstPainter& paint, const QSize& size, int pages, int lineAdjust, bool monochrome, bool enhanceReadability, bool dateTimeFooter, bool maintainAspectRatio, int pointStyleOrder, int lineStyleOrder, int lineWidthOrder, int maxLineWidth, int pointDensity );
     KstTopLevelViewPtr view() const;
     virtual void setCaption(const QString& szCaption);
 


More information about the Kst mailing list