karbon
vfill.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qdom.h>
00022 #include <kdebug.h>
00023
00024 #include <KoGenStyles.h>
00025 #include <KoOasisLoadingContext.h>
00026 #include <KoOasisStyles.h>
00027 #include <KoXmlNS.h>
00028
00029 #include "vfill.h"
00030
00031 VFill::VFill()
00032 : m_type( none )
00033 {
00034
00035
00036
00037
00038
00039
00040 }
00041
00042 VFill::VFill( const VColor &c )
00043 : m_type( solid )
00044 {
00045 m_color = c;
00046
00047 }
00048
00049 VFill::VFill( const VFill& fill )
00050 {
00051
00052 *this = fill;
00053 }
00054
00055 void
00056 VFill::save( QDomElement& element ) const
00057 {
00058 QDomElement me = element.ownerDocument().createElement( "FILL" );
00059 element.appendChild( me );
00060
00061 if( !( m_type == none ) )
00062 {
00063
00064 m_color.save( me );
00065 }
00066 if( m_type == grad )
00067 {
00068
00069 m_gradient.save( me );
00070 }
00071 else if( m_type == patt )
00072 {
00073
00074 m_pattern.save( me );
00075 }
00076 }
00077
00078 void
00079 VFill::saveOasis( KoGenStyles &mainStyles, KoGenStyle &style ) const
00080 {
00081 if( m_type == solid )
00082 {
00083 style.addProperty( "draw:fill", "solid" );
00084 style.addProperty( "draw:fill-color", QColor( m_color ).name() );
00085 if( m_color.opacity() < 1 )
00086 style.addProperty( "draw:opacity", QString( "%1%" ).arg( m_color.opacity() * 100. ) );
00087 }
00088 else if( m_type == grad )
00089 {
00090 style.addProperty( "draw:fill", "gradient" );
00091 QString grad = m_gradient.saveOasis( mainStyles );
00092 style.addProperty( "draw:fill-gradient-name", grad );
00093 if( m_color.opacity() < 1 )
00094 style.addProperty( "draw:opacity", QString( "%1%" ).arg( m_color.opacity() * 100. ) );
00095 }
00096 else if( m_type == patt )
00097 style.addProperty( "draw:fill", "hatch" );
00098 else
00099 style.addProperty( "draw:fill", "none" );
00100 }
00101
00102 void
00103 VFill::loadOasis( const QDomElement &, KoOasisLoadingContext &context, VObject* parent )
00104 {
00105 KoStyleStack &stack = context.styleStack();
00106 if( stack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
00107 {
00108 if( stack.attributeNS( KoXmlNS::draw, "fill" ) == "solid" )
00109 {
00110 setType( VFill::solid );
00111 setColor( QColor( stack.attributeNS( KoXmlNS::draw, "fill-color" ) ) );
00112 }
00113 else if( stack.attributeNS( KoXmlNS::draw, "fill" ) == "gradient" )
00114 {
00115 setType( VFill::grad );
00116 QString style = stack.attributeNS( KoXmlNS::draw, "fill-gradient-name" );
00117 kdDebug()<<" style gradient name :"<<style<<endl;
00118 QDomElement *grad = context.oasisStyles().drawStyles()[ style ];
00119 kdDebug()<<" style gradient name :"<< grad <<endl;
00120 if( grad )
00121 m_gradient.loadOasis( *grad, stack, parent );
00122 }
00123 if( stack.hasAttributeNS( KoXmlNS::draw, "opacity" ) )
00124 m_color.setOpacity( stack.attributeNS( KoXmlNS::draw, "opacity" ).remove( '%' ).toFloat() / 100. );
00125 }
00126 }
00127
00128 void
00129 VFill::load( const QDomElement& element )
00130 {
00131 m_type = none;
00132
00133
00134 QDomNodeList list = element.childNodes();
00135 for( uint i = 0; i < list.count(); ++i )
00136 {
00137 if( list.item( i ).isElement() )
00138 {
00139 QDomElement e = list.item( i ).toElement();
00140 if( e.tagName() == "COLOR" )
00141 {
00142 m_type = solid;
00143 m_color.load( e );
00144 }
00145 if( e.tagName() == "GRADIENT" )
00146 {
00147 m_type = grad;
00148 m_gradient.load( e );
00149 }
00150 else if( e.tagName() == "PATTERN" )
00151 {
00152 m_type = patt;
00153 m_pattern.load( e );
00154 }
00155 }
00156 }
00157 }
00158
00159 VFill&
00160 VFill::operator=( const VFill& fill )
00161 {
00162 if( this != &fill )
00163 {
00164
00165 m_type = fill.m_type;
00166 m_color = fill.m_color;
00167 m_gradient = fill.m_gradient;
00168 m_pattern = fill.m_pattern;
00169 }
00170
00171 return *this;
00172 }
00173
00174 void
00175 VFill::transform( const QWMatrix& m )
00176 {
00177 if( type() == VFill::grad )
00178 gradient().transform( m );
00179 else if( type() == VFill::patt )
00180 pattern().transform( m );
00181 }
|