karbon
vfillcmd.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
|