[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Fri Mar 12 18:23:43 CET 2004


CVS commit by arwalker: 

Added functionality to allow the ELOG plugin to request a view capture by sending an event.


  M +9 -0      kstevents.h   1.3
  M +53 -2     kstview.cpp   1.86
  M +2 -1      kstview.h   1.27


--- kdeextragear-2/kst/kst/kstevents.h  #1.2:1.3
@@ -20,6 +20,15 @@
 
 #include <qevent.h>
+#include <qdatastream.h>
 
 #define KstEventTypeThread     (QEvent::User + 1)
+#define KstELOGCaptureEvent    (QEvent::User + 2)
+#define KstELOGConfigureEvent  (QEvent::User + 3)
+
+typedef struct KstELOGCaptureStruct {
+  QBuffer*     pBuffer;
+  int                                    iWidth;
+  int                                    iHeight;
+};
 
 #endif

--- kdeextragear-2/kst/kst/kstview.cpp  #1.85:1.86
@@ -27,5 +27,5 @@
 #include <qpainter.h>
 #include <qtabwidget.h>
-
+#include <qbuffer.h>
 #include <kdebug.h>
 #include <kimageio.h>
@@ -46,5 +46,5 @@
 #include "kstsettings.h"
 #include "kstview.h"
-
+#include "kstevents.h"
 
 /** setup the view widget */
@@ -144,4 +144,55 @@ KstView::~KstView() {
 }
 
+void KstView::customEvent( QCustomEvent* pEvent ) {
+  if( pEvent->type() == KstELOGCaptureEvent ) {
+    KstELOGCaptureStruct* pCaptureStruct = (KstELOGCaptureStruct*)pEvent->data();
+    QImageIO imageIO( pCaptureStruct->pBuffer, "PNG" );
+    float w, h, tlx, tly;
+    QRect v;
+    KstPlot *pl = 0L;
+    double XBorder, maxXBorder = 0;
+    
+    QPixmap tmpPixmap(pCaptureStruct->iWidth, pCaptureStruct->iHeight);
+    tmpPixmap.fill(KstSettings::globalSettings()->backgroundColor);
+    
+    QPainter p(&tmpPixmap);
+    p.setBackgroundColor(KstSettings::globalSettings()->backgroundColor);
+    
+    v = p.viewport();
+    
+    // Find max border width
+    for (unsigned i = 0; i < KST::plotList.count(); i++) {
+      pl = KST::plotList.at(i);
+      w = v.width() * pl->width();
+      h = v.height() * pl->height();
+      tly = v.height() * pl->topLeftY();
+      tlx = v.width() * pl->topLeftX();
+      p.setViewport((int)tlx, (int)tly, (int)w, (int)h);
+      p.setWindow((int)0, (int)0, (int)w, (int)h);
+      XBorder = pl->getXBorder(p);
+      if (XBorder > maxXBorder)
+        maxXBorder = XBorder;
+    }
+    
+    for (unsigned i = 0; i < KST::plotList.count(); i++) {
+      pl = KST::plotList.at(i);
+      w = v.width() * pl->width();
+      h = v.height() * pl->height();
+      tly = v.height() * pl->topLeftY();
+      tlx = v.width() * pl->topLeftX();
+      p.setViewport((int)tlx, (int)tly, (int)w, (int)h);
+      p.setWindow((int)0, (int)0, (int)w, (int)h);
+      pl->paint(p, maxXBorder);
+    }
+    
+    imageIO.setImage( tmpPixmap.convertToImage() );
+    if( pCaptureStruct->pBuffer->open( IO_WriteOnly ) ) {
+      imageIO.write( );
+      pCaptureStruct->pBuffer->close( );
+      pCaptureStruct->pBuffer->reset( );
+    }
+  }
+}
+
 // FIXME: make this return an error code!
 void KstView::printToGraphicsFile(const QString &filename, int in_w, int in_h) {

--- kdeextragear-2/kst/kst/kstview.h  #1.26:1.27
@@ -109,4 +109,5 @@ protected:
   virtual void dragEnterEvent(QDragEnterEvent *e);
   virtual void dropEvent(QDropEvent *e);
+  virtual void customEvent(QCustomEvent *e);
 
   void updateTieBox(QPaintDevice *, unsigned int i_box);





More information about the Kst mailing list