karbon
vzordercmd.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <klocale.h>
00021
00022 #include "vzordercmd.h"
00023 #include "vselection.h"
00024 #include "vdocument.h"
00025 #include "vlayer.h"
00026
00027 VZOrderCmd::VZOrderCmd( VDocument *doc, VOrder state )
00028 : VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
00029 {
00030 m_selection = document()->selection()->clone();
00031 }
00032
00033 VZOrderCmd::VZOrderCmd( VDocument *doc, VObject *obj, VOrder state )
00034 : VCommand( doc, i18n( "Order Selection" ) ), m_state( state )
00035 {
00036 m_selection = new VSelection();
00037 m_selection->append( obj );
00038 }
00039
00040 VZOrderCmd::~VZOrderCmd()
00041 {
00042 delete( m_selection );
00043 }
00044
00045 void
00046 VZOrderCmd::execute()
00047 {
00048 if( m_state == sendToBack )
00049 {
00050 VObjectListIterator itr( document()->selection()->objects() );
00051 for ( itr.toLast() ; itr.current() ; --itr )
00052 {
00053
00054 VObjectList objects;
00055 VLayerListIterator litr( document()->layers() );
00056
00057 for ( ; litr.current(); ++litr )
00058 {
00059 objects = litr.current()->objects();
00060 VObjectListIterator itr2( objects );
00061 for ( ; itr2.current(); ++itr2 )
00062 if( itr2.current() == itr.current() )
00063 {
00064 litr.current()->sendToBack( *itr2.current() );
00065 itr2.current()->setState( VObject::selected );
00066 }
00067 }
00068 }
00069 }
00070 else if( m_state == bringToFront )
00071 {
00072 VObjectListIterator itr( document()->selection()->objects() );
00073 for ( ; itr.current() ; ++itr )
00074 {
00075
00076 VObjectList objects;
00077 VLayerListIterator litr( document()->layers() );
00078
00079 for ( ; litr.current(); ++litr )
00080 {
00081 objects = litr.current()->objects();
00082 VObjectListIterator itr2( objects );
00083 for ( ; itr2.current(); ++itr2 )
00084 if( itr2.current() == itr.current() )
00085 {
00086 litr.current()->bringToFront( *itr2.current() );
00087 itr2.current()->setState( VObject::selected );
00088 }
00089 }
00090 }
00091 }
00092 else if( m_state == up || m_state == down )
00093 {
00094 VSelection selection = *m_selection;
00095
00096 VLayerListIterator litr( document()->layers() );
00097 while( !selection.objects().isEmpty() && litr.current() )
00098 {
00099 for ( ; litr.current(); ++litr )
00100 {
00101 if( litr.current()->state() == VObject::deleted )
00102 continue;
00103 VObjectList objects = litr.current()->objects();
00104 VObjectList todo;
00105 VObjectListIterator objectItr( objects );
00106
00107 for ( ; objectItr.current(); ++objectItr )
00108 {
00109 VObjectListIterator selectionItr( selection.objects() );
00110 for ( ; selectionItr.current() ; ++selectionItr )
00111 {
00112 if( objectItr.current() == selectionItr.current() )
00113 {
00114 if( m_state == up )
00115 todo.prepend( objectItr.current() );
00116 else
00117 todo.append( objectItr.current() );
00118 }
00119 }
00120 }
00121
00122 kdDebug(38000) << "todo.count() : " << todo.count() << endl;
00123
00124
00125 VObjectListIterator todoItr( todo );
00126 for ( ; todoItr.current(); ++todoItr )
00127 {
00128 if( m_state == up )
00129 litr.current()->upwards( *todoItr.current() );
00130 else
00131 litr.current()->downwards( *todoItr.current() );
00132
00133 selection.take( *todoItr.current() );
00134
00135 todoItr.current()->setState( VObject::selected );
00136 }
00137 }
00138 }
00139 }
00140 setSuccess( true );
00141 }
00142
00143 void
00144 VZOrderCmd::unexecute()
00145 {
00146 if( m_state == sendToBack )
00147 {
00148 m_state = bringToFront;
00149 execute();
00150 m_state = sendToBack;
00151 }
00152 else if( m_state == bringToFront )
00153 {
00154 m_state = sendToBack;
00155 execute();
00156 m_state = bringToFront;
00157 }
00158 else if( m_state == up )
00159 {
00160 m_state = down;
00161 execute();
00162 m_state = up;
00163 }
00164 else if( m_state == down )
00165 {
00166 m_state = up;
00167 execute();
00168 m_state = down;
00169 }
00170 setSuccess( false );
00171 }
00172
|