22#include <KoGenStyles.h>
23#include <KoOasisStyles.h>
24#include <KoOasisContext.h>
26#include "KPrDocument.h"
33KPrBrush::KPrBrush(
const TQBrush &brush,
const TQColor &gColor1,
const TQColor &gColor2,
34 BCType gType, FillType fillType,
bool unbalanced,
35 int xfactor,
int yfactor )
36 : KoBrush( brush, gColor1,gColor2, gType, fillType, unbalanced, xfactor, yfactor )
40void KPrBrush::saveOasisFillStyle( KoGenStyle &styleObjectAuto, KoGenStyles& mainStyles )
const
42 switch ( getFillType() )
46 if( getBrush().style() != TQt::NoBrush )
48 KoOasisStyles::saveOasisFillStyle( styleObjectAuto, mainStyles, getBrush() );
52 styleObjectAuto.addProperty(
"draw:fill",
"none" );
57 styleObjectAuto.addProperty(
"draw:fill",
"gradient" );
58 styleObjectAuto.addProperty(
"draw:fill-gradient-name", saveOasisGradientStyle( mainStyles ) );
64TQString KPrBrush::saveOasisGradientStyle( KoGenStyles& mainStyles )
const
66 KoGenStyle gradientStyle( KPrDocument::STYLE_GRADIENT );
67 gradientStyle.addAttribute(
"draw:start-color", getGColor1().name() );
68 gradientStyle.addAttribute(
"draw:end-color", getGColor2().name() );
70 TQString unbalancedx(
"50%" );
71 TQString unbalancedy(
"50%" );
73 if ( getGUnbalanced() )
75 unbalancedx = TQString(
"%1%" ).arg( getGXFactor() / 4 + 50 );
76 unbalancedy = TQString(
"%1%" ).arg( getGYFactor() / 4 + 50 );
78 gradientStyle.addAttribute(
"draw:cx", unbalancedx );
79 gradientStyle.addAttribute(
"draw:cy", unbalancedy );
84 gradientStyle.addAttribute(
"draw:angle", 0 );
85 gradientStyle.addAttribute(
"draw:style",
"linear" );
88 gradientStyle.addAttribute(
"draw:angle", 0 );
89 gradientStyle.addAttribute(
"draw:style",
"linear" );
92 gradientStyle.addAttribute(
"draw:angle", 900 );
93 gradientStyle.addAttribute(
"draw:style",
"linear" );
96 gradientStyle.addAttribute(
"draw:angle", 450 );
97 gradientStyle.addAttribute(
"draw:style",
"linear" );
100 gradientStyle.addAttribute(
"draw:angle", 135 );
101 gradientStyle.addAttribute(
"draw:style",
"linear" );
104 gradientStyle.addAttribute(
"draw:angle", 0 );
105 gradientStyle.addAttribute(
"draw:style",
"radial" );
108 gradientStyle.addAttribute(
"draw:angle", 0 );
109 gradientStyle.addAttribute(
"draw:style",
"square" );
112 gradientStyle.addAttribute(
"draw:angle", 0 );
113 gradientStyle.addAttribute(
"draw:style",
"axial" );
116 gradientStyle.addAttribute(
"draw:angle", 0 );
117 gradientStyle.addAttribute(
"draw:style", 0 );
121 return mainStyles.lookup( gradientStyle,
"gradient" );
125void KPrBrush::loadOasisFillStyle( KoOasisContext &context,
const char * propertyType )
127 KoStyleStack &styleStack = context.styleStack();
128 styleStack.setTypeProperties( propertyType );
130 if ( styleStack.hasAttributeNS( KoXmlNS::draw,
"fill" ) )
132 const TQString fill = styleStack.attributeNS( KoXmlNS::draw,
"fill" );
133 kdDebug(33001) <<
" load object gradient fill type :" << fill << endl;
135 if ( fill ==
"solid" || fill ==
"hatch" )
137 setBrush( KoOasisStyles::loadOasisFillStyle( styleStack, fill, context.oasisStyles() ) );
139 else if ( fill ==
"gradient" )
141 TQString style = styleStack.attributeNS( KoXmlNS::draw,
"fill-gradient-name" );
142 TQDomElement* draw = context.oasisStyles().drawStyles()[style];
146 setGColor1( draw->attributeNS( KoXmlNS::draw,
"start-color", TQString() ) );
147 setGColor2( draw->attributeNS( KoXmlNS::draw,
"end-color", TQString() ) );
149 TQString type = draw->attributeNS( KoXmlNS::draw,
"style", TQString() );
150 kdDebug()<<
" type :"<<type<<endl;
151 if ( type ==
"linear" )
153 int angle = draw->attributeNS( KoXmlNS::draw,
"angle", TQString() ).toInt() / 10;
156 angle = abs( angle );
157 angle -= ( (int) ( angle / 360 ) ) * 360;
161 int lower, upper, nearAngle = 0;
162 for ( lower = 0, upper = 45; upper < 360; lower += 45, upper += 45 )
164 if ( upper >= angle )
166 int distanceToUpper = abs( angle - upper );
167 int distanceToLower = abs( angle - lower );
168 nearAngle = distanceToUpper > distanceToLower ? lower : upper;
173 if ( nearAngle == 0 || nearAngle == 180 )
174 setGType( BCT_GHORZ );
175 else if ( nearAngle == 90 || nearAngle == 270 )
176 setGType( BCT_GVERT );
177 else if ( nearAngle == 45 || nearAngle == 225 )
178 setGType( BCT_GDIAGONAL1 );
179 else if ( nearAngle == 135 || nearAngle == 315 )
180 setGType( BCT_GDIAGONAL2 );
182 if ( nearAngle == 180 || nearAngle == 270 || nearAngle == 225 || nearAngle == 315 )
184 setGColor1( draw->attributeNS( KoXmlNS::draw,
"end-color", TQString() ) );
185 setGColor2( draw->attributeNS( KoXmlNS::draw,
"start-color", TQString() ) );
188 else if ( type ==
"radial" || type ==
"ellipsoid" )
189 setGType( BCT_GCIRCLE );
190 else if ( type ==
"square" || type ==
"rectangular" )
191 setGType( BCT_GRECT );
192 else if ( type ==
"axial" )
193 setGType( BCT_GPIPECROSS );
195 setGType( BCT_PLAIN );
200 if ( draw->hasAttributeNS( KoXmlNS::draw,
"cx" ) )
201 x = draw->attributeNS( KoXmlNS::draw,
"cx", TQString() ).remove(
'%' ).toInt();
205 if ( draw->hasAttributeNS( KoXmlNS::draw,
"cy" ) )
206 y = draw->attributeNS( KoXmlNS::draw,
"cy", TQString() ).remove(
'%' ).toInt();
210 if ( x == 50 && y == 50 )
212 setGUnbalanced(
false );
218 setGUnbalanced(
true );
220 setGXFactor( 4 * x - 200 );
221 setGYFactor( 4 * y - 200 );
229 tmpBrush.setStyle(
static_cast<TQt::BrushStyle
>( 1 ) );
230 setBrush( tmpBrush );
231 setFillType( FT_GRADIENT );
233 else if ( fill ==
"none" )
237 else if ( fill ==
"bitmap" )