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