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

Adam Treat treat at kde.org
Fri Jun 15 01:49:18 CEST 2007


SVN commit 675751 by treat:

* Can not call setPen() inside paint event as
QGraphicsItem calls update() within setPen().
Instead, provide an overload that items can use
to draw instead of the base class rect().



 M  +1 -5      ellipseitem.cpp  
 M  +1 -1      ellipseitem.h  
 M  +1 -6      labelitem.cpp  
 M  +1 -1      labelitem.h  
 M  +1 -5      lineitem.cpp  
 M  +1 -1      lineitem.h  
 M  +2 -7      pictureitem.cpp  
 M  +1 -1      pictureitem.h  
 M  +2 -7      svgitem.cpp  
 M  +1 -1      svgitem.h  
 M  +11 -5     viewitem.cpp  
 M  +8 -7      viewitem.h  


--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.cpp #675750:675751
@@ -33,13 +33,9 @@
 }
 
 
-void EllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+void EllipseItem::paint(QPainter *painter) {
   const qreal w = pen().widthF();
   painter->drawEllipse(rect().adjusted(w, w, -w, -w));
-  QPen p = pen();
-  setPen(Qt::NoPen);
-  ViewItem::paint(painter, option, widget);
-  setPen(p);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.h #675750:675751
@@ -24,7 +24,7 @@
   virtual ~EllipseItem();
 
   virtual QPainterPath itemShape() const;
-  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+  virtual void paint(QPainter *painter);
 };
 
 class KST_EXPORT CreateEllipseCommand : public CreateCommand
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #675750:675751
@@ -31,7 +31,7 @@
 }
 
 
-void LabelItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+void LabelItem::paint(QPainter *painter) {
   if (!_parsed) {
     _parsed = Label::parse(_text);
   }
@@ -53,11 +53,6 @@
 
     painter->restore();
   }
-
-  QPen p = pen();
-  setPen(Qt::NoPen);
-  ViewItem::paint(painter, option, widget);
-  setPen(p);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.h #675750:675751
@@ -26,7 +26,7 @@
     LabelItem(View *parent, const QString& labelText);
     virtual ~LabelItem();
 
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+    virtual void paint(QPainter *painter);
 
   private:
     Label::Parsed *_parsed;
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #675750:675751
@@ -34,12 +34,8 @@
 }
 
 
-void LineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+void LineItem::paint(QPainter *painter) {
   painter->drawLine(_line);
-  QPen p = pen();
-  setPen(Qt::NoPen);
-  ViewItem::paint(painter, option, widget);
-  setPen(p);
 }
 
 QLineF LineItem::line() const {
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.h #675750:675751
@@ -25,7 +25,7 @@
   virtual ~LineItem();
 
   virtual QPainterPath itemShape() const;
-  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+  virtual void paint(QPainter *painter);
 
   QLineF line() const;
   void setLine(const QLineF &line);
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.cpp #675750:675751
@@ -27,17 +27,12 @@
 }
 
 
-void PictureItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+void PictureItem::paint(QPainter *painter) {
   // We can do better here.  Cache the scaled pixmap also.
-  if (!_image.isNull()) {
+  if (!_image.isNull() && rect().isValid()) {
     const qreal w = pen().widthF();
     painter->drawPixmap(rect().adjusted(w, w, -w, -w), _image, _image.rect());
   }
-
-  QPen p = pen();
-  setPen(Qt::NoPen);
-  ViewItem::paint(painter, option, widget);
-  setPen(p);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.h #675750:675751
@@ -23,7 +23,7 @@
     PictureItem(View *parent, const QImage &image);
     ~PictureItem();
 
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+    virtual void paint(QPainter *painter);
 
   private:
     QPixmap _image;
--- branches/work/kst/portto4/kst/src/libkstapp/svgitem.cpp #675750:675751
@@ -28,16 +28,11 @@
 }
 
 
-void SvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+void SvgItem::paint(QPainter *painter) {
   // We can do better here.  Cache the svg also.
-  if (_svg->isValid()) {
+  if (_svg->isValid() && rect().isValid()) {
     _svg->render(painter, rect());
   }
-
-  QPen p = pen();
-  setPen(Qt::NoPen);
-  ViewItem::paint(painter, option, widget);
-  setPen(p);
 }
 
 
--- branches/work/kst/portto4/kst/src/libkstapp/svgitem.h #675750:675751
@@ -25,7 +25,7 @@
     SvgItem(View *parent, const QString &file);
     ~SvgItem();
 
-    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+    virtual void paint(QPainter *painter);
 
   private:
     QSvgRenderer *_svg;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #675750:675751
@@ -241,6 +241,7 @@
 }
 
 void ViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
+
   painter->save();
   painter->setPen(Qt::DotLine);
   if (isSelected()) {
@@ -272,19 +273,24 @@
   painter->drawText(rect().bottomLeft(), "BL");
   painter->drawText(rect().bottomRight(), "BR");
 #endif
-
   painter->restore();
 
-  painter->setPen(pen());
-  painter->setBrush(brush());
-  painter->drawRect(rect());
-
   Q_UNUSED(option);
   Q_UNUSED(widget);
+
+  paint(painter); //this is the overload that subclasses should use...
+
 //   QGraphicsRectItem::paint(painter, option, widget);
 }
 
 
+void ViewItem::paint(QPainter *painter) {
+  painter->setPen(pen());
+  painter->setBrush(brush());
+  painter->drawRect(rect());
+}
+
+
 void ViewItem::remove() {
   RemoveCommand *remove = new RemoveCommand(this);
   remove->redo();
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #675750:675751
@@ -37,6 +37,11 @@
   ViewItem(View *parent);
   virtual ~ViewItem();
 
+  View *parentView() const;
+
+  MouseMode mouseMode() const;
+  void setMouseMode(MouseMode mode);
+
   QSize sizeOfGrip() const;
   QPainterPath topLeftGrip() const;
   QPainterPath topRightGrip() const;
@@ -52,17 +57,13 @@
 
   QRectF selectBoundingRect() const;
   QRectF gripBoundingRect() const;
+
   virtual QRectF boundingRect() const;
   virtual QPainterPath shape() const;
   virtual QPainterPath itemShape() const { return QGraphicsRectItem::shape(); }
+  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+  virtual void paint(QPainter *painter);
 
-  View *parentView() const;
-
-  MouseMode mouseMode() const;
-  void setMouseMode(MouseMode mode);
-
-  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
-
 Q_SIGNALS:
   void creationComplete();
 


More information about the Kst mailing list