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

List:       koffice-devel
Subject:    kpresenter patch. More code cleanup
From:       Thorsten Zachmann <t.zachmann () zagge ! de>
Date:       2004-01-06 6:34:53
Message-ID: 200401060734.53741.t.zachmann () zagge ! de
[Download RAW message or body]

Hello all,

this patch cleans up the soure in the usage of setting a pen.

Please review.

Have a nice day.

Thorsten

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

Index: kpresenter_view.h
===================================================================
RCS file: /home/kde/koffice/kpresenter/kpresenter_view.h,v
retrieving revision 1.318
diff -u -3 -p -r1.318 kpresenter_view.h
--- kpresenter_view.h	3 Jan 2004 06:58:44 -0000	1.318
+++ kpresenter_view.h	6 Jan 2004 06:26:52 -0000
@@ -734,6 +734,12 @@ protected:
     KCommand * applyAutoFormatToCurrentPage( const QPtrList<KoTextObject> & lst);
     void textStyleSelected( KoStyle *_sty );
 
+    /*
+     * create a command which sets the pen according to the flags
+     * for the selected objects on the active and sticky page
+     */
+    KCommand * getPenCmd( const QString &name, QPen pen, LineEnd lb, LineEnd le, int \
flags ); +
 private:
     void clearSpellChecker();
 
Index: kpresenter_view.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/kpresenter_view.cc,v
retrieving revision 1.994
diff -u -3 -p -r1.994 kpresenter_view.cc
--- kpresenter_view.cc	3 Jan 2004 06:58:44 -0000	1.994
+++ kpresenter_view.cc	6 Jan 2004 06:27:07 -0000
@@ -1878,28 +1878,10 @@ void KPresenterView::penChosen()
     QColor c = actionPenColor->color();
     if ( !m_canvas->currentTextObjectView() )
     {
-        KPrPage *page = m_canvas->activePage();
-        QPen e_pen = QPen(c, page->getPen(pen).width(), page->getPen(pen).style());
-
-        KMacroCommand *macro= 0L;
-
-        KCommand *cmd=page->setPen( e_pen, page->getLineBegin( lineBegin ), \
                page->getLineEnd( lineEnd ),
-                                    PenCmd::Color, page->objectList() );
-        if(cmd)
-        {
-            macro= new KMacroCommand(i18n( "Change Pen Color" ));
-            macro->addCommand(cmd);
-        }
-        cmd=stickyPage()->setPen( e_pen, page->getLineBegin( lineBegin ), \
                page->getLineEnd( lineEnd ),
-                                  PenCmd::Color, stickyPage()->objectList() );
-        if(cmd)
-        {
-            if (!macro )
-                macro= new KMacroCommand(i18n( "Change Pen Color" ));
-            macro->addCommand(cmd);
-        }
-        if(macro)
-            m_pKPresenterDoc->addCommand(macro);
+        KCommand * cmd( getPenCmd( i18n( "Change Pen Color" ), QPen(c), 
+                                   L_NORMAL, L_NORMAL, PenCmd::Color ) );
+        if( cmd )
+            m_pKPresenterDoc->addCommand( cmd );
         else
             pen.setColor( c );
     }
@@ -2024,29 +2006,10 @@ void KPresenterView::extraLineBeginDoubl
 
 void KPresenterView::setExtraLineBegin(LineEnd lb)
 {
-    KPrPage *page=m_canvas->activePage();
-    QPen e_pen = QPen(page->getPen(pen).color(), page->getPen(pen).width(), \
                page->getPen(pen).style());
-
-    KMacroCommand *macro=0L;
-
-    KCommand *cmd=page->setPen( e_pen, lb, page->getLineEnd( lineEnd ),
-                                PenCmd::LineBegin, page->objectList() );
-    if(cmd)
-    {
-        if ( !macro )
-            macro=new KMacroCommand(i18n("Change Line Begin"));
-        macro->addCommand(cmd);
-    }
-    cmd=stickyPage()->setPen( e_pen, lb, page->getLineEnd( lineEnd ),
-                              PenCmd::LineBegin, stickyPage()->objectList() );
-    if(cmd)
-    {
-        if ( !macro )
-            macro=new KMacroCommand(i18n("Change Line Begin"));
-        macro->addCommand(cmd);
-    }
-    if(macro)
-        kPresenterDoc()->addCommand(macro);
+    KCommand * cmd( getPenCmd( i18n("Change Line Begin"), QPen(), 
+                               lb, L_NORMAL, PenCmd::LineBegin ) );
+    if( cmd )
+        kPresenterDoc()->addCommand( cmd );
     else
         lineBegin = lb;
 }
