[Kst] branches/work/kst/viewpaint/kst/kst

George Staikos staikos at kde.org
Sat Jan 28 21:09:11 CET 2006


SVN commit 503325 by staikos:

fix pictures - unfortunately haven't fixed transparency yet, but this is an old
bug and should now be easy to fix.


 M  +42 -18    kstviewpicture.cpp  
 M  +3 -2      kstviewpicture.h  


--- branches/work/kst/viewpaint/kst/kst/kstviewpicture.cpp #503324:503325
@@ -27,6 +27,7 @@
 #include <kio/netaccess.h>
 #include <klocale.h>
 
+#include <qbitmap.h>
 #include <qfile.h>
 #include <qfileinfo.h>
 #include <qmetaobject.h>
@@ -67,28 +68,51 @@
 }
 
 
-void KstViewPicture::paint(KstPainter& p, const QRegion& bounds) {
+QRegion KstViewPicture::clipRegion() {
+  if (_clipMask.isNull()) {
+    _myClipMask = QRegion();
+    QBitmap bm1(_geom.bottomRight().x(), _geom.bottomRight().y(), true);
+    if (!bm1.isNull()) {
+      KstPainter p;
+      p.setMakingMask(true);
+      p.begin(&bm1);
+      p.setViewXForm(true);
+      KstBorderedViewObject::paintSelf(p, QRegion());
+      p.flush();
+      p.end();
+      _clipMask = QRegion(bm1);
+    }
+    QBitmap bm2(_geom.bottomRight().x(), _geom.bottomRight().y(), true);
+    if (!bm2.isNull()) {
+      KstPainter p;
+      p.setMakingMask(true);
+      p.begin(&bm2);
+      p.setViewXForm(true);
+      paintSelf(p, QRegion());
+      p.flush();
+      p.end();
+      _myClipMask = QRegion(bm2);
+    }
+  }
+
+  return _myClipMask | _clipMask;
+}
+
+
+void KstViewPicture::paintSelf(KstPainter& p, const QRegion& bounds) {
   p.save();
   if (p.makingMask()) {
     p.setRasterOp(Qt::SetROP);
-    KstBorderedViewObject::paint(p, bounds);
   } else {
-    KstBorderedViewObject::paint(p, bounds);
-    // FIXME: inefficient
-    if (p.type() != KstPainter::P_PRINT && p.type() != KstPainter::P_EXPORT) {
-      QRegion boundary = bounds & _lastClipRegion;
-      for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
-        boundary -= (*i)->clipRegion();
-      }
-      boundary -= p.uiMask();
-      p.setClipRegion(boundary);
-    }
+    const QRegion clip(clipRegion());
+    KstBorderedViewObject::paintSelf(p, bounds - _myClipMask);
+    p.setClipRegion(bounds & clip);
   }
 
   if (_image.isNull()) {
-    QRect r(_geom);
-    r.setWidth(_geom.width() - 1);
-    r.setHeight(_geom.height() - 1);
+    QRect r(contentsRect()); //_geom);
+    r.setWidth(r.width() - 1);
+    r.setHeight(r.height() - 1);
 
     // fill with X
     p.setBrush(QBrush(Qt::gray, Qt::SolidPattern));
@@ -111,13 +135,13 @@
       if (p.makingMask()) {
         // which indicates clipping / BW mode
         if (_iCache.hasAlphaBuffer()) {
-          p.drawImage(contentsRect().topLeft(), _iCache.createAlphaMask());
+          p.drawImage(cr.topLeft(), _iCache.createAlphaMask());
         } else {
           p.setBrush(Qt::color1);
-          p.drawRect(contentsRect());
+          p.drawRect(cr);
         }
       } else {
-        p.drawImage(contentsRect().topLeft(), _iCache);
+        p.drawImage(cr.topLeft(), _iCache);
       }
     }
   }
--- branches/work/kst/viewpaint/kst/kst/kstviewpicture.h #503324:503325
@@ -49,9 +49,9 @@
     int refreshTimer() const;
     
     virtual QMap<QString, QVariant> widgetHints(const QString& propertyName) const;
+    QRegion clipRegion();
 
-  public slots:
-    void paint(KstPainter& p, const QRegion& bounds);
+    void paintSelf(KstPainter& p, const QRegion& bounds);
 
   protected slots:
     void doRefresh();
@@ -64,6 +64,7 @@
     QString _url;
     int _refresh;
     QTimer *_timer;
+    QRegion _myClipMask;
 };
 
 typedef KstObjectList<KstViewPicturePtr> KstViewPictureList;


More information about the Kst mailing list