23#include <KoGenStyles.h>
24#include <KoStyleStack.h>
33: m_parent(0L), m_lineWidth(1.0), m_lineCap(capButt), m_lineJoin(joinMiter), m_miterLimit(10.0), m_type(none)
36VStroke::VStroke(
VObject* parent,
float width,
const VLineCap cap,
const VLineJoin join,
44 m_miterLimit = miterLimit;
47VStroke::VStroke(
const VColor &c,
VObject* parent,
float width,
const VLineCap cap,
const VLineJoin join,
55 m_miterLimit = miterLimit;
59VStroke::VStroke(
const VStroke& stroke )
66VStroke::setLineWidth(
float width )
76VStroke::save( TQDomElement& element )
const
78 TQDomElement me = element.ownerDocument().createElement(
"STROKE" );
79 element.appendChild( me );
82 if( m_lineWidth != 1.0 )
83 me.setAttribute(
"lineWidth", m_lineWidth );
84 if( !( m_lineCap == capButt ) )
85 me.setAttribute(
"lineCap", m_lineCap );
86 if( !( m_lineJoin == joinMiter ) )
87 me.setAttribute(
"lineJoin", m_lineJoin );
88 if( m_miterLimit != 10.0 )
89 me.setAttribute(
"miterLimit", m_miterLimit );
96 else if( m_type ==
grad )
99 m_gradient.save( me );
101 else if( m_type ==
patt )
104 m_pattern.save( me );
108 m_dashPattern.save( me );
112VStroke::saveOasis( KoGenStyle &style )
const
114 if( m_type ==
solid )
116 style.addProperty(
"draw:stroke",
"solid" );
117 style.addProperty(
"svg:stroke-color", TQColor( m_color ).name() );
118 style.addPropertyPt(
"svg:stroke-width", m_lineWidth );
120 style.addProperty(
"svg:stroke-opacity", TQString(
"%1%" ).arg( m_color.
opacity() * 100. ) );
122 else if( m_type == none )
123 style.addProperty(
"draw:stroke",
"none" );
129 if( m_lineJoin == joinRound )
130 style.addProperty(
"draw:stroke-linejoin",
"round" );
131 else if( m_lineJoin == joinBevel )
132 style.addProperty(
"draw:stroke-linejoin",
"bevel" );
133 else if( m_lineJoin == joinMiter )
134 style.addProperty(
"draw:stroke-linejoin",
"miter" );
138VStroke::loadOasis(
const KoStyleStack &stack )
140 if( stack.hasAttributeNS( KoXmlNS::draw,
"stroke" ))
142 if( stack.attributeNS( KoXmlNS::draw,
"stroke" ) ==
"solid" )
145 setColor( TQColor( stack.attributeNS( KoXmlNS::svg,
"stroke-color" ) ) );
146 if( stack.hasAttributeNS( KoXmlNS::svg,
"stroke-opacity" ) )
147 m_color.
setOpacity( stack.attributeNS( KoXmlNS::svg,
"stroke-opacity" ).remove(
'%' ).toFloat() / 100. );
148 TQString join = stack.attributeNS( KoXmlNS::draw,
"stroke-linejoin" );
149 if( !join.isEmpty() )
151 if( join ==
"round" )
152 m_lineJoin = joinRound;
153 else if( join ==
"bevel" )
154 m_lineJoin = joinBevel;
156 m_lineJoin = joinMiter;
159 else if( stack.attributeNS( KoXmlNS::draw,
"stroke" ) ==
"none" )
160 setType( VStroke::none );
162 if( stack.hasAttributeNS( KoXmlNS::svg,
"stroke-width" ) )
163 m_lineWidth = KoUnit::parseValue( stack.attributeNS( KoXmlNS::svg,
"stroke-width" ) );
164 if( m_lineWidth < 0.0 )
169VStroke::load(
const TQDomElement& element )
173 m_lineWidth = element.attribute(
"lineWidth",
"1.0" ).toDouble();
174 if( m_lineWidth < 0.0 )
177 switch( element.attribute(
"lineCap",
"0" ).toUShort() )
180 m_lineCap = capRound;
break;
182 m_lineCap = capSquare;
break;
187 switch( element.attribute(
"lineJoin",
"0" ).toUShort() )
190 m_lineJoin = joinRound;
break;
192 m_lineJoin = joinBevel;
break;
194 m_lineJoin = joinMiter;
197 m_miterLimit = element.attribute(
"miterLimit",
"10.0" ).toDouble();
198 if( m_miterLimit < 0.0 )
203 TQDomNodeList list = element.childNodes();
204 for( uint i = 0; i < list.count(); ++i )
206 if( list.item( i ).isElement() )
208 TQDomElement e = list.item( i ).toElement();
209 if( e.tagName() ==
"COLOR" )
214 else if( e.tagName() ==
"DASHPATTERN" )
216 m_dashPattern.load( e );
218 else if( e.tagName() ==
"GRADIENT" )
221 m_gradient.load( e );
223 else if( e.tagName() ==
"PATTERN" )
234VStroke::operator=(
const VStroke& stroke )
236 if(
this != &stroke )
239 m_type = stroke.m_type;
241 m_lineWidth = stroke.m_lineWidth;
246 m_lineCap = stroke.m_lineCap;
247 m_lineJoin = stroke.m_lineJoin;
248 m_miterLimit = stroke.m_miterLimit;
249 m_color = stroke.m_color;
250 m_dashPattern = stroke.m_dashPattern;
251 m_gradient = stroke.m_gradient;
252 m_pattern = stroke.m_pattern;
259VStroke::transform(
const TQWMatrix& m )
262 gradient().transform( m );
264 pattern().transform( m );
This class keeps track of color properties.
void setOpacity(float opacity)
Sets the color opacity.
void load(const TQDomElement &element)
Load this color's state from xml and initialize it accordingly.
float opacity() const
Returns the color opacity.
void save(TQDomElement &element) const
Save this color's state to xml.
The base class for all karbon objects.
void invalidateBoundingBox()
Invalidates the bounding box, so it has to be recalculated.
Manages stroke properties.