@@ -2093,29 +2056,10 @@ void KPresenterView::extraLineEndDoubleL
 
 void KPresenterView::setExtraLineEnd(LineEnd le)
 {
-    KPrPage *page=m_canvas->activePage();
-    QPen e_pen = QPen(page->getPen(pen).color(), page->getPen(pen).width(), \
                page->getPen(pen).style());
-
-    KMacroCommand *macro=0L;
-
-    KCommand *cmd=page->setPen( e_pen, page->getLineBegin( lineBegin ), le,
-                                PenCmd::LineEnd, page->objectList() );
-    if(cmd)
-    {
-        if (!macro )
-            macro=new KMacroCommand(i18n("Change Line End"));
-        macro->addCommand(cmd);
-    }
-    cmd=stickyPage()->setPen( e_pen, page->getLineBegin( lineBegin ), le,
-                              PenCmd::LineEnd, stickyPage()->objectList() );
-    if(cmd)
-    {
-        if (!macro )
-            macro=new KMacroCommand(i18n("Change Line End"));
-        macro->addCommand(cmd);
-    }
-    if(macro)
-        kPresenterDoc()->addCommand(macro);
+    KCommand * cmd( getPenCmd( i18n("Change Line End"), QPen(), 
+                               L_NORMAL, le, PenCmd::LineEnd ) );
+    if( cmd )
+        kPresenterDoc()->addCommand( cmd );
     else
         lineEnd = le;
 }
@@ -2152,32 +2096,13 @@ void KPresenterView::extraPenStyleNoPen(
 
 void KPresenterView::setExtraPenStyle( Qt::PenStyle style )
 {
-    KPrPage *page = m_canvas->activePage();
-    QPen e_pen = QPen(page->getPen(pen).color(), page->getPen(pen).width(), style );
-
-    KMacroCommand *macro=0L;
-
-    KCommand *cmd=page->setPen( e_pen, page->getLineBegin( lineBegin ), \
                page->getLineEnd( lineEnd ),
-                                PenCmd::Style, page->objectList() );
-    if(cmd)
-    {
-        if ( !macro )
-            macro=new KMacroCommand(i18n("Change Pen Style"));
-        macro->addCommand(cmd);
-    }
-    cmd=stickyPage()->setPen( e_pen, page->getLineBegin( lineBegin ), \
                page->getLineEnd( lineEnd ),
-                              PenCmd::Style, stickyPage()->objectList() );
-    if(cmd)
-    {
-        if ( !macro )
-            macro=new KMacroCommand(i18n("Change Pen Style"));
-
-        macro->addCommand(cmd);
-    }
-    if(macro)
-        kPresenterDoc()->addCommand(macro);
+    KCommand * cmd( getPenCmd( i18n("Change Pen Style"), QPen(style), 
+                               L_NORMAL, L_NORMAL, PenCmd::Style ) );
+    
+    if( cmd )
+        kPresenterDoc()->addCommand( cmd );
     else
-        pen = e_pen;
+        pen.setStyle( style );
 }
 
 void KPresenterView::extraPenWidth1()
@@ -2232,32 +2157,15 @@ void KPresenterView::extraPenWidth10()
 
 void KPresenterView::setExtraPenWidth( unsigned int width )
 {
-    KPrPage *page=m_canvas->activePage();
-    QPen e_pen = QPen(page->getPen(pen).color(), width, page->getPen(pen).style());
+    QPen tmpPen;
+    tmpPen.setWidth( width );
+    KCommand * cmd( getPenCmd( i18n("Change Pen Width"), tmpPen, 
+                               L_NORMAL, L_NORMAL, PenCmd::Width ) );
 
-    KMacroCommand *macro=0L;
-
-    KCommand *cmd=page->setPen( e_pen, page->getLineBegin( lineBegin ), \
                page->getLineEnd( lineEnd ),
-                                PenCmd::Width, page->objectList() );
-    if(cmd)
-    {
-        if ( !macro )
-            macro=new KMacroCommand(i18n("Change Pen Width"));
-        macro->addCommand(cmd);
-    }
-    cmd=stickyPage()->setPen( e_pen, page->getLineBegin( lineBegin ), \
                page->getLineEnd( lineEnd ),
-                              PenCmd::Width, stickyPage()->objectList() );
-    if(cmd)
-    {
-        if ( !macro )
-            macro=new KMacroCommand(i18n("Change Pen Width"));
-
-        macro->addCommand(cmd);
-    }
-    if(macro)
-        kPresenterDoc()->addCommand(macro);
+    if( cmd )
+        kPresenterDoc()->addCommand( cmd );
     else
-        pen = e_pen;
+        pen.setWidth( width );
 }
 
 void KPresenterView::newPageLayout( KoPageLayout _layout )
@@ -3376,23 +3284,13 @@ void KPresenterView::styleOk()
 
     if ((confPenDia = styleDia->getConfPenDia()))
     {
-        cmd=m_canvas->activePage()->setPen(confPenDia->getPen(), \
                confPenDia->getLineBegin(), confPenDia->getLineEnd(),
-                                           confPenDia->getPenConfigChange(), \
                m_canvas->activePage()->objectList());
-
+        cmd = getPenCmd( i18n( "Apply Properties" ), confPenDia->getPen(), \
confPenDia->getLineBegin(),  +                         confPenDia->getLineEnd(), \
confPenDia->getPenConfigChange() );  if(cmd)
         {
             if ( !macro)
                 macro=new KMacroCommand(i18n( "Apply Properties" ) );
-            macro->addCommand(cmd);
-        }
-
-        cmd=stickyPage()->setPen(confPenDia->getPen(), confPenDia->getLineBegin(), \
                confPenDia->getLineEnd(),
-                                 confPenDia->getPenConfigChange(), \
stickyPage()->objectList());  
-        if(cmd)
-        {
-            if ( !macro)
-                macro=new KMacroCommand(i18n( "Apply Properties" ) );
             macro->addCommand(cmd);
         }
     }
@@ -7181,4 +7079,26 @@ void KPresenterView::slotCorrectWord()
     }
 }
 
+KCommand * KPresenterView::getPenCmd( const QString &name, QPen pen, LineEnd lb, \
LineEnd le, int flags ) +{
+    KMacroCommand * macro = NULL;
+
+    KCommand * cmd = m_canvas->activePage()->setPen( pen, lb, le, flags );
+    if( cmd )
+    {
+        macro = new KMacroCommand( name );
+        macro->addCommand( cmd );
+    }
+    
+    cmd = stickyPage()->setPen( pen, lb, le, flags );
+    if( cmd )
+    {
+        if ( !macro )
+            macro = new KMacroCommand( name );
+        macro->addCommand( cmd );
+    }
+
+    return macro;
+}
+
 #include "kpresenter_view.moc"
Index: kprpage.h
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprpage.h,v
retrieving revision 1.107
diff -u -3 -p -r1.107 kprpage.h
--- kprpage.h	3 Jan 2004 06:58:45 -0000	1.107
+++ kprpage.h	6 Jan 2004 06:27:08 -0000
@@ -143,7 +143,7 @@ public:
 
     bool getProtectContent(bool prot) const;
 
-    KCommand* setPen( const QPen &pen, LineEnd lb, LineEnd le, int flags, \
QPtrList<KPObject> list); +    KCommand* setPen( const QPen &pen, LineEnd lb, LineEnd \
                le, int flags );
     KCommand* setBrush( const QBrush &brush, FillType ft, const  QColor& g1, const \
                QColor &g2, 
                         BCType gt, bool unbalanced, int xfactor, int yfactor, int \
flags );  
Index: kprpage.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/kprpage.cc,v
retrieving revision 1.233
diff -u -3 -p -r1.233 kprpage.cc
--- kprpage.cc	3 Jan 2004 06:50:10 -0000	1.233
+++ kprpage.cc	6 Jan 2004 06:27:13 -0000
@@ -1476,7 +1476,7 @@ KPPartObject* KPrPage::insertObject( con
     return kppartobject;
 }
 
-KCommand* KPrPage::setPen( const QPen &pen, LineEnd lb, LineEnd le, int flags, \
QPtrList<KPObject> /* list */) +KCommand* KPrPage::setPen( const QPen &pen, LineEnd \
lb, LineEnd le, int flags )  {
     PenCmd * cmd = NULL;
 



_______________________________________________
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