You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
4.6 KiB
182 lines
4.6 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2001, The Karbon Developers
|
||
|
Copyright (C) 2002, The Karbon Developers
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqdom.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
|
||
|
#include <KoGenStyles.h>
|
||
|
#include <KoOasisLoadingContext.h>
|
||
|
#include <KoOasisStyles.h>
|
||
|
#include <KoXmlNS.h>
|
||
|
|
||
|
#include "vfill.h"
|
||
|
|
||
|
VFill::VFill()
|
||
|
: m_type( none )
|
||
|
{
|
||
14 years ago
|
/*m_gradient.addStop( VColor( TQt::red.rgb() ), 0.0 );
|
||
|
m_gradient.addStop( VColor( TQt::yellow.rgb() ), 1.0 );
|
||
15 years ago
|
m_gradient.setOrigin( KoPoint( 0, 0 ) );
|
||
|
m_gradient.setVector( KoPoint( 0, 50 ) );
|
||
|
m_gradient.setSpreadMethod( gradient_spread_reflect );*/
|
||
|
//kdDebug(38000) << "Size of VFill : " << sizeof(*this) << endl;
|
||
|
}
|
||
|
|
||
|
VFill::VFill( const VColor &c )
|
||
|
: m_type( solid )
|
||
|
{
|
||
|
m_color = c;
|
||
|
//kdDebug(38000) << "Size of VFill : " << sizeof(*this) << endl;
|
||
|
}
|
||
|
|
||
|
VFill::VFill( const VFill& fill )
|
||
|
{
|
||
13 years ago
|
// doesn't copy parent:
|
||
15 years ago
|
*this = fill;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VFill::save( TQDomElement& element ) const
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomElement me = element.ownerDocument().createElement( "FILL" );
|
||
15 years ago
|
element.appendChild( me );
|
||
|
|
||
|
if( !( m_type == none ) )
|
||
|
{
|
||
|
// save color:
|
||
|
m_color.save( me );
|
||
|
}
|
||
|
if( m_type == grad )
|
||
|
{
|
||
|
// save gradient:
|
||
|
m_gradient.save( me );
|
||
|
}
|
||
|
else if( m_type == patt )
|
||
|
{
|
||
|
// save pattern:
|
||
|
m_pattern.save( me );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
|
VFill::saveOasis( KoGenStyles &mainStyles, KoGenStyle &style ) const
|
||
|
{
|
||
|
if( m_type == solid )
|
||
|
{
|
||
|
style.addProperty( "draw:fill", "solid" );
|
||
14 years ago
|
style.addProperty( "draw:fill-color", TQColor( m_color ).name() );
|
||
15 years ago
|
if( m_color.opacity() < 1 )
|
||
13 years ago
|
style.addProperty( "draw:opacity", TQString( "%1%" ).arg( m_color.opacity() * 100. ) );
|
||
15 years ago
|
}
|
||
|
else if( m_type == grad )
|
||
|
{
|
||
|
style.addProperty( "draw:fill", "gradient" );
|
||
14 years ago
|
TQString grad = m_gradient.saveOasis( mainStyles );
|
||
15 years ago
|
style.addProperty( "draw:fill-gradient-name", grad );
|
||
|
if( m_color.opacity() < 1 )
|
||
13 years ago
|
style.addProperty( "draw:opacity", TQString( "%1%" ).arg( m_color.opacity() * 100. ) );
|
||
15 years ago
|
}
|
||
|
else if( m_type == patt )
|
||
|
style.addProperty( "draw:fill", "hatch" );
|
||
|
else
|
||
|
style.addProperty( "draw:fill", "none" );
|
||
|
}
|
||
|
|
||
|
void
|
||
13 years ago
|
VFill::loadOasis( const TQDomElement &/*object*/, KoOasisLoadingContext &context, VObject* parent )
|
||
15 years ago
|
{
|
||
|
KoStyleStack &stack = context.styleStack();
|
||
|
if( stack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
|
||
|
{
|
||
|
if( stack.attributeNS( KoXmlNS::draw, "fill" ) == "solid" )
|
||
|
{
|
||
|
setType( VFill::solid );
|
||
14 years ago
|
setColor( TQColor( stack.attributeNS( KoXmlNS::draw, "fill-color" ) ) );
|
||
15 years ago
|
}
|
||
|
else if( stack.attributeNS( KoXmlNS::draw, "fill" ) == "gradient" )
|
||
|
{
|
||
|
setType( VFill::grad );
|
||
14 years ago
|
TQString style = stack.attributeNS( KoXmlNS::draw, "fill-gradient-name" );
|
||
15 years ago
|
kdDebug()<<" style gradient name :"<<style<<endl;
|
||
14 years ago
|
TQDomElement *grad = context.oasisStyles().drawStyles()[ style ];
|
||
15 years ago
|
kdDebug()<<" style gradient name :"<< grad <<endl;
|
||
|
if( grad )
|
||
13 years ago
|
m_gradient.loadOasis( *grad, stack, parent );
|
||
15 years ago
|
}
|
||
|
if( stack.hasAttributeNS( KoXmlNS::draw, "opacity" ) )
|
||
|
m_color.setOpacity( stack.attributeNS( KoXmlNS::draw, "opacity" ).remove( '%' ).toFloat() / 100. );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VFill::load( const TQDomElement& element )
|
||
15 years ago
|
{
|
||
|
m_type = none;
|
||
|
|
||
|
// load color:
|
||
14 years ago
|
TQDomNodeList list = element.childNodes();
|
||
15 years ago
|
for( uint i = 0; i < list.count(); ++i )
|
||
|
{
|
||
|
if( list.item( i ).isElement() )
|
||
|
{
|
||
14 years ago
|
TQDomElement e = list.item( i ).toElement();
|
||
15 years ago
|
if( e.tagName() == "COLOR" )
|
||
|
{
|
||
|
m_type = solid;
|
||
|
m_color.load( e );
|
||
|
}
|
||
|
if( e.tagName() == "GRADIENT" )
|
||
|
{
|
||
|
m_type = grad;
|
||
|
m_gradient.load( e );
|
||
|
}
|
||
|
else if( e.tagName() == "PATTERN" )
|
||
|
{
|
||
|
m_type = patt;
|
||
|
m_pattern.load( e );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
VFill&
|
||
|
VFill::operator=( const VFill& fill )
|
||
|
{
|
||
|
if( this != &fill )
|
||
|
{
|
||
13 years ago
|
// dont copy the parent!
|
||
15 years ago
|
m_type = fill.m_type;
|
||
|
m_color = fill.m_color;
|
||
|
m_gradient = fill.m_gradient;
|
||
|
m_pattern = fill.m_pattern;
|
||
|
}
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
void
|
||
14 years ago
|
VFill::transform( const TQWMatrix& m )
|
||
15 years ago
|
{
|
||
|
if( type() == VFill::grad )
|
||
|
gradient().transform( m );
|
||
|
else if( type() == VFill::patt )
|
||
|
pattern().transform( m );
|
||
|
}
|