00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kspread_brush.h"
00022
00023 #include <KoGenStyles.h>
00024 #include <KoOasisStyles.h>
00025 #include <KoOasisContext.h>
00026 #include <KoXmlNS.h>
00027
00028 KSpreadBrush::KSpreadBrush()
00029 : m_gColor1( Qt::red )
00030 , m_gColor2( Qt::green )
00031 , m_gType( BCT_GHORZ )
00032 , m_fillType( FT_BRUSH )
00033 , m_unbalanced( false )
00034 , m_xfactor( 100 )
00035 , m_yfactor( 100 )
00036 {
00037 }
00038
00039
00040 KSpreadBrush::KSpreadBrush( const QBrush &brush, const QColor &gColor1, const QColor &gColor2,
00041 BCType gType, FillType fillType, bool unbalanced,
00042 int xfactor, int yfactor )
00043 : m_brush( brush )
00044 , m_gColor1( gColor1 )
00045 , m_gColor2( gColor2 )
00046 , m_gType( gType )
00047 , m_fillType( fillType )
00048 , m_unbalanced( unbalanced )
00049 , m_xfactor( xfactor )
00050 , m_yfactor( yfactor )
00051 {
00052 }
00053
00054
00055 KSpreadBrush & KSpreadBrush::operator=( const KSpreadBrush &brush )
00056 {
00057 m_brush = brush.m_brush;
00058 m_gColor1 = brush.m_gColor1;
00059 m_gColor2 = brush.m_gColor2;
00060 m_gType = brush.m_gType;
00061 m_fillType = brush.m_fillType;
00062 m_unbalanced = brush.m_unbalanced;
00063 m_xfactor = brush.m_xfactor;
00064 m_yfactor = brush.m_yfactor;
00065 return *this;
00066 }
00067
00068
00069 void KSpreadBrush::saveOasisFillStyle( KoGenStyle &styleObjectAuto, KoGenStyles& mainStyles ) const
00070 {
00071 switch ( m_fillType )
00072 {
00073 case FT_BRUSH:
00074 {
00075 if( m_brush.style() != Qt::NoBrush )
00076 {
00077 KoOasisStyles::saveOasisFillStyle( styleObjectAuto, mainStyles, m_brush );
00078 }
00079 else
00080 {
00081 styleObjectAuto.addProperty( "draw:fill","none" );
00082 }
00083 break;
00084 }
00085 case FT_GRADIENT:
00086 styleObjectAuto.addProperty( "draw:fill","gradient" );
00087 #if 0
00088 styleObjectAuto.addProperty( "draw:fill-gradient-name", saveOasisGradientStyle( mainStyles ) );
00089 #endif
00090 break;
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 void KSpreadBrush::loadOasisFillStyle( KoOasisContext &context, const char * propertyType )
00157 {
00158 KoStyleStack &styleStack = context.styleStack();
00159 styleStack.setTypeProperties( propertyType );
00160
00161 if ( styleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
00162 {
00163 const QString fill = styleStack.attributeNS( KoXmlNS::draw, "fill" );
00164 kdDebug(33001) << " load object gradient fill type :" << fill << endl;
00165
00166 if ( fill == "solid" || fill == "hatch" )
00167 {
00168 setBrush( KoOasisStyles::loadOasisFillStyle( styleStack, fill, context.oasisStyles() ) );
00169 }
00170 else if ( fill == "gradient" )
00171 {
00172 QString style = styleStack.attributeNS( KoXmlNS::draw, "fill-gradient-name" );
00173 QDomElement* draw = context.oasisStyles().drawStyles()[style];
00174
00175 if ( draw )
00176 {
00177 setGColor1( draw->attributeNS( KoXmlNS::draw, "start-color", QString::null ) );
00178 setGColor2( draw->attributeNS( KoXmlNS::draw, "end-color", QString::null ) );
00179
00180 QString type = draw->attributeNS( KoXmlNS::draw, "style", QString::null );
00181 kdDebug()<<" type :"<<type<<endl;
00182 if ( type == "linear" )
00183 {
00184 int angle = draw->attributeNS( KoXmlNS::draw, "angle", QString::null ).toInt() / 10;
00185
00186
00187 angle = abs( angle );
00188 angle -= ( (int) ( angle / 360 ) ) * 360;
00189
00190
00191
00192 int lower, upper, nearAngle = 0;
00193 for ( lower = 0, upper = 45; upper < 360; lower += 45, upper += 45 )
00194 {
00195 if ( upper >= angle )
00196 {
00197 int distanceToUpper = abs( angle - upper );
00198 int distanceToLower = abs( angle - lower );
00199 nearAngle = distanceToUpper > distanceToLower ? lower : upper;
00200 break;
00201 }
00202 }
00203
00204 if ( nearAngle == 0 || nearAngle == 180 )
00205 setGType( BCT_GHORZ );
00206 else if ( nearAngle == 90 || nearAngle == 270 )
00207 setGType( BCT_GVERT );
00208 else if ( nearAngle == 45 || nearAngle == 225 )
00209 setGType( BCT_GDIAGONAL1 );
00210 else if ( nearAngle == 135 || nearAngle == 315 )
00211 setGType( BCT_GDIAGONAL2 );
00212 }
00213 else if ( type == "radial" || type == "ellipsoid" )
00214 setGType( BCT_GCIRCLE );
00215 else if ( type == "square" || type == "rectangular" )
00216 setGType( BCT_GRECT );
00217 else if ( type == "axial" )
00218 setGType( BCT_GPIPECROSS );
00219 else
00220 setGType( BCT_PLAIN );
00221
00222
00223
00224 int x, y;
00225 if ( draw->hasAttributeNS( KoXmlNS::draw, "cx" ) )
00226 x = draw->attributeNS( KoXmlNS::draw, "cx", QString::null ).remove( '%' ).toInt();
00227 else
00228 x = 50;
00229
00230 if ( draw->hasAttributeNS( KoXmlNS::draw, "cy" ) )
00231 y = draw->attributeNS( KoXmlNS::draw, "cy", QString::null ).remove( '%' ).toInt();
00232 else
00233 y = 50;
00234
00235 if ( x == 50 && y == 50 )
00236 {
00237 setGUnbalanced( false );
00238 setGXFactor( 100 );
00239 setGYFactor( 100 );
00240 }
00241 else
00242 {
00243 setGUnbalanced( true );
00244
00245 setGXFactor( 4 * x - 200 );
00246 setGYFactor( 4 * y - 200 );
00247 }
00248 }
00249
00250
00251
00252
00253 QBrush tmpBrush;
00254 tmpBrush.setStyle( static_cast<Qt::BrushStyle>( 1 ) );
00255 setBrush( tmpBrush );
00256 setFillType( FT_GRADIENT );
00257 }
00258 else if ( fill == "none" )
00259 {
00260
00261 }
00262 else if ( fill == "bitmap" )
00263 {
00264
00265
00266
00267
00268
00269 }
00270 }
00271 }