karbon

vungroupcmd.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 "vgroup.h"
00024 #include "vungroupcmd.h"
00025 #include "vselection.h"
00026 #include "vdocument.h"
00027 #include "vlayer.h"
00028 
00029 VUnGroupCmd::VUnGroupCmd( VDocument *doc )
00030     : VCommand( doc, i18n( "Ungroup Objects" ), "14_ungroup" )
00031 {
00032     m_group = dynamic_cast<VGroup *>( document()->selection()->objects().getFirst() );
00033     if( m_group )
00034         m_objects = m_group->objects();
00035 }
00036 
00037 VUnGroupCmd::~VUnGroupCmd()
00038 {
00039 }
00040 
00041 void
00042 VUnGroupCmd::execute()
00043 {
00044     if( !m_group )
00045         return;
00046 
00047     document()->selection()->clear();
00048 
00049     VObjectListIterator itr( m_group->objects() );
00050     for ( ; itr.current() ; ++itr )
00051     {
00052         // TODO : remove from corresponding VLayer
00053         document()->selection()->append( itr.current() );
00054     }
00055 
00056     VGroup* parent;
00057     if( ( parent = dynamic_cast<VGroup*>( m_group->parent() ) ) )
00058     {
00059         // unregister from parent:
00060         parent->take( *m_group );
00061 
00062         // inform all objects in this group about their new parent
00063         VObjectListIterator itr = m_group->objects();
00064 
00065         for ( ; itr.current() ; ++itr )
00066         {
00067             itr.current()->invalidateBoundingBox();
00068             parent->append( itr.current() );
00069         }
00070 
00071         m_group->clear();
00072         m_group->setState( VObject::deleted );
00073     }
00074 
00075     setSuccess( true );
00076 }
00077 
00078 void
00079 VUnGroupCmd::unexecute()
00080 {
00081     if( !m_group )
00082         return;
00083 
00084     VObjectListIterator itr( m_objects );
00085     for ( ; itr.current() ; ++itr )
00086     {
00087         // TODO : remove from corresponding VLayer
00088         document()->activeLayer()->take( *itr.current() );
00089         m_group->append( itr.current() );
00090     }
00091 
00092     m_group->setState( VObject::normal );
00093     document()->append( m_group );
00094     document()->selection()->clear();
00095     document()->selection()->append( m_group );
00096     
00097     setSuccess( false );
00098 }
00099 
KDE Home | KDE Accessibility Home | Description of Access Keys