karbon

vdeletenodescmd.cc

00001 /* This file is doc 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 
00022 #include <klocale.h>
00023 
00024 #include "vdeletenodescmd.h"
00025 #include "vselection.h"
00026 #include "vsegment.h"
00027 #include "vpath.h"
00028 #include "vdocument.h"
00029 
00030 VDeleteNodeCmd::VDeleteNodeCmd( VDocument *doc )
00031     : VCommand( doc, i18n( "Delete Node" ) )
00032 {
00033 }
00034 
00035 VDeleteNodeCmd::~VDeleteNodeCmd()
00036 {
00037 }
00038 
00039 void
00040 VDeleteNodeCmd::visitVSubpath( VSubpath& path )
00041 {
00042     VSegment* segment = path.first();
00043 
00044     path.next(); // skip begin segment
00045     while( segment )
00046     {
00047         if( segment->state() != VSegment::deleted && segment->knotIsSelected() )
00048         {
00049             segment->setState( VSegment::deleted );
00050             m_segments.append( segment );
00051         }
00052         segment = segment->next();
00053     }
00054     if( m_segments.count() > 0 )
00055         path.invalidateBoundingBox();
00056 }
00057 
00058 void
00059 VDeleteNodeCmd::execute()
00060 {
00061     VObjectListIterator itr( document()->selection()->objects() );
00062 
00063     for( ; itr.current() ; ++itr )
00064         visit( *itr.current() );
00065 
00066     setSuccess( m_segments.count() > 0 );
00067 }
00068 
00069 void
00070 VDeleteNodeCmd::unexecute()
00071 {
00072     QPtrListIterator<VSegment> itr( m_segments );
00073     for( ; itr.current() ; ++itr )
00074         itr.current()->setState( VSegment::normal );
00075     setSuccess( false );
00076 }
00077 
KDE Home | KDE Accessibility Home | Description of Access Keys