[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Patch kpresenter. Code cleanup
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2003-12-22 12:38:19
[Download RAW message or body]

Hello all,

this is the first patch for cleaning up the source of kpresenter (HEAD). 
Hopefully more patches to come. Please tell me what you think about it.

When I did the change I also noticed a small problem with the brushes. To 
reproduce:

-create to 2D Objects.
-set for one object a brush.
-now first select the filled an than the not filled object.
-now open the property dialog and close with OK

result: The filled object is no longer filled.

Should this be backported to kpresenter 1.3 or not as we are in deep freeze? 
The relevant code to fix the problem is in BrushCmd::execute().

So long and a Merry Christmas

Thorsten



["patch57" (text/x-diff)]

Index: kprcommand.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprcommand.cc,v
retrieving revision 1.160
diff -u -3 -p -r1.160 kprcommand.cc
--- kprcommand.cc	27 Aug 2003 14:45:39 -0000	1.160
+++ kprcommand.cc	22 Dec 2003 12:13:03 -0000
@@ -1061,44 +1061,37 @@ BrushCmd::~BrushCmd()
 
 void BrushCmd::execute()
 {
-    Brush tmpBrush = newBrush;
-
     for ( int i = 0; i < static_cast<int>( objects.count() ); i++ )
     {
-        if (!(flags & BrushColor))
-            if (newBrush.brush != Qt::NoBrush)
-                newBrush.brush = QBrush(oldBrush.at( i )->brush.color(), newBrush.brush.style());
-            else
-                newBrush.brush = QBrush(oldBrush.at( i )->brush.color(), Qt::NoBrush);
+        Brush tmpBrush = *oldBrush.at( i );
 
-        if (!(flags & BrushStyle))
-            if (newBrush.brush != Qt::NoBrush)
-                newBrush.brush = QBrush(newBrush.brush.color(), oldBrush.at( i )->brush.style());
-            else
-                newBrush.brush = QBrush(oldBrush.at( i )->brush.color(), Qt::NoBrush);
+        if ( flags & BrushColor )
+            tmpBrush.brush.setColor( newBrush.brush.color() );
 
-        if (!(flags & BrushGradientSelect))
-            newBrush.fillType = oldBrush.at( i )->fillType;
+        if ( flags & BrushStyle )
+            tmpBrush.brush.setStyle( newBrush.brush.style() );
 
-        if (!(flags & GradientColor1))
-            newBrush.gColor1 = oldBrush.at( i )->gColor1;
+        if ( flags & BrushGradientSelect )
+            tmpBrush.fillType = newBrush.fillType;
 
-        if (!(flags & GradientColor2))
-            newBrush.gColor2 = oldBrush.at( i )->gColor2;
+        if ( flags & GradientColor1 )
+            tmpBrush.gColor1 = newBrush.gColor1;
 
-        if (!(flags & GradientType))
-            newBrush.gType = oldBrush.at( i )->gType;
+        if ( flags & GradientColor2 )
+            tmpBrush.gColor2 = newBrush.gColor2;
 
-        if (!(flags & GradientBalanced))
+        if ( flags & GradientType )
+            tmpBrush.gType = newBrush.gType;
+
+        if ( flags & GradientBalanced )
         {
-            newBrush.unbalanced = oldBrush.at( i )->unbalanced;
-            newBrush.xfactor = oldBrush.at( i )->xfactor;
-            newBrush.yfactor = oldBrush.at( i )->yfactor;
+            tmpBrush.unbalanced = newBrush.unbalanced;
+            tmpBrush.xfactor = newBrush.xfactor;
+            tmpBrush.yfactor = newBrush.yfactor;
         }
 
-        applyBrush(objects.at( i ), &newBrush);
+        applyBrush( objects.at( i ), &tmpBrush );
     }
-    newBrush = tmpBrush;
 
     int pos=doc->pageList().findRef(m_page);
     doc->updateSideBarItem(pos, (m_page == doc->stickyPage()) ? true: false );
@@ -1106,143 +1099,18 @@ void BrushCmd::execute()
 
 void BrushCmd::applyBrush(KPObject *kpobject, Brush *tmpBrush)
 {
-    switch (kpobject->getType()) {
-    case OT_RECT: {
-        KPRectObject* obj=dynamic_cast<KPRectObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_ELLIPSE: {
-        KPEllipseObject* obj=dynamic_cast<KPEllipseObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_AUTOFORM: {
-        KPAutoformObject* obj=dynamic_cast<KPAutoformObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_PIE: {
-        KPPieObject* obj=dynamic_cast<KPPieObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_PART: {
-        KPPartObject* obj=dynamic_cast<KPPartObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_TEXT: {
-        KPTextObject* obj=dynamic_cast<KPTextObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_CLIPART:
-    case OT_PICTURE: {
-        KPPixmapObject *obj=dynamic_cast<KPPixmapObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_POLYGON: {
-        KPPolygonObject *obj=dynamic_cast<KPPolygonObject*>( kpobject );
-        if(obj)
-        {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    case OT_CLOSED_LINE: {
-        KPClosedLineObject *obj = dynamic_cast<KPClosedLineObject*>( kpobject );
-        if( obj ) {
-            obj->setBrush( tmpBrush->brush );
-            obj->setFillType( tmpBrush->fillType );
-            obj->setGColor1( tmpBrush->gColor1 );
-            obj->setGColor2( tmpBrush->gColor2 );
-            obj->setGType( tmpBrush->gType );
-            obj->setGUnbalanced( tmpBrush->unbalanced );
-            obj->setGXFactor( tmpBrush->xfactor );
-            obj->setGYFactor( tmpBrush->yfactor );
-            doc->repaint( obj );
-        }
-    } break;
-    default: break;
+    KP2DObject * obj = dynamic_cast<KP2DObject *>( kpobject );
+    if( obj )
+    {
+        obj->setBrush( tmpBrush->brush );
+        obj->setFillType( tmpBrush->fillType );
+        obj->setGColor1( tmpBrush->gColor1 );
+        obj->setGColor2( tmpBrush->gColor2 );
+        obj->setGType( tmpBrush->gType );
+        obj->setGUnbalanced( tmpBrush->unbalanced );
+        obj->setGXFactor( tmpBrush->xfactor );
+        obj->setGYFactor( tmpBrush->yfactor );
+        doc->repaint( obj );
     }
 }
 
Index: kprpage.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprpage.cc,v
retrieving revision 1.228
diff -u -3 -p -r1.228 kprpage.cc
--- kprpage.cc	15 Oct 2003 03:56:46 -0000	1.228
+++ kprpage.cc	22 Dec 2003 12:13:03 -0000
@@ -1762,136 +1762,16 @@ KCommand * KPrPage::setBrush( const QBru
             btmp = new BrushCmd::Brush;
             switch ( kpobject->getType() ) {
             case OT_RECT:
-            {
-                KPRectObject *obj=dynamic_cast<KPRectObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = QBrush( obj->getBrush() );
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_ELLIPSE:
-            {
-                KPEllipseObject *obj=dynamic_cast<KPEllipseObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = obj->getBrush();
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_AUTOFORM:
-            {
-                KPAutoformObject* obj=dynamic_cast<KPAutoformObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = QBrush( obj->getBrush() );
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_PIE:
-            {
-                KPPieObject *obj=dynamic_cast<KPPieObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = QBrush( obj->getBrush() );
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_PART:
-            {
-                KPPartObject *obj=dynamic_cast<KPPartObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = QBrush( obj->getBrush() );
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_TEXT:
-            {
-                KPTextObject *obj=dynamic_cast<KPTextObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = QBrush( obj->getBrush() );
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_CLIPART:
             case OT_PICTURE:
-            {
-                KPPixmapObject *obj=dynamic_cast<KPPixmapObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = QBrush( obj->getBrush() );
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_POLYGON:
-            {
-                KPPolygonObject *obj=dynamic_cast<KPPolygonObject*>( kpobject );
-                if(obj)
-                {
-                    btmp->brush = obj->getBrush();
-                    btmp->fillType = obj->getFillType();
-                    btmp->gColor1 = obj->getGColor1();
-                    btmp->gColor2 = obj->getGColor2();
-                    btmp->gType = obj->getGType();
-                    btmp->unbalanced = obj->getGUnbalanced();
-                    btmp->xfactor = obj->getGXFactor();
-                    btmp->yfactor = obj->getGYFactor();
-                }
-            }
-            break;
             case OT_CLOSED_LINE: {
-                KPClosedLineObject *obj = dynamic_cast<KPClosedLineObject*>( kpobject );
+                KP2DObject * obj = dynamic_cast<KP2DObject *>( kpobject );
                 if( obj ) {
                     btmp->brush = obj->getBrush();
                     btmp->fillType = obj->getFillType();


_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic