karbon

vfillcmd.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, The Karbon Developers
00003    Copyright (C) 2002, The Karbon Developers
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <klocale.h>
00022 
00023 #include "vfill.h"
00024 #include "vfillcmd.h"
00025 #include "vselection.h"
00026 #include "vdocument.h"
00027 #include "vcomposite.h"
00028 #include "vgroup.h"
00029 #include "vtext.h"
00030 
00031 VFillCmd::VFillCmd( VDocument *doc, const VFill &fill, const QString &icon )
00032     : VCommand( doc, i18n( "Fill Objects" ), icon ), m_fill( fill )
00033 {
00034     m_selection = document()->selection()->clone();
00035 
00036     if( m_selection->objects().count() == 1 )
00037         setName( i18n( "Fill Object" ) );
00038 }
00039 
00040 VFillCmd::~VFillCmd()
00041 {
00042     m_objects.clear();
00043     delete m_selection;
00044     m_selection = 0L;
00045 }
00046 
00047 void
00048 VFillCmd::changeFill( const VFill &fill )
00049 {
00050     m_fill = fill;
00051 
00052     if( !m_selection )
00053         m_selection = document()->selection()->clone();
00054 
00055     VObjectListIterator itr( m_selection->objects() );
00056 
00057     for( ; itr.current() ; ++itr )
00058     {
00059         visit( *itr.current() );
00060     }
00061 
00062     setSuccess( true );
00063 }
00064 
00065 void
00066 VFillCmd::visitVGroup( VGroup& group )
00067 {
00068     VObjectListIterator itr( group.objects() );
00069 
00070     for( ; itr.current() ; ++itr )
00071     {
00072         m_oldfills.push_back( VFill( *( itr.current()->fill() ) ) );
00073         itr.current()->setFill( m_fill );
00074         m_objects.append(itr.current() );
00075     }
00076 }
00077 
00078 void 
00079 VFillCmd::visitVPath( VPath& composite )
00080 {
00081     m_oldfills.push_back( VFill( *( composite.fill() ) ) );
00082     composite.setFill( m_fill );
00083     m_objects.append( &composite );
00084 }
00085 
00086 void
00087 VFillCmd::visitVText( VText& text )
00088 {
00089     m_oldfills.push_back( VFill( *( text.fill() ) ) );
00090     text.setFill( m_fill );
00091     m_objects.append( &text );
00092 }
00093 
00094 void
00095 VFillCmd::execute()
00096 {
00097     if( !m_selection )
00098         m_selection = document()->selection()->clone();
00099     VObjectListIterator itr( m_selection->objects() );
00100 
00101     for( ; itr.current() ; ++itr )
00102     {
00103         visit( *itr.current() );
00104     }
00105 
00106     setSuccess( true );
00107 }
00108 
00109 void
00110 VFillCmd::unexecute()
00111 {
00112     VObjectListIterator itr( m_objects );
00113 
00114     int i = 0;
00115 
00116     for( ; itr.current() ; ++itr )
00117     {
00118         itr.current()->setFill( m_oldfills[ i++ ] );
00119     }
00120 
00121     setSuccess( false );
00122 }
00123 
KDE Home | KDE Accessibility Home | Description of Access Keys