[Kst] branches/work/kst/1.6/kst/src/libkstapp

Andrew Walker arwalker at sumusltd.com
Wed Sep 26 02:51:12 CEST 2007


SVN commit 717070 by arwalker:

BUG:150170 use the transparent property and remove the transparentFill property

 M  +57 -27    kstviewbox.cpp  
 M  +5 -6      kstviewbox.h  
 M  +48 -23    kstviewellipse.cpp  
 M  +4 -4      kstviewellipse.h  


--- branches/work/kst/1.6/kst/src/libkstapp/kstviewbox.cpp #717069:717070
@@ -24,6 +24,7 @@
 #include <kglobal.h>
 #include <klocale.h>
 
+#include <qbitmap.h>
 #include <qmetaobject.h>
 #include <qpainter.h>
 #include <qmap.h>
@@ -36,8 +37,7 @@
   _yRound = 0;
   _cornerStyle = Qt::MiterJoin;
   _fallThroughTransparency = false;
-  setTransparent(true);
-  _transparentFill = false;
+  setTransparent(false);
   setFollowsFlow(true);
   _standardActions |= Delete | Edit;
 }
@@ -45,6 +45,10 @@
 
 KstViewBox::KstViewBox(const QDomElement& e)
 : KstViewObject(e), _borderColor(QColor(0, 0, 0)), _borderWidth(0) {
+  _xRound = 0;
+  _yRound = 0;
+  _cornerStyle = Qt::MiterJoin;
+  setTransparent(false);
 
   QDomNode n = e.firstChild();
   while (!n.isNull()) {
@@ -63,7 +67,6 @@
   _standardActions |= Delete | Edit;
   _layoutActions |= Delete | Raise | Lower | RaiseToTop | LowerToBottom | Rename | MoveTo | Copy | CopyTo;
   _fallThroughTransparency = false;
-  setTransparent(true);
   setFollowsFlow(true);
 }
 
@@ -76,7 +79,6 @@
   _cornerStyle = box._cornerStyle;
   _borderColor = box._borderColor;
   _borderWidth = box._borderWidth;
-  _transparentFill = box._transparentFill;
 
   // these always have these values
   _type = "Box";
@@ -117,36 +119,65 @@
   }
 
   // restrict the border width so we do not draw outside of the rectangle itself
