karbon

vdashpattern.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002, 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 "vdashpattern.h"
00023 
00024 VDashPattern::VDashPattern( double offset )
00025     : m_offset( offset )
00026 {
00027 }
00028 
00029 void
00030 VDashPattern::save( QDomElement& element ) const
00031 {
00032     if( m_array.size() != 0 )
00033     {
00034         QDomElement me = element.ownerDocument().createElement( "DASHPATTERN" );
00035         element.appendChild( me );
00036 
00037         if( m_offset != 0.0 )
00038             me.setAttribute( "offset", m_offset );
00039 
00040         QDomElement dash;
00041 
00042         QValueListConstIterator<float> itr;
00043         for( itr = m_array.begin(); itr != m_array.end(); ++itr )
00044         {
00045             dash = element.ownerDocument().createElement( "DASH" );
00046             me.appendChild( dash );
00047             dash.setAttribute( "l", *( itr ) );
00048         }
00049     }
00050 }
00051 
00052 void
00053 VDashPattern::load( const QDomElement& element )
00054 {
00055     m_offset = element.attribute( "offset", "0.0" ).toDouble();
00056 
00057     float value;
00058 
00059     QDomNodeList list = element.childNodes();
00060     for( uint i = 0; i < list.count(); ++i )
00061     {
00062         if( list.item( i ).isElement() )
00063         {
00064             QDomElement e = list.item( i ).toElement();
00065             if( e.tagName() == "DASH" )
00066             {
00067                 value = e.attribute( "l", "0.0" ).toFloat();
00068                 if( value < 0.0 )
00069                     value = 0.0;
00070 
00071                 m_array.append( value );
00072             }
00073         }
00074     }
00075 }
00076 
KDE Home | KDE Accessibility Home | Description of Access Keys