karbon

vclipgroup.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 #ifdef HAVE_CONFIG_H
00022 #include <config.h>
00023 #endif
00024 
00025 #include <qdom.h>
00026 
00027 #include <kdebug.h>
00028 
00029 #include "vclipgroup.h"
00030 #include "vgroup.h"
00031 #include "vcomposite.h"
00032 #include "vsegment.h"
00033 #include <vpainter.h>
00034 #include "vtext.h"
00035 VClipGroup::VClipGroup( VObject* parent, VState state ) : VGroup( parent, state ) {}
00036 VClipGroup::VClipGroup( const VClipGroup& group ) : VGroup( group ) {}
00037 
00038 VClipGroup::~VClipGroup() { }
00039 
00040 void VClipGroup::draw( VPainter* painter, const KoRect* rect ) const
00041 {
00042     return VGroup::draw( painter, rect );
00043     if(
00044         state() == deleted ||
00045         state() == hidden ||
00046         state() == hidden_locked )
00047     {
00048         return;
00049     }
00050 
00051     VObjectListIterator itr = m_objects;
00052 
00053     painter->save();
00054 
00055     PathRenderer renderer( painter );
00056     kdDebug(38000) << "calling painter setClipPath" << endl;
00057     painter->setClipPath();
00058 
00059     VObject *obj = itr.current();
00060     obj->accept( renderer );
00061     ++itr;
00062 
00063     for( ; itr.current(); ++itr )
00064         itr.current()->draw( painter, rect );
00065 
00066     painter->restore();
00067 }
00068 
00069 VClipGroup* VClipGroup::clone() const
00070 {
00071     return new VClipGroup( *this );
00072 }
00073 
00074 
00075 void VClipGroup::save( QDomElement& element ) const
00076 {
00077     QDomElement me = element.ownerDocument().createElement( "CLIP" );
00078     element.appendChild( me );
00079 
00080     // save objects:
00081     VObjectListIterator itr = m_objects;
00082 
00083     for( ; itr.current(); ++itr )
00084         itr.current()->save( me );
00085 }
00086 
00087 void VClipGroup::load( const QDomElement& element )
00088 {
00089     m_objects.setAutoDelete( true );
00090     m_objects.clear();
00091     m_objects.setAutoDelete( false );
00092 
00093     QDomNodeList list = element.childNodes();
00094     for( uint i = 0; i < list.count(); ++i )
00095     {
00096         if( list.item( i ).isElement() )
00097         {
00098             QDomElement e = list.item( i ).toElement();
00099 
00100             if( e.tagName() == "COMPOSITE" || e.tagName() == "PATH" ) // TODO : remove COMPOSITE later
00101             {
00102                 VPath* composite = new VPath( this );
00103                 composite->load( e );
00104                 append( composite );
00105             }
00106             else if( e.tagName() == "GROUP" )
00107             {
00108                 VGroup* group = new VGroup( this );
00109                 group->load( e );
00110                 append( group );
00111             }
00112             else if( e.tagName() == "CLIP" )
00113             {
00114                 VClipGroup* clip = new VClipGroup( this );
00115                 clip->load( e );
00116                 append( clip );
00117             }
00118             else if( e.tagName() == "TEXT" )
00119             {
00120 #ifdef HAVE_KARBONTEXT
00121                 VText *text = new VText( this );
00122                 text->load( e );
00123                 append( text );
00124 #endif
00125             }
00126         }
00127     }
00128 }
00129 
00130 PathRenderer::PathRenderer( VPainter *p_painter ) : VVisitor()
00131 {
00132     m_painter = p_painter;
00133 }
00134 
00135 PathRenderer::~PathRenderer() {}
00136 
00137 void PathRenderer::visitVSubpath( VSubpath& path )
00138 {
00139     if(!m_painter) return;
00140 
00141     if(path.isEmpty()) return;
00142 
00143     for(path.first(); VSegment *segment = path.current(); path.next() )
00144     {
00145         KoPoint p1;
00146         KoPoint p2;
00147         KoPoint p3;
00148 
00149         QString buffer;
00150 
00151         if(segment->state() != VSegment::deleted)
00152         {
00153             if (segment->isBegin()) {
00154                 p1 = segment->point( 0 );
00155 
00156                 kdDebug(38000) << "calling painter.moveTo with " << p1 << endl;
00157                 m_painter->moveTo( p1 );
00158             } else if (segment->isCurve()) {
00159                 p1 = segment->point( 0 );
00160                 p2 = segment->point( 1 );
00161                 p3 = segment->point( 2 );
00162 
00163                 kdDebug(38000) << "calling painter.curveTo with " << p1 << " " << p2 << " " << p3 << endl;
00164                 m_painter->curveTo( p1, p2, p3 );
00165 
00166             } else if (segment->isLine()) {
00167                 p1 = segment->point( 0 );
00168                 kdDebug(38000) << "calling painter.lineTo with " << p1 << endl;
00169                 m_painter->lineTo( p1 );
00170             }
00171         }
00172     }
00173 
00174     VVisitor::visitVSubpath(path);
00175 
00176 //  if( path.isClosed() ) m_painter->closePath();
00177 }
00178 
KDE Home | KDE Accessibility Home | Description of Access Keys