-  int bw(borderWidth() * p.lineWidthAdjustmentFactor());
-  if (bw > _geom.width() / 2) {
-    bw = _geom.width() / 2;
+  int borderWidthAdjusted(borderWidth() * p.lineWidthAdjustmentFactor());
+  if (borderWidthAdjusted > _geom.width() / 2) {
+    borderWidthAdjusted = _geom.width() / 2;
   }
-  if (bw > _geom.height()) {
-    bw = _geom.height() / 2;
+  if (borderWidthAdjusted > _geom.height()) {
+    borderWidthAdjusted = _geom.height() / 2;
   }
 
-  QPen pen(borderColor(), bw);
+  QRect r;
+  QPen pen(borderColor(), borderWidthAdjusted);
+
   pen.setJoinStyle(_cornerStyle);
-  if (bw == 0) {
+  if (borderWidthAdjusted == 0) {
     pen.setStyle(Qt::NoPen);
   }
   p.setPen(pen);
-  if (_transparentFill) {
+
+  if (_transparent) {
     p.setBrush(Qt::NoBrush);
   } else {
     p.setBrush(_foregroundColor);
   }
-  QRect r;
-  r.setX(_geom.left() + bw / 2);
-  r.setY(_geom.top() + bw / 2);
-  r.setWidth(_geom.width() - bw);
-  r.setHeight(_geom.height() - bw);
 
+  r.setX(_geom.left() + ( borderWidthAdjusted / 2 ));
+  r.setY(_geom.top() + ( borderWidthAdjusted / 2 ));
+  r.setWidth(_geom.width() - borderWidthAdjusted + 1);
+  r.setHeight(_geom.height() - borderWidthAdjusted + 1);
+
   p.drawRoundRect(r, _xRound, _yRound);
   p.restore();
 }
 
 
+QRegion KstViewBox::clipRegion() {
+  if (_clipMask.isNull()) {
+    if (transparent() || _xRound != 0 || _yRound != 0) {
+      QBitmap bm(_geom.bottomRight().x() + 1, _geom.bottomRight().y() + 1, true);
+      if (!bm.isNull()) {
+        KstPainter p;
+
+        p.begin(&bm);
+        p.setMakingMask(true);
+        p.setViewXForm(true);
+        paint(p, QRegion());
+        p.flush();
+        p.end();
+        _clipMask = QRegion(bm);
+      } else {
+        _clipMask = QRegion(); // only invalidate our own variable
+      }
+    } else {
+      _clipMask = QRegion(_geom);
+    }
+  }
+
+  return _clipMask;
+}
+
+
 void KstViewBox::save(QTextStream& ts, const QString& indent) {
   ts << indent << "<" << type() << ">" << endl;
   KstViewObject::save(ts, indent + "  ");
@@ -213,16 +244,13 @@
 }
 
 
-bool KstViewBox::transparentFill() const {
-  return _transparentFill;
+bool KstViewBox::transparent() const {
+  return KstViewObject::transparent();
 }
 
 
-void KstViewBox::setTransparentFill(bool yes) {
-  if (_transparentFill != yes) {
-    setDirty();
-    _transparentFill = yes;
-  }
+void KstViewBox::setTransparent(bool transparent) {
+  KstViewObject::setTransparent(transparent);
 }
 
 
@@ -276,16 +304,17 @@
 QMap<QString, QVariant > KstViewBox::widgetHints(const QString& propertyName) const {
   QMap<QString, QVariant> map = KstViewObject::widgetHints(propertyName);
   if (!map.empty()) {
-    return map;  
+    return map;
   }
+
   if (propertyName == "xRound") {
     map.insert(QString("_kst_widgetType"), QString("QSpinBox"));
     map.insert(QString("_kst_label"), i18n("X Roundness"));
-    map.insert(QString("minValue"), 0);   
+    map.insert(QString("minValue"), 0);
   } else if (propertyName == "yRound") {
     map.insert(QString("_kst_widgetType"), QString("QSpinBox"));
     map.insert(QString("_kst_label"), i18n("Y Roundness"));
-    map.insert(QString("minValue"), 0);  
+    map.insert(QString("minValue"), 0);
   } else if (propertyName == "foregroundColor") {
     map.insert(QString("_kst_widgetType"), QString("KColorButton"));
     map.insert(QString("_kst_label"), i18n("Fill Color"));
@@ -301,6 +330,7 @@
     map.insert(QString("_kst_label"), i18n("Border width"));
     map.insert(QString("minValue"), 0);
   }
+
   return map;
 }
 
--- branches/work/kst/1.6/kst/src/libkstapp/kstviewbox.h #717069:717070
@@ -29,7 +29,7 @@
   Q_OBJECT
   Q_PROPERTY(int xRound READ xRound WRITE setXRound)
   Q_PROPERTY(int yRound READ yRound WRITE setYRound)
-  Q_PROPERTY(bool transparentFill READ transparentFill WRITE setTransparentFill)
+  Q_PROPERTY(bool transparentFill READ transparent WRITE setTransparent)
   Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
   Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth)
   Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor)
@@ -42,18 +42,16 @@
 
     virtual KstViewObject* copyObjectQuietly(KstViewObject& parent, const QString& name = QString::null) const;
     virtual KstViewObject* copyObjectQuietly() const;
+    virtual QRegion clipRegion();
+
     void setXRound(int rnd);
     int xRound() const;
     void setYRound(int rnd);
     int yRound() const;
     void setCornerStyle(Qt::PenJoinStyle style);
     Qt::PenJoinStyle cornerStyle() const;
-    
-    bool transparentFill() const;
-    void setTransparentFill(bool yes);
 
     void paintSelf(KstPainter& p, const QRegion& bounds);
-
     void setBorderColor(const QColor& c);
     const QColor& borderColor() const;
 
@@ -65,6 +63,8 @@
     virtual QColor foregroundColor() const;
     virtual void setBackgroundColor(const QColor& color);
     virtual QColor backgroundColor() const;
+    virtual bool transparent() const;
+    virtual void setTransparent(bool transparent);
 
   public:
     void save(QTextStream& ts, const QString& indent = QString::null);
@@ -76,7 +76,6 @@
     int _borderWidth;
     int _xRound, _yRound;
     Qt::PenJoinStyle _cornerStyle;
-    bool _transparentFill;
 };
 
 typedef KstObjectList<KstViewBoxPtr> KstViewBoxList;
--- branches/work/kst/1.6/kst/src/libkstapp/kstviewellipse.cpp #717069:717070
@@ -20,6 +20,7 @@
 #include "kstviewellipse.h"
 #include "kstviewobjectfactory.h"
 
+#include <qbitmap.h>
 #include <qmetaobject.h>
 #include <qpainter.h>
 #include <qvariant.h>
@@ -29,21 +30,20 @@
 KstViewEllipse::KstViewEllipse()
 : KstViewObject("Ellipse"), _borderWidth(1) {
   _editTitle = i18n("Edit Ellipse");
-  setTransparent(true);
-  _transparentFill = false;
+  setTransparent(false);
   _standardActions |= Delete | Edit;
 }
 
 
 KstViewEllipse::KstViewEllipse(const QDomElement& e)
 : KstViewObject(e) {
-  _transparentFill = false;
+  setTransparent(false);
   QDomNode n = e.firstChild();
   while (!n.isNull()) {
-    QDomElement el = n.toElement(); 
+    QDomElement el = n.toElement();
     if (!el.isNull()) {
       if (metaObject()->findProperty(el.tagName().latin1(), true) > -1) {
-        setProperty(el.tagName().latin1(), QVariant(el.text()));  
+        setProperty(el.tagName().latin1(), QVariant(el.text()));
       }
     }
     n = n.nextSibling();
@@ -52,7 +52,6 @@
   // always have these values
   _type = "Ellipse";
   _editTitle = i18n("Edit Ellipse");
-  setTransparent(true);
   _standardActions |= Delete | Edit;
   _layoutActions |= Delete | Raise | Lower | RaiseToTop | LowerToBottom | Rename | MoveTo | Copy | CopyTo;
 }
@@ -60,7 +59,6 @@
 
 KstViewEllipse::KstViewEllipse(const KstViewEllipse& ellipse)
 : KstViewObject(ellipse) {
-  _transparentFill = ellipse._transparentFill;
   _borderWidth = ellipse._borderWidth;
   _borderColor = ellipse._borderColor;
 
@@ -115,16 +113,44 @@
   }
   QPen pen(bw > 0 ? _borderColor : _foregroundColor, bw);
   p.setPen(pen);
-  if (_transparentFill) {
+
+  if (_transparent) {
     p.setBrush(Qt::NoBrush);
   } else {
     p.setBrush(_foregroundColor);
   }
+
   p.drawEllipse(g.x() + bw/2, g.y() + bw/2, g.width() - bw, g.height() - bw);
   p.restore();
 }
 
 
+QRegion KstViewEllipse::clipRegion() {
+  if (_clipMask.isNull()) {
+    if (transparent() || !_children.isEmpty()) {
+      QBitmap bm(_geom.bottomRight().x() + 1, _geom.bottomRight().y() + 1, true);
+      if (!bm.isNull()) {
+        KstPainter p;
+
+        p.begin(&bm);
+        p.setMakingMask(true);
+        p.setViewXForm(true);
+        paint(p, QRegion());
+        p.flush();
+        p.end();
+        _clipMask = QRegion(bm);
+      } else {
+        _clipMask = QRegion(); // only invalidate our own variable
+      }
+    } else {
+      _clipMask = QRegion(_geom, QRegion::Ellipse);
+    }
+  }
+
+  return _clipMask;
+}
+
+
 QRegion KstViewEllipse::region() {
   return QRegion(geometry(), QRegion::Ellipse);
 }
@@ -176,23 +202,25 @@
 QMap<QString, QVariant> KstViewEllipse::widgetHints(const QString& propertyName) const {
   QMap<QString, QVariant> map = KstViewObject::widgetHints(propertyName);
   if (!map.empty()) {
-    return map;  
+    return map;
   }
+
   if (propertyName == "borderColor") {
     map.insert(QString("_kst_widgetType"), QString("KColorButton"));
-    map.insert(QString("_kst_label"), i18n("Border color"));  
+    map.insert(QString("_kst_label"), i18n("Border color"));
   } else if (propertyName == "borderWidth") {
     map.insert(QString("_kst_widgetType"), QString("QSpinBox"));
-    map.insert(QString("_kst_label"), i18n("Border width"));    
+    map.insert(QString("_kst_label"), i18n("Border width"));
     map.insert(QString("minValue"), 0);
   } else if (propertyName == "fillColor") {
     map.insert(QString("_kst_widgetType"), QString("KColorButton"));
-    map.insert(QString("_kst_label"), i18n("Fill Color"));    
+    map.insert(QString("_kst_label"), i18n("Fill Color"));
   } else if (propertyName == "transparentFill") {
     map.insert(QString("_kst_widgetType"), QString("QCheckBox"));
-    map.insert(QString("_kst_label"), QString::null);   
-    map.insert(QString("text"), i18n("Transparent fill")); 
-  }  
+    map.insert(QString("_kst_label"), QString::null);
+    map.insert(QString("text"), i18n("Transparent fill"));
+  }
+
   return map;
 }
 
@@ -210,20 +238,17 @@
 void KstViewEllipse::drawShadow(KstPainter& p, const QPoint& pos) {
   QRect rect(geometry());
   rect.moveTopLeft(pos);
-  p.drawEllipse(rect);  
+  p.drawEllipse(rect);
 }
 
 
-void KstViewEllipse::setTransparentFill(bool yes) {
-  if (_transparentFill != yes) {
-    _transparentFill = yes;
-    setDirty();
-  }
+void KstViewEllipse::setTransparent(bool transparent) {
+  KstViewObject::setTransparent(transparent);
 }
 
 
-bool KstViewEllipse::transparentFill() const {
-  return _transparentFill;
+bool KstViewEllipse::transparent() const {
+  return KstViewObject::transparent();
 }
 
 
--- branches/work/kst/1.6/kst/src/libkstapp/kstviewellipse.h #717069:717070
@@ -28,13 +28,14 @@
   Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
   Q_PROPERTY(int borderWidth READ borderWidth WRITE setBorderWidth)
   Q_PROPERTY(QColor fillColor READ foregroundColor WRITE setForegroundColor)
-  Q_PROPERTY(bool transparentFill READ transparentFill WRITE setTransparentFill)
+  Q_PROPERTY(bool transparentFill READ transparent WRITE setTransparent)
   public:
     KstViewEllipse();
     KstViewEllipse(const QDomElement& e);
     KstViewEllipse(const KstViewEllipse& ellipse);
     virtual ~KstViewEllipse();
 
+    virtual QRegion clipRegion();
     virtual KstViewObject* copyObjectQuietly(KstViewObject& parent, const QString& name = QString::null) const;
     virtual KstViewObject* copyObjectQuietly() const;
     virtual void setBorderColor(const QColor& to);
@@ -47,18 +48,17 @@
     virtual QMap<QString, QVariant> widgetHints(const QString& propertyName) const; 
     virtual signed int directionFor(const QPoint& pos);
     virtual QRegion region();
+    virtual bool transparent() const;
+    virtual void setTransparent(bool transparent);
 
     // can't have Q_PROPERTY in KstViewObject?
     virtual void setForegroundColor(const QColor& color);
     virtual QColor foregroundColor() const;
 
-    bool transparentFill() const;
-    void setTransparentFill(bool yes);
 
   private:
     int _borderWidth;
     QColor _borderColor;
-    bool _transparentFill;
 };
 
 typedef KstObjectList<KstViewEllipsePtr> KstViewEllipseList;


More information about the Kst mailing list