00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kspread_style.h"
00022 #include "kspread_util.h"
00023 #include "kspread_doc.h"
00024
00025 #include <kdebug.h>
00026 #include <koGlobal.h>
00027 #include <klocale.h>
00028 #include <koGenStyles.h>
00029 #include <qdom.h>
00030 #include <qbuffer.h>
00031 #include <koStyleStack.h>
00032 #include <koxmlwriter.h>
00033 #include <koxmlns.h>
00034
00035 static uint calculateValue( QPen const & pen )
00036 {
00037 uint n = pen.color().red() + pen.color().green() + pen.color().blue();
00038
00039 n += 1000 * pen.width();
00040 n += 10000 * (uint) pen.style();
00041
00042 return n;
00043 }
00044
00045 KSpreadStyle::KSpreadStyle()
00046 : m_parent( 0 ),
00047 m_type( AUTO ),
00048 m_usageCount( 0 ),
00049 m_featuresSet( 0 ),
00050 m_alignX( KSpreadFormat::Undefined ),
00051 m_alignY( KSpreadFormat::Middle ),
00052 m_floatFormat( KSpreadFormat::OnlyNegSigned ),
00053 m_floatColor( KSpreadFormat::AllBlack ),
00054 m_formatType( Generic_format ),
00055 m_fontFlags( 0 ),
00056 m_bgColor( Qt::white ),
00057 m_backGroundBrush( Qt::red, Qt::NoBrush ),
00058 m_rotateAngle( 0 ),
00059 m_indent( 0.0 ),
00060 m_precision( -1 ),
00061 m_properties( 0 )
00062 {
00063 QFont f( KoGlobal::defaultFont() );
00064 m_fontFamily = f.family();
00065 m_fontSize = f.pointSize();
00066
00067 QPen pen( Qt::black, 1, Qt::NoPen );
00068
00069 m_leftBorderPen = pen;
00070 m_topBorderPen = pen;
00071 m_rightBorderPen = pen;
00072 m_bottomBorderPen = pen;
00073 m_fallDiagonalPen = pen;
00074 m_goUpDiagonalPen = pen;
00075
00076 m_leftPenValue = calculateValue( pen );
00077 m_topPenValue = calculateValue( pen );
00078 m_rightPenValue = calculateValue( pen );
00079 m_bottomPenValue = calculateValue( pen );
00080
00081 m_currency.type = 0;
00082 }
00083
00084 KSpreadStyle::KSpreadStyle( KSpreadStyle * style )
00085 : m_parent( ( style->m_type == BUILTIN || style->m_type == CUSTOM ) ? (KSpreadCustomStyle *) style : 0 ),
00086 m_type( AUTO ),
00087 m_usageCount( 1 ),
00088 m_featuresSet( ( style->m_type == BUILTIN || style->m_type == CUSTOM ) ? 0 : style->m_featuresSet ),
00089 m_alignX( style->m_alignX ),
00090 m_alignY( style->m_alignY ),
00091 m_floatFormat( style->m_floatFormat ),
00092 m_floatColor( style->m_floatColor ),
00093 m_formatType( style->m_formatType ),
00094 m_fontFamily( style->m_fontFamily ),
00095 m_fontFlags( style->m_fontFlags ),
00096 m_fontSize( style->m_fontSize ),
00097 m_textPen( style->m_textPen ),
00098 m_bgColor( style->m_bgColor ),
00099 m_rightBorderPen( style->m_rightBorderPen ),
00100 m_bottomBorderPen( style->m_bottomBorderPen ),
00101 m_leftBorderPen( style->m_leftBorderPen ),
00102 m_topBorderPen( style->m_topBorderPen ),
00103 m_fallDiagonalPen( style->m_fallDiagonalPen ),
00104 m_goUpDiagonalPen( style->m_goUpDiagonalPen ),
00105 m_backGroundBrush( style->m_backGroundBrush ),
00106 m_rotateAngle( style->m_rotateAngle ),
00107 m_indent( style->m_indent ),
00108 m_strFormat( style->m_strFormat ),
00109 m_precision( style->m_precision ),
00110 m_prefix( style->m_prefix ),
00111 m_postfix( style->m_postfix ),
00112 m_currency( style->m_currency ),
00113 m_properties( style->m_properties )
00114 {
00115 }
00116
00117 KSpreadStyle::~KSpreadStyle()
00118 {
00119 }
00120
00121 void KSpreadStyle::loadOasisStyle( KoOasisStyles& oasisStyles, const QDomElement & element )
00122 {
00123 kdDebug()<<"void KSpreadStyle::loadOasisStyle( const QDomElement & element )**************: name :"<<endl;
00124 KoStyleStack styleStack;
00125 styleStack.push( element );
00126 styleStack.setTypeProperties( "table-cell" );
00127 QString str;
00128 if ( element.hasAttributeNS( KoXmlNS::style, "data-style-name" ) )
00129 {
00130
00131
00132
00133
00134
00135 QString tmp = oasisStyles.dataFormats()[element.attributeNS( KoXmlNS::style, "data-style-name" , QString::null)].prefix;
00136 if ( !tmp.isEmpty() )
00137 {
00138 m_prefix = tmp;
00139 m_featuresSet |= SPrefix;
00140 }
00141 tmp = oasisStyles.dataFormats()[element.attributeNS( KoXmlNS::style, "data-style-name" , QString::null)].suffix;
00142 if ( !tmp.isEmpty() )
00143 {
00144 m_postfix = tmp;
00145 m_featuresSet |= SPostfix;
00146 }
00147 tmp = oasisStyles.dataFormats()[element.attributeNS( KoXmlNS::style, "data-style-name" , QString::null)].formatStr;
00148 if ( !tmp.isEmpty() )
00149 {
00150 m_formatType = KSpreadStyle::formatType( tmp );
00151 m_featuresSet |= SFormatType;
00152 }
00153 }
00154 styleStack.setTypeProperties( "text" );
00155 if ( styleStack.hasAttributeNS( KoXmlNS::style, "font-name" ) )
00156 {
00157 m_fontFamily = styleStack.attributeNS( KoXmlNS::style, "font-name" );
00158 kdDebug()<<"styleStack.hasAttribute( style:font-name ) :"<<styleStack.hasAttributeNS( KoXmlNS::style, "font-name" )<<endl;
00159 m_featuresSet |= SFontFamily;
00160 m_featuresSet |= SFont;
00161 m_featuresSet |= SFontFlag;
00162 }
00163
00164 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-size" ) )
00165 {
00166 m_fontSize = KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "font-size" ),10.0 );
00167 m_featuresSet |= SFont;
00168 m_featuresSet |= SFontSize;
00169 m_featuresSet |= SFontFlag;
00170 }
00171 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-style" ) && styleStack.attributeNS( KoXmlNS::fo, "font-style" ) =="italic")
00172 {
00173 #if 0
00174 QDomElement font = format.namedItem( "font" ).toElement();
00175 if ( !font.isNull() )
00176 {
00177 QFont f( util_toFont( font ) );
00178 m_fontFamily = f.family();
00179 m_fontSize = f.pointSize();
00180 if ( f.italic() )
00181 m_fontFlags |= FItalic;
00182 if ( f.bold() )
00183 m_fontFlags |= FBold;
00184 if ( f.underline() )
00185 m_fontFlags |= FUnderline;
00186 if ( f.strikeOut() )
00187 m_fontFlags |= FStrike;
00188
00189 m_featuresSet |= SFont;
00190 m_featuresSet |= SFontFamily;
00191 m_featuresSet |= SFontFlag;
00192 m_featuresSet |= SFontSize;
00193 }
00194
00195 if ( format.hasAttribute( "font-family" ) )
00196 {
00197 m_fontFamily = format.attribute( "font-family" );
00198 m_featuresSet |= SFont;
00199 m_featuresSet |= SFontFamily;
00200 }
00201 #endif
00202 m_fontFlags |= FItalic;
00203 m_featuresSet |= SFontFlag;
00204
00205 }
00206 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-weight" ) )
00207 {
00208 m_fontFlags |= FBold;
00209 }
00210 if ( ( styleStack.hasAttributeNS( KoXmlNS::fo, "text-underline-style" ) &&styleStack.attributeNS( KoXmlNS::fo, "text-underline-style" )!="none" )
00211 || ( styleStack.hasAttributeNS( KoXmlNS::style, "text-underline-style" ) && styleStack.attributeNS( KoXmlNS::style, "text-underline-style" )!="none") )
00212 {
00213 m_fontFlags |= FUnderline;
00214 m_featuresSet |= SFontFlag;
00215 }
00216 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "color" ) )
00217 {
00218
00219 m_featuresSet |= STextPen;
00220 m_textPen=QPen( QColor( styleStack.attributeNS( KoXmlNS::fo, "color" ) ) );
00221 }
00222 if ( styleStack.hasAttributeNS( KoXmlNS::style, "text-underline-color" ) )
00223 {
00224
00225 }
00226 if ( styleStack.hasAttributeNS( KoXmlNS::style, "text-line-through-style" ) && styleStack.attributeNS( KoXmlNS::style, "text-line-through-style" )!="none"
00227 )
00228 {
00229 m_fontFlags |= FStrike;
00230 m_featuresSet |= SFontFlag;
00231 }
00232
00233 styleStack.setTypeProperties( "paragraph" );
00234 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "text-align" ) )
00235 {
00236
00237 str = styleStack.attributeNS( KoXmlNS::fo, "text-align" );
00238 kdDebug()<<"str :"<<str<<endl;
00239 if ( str == "center" )
00240 m_alignX = KSpreadFormat::Center;
00241 else if ( str == "end" )
00242 m_alignX = KSpreadFormat::Right;
00243 else if ( str == "start" )
00244 m_alignX = KSpreadFormat::Left;
00245 else
00246 m_alignX = KSpreadFormat::Undefined;
00247 m_featuresSet |= SAlignX;
00248 }
00249 styleStack.setTypeProperties( "table-cell" );
00250 if ( styleStack.hasAttributeNS( KoXmlNS::style, "vertical-align" ) )
00251 {
00252 str = styleStack.attributeNS( KoXmlNS::style, "vertical-align" );
00253 if ( str == "bottom" )
00254 m_alignY = KSpreadFormat::Bottom;
00255 else if ( str =="top" )
00256 m_alignY = KSpreadFormat::Top;
00257 else if ( str =="middle" )
00258 m_alignY = KSpreadFormat::Middle;
00259 m_featuresSet |= SAlignY;
00260 }
00261 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "background-color" ) )
00262 {
00263 m_bgColor = QColor( styleStack.attributeNS( KoXmlNS::fo, "background-color" ) );
00264 m_featuresSet |= SBackgroundColor;
00265 }
00266
00267 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "wrap-option" )&&( styleStack.attributeNS( KoXmlNS::fo, "wrap-option" )=="wrap" ) )
00268 {
00269 setProperty( PMultiRow );
00270 m_featuresSet |= SMultiRow;
00271 }
00272 if ( styleStack.hasAttributeNS( KoXmlNS::style, "cell-protect" ) )
00273 {
00274 str = styleStack.attributeNS( KoXmlNS::style, "cell-protect" );
00275 if ( str=="hidden-and-protected" )
00276 {
00277 setProperty( PHideAll );
00278 m_featuresSet |= SHideAll;
00279 }
00280 else if ( str == "protected formula-hidden" )
00281 {
00282 setProperty( PHideFormula );
00283 m_featuresSet |= SHideFormula;
00284 }
00285 else if ( str == "protected" )
00286 {
00287 setProperty( PNotProtected );
00288 m_featuresSet |= SNotProtected;
00289 }
00290 else if ( str =="formula-hidden" )
00291 {
00292
00293 #if 0
00294 setNotProtected( true );
00295 setHideFormula( true );
00296 setHideAll( false );
00297 #endif
00298 }
00299 }
00300 if ( styleStack.hasAttributeNS( KoXmlNS::style, "print-content" ) && ( styleStack.attributeNS( KoXmlNS::style, "print-content" )=="false" ) )
00301 {
00302 setProperty( PDontPrintText );
00303 m_featuresSet |= SDontPrintText;
00304
00305 }
00306 if ( styleStack.hasAttributeNS( KoXmlNS::style, "direction" ) && ( styleStack.attributeNS( KoXmlNS::style, "direction" )=="ttb" ) )
00307 {
00308 setProperty( PVerticalText );
00309 m_featuresSet |= SVerticalText;
00310
00311 }
00312 if ( styleStack.hasAttributeNS( KoXmlNS::style, "rotation-angle" ) )
00313 {
00314 bool ok;
00315 int a = styleStack.attributeNS( KoXmlNS::style, "rotation-angle" ).toInt( &ok );
00316 kdDebug()<<" rotation-angle :"<<a<<endl;
00317 if ( a != 0 )
00318 {
00319 m_rotateAngle= ( -a );
00320 m_featuresSet |= SAngle;
00321 }
00322 }
00323 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "margin-left" ) )
00324 {
00325
00326 setIndent( KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "margin-left" ),0.0 ) );
00327 m_featuresSet |= SIndent;
00328 }
00329 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border" ) )
00330 {
00331 str=styleStack.attributeNS( KoXmlNS::fo, "border" );
00332 QPen pen = convertOasisStringToPen( str );
00333 m_featuresSet |= SLeftBorder;
00334 m_featuresSet |= SRightBorder;
00335 m_featuresSet |= STopBorder;
00336 m_featuresSet |= SBottomBorder;
00337 m_leftBorderPen = pen;
00338 m_topBorderPen = pen;
00339 m_bottomBorderPen = pen;
00340 m_rightBorderPen = pen;
00341 }
00342 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-left" ) )
00343 {
00344 str=styleStack.attributeNS( KoXmlNS::fo, "border-left" );
00345 m_leftBorderPen = convertOasisStringToPen( str );
00346 m_featuresSet |= SLeftBorder;
00347 }
00348 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-right" ) )
00349 {
00350 str=styleStack.attributeNS( KoXmlNS::fo, "border-right" );
00351 m_rightBorderPen = convertOasisStringToPen( str );
00352 m_featuresSet |= SRightBorder;
00353 }
00354 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-top" ) )
00355 {
00356 str=styleStack.attributeNS( KoXmlNS::fo, "border-top" );
00357 m_topBorderPen = convertOasisStringToPen( str );
00358 m_featuresSet |= STopBorder;
00359 }
00360 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-bottom" ) )
00361 {
00362 str=styleStack.attributeNS( KoXmlNS::fo, "border-bottom" );
00363 m_bottomBorderPen = convertOasisStringToPen( str );
00364 m_featuresSet |= SBottomBorder;
00365 }
00366 if (styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-tl-br" ) )
00367 {
00368 str=styleStack.attributeNS( KoXmlNS::style, "diagonal-tl-br" );
00369 m_fallDiagonalPen = convertOasisStringToPen( str );
00370 m_featuresSet |= SFallDiagonal;
00371 }
00372 if (styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-bl-tr" ) )
00373 {
00374 str=styleStack.attributeNS( KoXmlNS::style, "diagonal-bl-tr" );
00375 m_goUpDiagonalPen = convertOasisStringToPen( str );
00376 m_featuresSet |= SGoUpDiagonal;
00377 }
00378
00379 if ( styleStack.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
00380 {
00381 kdDebug()<<" style name :"<<styleStack.attributeNS( KoXmlNS::draw, "style-name" )<<endl;
00382
00383 QDomElement * style = oasisStyles.styles()[styleStack.attributeNS( KoXmlNS::draw, "style-name" )];
00384 kdDebug()<<" style :"<<style<<endl;
00385 KoStyleStack drawStyleStack;
00386 drawStyleStack.push( *style );
00387 drawStyleStack.setTypeProperties( "graphic" );
00388 if ( drawStyleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
00389 {
00390 const QString fill = drawStyleStack.attributeNS( KoXmlNS::draw, "fill" );
00391 kdDebug()<<" load object gradient fill type :"<<fill<<endl;
00392
00393 if ( fill == "solid" || fill == "hatch" )
00394 {
00395 kdDebug()<<" Style ******************************************************\n";
00396 m_backGroundBrush=KoOasisStyles::loadOasisFillStyle( drawStyleStack, fill, oasisStyles );
00397 m_featuresSet |= SBackgroundBrush;
00398 }
00399 else
00400 kdDebug()<<" fill style not supported into kspread : "<<fill<<endl;
00401 }
00402 }
00403
00404 #if 0
00405 bool ok;
00406 if ( format.hasAttribute( "type" ) )
00407 {
00408 m_type = (StyleType) format.attribute( "type" ).toInt( &ok );
00409 if ( !ok )
00410 return false;
00411 }
00412
00413 if ( format.hasAttribute( "precision" ) )
00414 {
00415 int i = format.attribute( "precision" ).toInt( &ok );
00416 if ( i < -1 )
00417 {
00418 kdDebug(36001) << "Value out of range Cell::precision=" << i << endl;
00419 return false;
00420 }
00421 m_precision = i;
00422 m_featuresSet |= SPrecision;
00423 }
00424
00425 if ( format.hasAttribute( "float" ) )
00426 {
00427 KSpreadFormat::FloatFormat a = (KSpreadFormat::FloatFormat)format.attribute( "float" ).toInt( &ok );
00428 if ( !ok )
00429 return false;
00430 if ( (unsigned int) a >= 1 || (unsigned int) a <= 3 )
00431 {
00432 m_floatFormat = a;
00433 m_featuresSet |= SFloatFormat;
00434 }
00435 }
00436
00437 if ( format.hasAttribute( "floatcolor" ) )
00438 {
00439 KSpreadFormat::FloatColor a = (KSpreadFormat::FloatColor) format.attribute( "floatcolor" ).toInt( &ok );
00440 if ( !ok ) return false;
00441 if ( (unsigned int) a >= 1 || (unsigned int) a <= 2 )
00442 {
00443 m_floatColor = a;
00444 m_featuresSet |= SFloatColor;
00445 }
00446 }
00447
00448 if ( format.hasAttribute( "custom" ) )
00449 {
00450 m_strFormat = format.attribute( "custom" );
00451 m_featuresSet |= SCustomFormat;
00452 }
00453 if ( m_formatType == KSpreadFormat::Money )
00454 {
00455 if ( format.hasAttribute( "type" ) )
00456 {
00457 m_currency.type = format.attribute( "type" ).toInt( &ok );
00458 if (!ok)
00459 m_currency.type = 1;
00460 }
00461 if ( format.hasAttribute( "symbol" ) )
00462 {
00463 m_currency.symbol = format.attribute( "symbol" );
00464 }
00465 }
00466
00467
00468 QDomElement font = format.namedItem( "font" ).toElement();
00469 if ( !font.isNull() )
00470 {
00471 QFont f( util_toFont( font ) );
00472 m_fontFamily = f.family();
00473 m_fontSize = f.pointSize();
00474 if ( f.italic() )
00475 m_fontFlags |= FItalic;
00476 if ( f.bold() )
00477 m_fontFlags |= FBold;
00478 if ( f.underline() )
00479 m_fontFlags |= FUnderline;
00480 if ( f.strikeOut() )
00481 m_fontFlags |= FStrike;
00482
00483 m_featuresSet |= SFont;
00484 m_featuresSet |= SFontFamily;
00485 m_featuresSet |= SFontFlag;
00486 m_featuresSet |= SFontSize;
00487 }
00488
00489 if ( format.hasAttribute( "font-family" ) )
00490 {
00491 m_fontFamily = format.attribute( "font-family" );
00492 m_featuresSet |= SFont;
00493 m_featuresSet |= SFontFamily;
00494 }
00495
00496
00497 if ( format.hasAttribute( "font-flags" ) )
00498 {
00499 m_fontFlags = format.attribute( "font-flags" ).toInt( &ok );
00500 if ( !ok )
00501 return false;
00502 m_featuresSet |= SFont;
00503 m_featuresSet |= SFontFlag;
00504 }
00505
00506 if ( format.hasAttribute( "brushcolor" ) )
00507 {
00508 m_backGroundBrush.setColor( QColor( format.attribute( "brushcolor" ) ) );
00509 m_featuresSet |= SBackgroundBrush;
00510 }
00511
00512 if ( format.hasAttribute( "brushstyle" ) )
00513 {
00514 m_backGroundBrush.setStyle( (Qt::BrushStyle) format.attribute( "brushstyle" ).toInt( &ok ) );
00515 if ( !ok )
00516 return false;
00517 m_featuresSet |= SBackgroundBrush;
00518 }
00519
00520 QDomElement pen = format.namedItem( "pen" ).toElement();
00521 if ( !pen.isNull() )
00522 {
00523 m_textPen = util_toPen( pen );
00524 m_featuresSet |= STextPen;
00525 }
00526
00527 return true;
00528
00529 #endif
00530 }
00531
00532 FormatType KSpreadStyle::formatType( const QString &_format )
00533 {
00534 if ( _format == "# ?/2" )
00535 return fraction_half;
00536 else if ( _format =="# ?/4" )
00537 return fraction_quarter;
00538 else if ( _format == "# ?/8" )
00539 return fraction_eighth;
00540 else if ( _format == "# ?/16" )
00541 return fraction_sixteenth;
00542 else if ( _format == "# ?/10" )
00543 return fraction_tenth;
00544 else if ( _format == "# ?/100" )
00545 return fraction_hundredth;
00546 else if ( _format == "# ?/?" )
00547 return fraction_one_digit;
00548 else if ( _format == "# \?\?/\?\?" )
00549 return fraction_two_digits;
00550 else if ( _format == "# \?\?\?/\?\?\?" )
00551 return fraction_three_digits;
00552 else if ( _format == "dd-MMM-yy" )
00553 return date_format1;
00554 else if ( _format == "dd-MMM-yyyy" )
00555 return date_format2;
00556 else if ( _format == "d-MM" )
00557 return date_format3;
00558 else if ( _format == "dd-MM" )
00559 return date_format4;
00560 else if ( _format == "dd/MM/yy" )
00561 return date_format5;
00562 else if ( _format == "dd/MM/yyyy" )
00563 return date_format6;
00564 else if ( _format == "MMM-yy" )
00565 return date_format7;
00566 else if ( _format == "MMMM-yyyy" )
00567 return date_format9;
00568 else if ( _format == "MMMMM-yy" )
00569 return date_format10;
00570 else if ( _format == "dd/MMM" )
00571 return date_format11;
00572 else if ( _format == "dd/MM" )
00573 return date_format12;
00574 else if ( _format == "dd/MMM/yyyy" )
00575 return date_format13;
00576 else if ( _format == "yyyy/MMM/dd" )
00577 return date_format14;
00578 else if ( _format == "yyyy-MMM-dd" )
00579 return date_format15;
00580 else if ( _format == "yyyy/MM/dd" )
00581 return date_format16;
00582 else if ( _format == "d MMMM yyyy" )
00583 return date_format17;
00584 else if ( _format == "MM/dd/yyyy" )
00585 return date_format18;
00586 else if ( _format == "MM/dd/yy" )
00587 return date_format19;
00588 else if ( _format == "MMM/dd/yy" )
00589 return date_format20;
00590 else if ( _format == "MMM/dd/yyyy" )
00591 return date_format21;
00592 else if ( _format == "MMM-yyyy" )
00593 return date_format22;
00594 else if ( _format == "yyyy" )
00595 return date_format23;
00596 else if ( _format == "yy" )
00597 return date_format24;
00598 else if ( _format == "yyyy/MM/dd" )
00599 return date_format25;
00600 else if ( _format == "yyyy/MMM/dd" )
00601 return date_format26;
00602 else if ( _format == KGlobal::locale()->dateFormatShort() )
00603 return ShortDate_format;
00604 else if ( _format == KGlobal::locale()->dateFormat() )
00605 return TextDate_format;
00606 else if ( _format == "h:mm AP" )
00607 return Time_format1;
00608 else if ( _format == "h:mm:ss AP" )
00609 return Time_format2;
00610 else if ( _format == "hh \\h mm \\m\\i\\n ss \\s" )
00611 return Time_format3;
00612 else if ( _format == "hh:mm" )
00613 return Time_format4;
00614 else if ( _format == "hh:mm:ss" )
00615 return Time_format5;
00616 else if ( _format == "m:ss" )
00617 return Time_format6;
00618 else if ( _format == "h:mm:ss" )
00619 return Time_format7;
00620 else if ( _format == "h:mm" )
00621 return Time_format8;
00622 else
00623 return Number_format;
00624 }
00625
00626 QString KSpreadStyle::saveOasisStyleNumeric( KoGenStyles &mainStyles, FormatType _style, const QString &_prefix, const QString &_postfix,int _precision )
00627 {
00628 QString styleName;
00629 switch( _style )
00630 {
00631 case Number_format:
00632 styleName = saveOasisStyleNumericNumber( mainStyles,_style, _precision );
00633 break;
00634 case Text_format:
00635 styleName = saveOasisStyleNumericText( mainStyles,_style,_precision );
00636 break;
00637 case Money_format:
00638 styleName = saveOasisStyleNumericMoney( mainStyles,_style,_precision);
00639 break;
00640 case Percentage_format:
00641 styleName = saveOasisStyleNumericPercentage( mainStyles,_style,_precision );
00642 break;
00643 case Scientific_format:
00644 styleName = saveOasisStyleNumericScientific( mainStyles,_style, _prefix, _postfix,_precision );
00645 break;
00646 case ShortDate_format:
00647 case TextDate_format:
00648 styleName = saveOasisStyleNumericDate( mainStyles,_style );
00649 break;
00650 case Time_format:
00651 case SecondeTime_format:
00652 case Time_format1:
00653 case Time_format2:
00654 case Time_format3:
00655 case Time_format4:
00656 case Time_format5:
00657 case Time_format6:
00658 case Time_format7:
00659 case Time_format8:
00660 styleName = saveOasisStyleNumericTime( mainStyles,_style );
00661 break;
00662 case fraction_half:
00663 case fraction_quarter:
00664 case fraction_eighth:
00665 case fraction_sixteenth:
00666 case fraction_tenth:
00667 case fraction_hundredth:
00668 case fraction_one_digit:
00669 case fraction_two_digits:
00670 case fraction_three_digits:
00671 styleName = saveOasisStyleNumericFraction( mainStyles,_style, _prefix, _postfix );
00672 break;
00673 case date_format1:
00674 case date_format2:
00675 case date_format3:
00676 case date_format4:
00677 case date_format5:
00678 case date_format6:
00679 case date_format7:
00680 case date_format8:
00681 case date_format9:
00682 case date_format10:
00683 case date_format11:
00684 case date_format12:
00685 case date_format13:
00686 case date_format14:
00687 case date_format15:
00688 case date_format16:
00689 case date_format17:
00690 case date_format18:
00691 case date_format19:
00692 case date_format20:
00693 case date_format21:
00694 case date_format22:
00695 case date_format23:
00696 case date_format24:
00697 case date_format25:
00698 case date_format26:
00699 styleName = saveOasisStyleNumericDate( mainStyles,_style );
00700 break;
00701 case Custom_format:
00702 styleName = saveOasisStyleNumericCustom( mainStyles,_style );
00703 break;
00704 }
00705 return styleName;
00706 }
00707
00708 QString KSpreadStyle::saveOasisStyleNumericNumber( KoGenStyles&mainStyles, FormatType _style, int _precision )
00709 {
00710 return "";
00711 }
00712
00713 QString KSpreadStyle::saveOasisStyleNumericText( KoGenStyles&mainStyles, FormatType _style, int _precision )
00714 {
00715 return "";
00716 }
00717
00718 QString KSpreadStyle::saveOasisStyleNumericMoney( KoGenStyles&mainStyles, FormatType _style, int _precision )
00719 {
00720 QString format;
00721 return KoOasisStyles::saveOasisCurrencyStyle( mainStyles, format );
00722 }
00723
00724 QString KSpreadStyle::saveOasisStyleNumericPercentage( KoGenStyles&mainStyles, FormatType _style, int _precision )
00725 {
00726
00727
00728
00729
00730
00731 QString format;
00732 if ( _precision == -1 )
00733 format="0.00";
00734 else
00735 {
00736 QString tmp;
00737 for ( int i = 0; i <_precision; i++ )
00738 {
00739 tmp+="0";
00740 }
00741 format = "0."+tmp;
00742 }
00743 return KoOasisStyles::saveOasisPercentageStyle( mainStyles, format );
00744 }
00745
00746
00747 QString KSpreadStyle::saveOasisStyleNumericScientific( KoGenStyles&mainStyles, FormatType _style, const QString &_prefix, const QString _suffix, int _precision )
00748 {
00749
00750
00751
00752 QString format;
00753 if ( _precision == -1 )
00754 format="0.0E+00";
00755 else
00756 {
00757 QString tmp;
00758 for ( int i = 0; i <_precision; i++ )
00759 {
00760 tmp+="0";
00761 }
00762 format = "0."+tmp+"E+00";
00763 }
00764 return KoOasisStyles::saveOasisScientificStyle( mainStyles, format, _prefix,_suffix );
00765 }
00766
00767 QString KSpreadStyle::saveOasisStyleNumericDate( KoGenStyles&mainStyles, FormatType _style )
00768 {
00769 QString format;
00770 bool locale = false;
00771 switch( _style )
00772 {
00773
00774 case ShortDate_format:
00775 format = KGlobal::locale()->dateFormatShort();
00776 locale = true;
00777 break;
00778 case TextDate_format:
00779 format = KGlobal::locale()->dateFormat();
00780 locale = true;
00781 break;
00782 case date_format1:
00783 format = "dd-MMM-yy";
00784 break;
00785 case date_format2:
00786 format = "dd-MMM-yyyy";
00787 break;
00788 case date_format3:
00789 format = "dd-M";
00790 break;
00791 case date_format4:
00792 format = "dd-MM";
00793 break;
00794 case date_format5:
00795 format = "dd/MM/yy";
00796 break;
00797 case date_format6:
00798 format = "dd/MM/yyyy";
00799 break;
00800 case date_format7:
00801 format = "MMM-yy";
00802 break;
00803 case date_format8:
00804 format = "MMMM-yy";
00805 break;
00806 case date_format9:
00807 format = "MMMM-yyyy";
00808 break;
00809 case date_format10:
00810 format = "MMMMM-yy";
00811 break;
00812 case date_format11:
00813 format = "dd/MMM";
00814 break;
00815 case date_format12:
00816 format = "dd/MM";
00817 break;
00818 case date_format13:
00819 format = "dd/MMM/yyyy";
00820 break;
00821 case date_format14:
00822 format = "yyyy/MMM/dd";
00823 break;
00824 case date_format15:
00825 format = "yyyy-MMM-dd";
00826 break;
00827 case date_format16:
00828 format = "yyyy/MM/dd";
00829 break;
00830 case date_format17:
00831 format = "d MMMM yyyy";
00832 break;
00833 case date_format18:
00834 format = "MM/dd/yyyy";
00835 break;
00836 case date_format19:
00837 format = "MM/dd/yy";
00838 break;
00839 case date_format20:
00840 format = "MMM/dd/yy";
00841 break;
00842 case date_format21:
00843 format = "MMM/dd/yyyy";
00844 break;
00845 case date_format22:
00846 format = "MMM-yyyy";
00847 break;
00848 case date_format23:
00849 format = "yyyy";
00850 break;
00851 case date_format24:
00852 format = "yy";
00853 break;
00854 case date_format25:
00855 format = "yyyy/MM/dd";
00856 break;
00857 case date_format26:
00858 format = "yyyy/MMM/dd";
00859 break;
00860 default:
00861 kdDebug()<<"this date format is not defined ! :"<<_style<<endl;
00862 break;
00863 }
00864 return KoOasisStyles::saveOasisDateStyle( mainStyles, format, locale );
00865 }
00866
00867 QString KSpreadStyle::saveOasisStyleNumericCustom( KoGenStyles&mainStyles, FormatType _style )
00868 {
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883 return "";
00884 }
00885
00886 QString KSpreadStyle::saveOasisStyleNumericTime( KoGenStyles& mainStyles, FormatType _style )
00887 {
00888
00889
00890
00891
00892
00893
00894
00895
00896 QString format;
00897 bool locale = false;
00898
00899 switch( _style )
00900 {
00901 case Time_format:
00902 format = "hh:mm:ss";
00903 break;
00904 case SecondeTime_format:
00905 format = "hh:mm";
00906 break;
00907 case Time_format1:
00908 format = "h:mm AP";
00909 break;
00910 case Time_format2:
00911 format = "h:mm:ss AP";
00912 break;
00913 case Time_format3:
00914 format = "hh \\h mm \\m\\i\\n ss \\s";
00915 break;
00916 case Time_format4:
00917 format = "hh:mm";
00918 break;
00919 case Time_format5:
00920 format = "hh:mm:ss";
00921 break;
00922 case Time_format6:
00923 format = "m:ss";
00924 break;
00925 case Time_format7:
00926 format = "h:mm:ss";
00927 break;
00928 case Time_format8:
00929 format = "h:mm";
00930 break;
00931 default:
00932 kdDebug()<<"time format not defined :"<<_style<<endl;
00933 break;
00934 }
00935 return KoOasisStyles::saveOasisTimeStyle( mainStyles, format, locale );
00936 }
00937
00938
00939 QString KSpreadStyle::saveOasisStyleNumericFraction( KoGenStyles &mainStyles, FormatType _style, const QString &_prefix, const QString _suffix )
00940 {
00941
00942
00943
00944 QString format;
00945 switch( _style )
00946 {
00947 case fraction_half:
00948 format = "# ?/2";
00949 break;
00950 case fraction_quarter:
00951 format = "# ?/4";
00952 break;
00953 case fraction_eighth:
00954 format = "# ?/8";
00955 break;
00956 case fraction_sixteenth:
00957 format = "# ?/16";
00958 break;
00959 case fraction_tenth:
00960 format = "# ?/10";
00961 break;
00962 case fraction_hundredth:
00963 format = "# ?/100";
00964 break;
00965 case fraction_one_digit:
00966 format = "# ?/?";
00967 break;
00968 case fraction_two_digits:
00969 format = "# \?\?/\?\?";
00970 break;
00971 case fraction_three_digits:
00972 format = "# \?\?\?/\?\?\?";
00973 break;
00974 default:
00975 kdDebug()<<" fraction format not defined :"<<_style<<endl;
00976 break;
00977 }
00978
00979 return KoOasisStyles::saveOasisFractionStyle( mainStyles, format,_prefix, _suffix );
00980 }
00981
00982
00983 QString KSpreadStyle::saveOasisStyle( KoGenStyle &style, KoGenStyles &mainStyles )
00984 {
00985 if ( featureSet( SAlignX ) && alignX() != KSpreadFormat::Undefined )
00986 {
00987 QString value ="start";
00988 switch( alignX() )
00989 {
00990 case KSpreadFormat::Center:
00991 value = "center";
00992 break;
00993 case KSpreadFormat::Right:
00994 value = "end";
00995 break;
00996 case KSpreadFormat::Left:
00997 value = "start";
00998 break;
00999 }
01000 style.addProperty( "fo:text-align", value, KoGenStyle::ParagraphType );
01001 }
01002
01003 if ( featureSet( SAlignY ) && alignY() != KSpreadFormat::Middle )
01004 {
01005 style.addProperty( "style:vertical-align", ( alignY() == KSpreadFormat::Bottom ? "bottom" : "top" ) );
01006 }
01007 if ( featureSet( SBackgroundColor ) && m_bgColor != QColor() && m_bgColor.isValid() )
01008 style.addProperty( "fo:background-color", m_bgColor.name() );
01009
01010 if ( featureSet( SMultiRow ) && hasProperty( PMultiRow ) )
01011 style.addProperty( "fo:wrap-option", "wrap" );
01012 if ( featureSet( SVerticalText ) && hasProperty( PVerticalText ) )
01013 {
01014 style.addProperty( "style:direction", "ttb" );
01015 style.addProperty( "style:rotation-angle", "0" );
01016 style.addProperty( "style:rotation-align", "none" );
01017 }
01018 #if 0
01019 if ( featureSet( SFloatFormat ) )
01020 format.setAttribute( "float", (int) m_floatFormat );
01021
01022 if ( featureSet( SFloatColor ) )
01023 format.setAttribute( "floatcolor", (int)m_floatColor );
01024
01025 if ( featureSet( SCustomFormat ) && !strFormat().isEmpty() )
01026 format.setAttribute( "custom", m_strFormat );
01027
01028 if ( featureSet( SFormatType ) && formatType() == KSpreadFormat::Money )
01029 {
01030 format.setAttribute( "type", (int) m_currency.type );
01031 format.setAttribute( "symbol", m_currency.symbol );
01032 }
01033 #endif
01034 if ( featureSet( SAngle ) )
01035 {
01036 style.addProperty( "style:rotation-align", "none" );
01037 style.addProperty( "style:rotation-angle", QString::number( -1.0 *m_rotateAngle ) );
01038 }
01039 if ( featureSet( SIndent ) )
01040 {
01041 style.addPropertyPt("fo:margin-left", m_indent, KoGenStyle::ParagraphType );
01042
01043
01044
01045 }
01046 if ( featureSet( SDontPrintText ) && hasProperty( PDontPrintText ) )
01047 style.addProperty( "style:print-content", "false");
01048
01049 bool hideAll = false;
01050 bool hideFormula = false;
01051 bool isNotProtected = false;
01052
01053 if ( featureSet( SNotProtected ) && hasProperty( PNotProtected ) )
01054 isNotProtected = true;
01055
01056 if ( featureSet( SHideAll ) && hasProperty( PHideAll ) )
01057 hideAll=true;
01058
01059 if ( featureSet( SHideFormula ) && hasProperty( PHideFormula ) )
01060 hideFormula = true;
01061
01062 if ( hideAll )
01063 style.addProperty( "style:cell-protect", "hidden-and-protected" );
01064 else
01065 {
01066 if ( isNotProtected && !hideFormula )
01067 style.addProperty( "style:cell-protect", "none" );
01068 else
01069 {
01070 if ( isNotProtected && hideFormula )
01071 style.addProperty( "style:cell-protect", "formula-hidden" );
01072 else if ( hideFormula )
01073 style.addProperty( "style:cell-protect", "protected formula-hidden" );
01074 else if ( !isNotProtected )
01075 style.addProperty( "style:cell-protect", "protected" );
01076 }
01077 }
01078
01079 if ( featureSet( SLeftBorder ) &&featureSet( SRightBorder ) &&
01080 featureSet( STopBorder ) && featureSet( SBottomBorder ) &&
01081 ( m_leftBorderPen == m_topBorderPen )&&
01082 ( m_leftBorderPen == m_rightBorderPen )&&
01083 ( m_leftBorderPen == m_bottomBorderPen ) )
01084 {
01085 if ( ( m_leftBorderPen.width() != 0 ) && ( m_leftBorderPen.style() != Qt::NoPen ) )
01086 style.addProperty("fo:border", convertOasisPenToString( m_leftBorderPen ) );
01087 }
01088 else
01089 {
01090 if ( featureSet( SLeftBorder ) &&
01091 ( ( m_leftBorderPen.width() != 0 ) && ( m_leftBorderPen.style() != Qt::NoPen ) ) )
01092 style.addProperty( "fo:border-left", convertOasisPenToString( m_leftBorderPen ) );
01093
01094 if ( featureSet( SRightBorder ) &&
01095 ( ( m_rightBorderPen.width() != 0 ) && ( m_rightBorderPen.style() != Qt::NoPen ) ) )
01096 style.addProperty( "fo:border-right", convertOasisPenToString( m_rightBorderPen ) );
01097
01098 if ( featureSet( STopBorder ) &&
01099 ( ( m_topBorderPen.width() != 0 ) && ( m_topBorderPen.style() != Qt::NoPen ) ) )
01100 style.addProperty( "fo:border-top", convertOasisPenToString( m_topBorderPen ) );
01101
01102 if ( featureSet( SBottomBorder ) &&
01103 ( m_bottomBorderPen.width() != 0 ) && ( m_bottomBorderPen.style() != Qt::NoPen ) )
01104 style.addProperty( "fo:border-bottom", convertOasisPenToString( m_bottomBorderPen ) );
01105 }
01106 if ( featureSet( SFallDiagonal ) &&
01107 ( ( m_fallDiagonalPen.width() != 0 ) && ( m_fallDiagonalPen.style() != Qt::NoPen ) ) )
01108 {
01109 style.addProperty("style:diagonal-tl-br", convertOasisPenToString( m_fallDiagonalPen ) );
01110 }
01111 if ( featureSet( SGoUpDiagonal ) &&
01112 ( ( m_goUpDiagonalPen.width() != 0 ) && ( m_goUpDiagonalPen.style() != Qt::NoPen ) ))
01113 {
01114 style.addProperty("style:diagonal-bl-tr", convertOasisPenToString(m_goUpDiagonalPen ) );
01115 }
01116 if ( featureSet( SFontFamily ) )
01117 {
01118 style.addProperty("style:font-name", m_fontFamily, KoGenStyle::TextType );
01119 }
01120 if ( featureSet( SFontSize ) )
01121 {
01122 style.addPropertyPt("fo:font-size",m_fontSize, KoGenStyle::TextType );
01123 }
01124
01125 if (m_fontFlags & (uint) FBold )
01126 style.addProperty("fo:font-weight","bold", KoGenStyle::TextType );
01127 if ( m_fontFlags & (uint) FItalic )
01128 style.addProperty("fo:font-style", "italic", KoGenStyle::TextType );
01129 if ( m_fontFlags & (uint) FUnderline )
01130 {
01131
01132 style.addProperty( "style:text-underline-style", "solid", KoGenStyle::TextType );
01133
01134 style.addProperty( "style:text-underline-width", "auto", KoGenStyle::TextType );
01135 style.addProperty( "style:text-underline-color", "font-color", KoGenStyle::TextType );
01136 }
01137 if ( m_fontFlags & (uint) FStrike )
01138 style.addProperty( "style:text-line-through-style", "solid", KoGenStyle::TextType );
01139
01140 if ( featureSet( STextPen ) && m_textPen.color().isValid() )
01141 {
01142 style.addProperty("fo:color", m_textPen.color().name(), KoGenStyle::TextType );
01143 }
01144 if ( featureSet( SBackgroundBrush ) )
01145 {
01146 QString tmp = saveOasisBackgroundStyle( mainStyles, m_backGroundBrush );
01147 if ( !tmp.isEmpty() )
01148 style.addProperty("draw:style-name", tmp );
01149 }
01150 QString _prefix;
01151 QString _postfix;
01152 int _precision = -1;
01153 if ( featureSet( SPrefix ) && !prefix().isEmpty() )
01154 _prefix = m_prefix;
01155
01156 if ( featureSet( SPostfix ) && !postfix().isEmpty() )
01157 _postfix = m_postfix;
01158 if ( featureSet( SPrecision ) )
01159 _precision = m_precision;
01160
01161 return saveOasisStyleNumeric( mainStyles, m_formatType, _prefix, _postfix, _precision );
01162 }
01163
01164 QString KSpreadStyle::saveOasisBackgroundStyle( KoGenStyles &mainStyles, const QBrush &brush )
01165 {
01166 KoGenStyle styleobjectauto = KoGenStyle( KoGenStyle::STYLE_GRAPHICAUTO, "graphic" );
01167 KoOasisStyles::saveOasisFillStyle( styleobjectauto, mainStyles, brush );
01168 return mainStyles.lookup( styleobjectauto, "gr" );
01169 }
01170
01171 void KSpreadStyle::saveXML( QDomDocument & doc, QDomElement & format ) const
01172 {
01173 if ( featureSet( SAlignX ) && alignX() != KSpreadFormat::Undefined )
01174 format.setAttribute( "alignX", (int) m_alignX );
01175
01176 if ( featureSet( SAlignY ) && alignY() != KSpreadFormat::Middle )
01177 format.setAttribute( "alignY", (int) m_alignY );
01178
01179 if ( featureSet( SBackgroundColor ) && m_bgColor != QColor() && m_bgColor.isValid() )
01180 format.setAttribute( "bgcolor", m_bgColor.name() );
01181
01182 if ( featureSet( SMultiRow ) && hasProperty( PMultiRow ) )
01183 format.setAttribute( "multirow", "yes" );
01184
01185 if ( featureSet( SVerticalText ) && hasProperty( PVerticalText ) )
01186 format.setAttribute( "verticaltext", "yes" );
01187
01188 if ( featureSet( SPrecision ) )
01189 format.setAttribute( "precision", m_precision );
01190
01191 if ( featureSet( SPrefix ) && !prefix().isEmpty() )
01192 format.setAttribute( "prefix", m_prefix );
01193
01194 if ( featureSet( SPostfix ) && !postfix().isEmpty() )
01195 format.setAttribute( "postfix", m_postfix );
01196
01197 if ( featureSet( SFloatFormat ) )
01198 format.setAttribute( "float", (int) m_floatFormat );
01199
01200 if ( featureSet( SFloatColor ) )
01201 format.setAttribute( "floatcolor", (int)m_floatColor );
01202
01203 if ( featureSet( SFormatType ) )
01204 format.setAttribute( "format",(int) m_formatType );
01205
01206 if ( featureSet( SCustomFormat ) && !strFormat().isEmpty() )
01207 format.setAttribute( "custom", m_strFormat );
01208
01209 if ( featureSet( SFormatType ) && formatType() == Money_format )
01210 {
01211 format.setAttribute( "type", (int) m_currency.type );
01212 format.setAttribute( "symbol", m_currency.symbol );
01213 }
01214
01215 if ( featureSet( SAngle ) )
01216 format.setAttribute( "angle", m_rotateAngle );
01217
01218 if ( featureSet( SIndent ) )
01219 format.setAttribute( "indent", m_indent );
01220
01221 if ( featureSet( SDontPrintText ) && hasProperty( PDontPrintText ) )
01222 format.setAttribute( "dontprinttext", "yes" );
01223
01224 if ( featureSet( SNotProtected ) && hasProperty( PNotProtected ) )
01225 format.setAttribute( "noprotection", "yes" );
01226
01227 if ( featureSet( SHideAll ) && hasProperty( PHideAll ) )
01228 format.setAttribute( "hideall", "yes" );
01229
01230 if ( featureSet( SHideFormula ) && hasProperty( PHideFormula ) )
01231 format.setAttribute( "hideformula", "yes" );
01232
01233 if ( featureSet( SFontFamily ) )
01234 format.setAttribute( "font-family", m_fontFamily );
01235 if ( featureSet( SFontSize ) )
01236 format.setAttribute( "font-size", m_fontSize );
01237 if ( featureSet( SFontFlag ) )
01238 format.setAttribute( "font-flags", m_fontFlags );
01239
01240
01241
01242
01243 if ( featureSet( STextPen ) && m_textPen.color().isValid() )
01244 format.appendChild( util_createElement( "pen", m_textPen, doc ) );
01245
01246 if ( featureSet( SBackgroundBrush ) )
01247 {
01248 format.setAttribute( "brushcolor", m_backGroundBrush.color().name() );
01249 format.setAttribute( "brushstyle", (int) m_backGroundBrush.style() );
01250 }
01251
01252 if ( featureSet( SLeftBorder ) )
01253 {
01254 QDomElement left = doc.createElement( "left-border" );
01255 left.appendChild( util_createElement( "pen", m_leftBorderPen, doc ) );
01256 format.appendChild( left );
01257 }
01258
01259 if ( featureSet( STopBorder ) )
01260 {
01261 QDomElement top = doc.createElement( "top-border" );
01262 top.appendChild( util_createElement( "pen", m_topBorderPen, doc ) );
01263 format.appendChild( top );
01264 }
01265
01266 if ( featureSet( SRightBorder ) )
01267 {
01268 QDomElement right = doc.createElement( "right-border" );
01269 right.appendChild( util_createElement( "pen", m_rightBorderPen, doc ) );
01270 format.appendChild( right );
01271 }
01272
01273 if ( featureSet( SBottomBorder ) )
01274 {
01275 QDomElement bottom = doc.createElement( "bottom-border" );
01276 bottom.appendChild( util_createElement( "pen", m_bottomBorderPen, doc ) );
01277 format.appendChild( bottom );
01278 }
01279
01280 if ( featureSet( SFallDiagonal ) )
01281 {
01282 QDomElement fallDiagonal = doc.createElement( "fall-diagonal" );
01283 fallDiagonal.appendChild( util_createElement( "pen", m_fallDiagonalPen, doc ) );
01284 format.appendChild( fallDiagonal );
01285 }
01286
01287 if ( featureSet( SGoUpDiagonal ) )
01288 {
01289 QDomElement goUpDiagonal = doc.createElement( "up-diagonal" );
01290 goUpDiagonal.appendChild( util_createElement( "pen", m_goUpDiagonalPen, doc ) );
01291 format.appendChild( goUpDiagonal );
01292 }
01293 }
01294
01295 bool KSpreadStyle::loadXML( QDomElement & format )
01296 {
01297 bool ok;
01298 if ( format.hasAttribute( "type" ) )
01299 {
01300 m_type = (StyleType) format.attribute( "type" ).toInt( &ok );
01301 if ( !ok )
01302 return false;
01303 }
01304
01305 if ( format.hasAttribute( "alignX" ) )
01306 {
01307 KSpreadFormat::Align a = (KSpreadFormat::Align) format.attribute( "alignX" ).toInt( &ok );
01308 if ( !ok )
01309 return false;
01310 if ( (unsigned int) a >= 1 || (unsigned int) a <= 4 )
01311 {
01312 m_alignX = a;
01313 m_featuresSet |= SAlignX;
01314 }
01315 }
01316 if ( format.hasAttribute( "alignY" ) )
01317 {
01318 KSpreadFormat::AlignY a = (KSpreadFormat::AlignY) format.attribute( "alignY" ).toInt( &ok );
01319 if ( !ok )
01320 return false;
01321 if ( (unsigned int) a >= 1 || (unsigned int) a < 4 )
01322 {
01323 m_alignY = a;
01324 m_featuresSet |= SAlignY;
01325 }
01326 }
01327
01328 if ( format.hasAttribute( "bgcolor" ) )
01329 {
01330 m_bgColor = QColor( format.attribute( "bgcolor" ) );
01331
01332 if ( m_bgColor != Qt::white )
01333 m_featuresSet |= SBackgroundColor;
01334 }
01335
01336 if ( format.hasAttribute( "multirow" ) )
01337 {
01338 setProperty( PMultiRow );
01339 m_featuresSet |= SMultiRow;
01340 }
01341
01342 if ( format.hasAttribute( "verticaltext" ) )
01343 {
01344 setProperty( PVerticalText );
01345 m_featuresSet |= SVerticalText;
01346 }
01347
01348 if ( format.hasAttribute( "precision" ) )
01349 {
01350 int i = format.attribute( "precision" ).toInt( &ok );
01351 if ( i < -1 )
01352 {
01353 kdDebug(36001) << "Value out of range Cell::precision=" << i << endl;
01354 return false;
01355 }
01356 m_precision = i;
01357 m_featuresSet |= SPrecision;
01358 }
01359
01360 if ( format.hasAttribute( "float" ) )
01361 {
01362 KSpreadFormat::FloatFormat a = (KSpreadFormat::FloatFormat)format.attribute( "float" ).toInt( &ok );
01363 if ( !ok )
01364 return false;
01365 if ( (unsigned int) a >= 1 || (unsigned int) a <= 3 )
01366 {
01367 m_floatFormat = a;
01368 m_featuresSet |= SFloatFormat;
01369 }
01370 }
01371
01372 if ( format.hasAttribute( "floatcolor" ) )
01373 {
01374 KSpreadFormat::FloatColor a = (KSpreadFormat::FloatColor) format.attribute( "floatcolor" ).toInt( &ok );
01375 if ( !ok ) return false;
01376 if ( (unsigned int) a >= 1 || (unsigned int) a <= 2 )
01377 {
01378 m_floatColor = a;
01379 m_featuresSet |= SFloatColor;
01380 }
01381 }
01382
01383 if ( format.hasAttribute( "format" ) )
01384 {
01385 int fo = format.attribute( "format" ).toInt( &ok );
01386 if ( ! ok )
01387 return false;
01388 m_formatType = ( FormatType ) fo;
01389 m_featuresSet |= SFormatType;
01390 }
01391 if ( format.hasAttribute( "custom" ) )
01392 {
01393 m_strFormat = format.attribute( "custom" );
01394 m_featuresSet |= SCustomFormat;
01395 }
01396 if ( m_formatType == Money_format )
01397 {
01398 if ( format.hasAttribute( "type" ) )
01399 {
01400 m_currency.type = format.attribute( "type" ).toInt( &ok );
01401 if (!ok)
01402 m_currency.type = 1;
01403 }
01404 if ( format.hasAttribute( "symbol" ) )
01405 {
01406 m_currency.symbol = format.attribute( "symbol" );
01407 }
01408 m_featuresSet |= SFormatType;
01409 }
01410 if ( format.hasAttribute( "angle" ) )
01411 {
01412 m_rotateAngle = format.attribute( "angle" ).toInt( &ok );
01413 if ( !ok )
01414 return false;
01415 m_featuresSet |= SAngle;
01416 }
01417 if ( format.hasAttribute( "indent" ) )
01418 {
01419 m_indent = format.attribute( "indent" ).toDouble( &ok );
01420 if ( !ok )
01421 return false;
01422 m_featuresSet |= SIndent;
01423 }
01424 if ( format.hasAttribute( "dontprinttext" ) )
01425 {
01426 setProperty( PDontPrintText );
01427 m_featuresSet |= SDontPrintText;
01428 }
01429
01430 if ( format.hasAttribute( "noprotection" ) )
01431 {
01432 setProperty( PNotProtected );
01433 m_featuresSet |= SNotProtected;
01434 }
01435
01436 if ( format.hasAttribute( "hideall" ) )
01437 {
01438 setProperty( PHideAll );
01439 m_featuresSet |= SHideAll;
01440 }
01441
01442 if ( format.hasAttribute( "hideformula" ) )
01443 {
01444 setProperty( PHideFormula );
01445 m_featuresSet |= SHideFormula;
01446 }
01447
01448
01449 QDomElement font = format.namedItem( "font" ).toElement();
01450 if ( !font.isNull() )
01451 {
01452 QFont f( util_toFont( font ) );
01453 m_fontFamily = f.family();
01454 m_fontSize = f.pointSize();
01455 if ( f.italic() )
01456 m_fontFlags |= FItalic;
01457 if ( f.bold() )
01458 m_fontFlags |= FBold;
01459 if ( f.underline() )
01460 m_fontFlags |= FUnderline;
01461 if ( f.strikeOut() )
01462 m_fontFlags |= FStrike;
01463
01464 m_featuresSet |= SFont;
01465 m_featuresSet |= SFontFamily;
01466 m_featuresSet |= SFontFlag;
01467 m_featuresSet |= SFontSize;
01468 }
01469
01470 if ( format.hasAttribute( "font-family" ) )
01471 {
01472 m_fontFamily = format.attribute( "font-family" );
01473 m_featuresSet |= SFont;
01474 m_featuresSet |= SFontFamily;
01475 }
01476 if ( format.hasAttribute( "font-size" ) )
01477 {
01478 m_fontSize = format.attribute( "font-size" ).toInt( &ok );
01479 if ( !ok )
01480 return false;
01481 m_featuresSet |= SFont;
01482 m_featuresSet |= SFontSize;
01483 }
01484
01485 if ( format.hasAttribute( "font-flags" ) )
01486 {
01487 m_fontFlags = format.attribute( "font-flags" ).toInt( &ok );
01488 if ( !ok )
01489 return false;
01490 m_featuresSet |= SFont;
01491 m_featuresSet |= SFontFlag;
01492 }
01493
01494 if ( format.hasAttribute( "brushcolor" ) )
01495 {
01496 m_backGroundBrush.setColor( QColor( format.attribute( "brushcolor" ) ) );
01497
01498
01499
01500 }
01501
01502 if ( format.hasAttribute( "brushstyle" ) )
01503 {
01504 m_backGroundBrush.setStyle( (Qt::BrushStyle) format.attribute( "brushstyle" ).toInt( &ok ) );
01505 if ( !ok )
01506 return false;
01507
01508 if ( m_backGroundBrush.style() != Qt::NoBrush )
01509 m_featuresSet |= SBackgroundBrush;
01510 }
01511
01512 QDomElement pen = format.namedItem( "pen" ).toElement();
01513 if ( !pen.isNull() )
01514 {
01515 m_textPen = util_toPen( pen );
01516 if ( m_textPen.style() != Qt::NoPen )
01517 m_featuresSet |= STextPen;
01518 }
01519
01520 QDomElement left = format.namedItem( "left-border" ).toElement();
01521 if ( !left.isNull() )
01522 {
01523 QDomElement pen = left.namedItem( "pen" ).toElement();
01524 if ( !pen.isNull() )
01525 {
01526 m_leftBorderPen = util_toPen( pen );
01527 if ( m_leftBorderPen.style() != Qt::NoPen )
01528 m_featuresSet |= SLeftBorder;
01529 }
01530 }
01531
01532 QDomElement top = format.namedItem( "top-border" ).toElement();
01533 if ( !top.isNull() )
01534 {
01535 QDomElement pen = top.namedItem( "pen" ).toElement();
01536 if ( !pen.isNull() )
01537 {
01538 m_topBorderPen = util_toPen( pen );
01539 if ( m_topBorderPen.style() != Qt::NoPen )
01540 m_featuresSet |= STopBorder;
01541 }
01542 }
01543
01544 QDomElement right = format.namedItem( "right-border" ).toElement();
01545 if ( !right.isNull() )
01546 {
01547 QDomElement pen = right.namedItem( "pen" ).toElement();
01548 if ( !pen.isNull() )
01549 {
01550 m_rightBorderPen = util_toPen( pen );
01551 if ( m_rightBorderPen.style() != Qt::NoPen )
01552 m_featuresSet |= SRightBorder;
01553 }
01554 }
01555
01556 QDomElement bottom = format.namedItem( "bottom-border" ).toElement();
01557 if ( !bottom.isNull() )
01558 {
01559 QDomElement pen = bottom.namedItem( "pen" ).toElement();
01560 if ( !pen.isNull() )
01561 {
01562 m_bottomBorderPen = util_toPen( pen );
01563 if ( m_bottomBorderPen.style() != Qt::NoPen )
01564 m_featuresSet |= SBottomBorder;
01565 }
01566 }
01567
01568 QDomElement fallDiagonal = format.namedItem( "fall-diagonal" ).toElement();
01569 if ( !fallDiagonal.isNull() )
01570 {
01571 QDomElement pen = fallDiagonal.namedItem( "pen" ).toElement();
01572 if ( !pen.isNull() )
01573 {
01574 m_fallDiagonalPen = util_toPen( pen );
01575 if ( m_fallDiagonalPen.style() != Qt::NoPen )
01576 m_featuresSet |= SFallDiagonal;
01577 }
01578 }
01579
01580 QDomElement goUpDiagonal = format.namedItem( "up-diagonal" ).toElement();
01581 if ( !goUpDiagonal.isNull() )
01582 {
01583 QDomElement pen = goUpDiagonal.namedItem( "pen" ).toElement();
01584 if ( !pen.isNull() )
01585 {
01586 m_goUpDiagonalPen = util_toPen( pen );
01587 if ( m_goUpDiagonalPen.style() != Qt::NoPen )
01588 m_featuresSet |= SGoUpDiagonal;
01589 }
01590 }
01591
01592 if ( format.hasAttribute( "prefix" ) )
01593 {
01594 m_prefix = format.attribute( "prefix" );
01595 m_featuresSet |= SPrefix;
01596 }
01597 if ( format.hasAttribute( "postfix" ) )
01598 {
01599 m_postfix = format.attribute( "postfix" );
01600 m_featuresSet |= SPostfix;
01601 }
01602
01603 return true;
01604 }
01605
01606 void KSpreadStyle::setParent( KSpreadCustomStyle * parent )
01607 {
01608 m_parent = parent;
01609 if ( m_parent )
01610 m_parentName = m_parent->name();
01611 }
01612
01613 KSpreadCustomStyle * KSpreadStyle::parent() const
01614 {
01615 return m_parent;
01616 }
01617
01618 bool KSpreadStyle::release()
01619 {
01620 --m_usageCount;
01621
01622 if ( m_type == CUSTOM || m_type == BUILTIN )
01623 return false;
01624
01625 if ( m_usageCount < 1 )
01626 return true;
01627
01628 return false;
01629 }
01630
01631 void KSpreadStyle::addRef()
01632 {
01633 ++m_usageCount;
01634 }
01635
01636 bool KSpreadStyle::hasProperty( Properties p ) const
01637 {
01638 FlagsSet f;
01639 switch( p )
01640 {
01641 case PDontPrintText:
01642 f = SDontPrintText;
01643 break;
01644 case PCustomFormat:
01645 f = SCustomFormat;
01646 break;
01647 case PNotProtected:
01648 f = SNotProtected;
01649 break;
01650 case PHideAll:
01651 f = SHideAll;
01652 break;
01653 case PHideFormula:
01654 f = SHideFormula;
01655 break;
01656 case PMultiRow:
01657 f = SMultiRow;
01658 break;
01659 case PVerticalText:
01660 f = SVerticalText;
01661 break;
01662 default:
01663 kdWarning() << "Unhandled property" << endl;
01664 return ( m_properties & (uint) p );
01665 }
01666
01667 return ( !m_parent || featureSet( f ) ? ( m_properties & (uint) p ) : m_parent->hasProperty( p ) );
01668 }
01669
01670 bool KSpreadStyle::hasFeature( FlagsSet f, bool withoutParent ) const
01671 {
01672 bool b = ( m_featuresSet & (uint) f );
01673
01674
01675 if ( m_parent && !withoutParent )
01676 b = ( m_parent->hasFeature( f, withoutParent ) ? true : b );
01677
01678 return b;
01679 }
01680
01681 QFont KSpreadStyle::font() const
01682 {
01683 QString family = fontFamily();
01684 int size = fontSize();
01685 uint ff = fontFlags();
01686
01687 QFont f( family, size );
01688 if ( ff & (uint) FBold )
01689 f.setBold( true );
01690 if ( ff & (uint) FItalic )
01691 f.setItalic( true );
01692 if ( ff & (uint) FUnderline )
01693 f.setUnderline( true );
01694 if ( ff & (uint) FStrike )
01695 f.setStrikeOut( true );
01696
01697 return f;
01698 }
01699
01700 QString const & KSpreadStyle::fontFamily() const
01701 {
01702 return ( !m_parent || featureSet( SFontFamily ) ? m_fontFamily : m_parent->fontFamily() );
01703 }
01704
01705 uint KSpreadStyle::fontFlags() const
01706 {
01707 return ( !m_parent || featureSet( SFontFlag ) ? m_fontFlags : m_parent->fontFlags() );
01708 }
01709
01710 int KSpreadStyle::fontSize() const
01711 {
01712 return ( !m_parent || featureSet( SFontSize ) ? m_fontSize : m_parent->fontSize() );
01713 }
01714
01715 QPen const & KSpreadStyle::pen() const
01716 {
01717 return ( !m_parent || featureSet( STextPen ) ? m_textPen : m_parent->pen() );
01718 }
01719
01720 QColor const & KSpreadStyle::bgColor() const
01721 {
01722 return ( !m_parent || featureSet( SBackgroundColor ) ? m_bgColor : m_parent->bgColor() );
01723 }
01724
01725 QPen const & KSpreadStyle::rightBorderPen() const
01726 {
01727 return ( !m_parent || featureSet( SRightBorder ) ? m_rightBorderPen : m_parent->rightBorderPen() );
01728 }
01729
01730 QPen const & KSpreadStyle::bottomBorderPen() const
01731 {
01732 return ( !m_parent || featureSet( SBottomBorder ) ? m_bottomBorderPen : m_parent->bottomBorderPen() );
01733 }
01734
01735 QPen const & KSpreadStyle::leftBorderPen() const
01736 {
01737 return ( !m_parent || featureSet( SLeftBorder ) ? m_leftBorderPen : m_parent->leftBorderPen() );
01738 }
01739
01740 QPen const & KSpreadStyle::topBorderPen() const
01741 {
01742 return ( !m_parent || featureSet( STopBorder ) ? m_topBorderPen : m_parent->topBorderPen() );
01743 }
01744
01745 QPen const & KSpreadStyle::fallDiagonalPen() const
01746 {
01747 return ( !m_parent || featureSet( SFallDiagonal ) ? m_fallDiagonalPen : m_parent->fallDiagonalPen() );
01748 }
01749
01750 QPen const & KSpreadStyle::goUpDiagonalPen() const
01751 {
01752 return ( !m_parent || featureSet( SGoUpDiagonal ) ? m_goUpDiagonalPen : m_parent->goUpDiagonalPen() );
01753 }
01754
01755 int KSpreadStyle::precision() const
01756 {
01757 return ( !m_parent || featureSet( SPrecision ) ? m_precision : m_parent->precision() );
01758 }
01759
01760 int KSpreadStyle::rotateAngle() const
01761 {
01762 return ( !m_parent || featureSet( SAngle ) ? m_rotateAngle : m_parent->rotateAngle() );
01763 }
01764
01765 double KSpreadStyle::indent() const
01766 {
01767 return ( !m_parent || featureSet( SIndent ) ? m_indent : m_parent->indent() );
01768 }
01769
01770 QBrush const & KSpreadStyle::backGroundBrush() const
01771 {
01772 return ( !m_parent || featureSet( SBackgroundBrush ) ? m_backGroundBrush : m_parent->backGroundBrush() );
01773 }
01774
01775 KSpreadFormat::Align KSpreadStyle::alignX() const
01776 {
01777 return ( !m_parent || featureSet( SAlignX ) ? m_alignX : m_parent->alignX() );
01778 }
01779
01780 KSpreadFormat::AlignY KSpreadStyle::alignY() const
01781 {
01782 return ( !m_parent || featureSet( SAlignY ) ? m_alignY : m_parent->alignY() );
01783 }
01784
01785 KSpreadFormat::FloatFormat KSpreadStyle::floatFormat() const
01786 {
01787 return ( !m_parent || featureSet( SFloatFormat ) ? m_floatFormat : m_parent->floatFormat() );
01788 }
01789
01790 KSpreadFormat::FloatColor KSpreadStyle::floatColor() const
01791 {
01792 return ( !m_parent || featureSet( SFloatColor ) ? m_floatColor : m_parent->floatColor() );
01793 }
01794
01795 FormatType KSpreadStyle::formatType() const
01796 {
01797 return ( !m_parent || featureSet( SFormatType ) ? m_formatType : m_parent->formatType() );
01798 }
01799
01800 KSpreadFormat::Currency const & KSpreadStyle::currency() const
01801 {
01802 return ( !m_parent || featureSet( SFormatType ) ? m_currency : m_parent->currency() );
01803 }
01804
01805 QString const & KSpreadStyle::strFormat() const
01806 {
01807 return ( !m_parent || featureSet( SCustomFormat ) ? m_strFormat : m_parent->strFormat() );
01808 }
01809
01810 QString const & KSpreadStyle::prefix() const
01811 {
01812 return ( !m_parent || featureSet( SPrefix ) ? m_prefix : m_parent->prefix() );
01813 }
01814
01815 QString const & KSpreadStyle::postfix() const
01816 {
01817 return ( !m_parent || featureSet( SPostfix ) ? m_postfix : m_parent->postfix() );
01818 }
01819
01820
01821
01822 KSpreadStyle * KSpreadStyle::setAlignX( KSpreadFormat::Align alignX )
01823 {
01824 if ( m_type != AUTO || m_usageCount > 1 )
01825 {
01826 KSpreadStyle * style = new KSpreadStyle( this );
01827 style->m_alignX = alignX;
01828 style->m_featuresSet |= SAlignX;
01829 return style;
01830 }
01831
01832 m_alignX = alignX;
01833 m_featuresSet |= SAlignX;
01834 return this;
01835 }
01836
01837 KSpreadStyle * KSpreadStyle::setAlignY( KSpreadFormat::AlignY alignY )
01838 {
01839 if ( m_type != AUTO || m_usageCount > 1 )
01840 {
01841 KSpreadStyle * style = new KSpreadStyle( this );
01842 style->m_alignY = alignY;
01843 style->m_featuresSet |= SAlignY;
01844 return style;
01845 }
01846
01847 m_alignY = alignY;
01848 m_featuresSet |= SAlignY;
01849 return this;
01850 }
01851
01852 KSpreadStyle * KSpreadStyle::setFont( QFont const & f )
01853 {
01854 if ( m_type != AUTO || m_usageCount > 1 )
01855 {
01856 KSpreadStyle * style = new KSpreadStyle( this );
01857 if ( style->m_fontFamily != f.family() )
01858 {
01859 style->m_fontFamily = f.family();
01860 style->m_featuresSet |= SFont;
01861 style->m_featuresSet |= SFontFamily;
01862 }
01863 if ( style->m_fontSize != f.pointSize() )
01864 {
01865 style->m_fontSize = f.pointSize();
01866 style->m_featuresSet |= SFont;
01867 style->m_featuresSet |= SFontSize;
01868 }
01869 if ( f.italic() != (m_fontFlags & (uint) FItalic ) )
01870 {
01871 if ( f.italic() )
01872 style->m_fontFlags |= FItalic;
01873 else
01874 style->m_fontFlags &= ~(uint) FItalic;
01875 style->m_featuresSet |= SFont;
01876 style->m_featuresSet |= SFontFlag;
01877 }
01878 if ( f.bold() != (m_fontFlags & (uint) FBold ) )
01879 {
01880 if ( f.bold() )
01881 style->m_fontFlags |= FBold;
01882 else
01883 style->m_fontFlags &= ~(uint) FBold;
01884 style->m_featuresSet |= SFont;
01885 style->m_featuresSet |= SFontFlag;
01886 }
01887 if ( f.underline() != (m_fontFlags & (uint) FUnderline ) )
01888 {
01889 if ( f.underline() )
01890 style->m_fontFlags |= FUnderline;
01891 else
01892 style->m_fontFlags &= ~(uint) FUnderline;
01893 style->m_featuresSet |= SFont;
01894 style->m_featuresSet |= SFontFlag;
01895 }
01896 if ( f.strikeOut() != (m_fontFlags & (uint) FStrike ) )
01897 {
01898 if ( f.strikeOut() )
01899 style->m_fontFlags |= FStrike;
01900 else
01901 style->m_fontFlags &= ~(uint) FStrike;
01902 style->m_featuresSet |= SFont;
01903 style->m_featuresSet |= SFontFlag;
01904 }
01905
01906 return style;
01907 }
01908
01909 if ( m_fontFamily != f.family() )
01910 {
01911 m_fontFamily = f.family();
01912 m_featuresSet |= SFont;
01913 m_featuresSet |= SFontFamily;
01914 }
01915 if ( m_fontSize != f.pointSize() )
01916 {
01917 m_fontSize = f.pointSize();
01918 m_featuresSet |= SFont;
01919 m_featuresSet |= SFontSize;
01920 }
01921 if ( f.italic() != (m_fontFlags & (uint) FItalic ) )
01922 {
01923 if ( f.italic() )
01924 m_fontFlags |= FItalic;
01925 else
01926 m_fontFlags &= ~(uint) FItalic;
01927 m_featuresSet |= SFont;
01928 m_featuresSet |= SFontFlag;
01929 }
01930 if ( f.bold() != (m_fontFlags & (uint) FBold ) )
01931 {
01932 if ( f.bold() )
01933 m_fontFlags |= FBold;
01934 else
01935 m_fontFlags &= ~(uint) FBold;
01936 m_featuresSet |= SFont;
01937 m_featuresSet |= SFontFlag;
01938 }
01939 if ( f.underline() != (m_fontFlags & (uint) FUnderline ) )
01940 {
01941 if ( f.underline() )
01942 m_fontFlags |= FUnderline;
01943 else
01944 m_fontFlags &= ~(uint) FUnderline;
01945 m_featuresSet |= SFont;
01946 m_featuresSet |= SFontFlag;
01947 }
01948 if ( f.strikeOut() != (m_fontFlags & (uint) FStrike ) )
01949 {
01950 if ( f.strikeOut() )
01951 m_fontFlags |= FStrike;
01952 else
01953 m_fontFlags &= ~(uint) FStrike;
01954 m_featuresSet |= SFont;
01955 m_featuresSet |= SFontFlag;
01956 }
01957
01958 return this;
01959 }
01960
01961 KSpreadStyle * KSpreadStyle::setFontFamily( QString const & fam )
01962 {
01963 if ( m_type != AUTO || m_usageCount > 1 )
01964 {
01965 if ( m_fontFamily != fam )
01966 {
01967 KSpreadStyle * style = new KSpreadStyle( this );
01968 style->m_fontFamily = fam;
01969 style->m_featuresSet |= SFontFamily;
01970 style->m_featuresSet |= SFont;
01971 return style;
01972 }
01973 return this;
01974 }
01975
01976 m_fontFamily = fam;
01977 m_featuresSet |= SFont;
01978 m_featuresSet |= SFontFamily;
01979 return this;
01980 }
01981
01982 KSpreadStyle * KSpreadStyle::setFontFlags( uint flags )
01983 {
01984 if ( m_type != AUTO || m_usageCount > 1 )
01985 {
01986 if ( m_fontFlags != flags )
01987 {
01988 KSpreadStyle * style = new KSpreadStyle( this );
01989 style->m_fontFlags = flags;
01990 style->m_featuresSet |= SFontFlag;
01991 style->m_featuresSet |= SFont;
01992 return style;
01993 }
01994 return this;
01995 }
01996
01997 m_fontFlags = flags;
01998 m_featuresSet |= SFont;
01999 m_featuresSet |= SFontFlag;
02000 return this;
02001 }
02002
02003 KSpreadStyle * KSpreadStyle::setFontSize( int size )
02004 {
02005 if ( m_type != AUTO || m_usageCount > 1 )
02006 {
02007 if ( m_fontSize != size )
02008 {
02009 KSpreadStyle * style = new KSpreadStyle( this );
02010 style->m_fontSize = size;
02011 style->m_featuresSet |= SFontSize;
02012 style->m_featuresSet |= SFont;
02013 return style;
02014 }
02015 return this;
02016 }
02017
02018 m_fontSize = size;
02019 m_featuresSet |= SFont;
02020 m_featuresSet |= SFontSize;
02021 return this;
02022 }
02023
02024 KSpreadStyle * KSpreadStyle::setPen( QPen const & pen )
02025 {
02026 if ( m_type != AUTO || m_usageCount > 1 )
02027 {
02028 KSpreadStyle * style = new KSpreadStyle( this );
02029 style->m_textPen = pen;
02030 if ( style->m_textPen.style() != Qt::NoPen )
02031 style->m_featuresSet |= STextPen;
02032 return style;
02033 }
02034
02035 m_textPen = pen;
02036 if ( m_textPen.style() != Qt::NoPen )
02037 m_featuresSet |= STextPen;
02038 return this;
02039 }
02040
02041 KSpreadStyle * KSpreadStyle::setBgColor( QColor const & color )
02042 {
02043 if ( m_type != AUTO || m_usageCount > 1 )
02044 {
02045 KSpreadStyle * style = new KSpreadStyle( this );
02046 style->m_bgColor = color;
02047 if ( style->m_bgColor != Qt::white )
02048 style->m_featuresSet |= SBackgroundColor;
02049 return style;
02050 }
02051
02052 m_bgColor = color;
02053 if ( m_bgColor != Qt::white )
02054 m_featuresSet |= SBackgroundColor;
02055 return this;
02056 }
02057
02058 KSpreadStyle * KSpreadStyle::setRightBorderPen( QPen const & pen )
02059 {
02060 if ( m_type != AUTO || m_usageCount > 1 )
02061 {
02062 KSpreadStyle * style = new KSpreadStyle( this );
02063 style->m_rightBorderPen = pen;
02064 style->m_rightPenValue = calculateValue( pen );
02065 if ( style->m_rightBorderPen.style() != Qt::NoPen )
02066 style->m_featuresSet |= SRightBorder;
02067 return style;
02068 }
02069
02070 m_rightBorderPen = pen;
02071 m_rightPenValue = calculateValue( pen );
02072 if ( m_rightBorderPen.style() != Qt::NoPen )
02073 m_featuresSet |= SRightBorder;
02074 return this;
02075 }
02076
02077 KSpreadStyle * KSpreadStyle::setBottomBorderPen( QPen const & pen )
02078 {
02079 if ( m_type != AUTO || m_usageCount > 1 )
02080 {
02081 KSpreadStyle * style = new KSpreadStyle( this );
02082 style->m_bottomBorderPen = pen;
02083 style->m_bottomPenValue = calculateValue( pen );
02084 if ( style->m_bottomBorderPen.style() != Qt::NoPen )
02085 style->m_featuresSet |= SBottomBorder;
02086 return style;
02087 }
02088
02089 m_bottomBorderPen = pen;
02090 m_bottomPenValue = calculateValue( pen );
02091 if ( m_bottomBorderPen.style() != Qt::NoPen )
02092 m_featuresSet |= SBottomBorder;
02093 return this;
02094 }
02095
02096 KSpreadStyle * KSpreadStyle::setLeftBorderPen( QPen const & pen )
02097 {
02098 if ( m_type != AUTO || m_usageCount > 1 )
02099 {
02100 KSpreadStyle * style = new KSpreadStyle( this );
02101 style->m_leftBorderPen = pen;
02102 style->m_leftPenValue = calculateValue( pen );
02103 if ( style->m_leftBorderPen.style() != Qt::NoPen )
02104 style->m_featuresSet |= SLeftBorder;
02105 return style;
02106 }
02107
02108 m_leftBorderPen = pen;
02109 m_leftPenValue = calculateValue( pen );
02110 if ( m_leftBorderPen.style() != Qt::NoPen )
02111 m_featuresSet |= SLeftBorder;
02112 return this;
02113 }
02114
02115 KSpreadStyle * KSpreadStyle::setTopBorderPen( QPen const & pen )
02116 {
02117 if ( m_type != AUTO || m_usageCount > 1 )
02118 {
02119 KSpreadStyle * style = new KSpreadStyle( this );
02120 style->m_topBorderPen = pen;
02121 style->m_topPenValue = calculateValue( pen );
02122 if ( style->m_topBorderPen.style() != Qt::NoPen )
02123 style->m_featuresSet |= STopBorder;
02124 return style;
02125 }
02126
02127 m_topBorderPen = pen;
02128 m_topPenValue = calculateValue( pen );
02129 if ( m_topBorderPen.style() != Qt::NoPen )
02130 m_featuresSet |= STopBorder;
02131 return this;
02132 }
02133
02134 KSpreadStyle * KSpreadStyle::setFallDiagonalPen( QPen const & pen )
02135 {
02136 if ( m_type != AUTO || m_usageCount > 1 )
02137 {
02138 KSpreadStyle * style = new KSpreadStyle( this );
02139 style->m_fallDiagonalPen = pen;
02140 if ( style->m_fallDiagonalPen.style() != Qt::NoPen )
02141 style->m_featuresSet |= SFallDiagonal;
02142 return style;
02143 }
02144
02145 m_fallDiagonalPen = pen;
02146 if ( m_fallDiagonalPen.style() != Qt::NoPen )
02147 m_featuresSet |= SFallDiagonal;
02148 return this;
02149 }
02150
02151 KSpreadStyle * KSpreadStyle::setGoUpDiagonalPen( QPen const & pen )
02152 {
02153 if ( m_type != AUTO || m_usageCount > 1 )
02154 {
02155 KSpreadStyle * style = new KSpreadStyle( this );
02156 style->m_goUpDiagonalPen = pen;
02157 if ( style->m_goUpDiagonalPen.style() != Qt::NoPen )
02158 style->m_featuresSet |= SGoUpDiagonal;
02159 return style;
02160 }
02161
02162 m_goUpDiagonalPen = pen;
02163 if ( m_goUpDiagonalPen.style() != Qt::NoPen )
02164 m_featuresSet |= SGoUpDiagonal;
02165 return this;
02166 }
02167
02168 KSpreadStyle * KSpreadStyle::setRotateAngle( int angle )
02169 {
02170 if ( m_type != AUTO || m_usageCount > 1 )
02171 {
02172 KSpreadStyle * style = new KSpreadStyle( this );
02173 style->m_rotateAngle = angle;
02174 style->m_featuresSet |= SAngle;
02175 return style;
02176 }
02177
02178 m_rotateAngle = angle;
02179 m_featuresSet |= SAngle;
02180 return this;
02181 }
02182
02183 KSpreadStyle * KSpreadStyle::setIndent( double indent )
02184 {
02185 if ( m_type != AUTO || m_usageCount > 1 )
02186 {
02187 KSpreadStyle * style = new KSpreadStyle( this );
02188 style->m_indent = indent;
02189 style->m_featuresSet |= SIndent;
02190 return style;
02191 }
02192
02193 m_indent = indent;
02194 m_featuresSet |= SIndent;
02195 return this;
02196 }
02197
02198 KSpreadStyle * KSpreadStyle::setBackGroundBrush( QBrush const & brush )
02199 {
02200 if ( m_type != AUTO || m_usageCount > 1 )
02201 {
02202 KSpreadStyle * style = new KSpreadStyle( this );
02203 style->m_backGroundBrush = brush;
02204 if ( style->m_backGroundBrush.style() != Qt::NoBrush )
02205 style->m_featuresSet |= SBackgroundBrush;
02206 return style;
02207 }
02208
02209 m_backGroundBrush = brush;
02210 if ( m_backGroundBrush.style() != Qt::NoBrush )
02211 m_featuresSet |= SBackgroundBrush;
02212 return this;
02213 }
02214
02215 KSpreadStyle * KSpreadStyle::setFloatFormat( KSpreadFormat::FloatFormat format )
02216 {
02217 if ( m_type != AUTO || m_usageCount > 1 )
02218 {
02219 KSpreadStyle * style = new KSpreadStyle( this );
02220 style->m_floatFormat = format;
02221 style->m_featuresSet |= SFloatFormat;
02222 return style;
02223 }
02224
02225 m_floatFormat = format;
02226 m_featuresSet |= SFloatFormat;
02227 return this;
02228 }
02229
02230 KSpreadStyle * KSpreadStyle::setFloatColor( KSpreadFormat::FloatColor color )
02231 {
02232 if ( m_type != AUTO || m_usageCount > 1 )
02233 {
02234 KSpreadStyle * style = new KSpreadStyle( this );
02235 style->m_floatColor = color;
02236 style->m_featuresSet |= SFloatColor;
02237 return style;
02238 }
02239
02240 m_floatColor = color;
02241 m_featuresSet |= SFloatColor;
02242 return this;
02243 }
02244
02245 KSpreadStyle * KSpreadStyle::setStrFormat( QString const & strFormat )
02246 {
02247 if ( m_type != AUTO || m_usageCount > 1 )
02248 {
02249 KSpreadStyle * style = new KSpreadStyle( this );
02250 style->m_strFormat = strFormat;
02251 style->m_featuresSet |= SCustomFormat;
02252 return style;
02253 }
02254
02255 m_strFormat = strFormat;
02256 m_featuresSet |= SCustomFormat;
02257 return this;
02258 }
02259
02260 KSpreadStyle * KSpreadStyle::setPrecision( int precision )
02261 {
02262 if ( m_type != AUTO || m_usageCount > 1 )
02263 {
02264 KSpreadStyle * style = new KSpreadStyle( this );
02265 style->m_precision = precision;
02266 style->m_featuresSet |= SPrecision;
02267 return style;
02268 }
02269
02270 m_precision = precision;
02271 m_featuresSet |= SPrecision;
02272 return this;
02273 }
02274
02275 KSpreadStyle * KSpreadStyle::setPrefix( QString const & prefix )
02276 {
02277 if ( m_type != AUTO || m_usageCount > 1 )
02278 {
02279 KSpreadStyle * style = new KSpreadStyle( this );
02280 style->m_prefix = prefix;
02281 style->m_featuresSet |= SPrefix;
02282 return style;
02283 }
02284
02285 m_prefix = prefix;
02286 m_featuresSet |= SPrefix;
02287 return this;
02288 }
02289
02290 KSpreadStyle * KSpreadStyle::setPostfix( QString const & postfix )
02291 {
02292 if ( m_type != AUTO || m_usageCount > 1 )
02293 {
02294 KSpreadStyle * style = new KSpreadStyle( this );
02295 style->m_postfix = postfix;
02296 style->m_featuresSet |= SPostfix;
02297 return style;
02298 }
02299
02300 m_postfix = postfix;
02301 m_featuresSet |= SPostfix;
02302 return this;
02303 }
02304
02305 KSpreadStyle * KSpreadStyle::setCurrency( KSpreadFormat::Currency const & currency )
02306 {
02307 if ( m_type != AUTO || m_usageCount > 1 )
02308 {
02309 KSpreadStyle * style = new KSpreadStyle( this );
02310 style->m_currency = currency;
02311 style->m_featuresSet |= SFormatType;
02312 return style;
02313 }
02314
02315 m_currency = currency;
02316 m_featuresSet |= SFormatType;
02317 return this;
02318 }
02319
02320 KSpreadStyle * KSpreadStyle::setProperty( Properties p )
02321 {
02322 if ( m_type != AUTO || m_usageCount > 1 )
02323 {
02324 KSpreadStyle * style = new KSpreadStyle( this );
02325 style->m_properties |= (uint) p;
02326 switch( p )
02327 {
02328 case PDontPrintText:
02329 style->m_featuresSet |= SDontPrintText;
02330 break;
02331 case PCustomFormat:
02332 style->m_featuresSet |= SCustomFormat;
02333 break;
02334 case PNotProtected:
02335 style->m_featuresSet |= SNotProtected;
02336 break;
02337 case PHideAll:
02338 style->m_featuresSet |= SHideAll;
02339 break;
02340 case PHideFormula:
02341 style->m_featuresSet |= SHideFormula;
02342 break;
02343 case PMultiRow:
02344 style->m_featuresSet |= SMultiRow;
02345 break;
02346 case PVerticalText:
02347 style->m_featuresSet |= SVerticalText;
02348 break;
02349 default:
02350 kdWarning() << "Unhandled property" << endl;
02351 }
02352 return style;
02353 }
02354
02355 m_properties |= (uint) p;
02356 switch( p )
02357 {
02358 case PDontPrintText:
02359 m_featuresSet |= SDontPrintText;
02360 break;
02361 case PCustomFormat:
02362 m_featuresSet |= SCustomFormat;
02363 break;
02364 case PNotProtected:
02365 m_featuresSet |= SNotProtected;
02366 break;
02367 case PHideAll:
02368 m_featuresSet |= SHideAll;
02369 break;
02370 case PHideFormula:
02371 m_featuresSet |= SHideFormula;
02372 break;
02373 case PMultiRow:
02374 m_featuresSet |= SMultiRow;
02375 break;
02376 case PVerticalText:
02377 m_featuresSet |= SVerticalText;
02378 break;
02379 default:
02380 kdWarning() << "Unhandled property" << endl;
02381 }
02382 return this;
02383 }
02384
02385 KSpreadStyle * KSpreadStyle::clearProperty( Properties p )
02386 {
02387 if ( m_type != AUTO || m_usageCount > 1 )
02388 {
02389 KSpreadStyle * style = new KSpreadStyle( this );
02390 style->m_properties &= ~(uint) p;
02391 switch( p )
02392 {
02393 case PDontPrintText:
02394 style->m_featuresSet |= SDontPrintText;
02395 break;
02396 case PCustomFormat:
02397 style->m_featuresSet |= SCustomFormat;
02398 break;
02399 case PNotProtected:
02400 style->m_featuresSet |= SNotProtected;
02401 break;
02402 case PHideAll:
02403 style->m_featuresSet |= SHideAll;
02404 break;
02405 case PHideFormula:
02406 style->m_featuresSet |= SHideFormula;
02407 break;
02408 case PMultiRow:
02409 style->m_featuresSet |= SMultiRow;
02410 break;
02411 case PVerticalText:
02412 style->m_featuresSet |= SVerticalText;
02413 break;
02414 default:
02415 kdWarning() << "Unhandled property" << endl;
02416 }
02417 return style;
02418 }
02419
02420 m_properties &= ~(uint) p;
02421 switch( p )
02422 {
02423 case PDontPrintText:
02424 m_featuresSet |= SDontPrintText;
02425 break;
02426 case PCustomFormat:
02427 m_featuresSet |= SCustomFormat;
02428 break;
02429 case PNotProtected:
02430 m_featuresSet |= SNotProtected;
02431 break;
02432 case PHideAll:
02433 m_featuresSet |= SHideAll;
02434 break;
02435 case PHideFormula:
02436 m_featuresSet |= SHideFormula;
02437 break;
02438 case PMultiRow:
02439 m_featuresSet |= SMultiRow;
02440 break;
02441 case PVerticalText:
02442 m_featuresSet |= SVerticalText;
02443 break;
02444 default:
02445 kdWarning() << "Unhandled property" << endl;
02446 }
02447 return this;
02448 }
02449
02450
02451 KSpreadStyle * KSpreadStyle::setFormatType( FormatType format )
02452 {
02453 if ( m_type != AUTO || m_usageCount > 1 )
02454 {
02455 KSpreadStyle * style = new KSpreadStyle( this );
02456 style->m_formatType = format;
02457 style->m_featuresSet |= SFormatType;
02458 return style;
02459 }
02460
02461 m_formatType = format;
02462 m_featuresSet |= SFormatType;
02463 return this;
02464 }
02465
02466
02473 KSpreadCustomStyle::KSpreadCustomStyle()
02474 : KSpreadStyle(),
02475 m_name( i18n("Default") )
02476 {
02477 m_parent = 0;
02478 }
02479
02480 KSpreadCustomStyle::KSpreadCustomStyle( KSpreadStyle * parent, QString const & name )
02481 : KSpreadStyle(),
02482 m_name( name )
02483 {
02484 m_type = CUSTOM;
02485 m_parent = 0;
02486
02487
02488 if ( parent->hasProperty( PDontPrintText ) )
02489 addProperty( PDontPrintText );
02490 if ( parent->hasProperty( PCustomFormat ) )
02491 addProperty( PCustomFormat );
02492 if ( parent->hasProperty( PNotProtected ) )
02493 addProperty( PNotProtected );
02494 if ( parent->hasProperty( PHideAll ) )
02495 addProperty( PHideAll );
02496 if ( parent->hasProperty( PHideFormula ) )
02497 addProperty( PHideFormula );
02498 if ( parent->hasProperty( PMultiRow ) )
02499 addProperty( PMultiRow );
02500 if ( parent->hasProperty( PVerticalText ) )
02501 addProperty( PVerticalText );
02502
02503 changeAlignX( parent->alignX() );
02504 changeAlignY( parent->alignY() );
02505 changeFloatFormat( parent->floatFormat() );
02506 changeFloatColor( parent->floatColor() );
02507 changeFormatType( parent->formatType() );
02508 changeFontFamily( parent->fontFamily() );
02509 changeFontSize( parent->fontSize() );
02510 changeFontFlags( parent->fontFlags() );
02511 changePen( parent->pen() );
02512 changeBgColor( parent->bgColor() );
02513 changeRightBorderPen( parent->rightBorderPen() );
02514 changeBottomBorderPen( parent->bottomBorderPen() );
02515 changeLeftBorderPen( parent->leftBorderPen() );
02516 changeTopBorderPen( parent->topBorderPen() );
02517 changeFallBorderPen( parent->fallDiagonalPen() );
02518 changeGoUpBorderPen( parent->goUpDiagonalPen() );
02519 changeBackGroundBrush( parent->backGroundBrush() );
02520 changeRotateAngle( parent->rotateAngle() );
02521 changeIndent( parent->indent() );
02522 changeStrFormat( parent->strFormat() );
02523 changePrecision( parent->precision() );
02524 changePrefix( parent->prefix() );
02525 changePostfix( parent->postfix() );
02526 changeCurrency( parent->currency() );
02527 }
02528
02529 KSpreadCustomStyle::KSpreadCustomStyle( QString const & name, KSpreadCustomStyle * parent )
02530 : KSpreadStyle(),
02531 m_name( name )
02532 {
02533 m_parent = parent;
02534 if ( m_parent )
02535 m_parentName = m_parent->name();
02536 }
02537
02538 KSpreadCustomStyle::~KSpreadCustomStyle()
02539 {
02540 }
02541
02542 void KSpreadCustomStyle::saveOasis( KoGenStyles &mainStyles )
02543 {
02544 if ( m_name.isEmpty() )
02545 return;
02546 KoGenStyle gs;
02547 if ( m_type == AUTO )
02548 gs = KoGenStyle(KSpreadDoc::STYLE_DEFAULTSTYLE );
02549 else
02550 gs = KoGenStyle( KSpreadDoc::STYLE_USERSTYLE );
02551 if ( m_parent )
02552 gs.addAttribute( "style:parent-style-name", m_parent->name() );
02553 gs.addAttribute( "style:display-name", m_name );
02554 QString numericStyle = saveOasisStyle( gs, mainStyles );
02555 if ( !numericStyle.isEmpty() )
02556 gs.addAttribute( "style:data-style-name", numericStyle );
02557 mainStyles.lookup( gs, "custom-style" );
02558 }
02559
02560 void KSpreadCustomStyle::loadOasis( KoOasisStyles& oasisStyles, const QDomElement & style, const QString & name )
02561 {
02562 m_name = name;
02563 if ( style.hasAttributeNS( KoXmlNS::style, "parent-style-name" ) )
02564 m_parentName = style.attributeNS( KoXmlNS::style, "parent-style-name", QString::null );
02565
02566
02567 m_type = CUSTOM;
02568
02569 KSpreadStyle::loadOasisStyle( oasisStyles, style );
02570 }
02571
02572 void KSpreadCustomStyle::save( QDomDocument & doc, QDomElement & styles )
02573 {
02574 if ( m_name.isEmpty() )
02575 return;
02576
02577 QDomElement style( doc.createElement( "style" ) );
02578 style.setAttribute( "type", (int) m_type );
02579 if ( m_parent )
02580 style.setAttribute( "parent", m_parent->name() );
02581 style.setAttribute( "name", m_name );
02582
02583 QDomElement format( doc.createElement( "format" ) );
02584 saveXML( doc, format );
02585 style.appendChild( format );
02586
02587 styles.appendChild( style );
02588 }
02589
02590 bool KSpreadCustomStyle::loadXML( QDomElement const & style, QString const & name )
02591 {
02592 m_name = name;
02593
02594 if ( style.hasAttribute( "parent" ) )
02595 m_parentName = style.attribute( "parent" );
02596
02597 if ( !style.hasAttribute( "type" ) )
02598 return false;
02599
02600 bool ok = true;
02601 m_type = (StyleType) style.attribute( "type" ).toInt( &ok );
02602 if ( !ok )
02603 return false;
02604
02605 QDomElement f( style.namedItem( "format" ).toElement() );
02606 if ( !f.isNull() )
02607 if ( !KSpreadStyle::loadXML( f ) )
02608 return false;
02609
02610 return true;
02611 }
02612
02613 void KSpreadCustomStyle::setName( QString const & name )
02614 {
02615 m_name = name;
02616 }
02617
02618 void KSpreadCustomStyle::refreshParentName()
02619 {
02620 if ( m_parent )
02621 m_parentName = m_parent->name();
02622 }
02623
02624 bool KSpreadCustomStyle::definesAll() const
02625 {
02626 if ( !( m_featuresSet & (uint) SAlignX ) )
02627 return false;
02628 if ( !( m_featuresSet & (uint) SAlignY ) )
02629 return false;
02630 if ( !( m_featuresSet & (uint) SPrefix ) )
02631 return false;
02632 if ( !( m_featuresSet & (uint) SPostfix ) )
02633 return false;
02634 if ( !( m_featuresSet & (uint) SLeftBorder ) )
02635 return false;
02636 if ( !( m_featuresSet & (uint) SRightBorder ) )
02637 return false;
02638 if ( !( m_featuresSet & (uint) STopBorder ) )
02639 return false;
02640 if ( !( m_featuresSet & (uint) SBottomBorder ) )
02641 return false;
02642 if ( !( m_featuresSet & (uint) SFallDiagonal ) )
02643 return false;
02644 if ( !( m_featuresSet & (uint) SGoUpDiagonal ) )
02645 return false;
02646 if ( !( m_featuresSet & (uint) SBackgroundBrush ) )
02647 return false;
02648 if ( !( m_featuresSet & (uint) SFontFamily ) )
02649 return false;
02650 if ( !( m_featuresSet & (uint) SFontSize ) )
02651 return false;
02652 if ( !( m_featuresSet & (uint) SFontFlag ) )
02653 return false;
02654 if ( !( m_featuresSet & (uint) STextPen ) )
02655 return false;
02656 if ( !( m_featuresSet & (uint) SBackgroundColor ) )
02657 return false;
02658 if ( !( m_featuresSet & (uint) SFloatFormat ) )
02659 return false;
02660 if ( !( m_featuresSet & (uint) SFloatColor ) )
02661 return false;
02662 if ( !( m_featuresSet & (uint) SMultiRow ) )
02663 return false;
02664 if ( !( m_featuresSet & (uint) SVerticalText ) )
02665 return false;
02666 if ( !( m_featuresSet & (uint) SPrecision ) )
02667 return false;
02668 if ( !( m_featuresSet & (uint) SFormatType ) )
02669 return false;
02670 if ( !( m_featuresSet & (uint) SAngle ) )
02671 return false;
02672 if ( !( m_featuresSet & (uint) SIndent ) )
02673 return false;
02674 if ( !( m_featuresSet & (uint) SDontPrintText ) )
02675 return false;
02676 if ( !( m_featuresSet & (uint) SCustomFormat ) )
02677 return false;
02678 if ( !( m_featuresSet & (uint) SNotProtected ) )
02679 return false;
02680 if ( !( m_featuresSet & (uint) SHideAll ) )
02681 return false;
02682 if ( !( m_featuresSet & (uint) SHideFormula ) )
02683 return false;
02684
02685 return true;
02686 }
02687
02688 void KSpreadCustomStyle::changeAlignX( KSpreadFormat::Align alignX )
02689 {
02690 m_alignX = alignX;
02691 m_featuresSet |= SAlignX;
02692 }
02693
02694 void KSpreadCustomStyle::changeAlignY( KSpreadFormat::AlignY alignY )
02695 {
02696 m_alignY = alignY;
02697 m_featuresSet |= SAlignY;
02698 }
02699
02700 void KSpreadCustomStyle::changeFont( QFont const & f )
02701 {
02702 if ( m_fontFamily != f.family() )
02703 {
02704 m_fontFamily = f.family();
02705 m_featuresSet |= SFontFamily;
02706 m_featuresSet |= SFont;
02707 }
02708 if ( m_fontSize != f.pointSize() )
02709 {
02710 m_fontSize = f.pointSize();
02711 m_featuresSet |= SFont;
02712 m_featuresSet |= SFontSize;
02713 }
02714
02715 if ( f.italic() != (m_fontFlags & (uint) FItalic ) )
02716 {
02717 if ( f.italic() )
02718 m_fontFlags |= FItalic;
02719 else
02720 m_fontFlags &= ~(uint) FItalic;
02721 m_featuresSet |= SFont;
02722 m_featuresSet |= SFontFlag;
02723 }
02724 if ( f.bold() != (m_fontFlags & (uint) FBold ) )
02725 {
02726 if ( f.bold() )
02727 m_fontFlags |= FBold;
02728 else
02729 m_fontFlags &= ~(uint) FBold;
02730 m_featuresSet |= SFont;
02731 m_featuresSet |= SFontFlag;
02732 }
02733 if ( f.underline() != (m_fontFlags & (uint) FUnderline ) )
02734 {
02735 if ( f.underline() )
02736 m_fontFlags |= FUnderline;
02737 else
02738 m_fontFlags &= ~(uint) FUnderline;
02739 m_featuresSet |= SFont;
02740 m_featuresSet |= SFontFlag;
02741 }
02742 if ( f.strikeOut() != (m_fontFlags & (uint) FStrike ) )
02743 {
02744 if ( f.strikeOut() )
02745 m_fontFlags |= FStrike;
02746 else
02747 m_fontFlags &= ~(uint) FStrike;
02748 m_featuresSet |= SFont;
02749 m_featuresSet |= SFontFlag;
02750 }
02751 }
02752
02753 void KSpreadCustomStyle::changeFontFamily( QString const & fam )
02754 {
02755 if ( m_fontFamily != fam )
02756 {
02757 m_fontFamily = fam;
02758 m_featuresSet |= SFont;
02759 m_featuresSet |= SFontFamily;
02760 }
02761 }
02762
02763 void KSpreadCustomStyle::changeFontSize( int size )
02764 {
02765 if ( m_fontSize != size )
02766 {
02767 m_fontSize = size;
02768 m_featuresSet |= SFont;
02769 m_featuresSet |= SFontSize;
02770 }
02771 }
02772
02773 void KSpreadCustomStyle::changeFontFlags( uint flags )
02774 {
02775 if ( m_fontFlags != flags )
02776 {
02777 m_fontFlags = flags;
02778 m_featuresSet |= SFont;
02779 m_featuresSet |= SFontFlag;
02780 }
02781 }
02782
02783 void KSpreadCustomStyle::changeTextColor( QColor const & color )
02784 {
02785 m_textPen.setColor( color );
02786 m_featuresSet |= STextPen;
02787 }
02788
02789 void KSpreadCustomStyle::changePen( QPen const & pen )
02790 {
02791 m_textPen = pen;
02792 m_featuresSet |= STextPen;
02793 }
02794
02795 void KSpreadCustomStyle::changeBgColor( QColor const & color )
02796 {
02797 m_bgColor = color;
02798 m_featuresSet |= SBackgroundColor;
02799 }
02800
02801 void KSpreadCustomStyle::changeRightBorderPen( QPen const & pen )
02802 {
02803 m_rightBorderPen = pen;
02804 m_rightPenValue = calculateValue( pen );
02805 m_featuresSet |= SRightBorder;
02806 }
02807
02808 void KSpreadCustomStyle::changeBottomBorderPen( QPen const & pen )
02809 {
02810 m_bottomBorderPen = pen;
02811 m_bottomPenValue = calculateValue( pen );
02812 m_featuresSet |= SBottomBorder;
02813 }
02814
02815 void KSpreadCustomStyle::changeLeftBorderPen( QPen const & pen )
02816 {
02817 m_leftBorderPen = pen;
02818 m_leftPenValue = calculateValue( pen );
02819 m_featuresSet |= SLeftBorder;
02820 }
02821
02822 void KSpreadCustomStyle::changeTopBorderPen( QPen const & pen )
02823 {
02824 m_topBorderPen = pen;
02825 m_topPenValue = calculateValue( pen );
02826 m_featuresSet |= STopBorder;
02827 }
02828
02829 void KSpreadCustomStyle::changeFallBorderPen( QPen const & pen )
02830 {
02831 m_fallDiagonalPen = pen;
02832 m_featuresSet |= SFallDiagonal;
02833 }
02834
02835 void KSpreadCustomStyle::changeGoUpBorderPen( QPen const & pen )
02836 {
02837 m_goUpDiagonalPen = pen;
02838 m_featuresSet |= SGoUpDiagonal;
02839 }
02840
02841 void KSpreadCustomStyle::changeRotateAngle( int angle )
02842 {
02843 m_rotateAngle = angle;
02844 m_featuresSet |= SAngle;
02845 }
02846
02847 void KSpreadCustomStyle::changeIndent( double indent )
02848 {
02849 m_indent = indent;
02850 m_featuresSet |= SIndent;
02851 }
02852
02853 void KSpreadCustomStyle::changeBackGroundBrush( QBrush const & brush )
02854 {
02855 m_backGroundBrush = brush;
02856 m_featuresSet |= SBackgroundBrush;
02857 }
02858
02859 void KSpreadCustomStyle::changeFloatFormat( KSpreadFormat::FloatFormat format )
02860 {
02861 m_floatFormat = format;
02862 m_featuresSet |= SFloatFormat;
02863 }
02864
02865 void KSpreadCustomStyle::changeFloatColor( KSpreadFormat::FloatColor color )
02866 {
02867 m_floatColor = color;
02868 m_featuresSet |= SFloatColor;
02869 }
02870
02871 void KSpreadCustomStyle::changeFormatType( FormatType format )
02872 {
02873 m_formatType = format;
02874 m_featuresSet |= SFormatType;
02875 }
02876
02877 void KSpreadCustomStyle::changeStrFormat( QString const & strFormat )
02878 {
02879 m_strFormat = strFormat;
02880 m_featuresSet |= SCustomFormat;
02881 }
02882
02883 void KSpreadCustomStyle::changePrecision( int precision )
02884 {
02885 m_precision = precision;
02886 m_featuresSet |= SPrecision;
02887 }
02888
02889 void KSpreadCustomStyle::changePrefix( QString const & prefix )
02890 {
02891 m_prefix = prefix;
02892 m_featuresSet |= SPrefix;
02893 }
02894
02895 void KSpreadCustomStyle::changePostfix( QString const & postfix )
02896 {
02897 m_postfix = postfix;
02898 m_featuresSet |= SPostfix;
02899 }
02900
02901 void KSpreadCustomStyle::changeCurrency( KSpreadFormat::Currency const & currency )
02902 {
02903 m_currency = currency;
02904 }
02905
02906 void KSpreadCustomStyle::addProperty( Properties p )
02907 {
02908 m_properties |= (uint) p;
02909 switch( p )
02910 {
02911 case PDontPrintText:
02912 m_featuresSet |= SDontPrintText;
02913 break;
02914 case PCustomFormat:
02915 m_featuresSet |= SCustomFormat;
02916 break;
02917 case PNotProtected:
02918 m_featuresSet |= SNotProtected;
02919 break;
02920 case PHideAll:
02921 m_featuresSet |= SHideAll;
02922 break;
02923 case PHideFormula:
02924 m_featuresSet |= SHideFormula;
02925 break;
02926 case PMultiRow:
02927 m_featuresSet |= SMultiRow;
02928 break;
02929 case PVerticalText:
02930 m_featuresSet |= SVerticalText;
02931 break;
02932 default:
02933 kdWarning() << "Unhandled property" << endl;
02934 }
02935 }
02936
02937 void KSpreadCustomStyle::removeProperty( Properties p )
02938 {
02939 m_properties &= ~(uint) p;
02940 switch( p )
02941 {
02942 case PDontPrintText:
02943 m_featuresSet &= SDontPrintText;
02944 break;
02945 case PCustomFormat:
02946 m_featuresSet &= SCustomFormat;
02947 break;
02948 case PNotProtected:
02949 m_featuresSet &= SNotProtected;
02950 break;
02951 case PHideAll:
02952 m_featuresSet &= SHideAll;
02953 break;
02954 case PHideFormula:
02955 m_featuresSet &= SHideFormula;
02956 break;
02957 case PMultiRow:
02958 m_featuresSet &= SMultiRow;
02959 break;
02960 case PVerticalText:
02961 m_featuresSet &= SVerticalText;
02962 break;
02963 default:
02964 kdWarning() << "Unhandled property" << endl;
02965 }
02966 }
02967
02968