karbon
vcomputeboundingbox.cc
00001 /* This file is part of the KDE project 00002 Copyright (C) 2006 Jan Hambrecht <jaham@gmx.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 00021 #include "vcomputeboundingbox.h" 00022 #include "vdocument.h" 00023 #include "vlayer.h" 00024 #include "vgroup.h" 00025 #include "vcomposite.h" 00026 #include "vtext.h" 00027 #include "vimage.h" 00028 00029 VComputeBoundingBox::VComputeBoundingBox( bool omitHidden ) 00030 : m_omitHidden( omitHidden ) 00031 { 00032 } 00033 00034 void 00035 VComputeBoundingBox::visitVDocument( VDocument& document ) 00036 { 00037 VLayerListIterator itr( document.layers() ); 00038 00039 for( ; itr.current(); ++itr ) 00040 { 00041 if( itr.current()->state() == VObject::deleted ) 00042 continue; 00043 // do not use hidden layers 00044 if( m_omitHidden && ! isVisible( itr.current() ) ) 00045 continue; 00046 itr.current()->accept( *this ); 00047 } 00048 } 00049 00050 void 00051 VComputeBoundingBox::visitVLayer( VLayer& layer ) 00052 { 00053 VObjectListIterator itr( layer.objects() ); 00054 00055 for( ; itr.current(); ++itr ) 00056 { 00057 if( itr.current()->state() == VObject::deleted ) 00058 continue; 00059 // do not export hidden objects 00060 if( m_omitHidden && ! isVisible( itr.current() ) ) 00061 continue; 00062 itr.current()->accept( *this ); 00063 } 00064 } 00065 00066 void 00067 VComputeBoundingBox::visitVGroup( VGroup& group ) 00068 { 00069 VObjectListIterator itr( group.objects() ); 00070 00071 for( ; itr.current(); ++itr ) 00072 { 00073 if( itr.current()->state() == VObject::deleted ) 00074 continue; 00075 // do not use hidden child objects 00076 if( m_omitHidden && ! isVisible( itr.current() ) ) 00077 continue; 00078 itr.current()->accept( *this ); 00079 } 00080 } 00081 00082 void 00083 VComputeBoundingBox::visitVPath( VPath& composite ) 00084 { 00085 m_boundingBox |= composite.boundingBox(); 00086 } 00087 00088 void 00089 VComputeBoundingBox::visitVText( VText& text ) 00090 { 00091 m_boundingBox |= text.boundingBox(); 00092 } 00093 00094 void 00095 VComputeBoundingBox::visitVImage( VImage& img ) 00096 { 00097 m_boundingBox |= img.boundingBox(); 00098 } 00099 00100 bool 00101 VComputeBoundingBox::isVisible( const VObject* object ) const 00102 { 00103 return object->state() != VObject::hidden && object->state() != VObject::hidden_locked; 00104 } 00105 00106 const KoRect& 00107 VComputeBoundingBox::boundingRect() const 00108 { 00109 return m_boundingBox; 00110 }