karbon

vlayer.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, 2002, 2003 The Karbon Developers
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 #include <qdom.h>
00021 
00022 #include <klocale.h>
00023 #include <KoRect.h>
00024 
00025 #include "vcomposite.h"
00026 #include "vdocument.h"
00027 #include "vgroup.h"
00028 #include "vlayer.h"
00029 #include "vobject.h"
00030 #include "vtext.h"
00031 #include "vvisitor.h"
00032 #include "vlayer_iface.h"
00033 #include <kdebug.h>
00034 #include "vclipgroup.h"
00035 #include "vfill.h"
00036 #include "vstroke.h"
00037 
00038 VLayer::VLayer( VObject* parent, VState state )
00039     : VGroup( parent, state )
00040 {
00041     setName( "Layer" );
00042     // HACK : vlayer just shouldn't have fill/stroke at all
00043     delete m_fill;
00044     m_fill = 0L;
00045     delete m_stroke;
00046     m_stroke = 0L;
00047 }
00048 
00049 VLayer::VLayer( const VLayer& layer )
00050     : VGroup( layer )
00051 {
00052 }
00053 
00054 VLayer::~VLayer()
00055 {
00056 }
00057 
00058 DCOPObject* VLayer::dcopObject()
00059 {
00060     if ( !m_dcop )
00061         m_dcop = new VLayerIface( this );
00062 
00063     return m_dcop;
00064 }
00065 
00066 void
00067 VLayer::draw( VPainter* painter, const KoRect* rect ) const
00068 {
00069     if(
00070         state() == deleted ||
00071         state() == hidden ||
00072         state() == hidden_locked )
00073     {
00074         return;
00075     }
00076 
00077     VObjectListIterator itr = m_objects;
00078 
00079     for ( ; itr.current(); ++itr )
00080         itr.current()->draw( painter, rect );
00081 }
00082 
00083 void
00084 VLayer::bringToFront( const VObject& object )
00085 {
00086     if( m_objects.getLast() == &object ) return;
00087 
00088     m_objects.remove( &object );
00089 
00090     m_objects.append( &object );
00091 }
00092 
00093 void
00094 VLayer::upwards( const VObject& object )
00095 {
00096     if( m_objects.getLast() == &object ) return;
00097 
00098     m_objects.remove( &object );
00099 
00100     if( m_objects.current() != m_objects.getLast() )
00101     {
00102         m_objects.next();
00103         m_objects.insert( m_objects.at(), &object );
00104     }
00105     else
00106         m_objects.append( &object );
00107 }
00108 
00109 void
00110 VLayer::downwards( const VObject& object )
00111 {
00112     if( m_objects.getFirst() == &object ) return;
00113 
00114     int index = m_objects.find( &object );
00115     bool bLast = m_objects.getLast() == &object;
00116     m_objects.remove( index );
00117 
00118     if( !bLast ) m_objects.prev();
00119 
00120     m_objects.insert( m_objects.at(), &object );
00121 }
00122 
00123 void
00124 VLayer::sendToBack( const VObject& object )
00125 {
00126     if( m_objects.getFirst() == &object ) return;
00127 
00128     m_objects.remove( &object );
00129 
00130     m_objects.prepend( &object );
00131 }
00132 
00133 void
00134 VLayer::save( QDomElement& element ) const
00135 {
00136     if( state() != deleted )
00137     {
00138         QDomElement me = element.ownerDocument().createElement( "LAYER" );
00139         element.appendChild( me );
00140 
00141         if( state() == normal || state() == normal_locked || state() == VObject::selected )
00142             me.setAttribute( "visible", 1 );
00143 
00144         // save objects:
00145         VObjectListIterator itr = m_objects;
00146         for ( ; itr.current(); ++itr )
00147             itr.current()->save( me );
00148 
00149         VObject::save( me );
00150     }
00151 }
00152 
00153 void
00154 VLayer::saveOasis( KoStore *store, KoXmlWriter *docWriter, KoGenStyles &mainStyles, int &index ) const
00155 {
00156     // save objects:
00157     VObjectListIterator itr = m_objects;
00158 
00159     for ( ; itr.current(); ++itr )
00160         itr.current()->saveOasis( store, docWriter, mainStyles, ++index );
00161 }
00162 
00163 void
00164 VLayer::load( const QDomElement& element )
00165 {
00166     setState( element.attribute( "visible" ) == 0 ? hidden : normal );
00167     VGroup::load( element );
00168 }
00169 
00170 
00171 VLayer*
00172 VLayer::clone() const
00173 {
00174     return new VLayer( *this );
00175 }
00176 
00177 void
00178 VLayer::accept( VVisitor& visitor )
00179 {
00180     visitor.visitVLayer( *this );
00181 }
00182 
KDE Home | KDE Accessibility Home | Description of Access Keys