kspread

kspread_style.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Norbert Andres, nandres@web.de
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqdom.h>
21#include <tqbuffer.h>
22
23#include <kdebug.h>
24#include <tdelocale.h>
25
26#include <KoGlobal.h>
27#include <KoGenStyles.h>
28#include <KoOasisStyles.h>
29#include <KoStyleStack.h>
30#include <KoXmlWriter.h>
31#include <KoXmlNS.h>
32
33#include "kspread_util.h"
34#include "kspread_doc.h"
35
36#include "kspread_style.h"
37
38using namespace KSpread;
39
40static uint calculateValue( TQPen const & pen )
41{
42 uint n = pen.color().red() + pen.color().green() + pen.color().blue();
43
44 n += 1000 * pen.width();
45 n += 10000 * (uint) pen.style();
46
47 return n;
48}
49
51 : m_parent( 0 ),
52 m_type( AUTO ),
53 m_usageCount( 1 ),
54 m_featuresSet( 0 ),
55 m_alignX( Format::Undefined ),
56 m_alignY( Format::Middle ),
57 m_floatFormat( Format::OnlyNegSigned ),
58 m_floatColor( Format::AllBlack ),
59 m_formatType( Generic_format ),
60 m_fontFlags( 0 ),
61 m_bgColor( TQt::white ),
62 m_backGroundBrush( TQt::red, TQt::NoBrush ),
63 m_rotateAngle( 0 ),
64 m_indent( 0.0 ),
65 m_precision( -1 ),
66 m_properties( 0 )
67{
68 TQFont f( KoGlobal::defaultFont() );
69 m_fontFamily = f.family();
70 m_fontSize = f.pointSize();
71
72 TQPen pen( TQt::black, 1, TQt::NoPen );
73
74 m_textPen = pen;
75 m_leftBorderPen = pen;
76 m_topBorderPen = pen;
77 m_rightBorderPen = pen;
81
82 m_leftPenValue = calculateValue( pen );
83 m_topPenValue = calculateValue( pen );
84 m_rightPenValue = calculateValue( pen );
85 m_bottomPenValue = calculateValue( pen );
86
87 m_currency.type = 0;
88}
89
91 : m_parent( ( style->m_type == BUILTIN || style->m_type == CUSTOM ) ? (CustomStyle *) style : 0 ),
92 m_type( AUTO ),
93 m_usageCount( 1 ),
94 m_featuresSet( ( style->m_type == BUILTIN || style->m_type == CUSTOM ) ? 0 : style->m_featuresSet ),
95 m_alignX( style->m_alignX ),
96 m_alignY( style->m_alignY ),
97 m_floatFormat( style->m_floatFormat ),
98 m_floatColor( style->m_floatColor ),
99 m_formatType( style->m_formatType ),
100 m_fontFamily( style->m_fontFamily ),
101 m_fontFlags( style->m_fontFlags ),
102 m_fontSize( style->m_fontSize ),
103 m_textPen( style->m_textPen ),
104 m_bgColor( style->m_bgColor ),
105 m_rightBorderPen( style->m_rightBorderPen ),
106 m_bottomBorderPen( style->m_bottomBorderPen ),
107 m_leftBorderPen( style->m_leftBorderPen ),
108 m_topBorderPen( style->m_topBorderPen ),
109 m_fallDiagonalPen( style->m_fallDiagonalPen ),
110 m_goUpDiagonalPen( style->m_goUpDiagonalPen ),
111 m_backGroundBrush( style->m_backGroundBrush ),
112 m_rotateAngle( style->m_rotateAngle ),
113 m_indent( style->m_indent ),
114 m_strFormat( style->m_strFormat ),
115 m_precision( style->m_precision ),
116 m_prefix( style->m_prefix ),
117 m_postfix( style->m_postfix ),
118 m_currency( style->m_currency ),
119 m_properties( style->m_properties )
120{
121}
122
124{
125}
126
127bool Style::operator == (const Style& style) const
128{
129 //This is prone to error because if someone adds additional
130 //properties to the style class they will have to remember
131 //to correct this function - can we do this a better way?
132 if ( m_featuresSet != style.m_featuresSet )
133 return false;
134 if ( m_type != style.m_type )
135 return false;
136 // NOTE Stefan: Only compare the values of the set features.
137 if ( // layout (4)
138 ( m_featuresSet & SAlignX ) && ( m_alignX != style.m_alignX ) ||
139 ( m_featuresSet & SAlignY ) && ( m_alignY != style.m_alignY ) ||
140 ( m_featuresSet & SAngle ) && ( m_rotateAngle != style.m_rotateAngle ) ||
141 ( m_featuresSet & SIndent ) && ( m_indent != style.m_indent ) ||
142 // background (2)
143 ( m_featuresSet & SBackgroundColor ) && ( m_bgColor != style.m_bgColor ) ||
144 ( m_featuresSet & SBackgroundBrush ) && ( m_backGroundBrush != style.m_backGroundBrush ) ||
145 // borders (6)
146 ( m_featuresSet & SRightBorder ) && ( m_rightBorderPen != style.m_rightBorderPen ) ||
147 ( m_featuresSet & SBottomBorder ) && ( m_bottomBorderPen != style.m_bottomBorderPen ) ||
148 ( m_featuresSet & SLeftBorder ) && ( m_leftBorderPen != style.m_leftBorderPen ) ||
149 ( m_featuresSet & STopBorder ) && ( m_topBorderPen != style.m_topBorderPen ) ||
150 ( m_featuresSet & SFallDiagonal ) && ( m_fallDiagonalPen != style.m_fallDiagonalPen ) ||
151 ( m_featuresSet & SGoUpDiagonal ) && ( m_goUpDiagonalPen != style.m_goUpDiagonalPen ) ||
152 // format (7) (SFormatType twice)
153 ( m_featuresSet & SPrecision ) && ( m_precision != style.m_precision ) ||
154 ( m_featuresSet & SPrefix ) && ( m_prefix != style.m_prefix ) ||
155 ( m_featuresSet & SPostfix ) && ( m_postfix != style.m_postfix ) ||
156 ( m_featuresSet & SFloatFormat ) && ( m_floatFormat != style.m_floatFormat ) ||
157 ( m_featuresSet & SFloatColor ) && ( m_floatColor != style.m_floatColor ) ||
158 ( m_featuresSet & SFormatType ) && ( m_formatType != style.m_formatType ) ||
159 ( m_featuresSet & SFormatType ) && ( m_currency.type != style.m_currency.type ) ||
160 ( m_featuresSet & SCustomFormat ) && ( m_strFormat != style.m_strFormat ) ||
161 // font (4)
162 ( m_featuresSet & SFontFamily ) && ( m_fontFamily != style.m_fontFamily ) ||
163 ( m_featuresSet & SFontFlag ) && ( m_fontFlags != style.m_fontFlags ) ||
164 ( m_featuresSet & SFontSize ) && ( m_fontSize != style.m_fontSize ) ||
165 ( m_featuresSet & STextPen ) && ( m_textPen != style.m_textPen ) )
166 {
167 return false;
168 }
169 // Properties (7)
170 const uint differingProperties = m_properties xor style.m_properties;
171 if ( ( m_featuresSet & SDontPrintText ) && ( differingProperties & PDontPrintText ) ||
172 ( m_featuresSet & SCustomFormat ) && ( differingProperties & PCustomFormat ) ||
173 ( m_featuresSet & SNotProtected ) && ( differingProperties & PNotProtected ) ||
174 ( m_featuresSet & SHideAll ) && ( differingProperties & PHideAll ) ||
175 ( m_featuresSet & SHideFormula ) && ( differingProperties & PHideFormula ) ||
176 ( m_featuresSet & SMultiRow ) && ( differingProperties & PMultiRow ) ||
177 ( m_featuresSet & SVerticalText ) && ( differingProperties & PVerticalText ) )
178 {
179 return false;
180 }
181 return true;
182}
183
184void Style::loadOasisStyle( KoOasisStyles& oasisStyles, const TQDomElement & element )
185{
186 // NOTE Stefan: Don't fill the style stack with the parent styles!
187 KoStyleStack styleStack;
188 styleStack.push( element );
189 styleStack.setTypeProperties( "table-cell" );
190 loadOasisTableCellProperties( oasisStyles, styleStack );
191 styleStack.setTypeProperties( "text" );
192 loadOasisTextProperties( oasisStyles, styleStack );
193 styleStack.setTypeProperties( "paragraph" );
194 loadOasisParagraphProperties( oasisStyles, styleStack );
195
196 loadOasisDataStyle( oasisStyles, element );
197}
198
199void Style::loadOasisDataStyle( KoOasisStyles& oasisStyles, const TQDomElement& element )
200{
201 TQString str;
202 if ( element.hasAttributeNS( KoXmlNS::style, "data-style-name" ) )
203 {
204// kdDebug()<<"element.attribute( style:data-style-name ) :"<<element.attributeNS( KoXmlNS::style, "data-style-name", TQString() )<<endl;
205// kdDebug()<< " oasisStyles.dataFormats()[...] :"<< oasisStyles.dataFormats()[element.attributeNS( KoXmlNS::style, "data-style-name" , TQString())].formatStr<<endl;
206// kdDebug()<< " oasisStyles.dataFormats()[...] prefix :"<< oasisStyles.dataFormats()[element.attributeNS( KoXmlNS::style, "data-style-name" , TQString())].prefix<<endl;
207// kdDebug()<< " oasisStyles.dataFormats()[...] suffix :"<< oasisStyles.dataFormats()[element.attributeNS( KoXmlNS::style, "data-style-name" , TQString())].suffix<<endl;
208
209 const TQString styleName = element.attributeNS( KoXmlNS::style, "data-style-name", TQString() );
210 if ( oasisStyles.dataFormats().contains(styleName) )
211 {
212 const KoOasisStyles::NumericStyleFormat dataStyle = oasisStyles.dataFormats()[styleName];
213
214 TQString tmp = dataStyle.prefix;
215 if ( !tmp.isEmpty() )
216 {
217 m_prefix = tmp;
218 m_featuresSet |= SPrefix;
219 }
220 tmp = dataStyle.suffix;
221 if ( !tmp.isEmpty() )
222 {
223 m_postfix = tmp;
224 m_featuresSet |= SPostfix;
225 }
226 // determine data formatting
227 switch (dataStyle.type)
228 {
229 case KoOasisStyles::NumericStyleFormat::Number:
230 m_formatType = Number_format;
231 m_featuresSet |= SFormatType;
232 break;
233 case KoOasisStyles::NumericStyleFormat::Scientific:
234 m_formatType = Scientific_format;
235 m_featuresSet |= SFormatType;
236 break;
237 case KoOasisStyles::NumericStyleFormat::Currency:
238 kdDebug() << " currency-symbol: " << dataStyle.currencySymbol << endl;
239 if (!dataStyle.currencySymbol.isEmpty())
240 {
241 Currency currency(dataStyle.currencySymbol);
242 m_currency.type = currency.getIndex();
243 m_currency.symbol = currency.getDisplayCode();
244 }
245 m_formatType = Money_format;
246 m_featuresSet |= SFormatType;
247 break;
248 case KoOasisStyles::NumericStyleFormat::Percentage:
249 m_formatType = Percentage_format;
250 m_featuresSet |= SFormatType;
251 break;
252 case KoOasisStyles::NumericStyleFormat::Fraction:
253 // determine format of fractions, dates and times by using the
254 // formatting string
255 tmp = dataStyle.formatStr;
256 if ( !tmp.isEmpty() )
257 {
258 m_formatType = Style::fractionType( tmp );
259 m_featuresSet |= SFormatType;
260 }
261 break;
262 case KoOasisStyles::NumericStyleFormat::Date:
263 // determine format of fractions, dates and times by using the
264 // formatting string
265 tmp = dataStyle.formatStr;
266 if ( !tmp.isEmpty() )
267 {
268 m_formatType = Style::dateType( tmp );
269 m_featuresSet |= SFormatType;
270 }
271 break;
272 case KoOasisStyles::NumericStyleFormat::Time:
273 // determine format of fractions, dates and times by using the
274 // formatting string
275 tmp = dataStyle.formatStr;
276 if ( !tmp.isEmpty() )
277 {
278 m_formatType = Style::timeType( tmp );
279 m_featuresSet |= SFormatType;
280 }
281 break;
282 case KoOasisStyles::NumericStyleFormat::Boolean:
283 m_formatType = Number_format;
284 m_featuresSet |= SFormatType;
285 break;
286 case KoOasisStyles::NumericStyleFormat::Text:
287 m_formatType = Text_format;
288 m_featuresSet |= SFormatType;
289 break;
290 }
291
292 if (dataStyle.precision > -1)
293 {
294 m_precision = dataStyle.precision;
295 m_featuresSet |= SPrecision;
296 }
297 }
298 }
299}
300
301void Style::loadOasisParagraphProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack )
302{
303 Q_UNUSED( oasisStyles );
304 kdDebug() << "\t paragraph-properties" << endl;
305 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "text-align" ) )
306 {
307 TQString str = styleStack.attributeNS( KoXmlNS::fo, "text-align" );
308 if ( str == "center" )
309 m_alignX = Format::Center;
310 else if ( str == "end" )
311 m_alignX = Format::Right;
312 else if ( str == "start" )
313 m_alignX = Format::Left;
314 else
315 m_alignX = Format::Undefined;
316 m_featuresSet |= SAlignX;
317 kdDebug() << "\t\t text-align: " << str << endl;
318 }
319}
320
321void Style::loadOasisTableCellProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack )
322{
323 TQString str;
324 if ( styleStack.hasAttributeNS( KoXmlNS::style, "vertical-align" ) )
325 {
326 m_alignY = Format::UndefinedY;
327
328 str = styleStack.attributeNS( KoXmlNS::style, "vertical-align" );
329 if ( str == "bottom" )
330 m_alignY = Format::Bottom;
331 else if ( str =="top" )
332 m_alignY = Format::Top;
333 else if ( str =="middle" )
334 m_alignY = Format::Middle;
335
336 if (m_alignY != Format::UndefinedY) // file's property is invalid
337 m_featuresSet |= SAlignY;
338 }
339 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "background-color" ) )
340 {
341 m_bgColor = TQColor( styleStack.attributeNS( KoXmlNS::fo, "background-color" ) );
342 if ( m_bgColor.isValid() && m_bgColor != TQt::white )
343 m_featuresSet |= SBackgroundColor;
344 }
345
346 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "wrap-option" )&&( styleStack.attributeNS( KoXmlNS::fo, "wrap-option" )=="wrap" ) )
347 {
348 setProperty( PMultiRow );
349 m_featuresSet |= SMultiRow;
350 }
351 if ( styleStack.hasAttributeNS( KoXmlNS::style, "cell-protect" ) )
352 {
353 str = styleStack.attributeNS( KoXmlNS::style, "cell-protect" );
354 if ( str=="hidden-and-protected" )
355 {
356 setProperty( PHideAll );
357 m_featuresSet |= SHideAll;
358 }
359 else if ( str == "protected formula-hidden" )
360 {
361 setProperty( PHideFormula );
362 m_featuresSet |= SHideFormula;
363 }
364 else if ( str == "protected" )
365 {
366 setProperty( PNotProtected );
367 m_featuresSet |= SNotProtected;
368 }
369 else if ( str =="formula-hidden" )
370 {
371 //FIXME !!!!
372#if 0
373 setNotProtected( true );
374 setHideFormula( true );
375 setHideAll( false );
376#endif
377 }
378 }
379 if ( styleStack.hasAttributeNS( KoXmlNS::style, "print-content" ) && ( styleStack.attributeNS( KoXmlNS::style, "print-content" )=="false" ) )
380 {
381 setProperty( PDontPrintText );
382 m_featuresSet |= SDontPrintText;
383
384 }
385 if ( styleStack.hasAttributeNS( KoXmlNS::style, "direction" ) && ( styleStack.attributeNS( KoXmlNS::style, "direction" )=="ttb" ) )
386 {
387 setProperty( PVerticalText );
388 m_featuresSet |= SVerticalText;
389
390 }
391 if ( styleStack.hasAttributeNS( KoXmlNS::style, "rotation-angle" ) )
392 {
393 bool ok;
394 int a = styleStack.attributeNS( KoXmlNS::style, "rotation-angle" ).toInt( &ok );
395 kdDebug()<<" rotation-angle :"<<a<<endl;
396 if ( a != 0 )
397 {
398 m_rotateAngle= ( -a );
399 m_featuresSet |= SAngle;
400 }
401 }
402 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "margin-left" ) )
403 {
404 //todo fix me
405 setIndent( KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "margin-left" ),0.0 ) );
406 m_featuresSet |= SIndent;
407 }
408 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border" ) )
409 {
410 str=styleStack.attributeNS( KoXmlNS::fo, "border" );
411 TQPen pen = convertOasisStringToPen( str );
412 m_featuresSet |= SLeftBorder;
413 m_featuresSet |= SRightBorder;
414 m_featuresSet |= STopBorder;
415 m_featuresSet |= SBottomBorder;
416 m_leftBorderPen = pen;
417 m_topBorderPen = pen;
418 m_bottomBorderPen = pen;
419 m_rightBorderPen = pen;
420 }
421 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-left" ) )
422 {
423 str=styleStack.attributeNS( KoXmlNS::fo, "border-left" );
424 m_leftBorderPen = convertOasisStringToPen( str );
425 m_featuresSet |= SLeftBorder;
426 }
427 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-right" ) )
428 {
429 str=styleStack.attributeNS( KoXmlNS::fo, "border-right" );
430 m_rightBorderPen = convertOasisStringToPen( str );
431 m_featuresSet |= SRightBorder;
432 }
433 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-top" ) )
434 {
435 str=styleStack.attributeNS( KoXmlNS::fo, "border-top" );
436 m_topBorderPen = convertOasisStringToPen( str );
437 m_featuresSet |= STopBorder;
438 }
439 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-bottom" ) )
440 {
441 str=styleStack.attributeNS( KoXmlNS::fo, "border-bottom" );
442 m_bottomBorderPen = convertOasisStringToPen( str );
443 m_featuresSet |= SBottomBorder;
444 }
445 if (styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-tl-br" ) )
446 {
447 str=styleStack.attributeNS( KoXmlNS::style, "diagonal-tl-br" );
448 m_fallDiagonalPen = convertOasisStringToPen( str );
449 m_featuresSet |= SFallDiagonal;
450 }
451 if (styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-bl-tr" ) )
452 {
453 str=styleStack.attributeNS( KoXmlNS::style, "diagonal-bl-tr" );
454 m_goUpDiagonalPen = convertOasisStringToPen( str );
455 m_featuresSet |= SGoUpDiagonal;
456 }
457
458 if ( styleStack.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
459 {
460 kdDebug()<<" style name :"<<styleStack.attributeNS( KoXmlNS::draw, "style-name" )<<endl;
461
462 const TQDomElement * style = oasisStyles.findStyle( styleStack.attributeNS( KoXmlNS::draw, "style-name" ), "graphic" );
463 kdDebug()<<" style :"<<style<<endl;
464 if ( style )
465 {
466 KoStyleStack drawStyleStack;
467 drawStyleStack.push( *style );
468 drawStyleStack.setTypeProperties( "graphic" );
469 if ( drawStyleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
470 {
471 const TQString fill = drawStyleStack.attributeNS( KoXmlNS::draw, "fill" );
472 kdDebug()<<" load object gradient fill type :"<<fill<<endl;
473
474 if ( fill == "solid" || fill == "hatch" )
475 {
476 kdDebug()<<" Style ******************************************************\n";
477 m_backGroundBrush=KoOasisStyles::loadOasisFillStyle( drawStyleStack, fill, oasisStyles );
478 m_featuresSet |= SBackgroundBrush;
479 }
480 else
481 kdDebug()<<" fill style not supported into kspread : "<<fill<<endl;
482 }
483 }
484 }
485}
486
487void Style::loadOasisTextProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack )
488{
489 Q_UNUSED( oasisStyles );
490 // fo:font-size="13pt"
491 // fo:font-style="italic"
492 // style:text-underline="double"
493 // style:text-underline-color="font-color"
494 // fo:font-weight="bold"
495 kdDebug() << "\t text-properties" << endl;
496 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-family" ) )
497 {
498 m_fontFamily = styleStack.attributeNS( KoXmlNS::fo, "font-family" ); // FIXME Stefan: sanity check
499 m_featuresSet |= SFontFamily;
500 m_featuresSet |= SFont;
501 kdDebug() << "\t\t fo:font-family: " << m_fontFamily << endl;
502 }
503 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-size" ) )
504 {
505 m_fontSize = (int) KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "font-size" ), 10.0 ); // FIXME Stefan: fallback to default
506 m_featuresSet |= SFontSize;
507 m_featuresSet |= SFont;
508 kdDebug() << "\t\t fo:font-size: " << m_fontSize << endl;
509 }
510 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-style" ) )
511 {
512 if ( styleStack.attributeNS( KoXmlNS::fo, "font-style" ) == "italic" ) // "normal", "oblique"
513 {
514 m_fontFlags |= FItalic;
515 m_featuresSet |= SFontFlag;
516 m_featuresSet |= SFont;
517 kdDebug() << "\t\t fo:font-style: " << "italic" << endl;
518 }
519 }
520 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "font-weight" ) )
521 {
522 if ( styleStack.attributeNS( KoXmlNS::fo, "font-weight" ) == "bold" ) // "normal", "100", "200", ...
523 {
524 m_fontFlags |= FBold;
525 m_featuresSet |= SFontFlag;
526 m_featuresSet |= SFont;
527 kdDebug() << "\t\t fo:font-weight: " << "bold" << endl;
528 }
529 }
530 if ( styleStack.hasAttributeNS( KoXmlNS::style, "text-underline-style" ) )
531 {
532 if ( styleStack.attributeNS( KoXmlNS::style, "text-underline-style" ) != "none" )
533 {
534 m_fontFlags |= FUnderline;
535 m_featuresSet |= SFontFlag;
536 m_featuresSet |= SFont;
537 kdDebug() << "\t\t style:text-underline-style: " << "solid (actually: !none)" << endl;
538 }
539 }
540 if ( styleStack.hasAttributeNS( KoXmlNS::style, "text-underline-width" ) )
541 {
542 //TODO
543 }
544 if ( styleStack.hasAttributeNS( KoXmlNS::style, "text-underline-color" ) )
545 {
546 //TODO
547 }
548 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "color" ) )
549 {
550 TQColor color = TQColor( styleStack.attributeNS( KoXmlNS::fo, "color" ) );
551 if ( color.isValid() )
552 {
553 m_featuresSet |= STextPen;
554 m_textPen = TQPen( color );
555 kdDebug() << "\t\t fo:color: " << TQString(color.name()) << endl;
556 }
557 }
558 if ( styleStack.hasAttributeNS( KoXmlNS::style, "text-line-through-style" ) )
559 {
560 if ( styleStack.attributeNS( KoXmlNS::style, "text-line-through-style" ) != "none"
561 /*&& styleStack.attributeNS("text-line-through-style")=="solid"*/ )
562 {
563 m_fontFlags |= FStrike;
564 m_featuresSet |= SFontFlag;
565 m_featuresSet |= SFont;
566 kdDebug() << "\t\t text-line-through-style: " << "solid (actually: !none)" << endl;
567 }
568 }
569}
570
571static TQString convertDateFormat( const TQString& date )
572{
573 TQString result = date;
574 result.replace( "%Y", "yyyy" );
575 result.replace( "%y", "yy" );
576 result.replace( "%n", "M" );
577 result.replace( "%m", "MM" );
578 result.replace( "%e", "d" );
579 result.replace( "%d", "dd" );
580 result.replace( "%b", "MMM" );
581 result.replace( "%B", "MMMM" );
582 result.replace( "%a", "ddd" );
583 result.replace( "%A", "dddd" );
584 return result;
585}
586
587FormatType Style::dateType( const TQString &_format )
588{
589 const TQString dateFormatShort = convertDateFormat( TDEGlobal::locale()->dateFormatShort() );
590 const TQString dateFormat = convertDateFormat( TDEGlobal::locale()->dateFormat() );
591
592 if ( _format == "dd-MMM-yy" )
593 return date_format1;
594 else if ( _format == "dd-MMM-yyyy" )
595 return date_format2;
596 else if ( _format == "d-MM" )
597 return date_format3;
598 else if ( _format == "dd-MM" ) //TODO ???????
599 return date_format4;
600 else if ( _format == "dd/MM/yy" )
601 return date_format5;
602 else if ( _format == "dd/MM/yyyy" )
603 return date_format6;
604 else if ( _format == "MMM-yy" )
605 return date_format7;
606 else if ( _format == "MMMM-yyyy" )
607 return date_format9;
608 else if ( _format == "MMMMM-yy" )
609 return date_format10;
610 else if ( _format == "dd/MMM" )
611 return date_format11;
612 else if ( _format == "dd/MM" )
613 return date_format12;
614 else if ( _format == "dd/MMM/yyyy" )
615 return date_format13;
616 else if ( _format == "yyyy/MMM/dd" )
617 return date_format14;
618 else if ( _format == "yyyy-MMM-dd" )
619 return date_format15;
620 else if ( _format == "yyyy/MM/dd" )
621 return date_format16;
622 else if ( _format == "d MMMM yyyy" )
623 return date_format17;
624 else if ( _format == "MM/dd/yyyy" )
625 return date_format18;
626 else if ( _format == "MM/dd/yy" )
627 return date_format19;
628 else if ( _format == "MMM/dd/yy" )
629 return date_format20;
630 else if ( _format == "MMM/dd/yyyy" )
631 return date_format21;
632 else if ( _format == "MMM-yyyy" )
633 return date_format22;
634 else if ( _format == "yyyy" )
635 return date_format23;
636 else if ( _format == "yy" )
637 return date_format24;
638 else if ( _format == "yyyy/MM/dd" )
639 return date_format25;
640 else if ( _format == "yyyy/MMM/dd" )
641 return date_format26;
642 else if ( _format == dateFormatShort )
643 return ShortDate_format;
644 else if ( _format == dateFormat )
645 return TextDate_format;
646 else
647 return ShortDate_format;
648}
649
650FormatType Style::timeType( const TQString &_format )
651{
652 if ( _format == "h:mm AP" )
653 return Time_format1;
654 else if ( _format == "h:mm:ss AP" )
655 return Time_format2;
656 else if ( _format == "hh \\h mm \\m\\i\\n ss \\s" )
657 return Time_format3;
658 else if ( _format == "hh:mm" )
659 return Time_format4;
660 else if ( _format == "hh:mm:ss" )
661 return Time_format5;
662 else if ( _format == "m:ss" )
663 return Time_format6;
664 else if ( _format == "h:mm:ss" )
665 return Time_format7;
666 else if ( _format == "h:mm" )
667 return Time_format8;
668 else
669 return Time_format;
670}
671
672FormatType Style::fractionType( const TQString &_format )
673{
674 if ( _format == "# ?/2" )
675 return fraction_half;
676 else if ( _format =="# ?/4" )
677 return fraction_quarter;
678 else if ( _format == "# ?/8" )
679 return fraction_eighth;
680 else if ( _format == "# ?/16" )
681 return fraction_sixteenth;
682 else if ( _format == "# ?/10" )
683 return fraction_tenth;
684 else if ( _format == "# ?/100" )
685 return fraction_hundredth;
686 else if ( _format == "# ?/?" )
687 return fraction_one_digit;
688 else if ( _format == "# \?\?/\?\?" )
689 return fraction_two_digits;
690 else if ( _format == "# \?\?\?/\?\?\?" )
691 return fraction_three_digits;
692 else
693 return fraction_half;
694}
695
696TQString Style::saveOasisStyleNumeric( KoGenStyle &style, KoGenStyles &mainStyles,
697 FormatType _style,
698 const TQString &_prefix, const TQString &_postfix,
699 int _precision, const TQString& symbol )
700{
701// kdDebug() << k_funcinfo << endl;
702 TQString styleName;
703 TQString valueType;
704 switch( _style )
705 {
706 case Number_format:
707 styleName = saveOasisStyleNumericNumber( mainStyles, _style, _precision, _prefix, _postfix );
708 valueType = "float";
709 break;
710 case Text_format:
711 styleName = saveOasisStyleNumericText( mainStyles, _style, _precision, _prefix, _postfix );
712 valueType = "string";
713 break;
714 case Money_format:
715 styleName = saveOasisStyleNumericMoney( mainStyles, _style,symbol, _precision, _prefix, _postfix );
716 valueType = "currency";
717 break;
718 case Percentage_format:
719 styleName = saveOasisStyleNumericPercentage( mainStyles, _style, _precision, _prefix, _postfix );
720 valueType = "percentage";
721 break;
722 case Scientific_format:
723 styleName = saveOasisStyleNumericScientific( mainStyles, _style, _prefix, _postfix, _precision );
724 valueType = "float";
725 break;
726 case ShortDate_format:
727 case TextDate_format:
728 styleName = saveOasisStyleNumericDate( mainStyles, _style, _prefix, _postfix );
729 valueType = "date";
730 break;
731 case Time_format:
732 case SecondeTime_format:
733 case Time_format1:
734 case Time_format2:
735 case Time_format3:
736 case Time_format4:
737 case Time_format5:
738 case Time_format6:
739 case Time_format7:
740 case Time_format8:
741 styleName = saveOasisStyleNumericTime( mainStyles, _style, _prefix, _postfix );
742 valueType = "time";
743 break;
744 case fraction_half:
745 case fraction_quarter:
746 case fraction_eighth:
747 case fraction_sixteenth:
748 case fraction_tenth:
749 case fraction_hundredth:
750 case fraction_one_digit:
751 case fraction_two_digits:
752 case fraction_three_digits:
753 styleName = saveOasisStyleNumericFraction( mainStyles,_style, _prefix, _postfix );
754 valueType = "float";
755 break;
756 case date_format1:
757 case date_format2:
758 case date_format3:
759 case date_format4:
760 case date_format5:
761 case date_format6:
762 case date_format7:
763 case date_format8:
764 case date_format9:
765 case date_format10:
766 case date_format11:
767 case date_format12:
768 case date_format13:
769 case date_format14:
770 case date_format15:
771 case date_format16:
772 case date_format17:
773 case date_format18:
774 case date_format19:
775 case date_format20:
776 case date_format21:
777 case date_format22:
778 case date_format23:
779 case date_format24:
780 case date_format25:
781 case date_format26:
782 styleName = saveOasisStyleNumericDate( mainStyles, _style, _prefix, _postfix );
783 valueType = "date";
784 break;
785 case Custom_format:
786 styleName = saveOasisStyleNumericCustom( mainStyles, _style, _prefix, _postfix );
787 break;
788 case Generic_format:
789 case No_format:
790 if (_precision > -1 || !_prefix.isEmpty() || !_postfix.isEmpty())
791 {
792 styleName = saveOasisStyleNumericNumber( mainStyles, _style, _precision, _prefix, _postfix );
793 valueType = "float";
794 }
795 break;
796 }
797 if ( !styleName.isEmpty() )
798 {
799 style.addAttribute( "style:data-style-name", styleName );
800 }
801 return styleName;
802}
803
804TQString Style::saveOasisStyleNumericNumber( KoGenStyles& mainStyles, FormatType /*_style*/, int _precision,
805 const TQString &_prefix, const TQString &_suffix )
806{
807 TQString format;
808 if ( _precision == -1 )
809 format="0";
810 else
811 {
812 TQString tmp;
813 for ( int i = 0; i <_precision; i++ )
814 {
815 tmp+="0";
816 }
817 format = "0."+tmp;
818 }
819 return KoOasisStyles::saveOasisNumberStyle( mainStyles, format, _prefix, _suffix );
820}
821
822TQString Style::saveOasisStyleNumericText( KoGenStyles& /*mainStyles*/, FormatType /*_style*/, int /*_precision*/,
823 const TQString &/*_prefix*/, const TQString &/*_suffix*/ )
824{
825 return "";
826}
827
828TQString Style::saveOasisStyleNumericMoney( KoGenStyles& mainStyles, FormatType /*_style*/,
829 const TQString& symbol, int _precision,
830 const TQString &_prefix, const TQString &_suffix )
831{
832 TQString format;
833 if ( _precision == -1 )
834 format="0";
835 else
836 {
837 TQString tmp;
838 for ( int i = 0; i <_precision; i++ )
839 {
840 tmp+="0";
841 }
842 format = "0."+tmp;
843 }
844 return KoOasisStyles::saveOasisCurrencyStyle( mainStyles, format, symbol, _prefix, _suffix );
845}
846
847TQString Style::saveOasisStyleNumericPercentage( KoGenStyles&mainStyles, FormatType /*_style*/,
848 int _precision,
849 const TQString &_prefix, const TQString &_suffix )
850{
851 //<number:percentage-style style:name="N106" style:family="data-style">
852 //<number:number number:decimal-places="6" number:min-integer-digits="1"/>
853 //<number:text>%</number:text>
854 //</number:percentage-style>
855 //TODO add decimal etc.
856 TQString format;
857 if ( _precision == -1 )
858 format="0";
859 else
860 {
861 TQString tmp;
862 for ( int i = 0; i <_precision; i++ )
863 {
864 tmp+="0";
865 }
866 format = "0."+tmp;
867 }
868 return KoOasisStyles::saveOasisPercentageStyle( mainStyles, format, _prefix, _suffix );
869}
870
871
872TQString Style::saveOasisStyleNumericScientific( KoGenStyles&mainStyles, FormatType /*_style*/,
873 const TQString &_prefix, const TQString _suffix, int _precision )
874{
875 //<number:number-style style:name="N60" style:family="data-style">
876 // <number:scientific-number number:decimal-places="2" number:min-integer-digits="1" number:min-exponent-digits="3"/>
877 //</number:number-style>
878 TQString format;
879 if ( _precision == -1 )
880 format="0E+00";
881 else
882 {
883 TQString tmp;
884 for ( int i = 0; i <_precision; i++ )
885 {
886 tmp+="0";
887 }
888 format = "0."+tmp+"E+00";
889 }
890 return KoOasisStyles::saveOasisScientificStyle( mainStyles, format, _prefix, _suffix );
891}
892
893TQString Style::saveOasisStyleNumericDate( KoGenStyles&mainStyles, FormatType _style,
894 const TQString &_prefix, const TQString &_suffix )
895{
896 TQString format;
897 bool locale = false;
898 switch( _style )
899 {
900 //TODO fixme use locale of kspread and not kglobal
901 case ShortDate_format:
902 format = TDEGlobal::locale()->dateFormatShort();
903 locale = true;
904 break;
905 case TextDate_format:
906 format = TDEGlobal::locale()->dateFormat();
907 locale = true;
908 break;
909 case date_format1:
910 format = "dd-MMM-yy";
911 break;
912 case date_format2:
913 format = "dd-MMM-yyyy";
914 break;
915 case date_format3:
916 format = "dd-M";
917 break;
918 case date_format4:
919 format = "dd-MM";
920 break;
921 case date_format5:
922 format = "dd/MM/yy";
923 break;
924 case date_format6:
925 format = "dd/MM/yyyy";
926 break;
927 case date_format7:
928 format = "MMM-yy";
929 break;
930 case date_format8:
931 format = "MMMM-yy";
932 break;
933 case date_format9:
934 format = "MMMM-yyyy";
935 break;
936 case date_format10:
937 format = "MMMMM-yy";
938 break;
939 case date_format11:
940 format = "dd/MMM";
941 break;
942 case date_format12:
943 format = "dd/MM";
944 break;
945 case date_format13:
946 format = "dd/MMM/yyyy";
947 break;
948 case date_format14:
949 format = "yyyy/MMM/dd";
950 break;
951 case date_format15:
952 format = "yyyy-MMM-dd";
953 break;
954 case date_format16:
955 format = "yyyy/MM/dd";
956 break;
957 case date_format17:
958 format = "d MMMM yyyy";
959 break;
960 case date_format18:
961 format = "MM/dd/yyyy";
962 break;
963 case date_format19:
964 format = "MM/dd/yy";
965 break;
966 case date_format20:
967 format = "MMM/dd/yy";
968 break;
969 case date_format21:
970 format = "MMM/dd/yyyy";
971 break;
972 case date_format22:
973 format = "MMM-yyyy";
974 break;
975 case date_format23:
976 format = "yyyy";
977 break;
978 case date_format24:
979 format = "yy";
980 break;
981 case date_format25:
982 format = "yyyy/MM/dd";
983 break;
984 case date_format26:
985 format = "yyyy/MMM/dd";
986 break;
987 default:
988 kdDebug()<<"this date format is not defined ! :"<<_style<<endl;
989 break;
990 }
991 return KoOasisStyles::saveOasisDateStyle( mainStyles, format, locale, _prefix, _suffix );
992}
993
994TQString Style::saveOasisStyleNumericCustom( KoGenStyles& /*mainStyles*/, FormatType /*_style*/,
995 const TQString &/*_prefix*/, const TQString &/*_suffix*/ )
996{
997 //TODO
998 //<number:date-style style:name="N50" style:family="data-style" number:automatic-order="true" number:format-source="language">
999 //<number:month/>
1000 //<number:text>/</number:text>
1001 //<number:day/>
1002 //<number:text>/</number:text>
1003 //<number:year/>
1004 //<number:text> </number:text>
1005 //<number:hours number:style="long"/>
1006 //<number:text>:</number:text>
1007 //<number:minutes number:style="long"/>
1008 // <number:text> </number:text>
1009 //<number:am-pm/>
1010 //</number:date-style>
1011 return "";
1012}
1013
1014TQString Style::saveOasisStyleNumericTime( KoGenStyles& mainStyles, FormatType _style,
1015 const TQString &_prefix, const TQString &_suffix )
1016{
1017 //<number:time-style style:name="N42" style:family="data-style">
1018 //<number:hours number:style="long"/>
1019 //<number:text>:</number:text>
1020 //<number:minutes number:style="long"/>
1021 //<number:text> </number:text>
1022 //<number:am-pm/>
1023 //</number:time-style>
1024
1025 TQString format;
1026 bool locale = false;
1027 //TODO use format
1028 switch( _style )
1029 {
1030 case Time_format: //TODO FIXME
1031 format = "hh:mm:ss";
1032 break;
1033 case SecondeTime_format: //TODO FIXME
1034 format = "hh:mm";
1035 break;
1036 case Time_format1:
1037 format = "h:mm AP";
1038 break;
1039 case Time_format2:
1040 format = "h:mm:ss AP";
1041 break;
1042 case Time_format3: // 9 h 01 min 28 s
1043 format = "hh \\h mm \\m\\i\\n ss \\s";
1044 break;
1045 case Time_format4:
1046 format = "hh:mm";
1047 break;
1048 case Time_format5:
1049 format = "hh:mm:ss";
1050 break;
1051 case Time_format6:
1052 format = "m:ss";
1053 break;
1054 case Time_format7:
1055 format = "h:mm:ss";
1056 break;
1057 case Time_format8:
1058 format = "h:mm";
1059 break;
1060 default:
1061 kdDebug()<<"time format not defined :"<<_style<<endl;
1062 break;
1063 }
1064 return KoOasisStyles::saveOasisTimeStyle( mainStyles, format, locale, _prefix, _suffix );
1065}
1066
1067
1068TQString Style::saveOasisStyleNumericFraction( KoGenStyles &mainStyles, FormatType _style,
1069 const TQString &_prefix, const TQString _suffix )
1070{
1071 //<number:number-style style:name="N71" style:family="data-style">
1072 //<number:fraction number:min-integer-digits="0" number:min-numerator-digits="2" number:min-denominator-digits="2"/>
1073 //</number:number-style>
1074 TQString format;
1075 switch( _style )
1076 {
1077 case fraction_half:
1078 format = "# ?/2";
1079 break;
1080 case fraction_quarter:
1081 format = "# ?/4";
1082 break;
1083 case fraction_eighth:
1084 format = "# ?/8";
1085 break;
1086 case fraction_sixteenth:
1087 format = "# ?/16";
1088 break;
1089 case fraction_tenth:
1090 format = "# ?/10";
1091 break;
1092 case fraction_hundredth:
1093 format = "# ?/100";
1094 break;
1095 case fraction_one_digit:
1096 format = "# ?/?";
1097 break;
1098 case fraction_two_digits:
1099 format = "# \?\?/\?\?";
1100 break;
1101 case fraction_three_digits:
1102 format = "# \?\?\?/\?\?\?";
1103 break;
1104 default:
1105 kdDebug()<<" fraction format not defined :"<<_style<<endl;
1106 break;
1107 }
1108
1109 return KoOasisStyles::saveOasisFractionStyle( mainStyles, format, _prefix, _suffix );
1110}
1111
1112TQString Style::saveOasis( KoGenStyle& style, KoGenStyles& mainStyles )
1113{
1114 // KSpread::Style is definitly an OASIS auto style,
1115 // but don't overwrite it, if it already exists
1116 if (style.type() == 0)
1117 style = KoGenStyle( Doc::STYLE_CELL_AUTO, "table-cell" );
1118 // doing the real work
1119 saveOasisStyle( style, mainStyles );
1120 return TQString();
1121}
1122
1123void Style::saveOasisStyle( KoGenStyle &style, KoGenStyles &mainStyles )
1124{
1125#ifndef NDEBUG
1126 //if (type() == BUILTIN )
1127 // kdDebug() << "BUILTIN" << endl;
1128 //else if (type() == CUSTOM )
1129 // kdDebug() << "CUSTOM" << endl;
1130 //else if (type() == AUTO )
1131 // kdDebug() << "AUTO" << endl;
1132#endif
1133
1134 // don't store parent, if it's the default style
1135 if ( m_parent && (m_parent->type() != BUILTIN || m_parent->name() != "Default") )
1136 // FIXME this is not the OASIS parent style's name. it's its display name!
1137 style.addAttribute( "style:parent-style-name", m_parent->name() );
1138
1139 if ( featureSet( SAlignX ) && alignX() != Format::Undefined )
1140 {
1141 TQString value;
1142 switch( alignX() )
1143 {
1144 case Format::Center:
1145 value = "center";
1146 break;
1147 case Format::Right:
1148 value = "end";
1149 break;
1150 case Format::Left:
1151 value = "start";
1152 break;
1153 case Format::Undefined:
1154 break;
1155 }
1156 if ( !value.isEmpty() )
1157 {
1158 style.addProperty( "style:text-align-source", "fix" ); // table-cell-properties
1159 style.addProperty( "fo:text-align", value, KoGenStyle::ParagraphType );
1160 }
1161 }
1162
1163 if ( featureSet( SAlignY ) )
1164 {
1165 TQString value;
1166 switch( alignY() )
1167 {
1168 case Format::Top:
1169 value = "top";
1170 break;
1171 case Format::Middle:
1172 value = "middle";
1173 break;
1174 case Format::Bottom:
1175 value = "bottom";
1176 break;
1177 case Format::UndefinedY:
1178 default:
1179 break;
1180 }
1181 if (!value.isEmpty()) // sanity
1182 style.addProperty( "style:vertical-align", value );
1183 }
1184
1185 if ( featureSet( SBackgroundColor ) && m_bgColor != TQColor() && m_bgColor.isValid() )
1186 style.addProperty( "fo:background-color", colorName(m_bgColor) );
1187
1188 if ( featureSet( SMultiRow ) && hasProperty( PMultiRow ) )
1189 style.addProperty( "fo:wrap-option", "wrap" );
1190
1191 if ( featureSet( SVerticalText ) && hasProperty( PVerticalText ) )
1192 {
1193 style.addProperty( "style:direction", "ttb" );
1194 style.addProperty( "style:rotation-angle", "0" );
1195 style.addProperty( "style:rotation-align", "none" );
1196 }
1197#if 0
1198 if ( featureSet( SFloatFormat ) )
1199 format.setAttribute( "float", (int) m_floatFormat );
1200
1201 if ( featureSet( SFloatColor ) )
1202 format.setAttribute( "floatcolor", (int)m_floatColor );
1203
1204 if ( featureSet( SCustomFormat ) && !strFormat().isEmpty() )
1205 format.setAttribute( "custom", m_strFormat );
1206
1207 if ( featureSet( SFormatType ) && formatType() == Format::Money )
1208 {
1209 format.setAttribute( "type", (int) m_currency.type );
1210 format.setAttribute( "symbol", m_currency.symbol );
1211 }
1212#endif
1213 if ( featureSet( SAngle ) && m_rotateAngle != 0 )
1214 {
1215 style.addProperty( "style:rotation-align", "none" );
1216 style.addProperty( "style:rotation-angle", TQString::number( -1.0 *m_rotateAngle ) );
1217 }
1218
1219 if ( featureSet( SIndent ) && m_indent != 0.0 )
1220 {
1221 style.addPropertyPt("fo:margin-left", m_indent, KoGenStyle::ParagraphType );
1222 //FIXME
1223 //if ( a == Format::Undefined )
1224 //currentCellStyle.addProperty("fo:text-align", "start" );
1225 }
1226
1227 if ( featureSet( SDontPrintText ) && hasProperty( PDontPrintText ) )
1228 style.addProperty( "style:print-content", "false");
1229
1230 // protection
1231 bool hideAll = false;
1232 bool hideFormula = false;
1233 bool isNotProtected = false;
1234
1235 if ( featureSet( SNotProtected ) && hasProperty( PNotProtected ) )
1236 isNotProtected = true;
1237
1238 if ( featureSet( SHideAll ) && hasProperty( PHideAll ) )
1239 hideAll=true;
1240
1241 if ( featureSet( SHideFormula ) && hasProperty( PHideFormula ) )
1242 hideFormula = true;
1243
1244 if ( hideAll )
1245 style.addProperty( "style:cell-protect", "hidden-and-protected" );
1246 else
1247 {
1248 if ( isNotProtected && !hideFormula )
1249 style.addProperty( "style:cell-protect", "none" );
1250 else if ( isNotProtected && hideFormula )
1251 style.addProperty( "style:cell-protect", "formula-hidden" );
1252 else if ( hideFormula )
1253 style.addProperty( "style:cell-protect", "protected formula-hidden" );
1254 else if ( featureSet( SNotProtected ) && !hasProperty( PNotProtected ) )
1255 // write out, only if it is explicity set
1256 style.addProperty( "style:cell-protect", "protected" );
1257 }
1258
1259 // borders
1260 // NOTE Stefan: TQPen api docs:
1261 // For horizontal and vertical lines a line width of 0 is
1262 // the same as a line width of 1.
1263 // A line width of 0 will produce a 1 pixel wide line using
1264 // a fast algorithm for diagonals. A line width of 1 will
1265 // also produce a 1 pixel wide line, but uses a slower more
1266 // accurate algorithm for diagonals.
1267 if ( featureSet( SLeftBorder ) && featureSet( SRightBorder ) &&
1268 featureSet( STopBorder ) && featureSet( SBottomBorder ) &&
1272 {
1273 if ( m_leftBorderPen.style() != TQt::NoPen )
1274 style.addProperty("fo:border", convertOasisPenToString( m_leftBorderPen ) );
1275 }
1276 else
1277 {
1278 if ( featureSet( SLeftBorder ) && ( m_leftBorderPen.style() != TQt::NoPen ) )
1279 style.addProperty( "fo:border-left", convertOasisPenToString( m_leftBorderPen ) );
1280
1281 if ( featureSet( SRightBorder ) && ( m_rightBorderPen.style() != TQt::NoPen ) )
1282 style.addProperty( "fo:border-right", convertOasisPenToString( m_rightBorderPen ) );
1283
1284 if ( featureSet( STopBorder ) && ( m_topBorderPen.style() != TQt::NoPen ) )
1285 style.addProperty( "fo:border-top", convertOasisPenToString( m_topBorderPen ) );
1286
1287 if ( featureSet( SBottomBorder ) && ( m_bottomBorderPen.style() != TQt::NoPen ) )
1288 style.addProperty( "fo:border-bottom", convertOasisPenToString( m_bottomBorderPen ) );
1289 }
1290 if ( featureSet( SFallDiagonal ) && ( m_fallDiagonalPen.style() != TQt::NoPen ) )
1291 {
1292 style.addProperty("style:diagonal-tl-br", convertOasisPenToString( m_fallDiagonalPen ) );
1293 }
1294 if ( featureSet( SGoUpDiagonal ) && ( m_goUpDiagonalPen.style() != TQt::NoPen ) )
1295 {
1296 style.addProperty("style:diagonal-bl-tr", convertOasisPenToString(m_goUpDiagonalPen ) );
1297 }
1298
1299 // font
1300 if ( featureSet( SFontFamily ) ) // !m_fontFamily.isEmpty() == true
1301 {
1302 style.addProperty("fo:font-family", m_fontFamily, KoGenStyle::TextType );
1303 }
1304 if ( featureSet( SFontSize ) ) // m_fontSize != 0
1305 {
1306 style.addPropertyPt("fo:font-size",m_fontSize, KoGenStyle::TextType );
1307 }
1308
1309 if ( featureSet( SFontFlag ) && m_fontFlags & (uint) FBold )
1310 style.addProperty("fo:font-weight","bold", KoGenStyle::TextType );
1311
1312 if ( featureSet( SFontFlag ) && m_fontFlags & (uint) FItalic )
1313 style.addProperty("fo:font-style", "italic", KoGenStyle::TextType );
1314
1315 if ( featureSet( SFontFlag ) && m_fontFlags & (uint) FUnderline )
1316 {
1317 //style:text-underline-style="solid" style:text-underline-width="auto"
1318 style.addProperty( "style:text-underline-style", "solid", KoGenStyle::TextType );
1319 //copy from oo-129
1320 style.addProperty( "style:text-underline-width", "auto", KoGenStyle::TextType );
1321 style.addProperty( "style:text-underline-color", "font-color", KoGenStyle::TextType );
1322 }
1323
1324 if ( featureSet( SFontFlag ) && m_fontFlags & (uint) FStrike )
1325 style.addProperty( "style:text-line-through-style", "solid", KoGenStyle::TextType );
1326
1327 if ( featureSet( STextPen ) && m_textPen.color().isValid() ) // always save; default: m_textPen.style() == TQt::NoPen
1328 {
1329 style.addProperty("fo:color", colorName(m_textPen.color()), KoGenStyle::TextType );
1330 }
1331
1332 //I don't think there is a reason why the background brush should be saved if it is null,
1333 //but remove the check if it causes problems. -- Robert Knight <robertknight@gmail.com>
1334 if ( featureSet( SBackgroundBrush ) && (m_backGroundBrush.style() != TQt::NoBrush) )
1335 {
1336 TQString tmp = saveOasisBackgroundStyle( mainStyles, m_backGroundBrush );
1337 if ( !tmp.isEmpty() )
1338 style.addProperty("draw:style-name", tmp );
1339 }
1340
1341 TQString _prefix;
1342 TQString _postfix;
1343 int _precision = -1;
1344 if ( featureSet( SPrefix ) && !prefix().isEmpty() )
1345 _prefix = m_prefix;
1346 if ( featureSet( SPostfix ) && !postfix().isEmpty() )
1347 _postfix = m_postfix;
1348 if ( featureSet( SPrecision ) && m_precision != -1 )
1349 _precision = m_precision;
1350
1351 TQString symbol;
1352 if ( featureSet( SFormatType ) && m_formatType == Money_format )
1353 {
1354 symbol = Currency::getCurrencyCode(m_currency.type);
1355 }
1356
1357 TQString numericStyle = saveOasisStyleNumeric( style, mainStyles, m_formatType,
1358 _prefix, _postfix, _precision,
1359 symbol );
1360 if ( !numericStyle.isEmpty() )
1361 style.addAttribute( "style:data-style-name", numericStyle );
1362}
1363
1364TQString Style::saveOasisBackgroundStyle( KoGenStyles &mainStyles, const TQBrush &brush )
1365{
1366 KoGenStyle styleobjectauto = KoGenStyle( KoGenStyle::STYLE_GRAPHICAUTO, "graphic" );
1367 KoOasisStyles::saveOasisFillStyle( styleobjectauto, mainStyles, brush );
1368 return mainStyles.lookup( styleobjectauto, "gr" );
1369}
1370
1371void Style::saveXML( TQDomDocument & doc, TQDomElement & format ) const
1372{
1373 if ( featureSet( SAlignX ) && alignX() != Format::Undefined )
1374 format.setAttribute( "alignX", (int) m_alignX );
1375
1376 if ( featureSet( SAlignY ) && alignY() != Format::Middle )
1377 format.setAttribute( "alignY", (int) m_alignY );
1378
1379 if ( featureSet( SBackgroundColor ) && m_bgColor != TQColor() && m_bgColor.isValid() )
1380 format.setAttribute( "bgcolor", m_bgColor.name() );
1381
1382 if ( featureSet( SMultiRow ) && hasProperty( PMultiRow ) )
1383 format.setAttribute( "multirow", "yes" );
1384
1385 if ( featureSet( SVerticalText ) && hasProperty( PVerticalText ) )
1386 format.setAttribute( "verticaltext", "yes" );
1387
1388 if ( featureSet( SPrecision ) )
1389 format.setAttribute( "precision", m_precision );
1390
1391 if ( featureSet( SPrefix ) && !prefix().isEmpty() )
1392 format.setAttribute( "prefix", m_prefix );
1393
1394 if ( featureSet( SPostfix ) && !postfix().isEmpty() )
1395 format.setAttribute( "postfix", m_postfix );
1396
1397 if ( featureSet( SFloatFormat ) )
1398 format.setAttribute( "float", (int) m_floatFormat );
1399
1400 if ( featureSet( SFloatColor ) )
1401 format.setAttribute( "floatcolor", (int)m_floatColor );
1402
1403 if ( featureSet( SFormatType ) )
1404 format.setAttribute( "format",(int) m_formatType );
1405
1406 if ( featureSet( SCustomFormat ) && !strFormat().isEmpty() )
1407 format.setAttribute( "custom", m_strFormat );
1408
1409 if ( featureSet( SFormatType ) && formatType() == Money_format )
1410 {
1411 format.setAttribute( "type", (int) m_currency.type );
1412 format.setAttribute( "symbol", m_currency.symbol );
1413 }
1414
1415 if ( featureSet( SAngle ) )
1416 format.setAttribute( "angle", m_rotateAngle );
1417
1418 if ( featureSet( SIndent ) )
1419 format.setAttribute( "indent", m_indent );
1420
1421 if ( featureSet( SDontPrintText ) && hasProperty( PDontPrintText ) )
1422 format.setAttribute( "dontprinttext", "yes" );
1423
1424 if ( featureSet( SNotProtected ) && hasProperty( PNotProtected ) )
1425 format.setAttribute( "noprotection", "yes" );
1426
1427 if ( featureSet( SHideAll ) && hasProperty( PHideAll ) )
1428 format.setAttribute( "hideall", "yes" );
1429
1430 if ( featureSet( SHideFormula ) && hasProperty( PHideFormula ) )
1431 format.setAttribute( "hideformula", "yes" );
1432
1433 if ( featureSet( SFontFamily ) )
1434 format.setAttribute( "font-family", m_fontFamily );
1435 if ( featureSet( SFontSize ) )
1436 format.setAttribute( "font-size", m_fontSize );
1437 if ( featureSet( SFontFlag ) )
1438 format.setAttribute( "font-flags", m_fontFlags );
1439
1440 // if ( featureSet( SFont ) )
1441 // format.appendChild( util_createElement( "font", m_textFont, doc ) );
1442
1443 if ( featureSet( STextPen ) && m_textPen.color().isValid() )
1444 format.appendChild( util_createElement( "pen", m_textPen, doc ) );
1445
1446 if ( featureSet( SBackgroundBrush ) )
1447 {
1448 format.setAttribute( "brushcolor", m_backGroundBrush.color().name() );
1449 format.setAttribute( "brushstyle", (int) m_backGroundBrush.style() );
1450 }
1451
1452 if ( featureSet( SLeftBorder ) )
1453 {
1454 TQDomElement left = doc.createElement( "left-border" );
1455 left.appendChild( util_createElement( "pen", m_leftBorderPen, doc ) );
1456 format.appendChild( left );
1457 }
1458
1459 if ( featureSet( STopBorder ) )
1460 {
1461 TQDomElement top = doc.createElement( "top-border" );
1462 top.appendChild( util_createElement( "pen", m_topBorderPen, doc ) );
1463 format.appendChild( top );
1464 }
1465
1466 if ( featureSet( SRightBorder ) )
1467 {
1468 TQDomElement right = doc.createElement( "right-border" );
1469 right.appendChild( util_createElement( "pen", m_rightBorderPen, doc ) );
1470 format.appendChild( right );
1471 }
1472
1473 if ( featureSet( SBottomBorder ) )
1474 {
1475 TQDomElement bottom = doc.createElement( "bottom-border" );
1476 bottom.appendChild( util_createElement( "pen", m_bottomBorderPen, doc ) );
1477 format.appendChild( bottom );
1478 }
1479
1480 if ( featureSet( SFallDiagonal ) )
1481 {
1482 TQDomElement fallDiagonal = doc.createElement( "fall-diagonal" );
1483 fallDiagonal.appendChild( util_createElement( "pen", m_fallDiagonalPen, doc ) );
1484 format.appendChild( fallDiagonal );
1485 }
1486
1487 if ( featureSet( SGoUpDiagonal ) )
1488 {
1489 TQDomElement goUpDiagonal = doc.createElement( "up-diagonal" );
1490 goUpDiagonal.appendChild( util_createElement( "pen", m_goUpDiagonalPen, doc ) );
1491 format.appendChild( goUpDiagonal );
1492 }
1493}
1494
1495bool Style::loadXML( TQDomElement & format )
1496{
1497 bool ok;
1498 if ( format.hasAttribute( "type" ) )
1499 {
1500 m_type = (StyleType) format.attribute( "type" ).toInt( &ok );
1501 if ( !ok )
1502 return false;
1503 }
1504
1505 if ( format.hasAttribute( "alignX" ) )
1506 {
1507 Format::Align a = (Format::Align) format.attribute( "alignX" ).toInt( &ok );
1508 if ( !ok )
1509 return false;
1510 if ( (unsigned int) a >= 1 || (unsigned int) a <= 4 )
1511 {
1512 m_alignX = a;
1513 m_featuresSet |= SAlignX;
1514 }
1515 }
1516 if ( format.hasAttribute( "alignY" ) )
1517 {
1518 Format::AlignY a = (Format::AlignY) format.attribute( "alignY" ).toInt( &ok );
1519 if ( !ok )
1520 return false;
1521 if ( (unsigned int) a >= 1 || (unsigned int) a < 4 )
1522 {
1523 m_alignY = a;
1524 m_featuresSet |= SAlignY;
1525 }
1526 }
1527
1528 if ( format.hasAttribute( "bgcolor" ) )
1529 {
1530 m_bgColor = TQColor( format.attribute( "bgcolor" ) );
1531 // FIXME: Is white always correct here?
1532 if ( m_bgColor != TQt::white )
1533 m_featuresSet |= SBackgroundColor;
1534 }
1535
1536 if ( format.hasAttribute( "multirow" ) )
1537 {
1538 setProperty( PMultiRow );
1539 m_featuresSet |= SMultiRow;
1540 }
1541
1542 if ( format.hasAttribute( "verticaltext" ) )
1543 {
1544 setProperty( PVerticalText );
1545 m_featuresSet |= SVerticalText;
1546 }
1547
1548 if ( format.hasAttribute( "precision" ) )
1549 {
1550 int i = format.attribute( "precision" ).toInt( &ok );
1551 if ( i < -1 )
1552 {
1553 kdDebug(36001) << "Value out of range Cell::precision=" << i << endl;
1554 return false;
1555 }
1556 m_precision = i;
1557 m_featuresSet |= SPrecision;
1558 }
1559
1560 if ( format.hasAttribute( "float" ) )
1561 {
1562 Format::FloatFormat a = (Format::FloatFormat)format.attribute( "float" ).toInt( &ok );
1563 if ( !ok )
1564 return false;
1565 if ( (unsigned int) a >= 1 || (unsigned int) a <= 3 )
1566 {
1567 m_floatFormat = a;
1568 m_featuresSet |= SFloatFormat;
1569 }
1570 }
1571
1572 if ( format.hasAttribute( "floatcolor" ) )
1573 {
1574 Format::FloatColor a = (Format::FloatColor) format.attribute( "floatcolor" ).toInt( &ok );
1575 if ( !ok ) return false;
1576 if ( (unsigned int) a >= 1 || (unsigned int) a <= 2 )
1577 {
1578 m_floatColor = a;
1579 m_featuresSet |= SFloatColor;
1580 }
1581 }
1582
1583 if ( format.hasAttribute( "format" ) )
1584 {
1585 int fo = format.attribute( "format" ).toInt( &ok );
1586 if ( ! ok )
1587 return false;
1588 m_formatType = ( FormatType ) fo;
1589 m_featuresSet |= SFormatType;
1590 }
1591 if ( format.hasAttribute( "custom" ) )
1592 {
1593 m_strFormat = format.attribute( "custom" );
1594 m_featuresSet |= SCustomFormat;
1595 }
1596 if ( m_formatType == Money_format )
1597 {
1598 if ( format.hasAttribute( "type" ) )
1599 {
1600 m_currency.type = format.attribute( "type" ).toInt( &ok );
1601 if (!ok)
1602 m_currency.type = 1;
1603 }
1604 if ( format.hasAttribute( "symbol" ) )
1605 {
1606 m_currency.symbol = format.attribute( "symbol" );
1607 }
1608 m_featuresSet |= SFormatType;
1609 }
1610 if ( format.hasAttribute( "angle" ) )
1611 {
1612 m_rotateAngle = format.attribute( "angle" ).toInt( &ok );
1613 if ( !ok )
1614 return false;
1615 m_featuresSet |= SAngle;
1616 }
1617 if ( format.hasAttribute( "indent" ) )
1618 {
1619 m_indent = format.attribute( "indent" ).toDouble( &ok );
1620 if ( !ok )
1621 return false;
1622 m_featuresSet |= SIndent;
1623 }
1624 if ( format.hasAttribute( "dontprinttext" ) )
1625 {
1626 setProperty( PDontPrintText );
1627 m_featuresSet |= SDontPrintText;
1628 }
1629
1630 if ( format.hasAttribute( "noprotection" ) )
1631 {
1632 setProperty( PNotProtected );
1633 m_featuresSet |= SNotProtected;
1634 }
1635
1636 if ( format.hasAttribute( "hideall" ) )
1637 {
1638 setProperty( PHideAll );
1639 m_featuresSet |= SHideAll;
1640 }
1641
1642 if ( format.hasAttribute( "hideformula" ) )
1643 {
1644 setProperty( PHideFormula );
1645 m_featuresSet |= SHideFormula;
1646 }
1647
1648 // TODO: remove that...
1649 TQDomElement font = format.namedItem( "font" ).toElement();
1650 if ( !font.isNull() )
1651 {
1652 TQFont f( util_toFont( font ) );
1653 m_fontFamily = f.family();
1654 m_fontSize = f.pointSize();
1655 if ( f.italic() )
1656 m_fontFlags |= FItalic;
1657 if ( f.bold() )
1658 m_fontFlags |= FBold;
1659 if ( f.underline() )
1660 m_fontFlags |= FUnderline;
1661 if ( f.strikeOut() )
1662 m_fontFlags |= FStrike;
1663
1664 m_featuresSet |= SFont;
1665 m_featuresSet |= SFontFamily;
1666 m_featuresSet |= SFontFlag;
1667 m_featuresSet |= SFontSize;
1668 }
1669
1670 if ( format.hasAttribute( "font-family" ) )
1671 {
1672 m_fontFamily = format.attribute( "font-family" );
1673 m_featuresSet |= SFont;
1674 m_featuresSet |= SFontFamily;
1675 }
1676 if ( format.hasAttribute( "font-size" ) )
1677 {
1678 m_fontSize = format.attribute( "font-size" ).toInt( &ok );
1679 if ( !ok )
1680 return false;
1681 m_featuresSet |= SFont;
1682 m_featuresSet |= SFontSize;
1683 }
1684
1685 if ( format.hasAttribute( "font-flags" ) )
1686 {
1687 m_fontFlags = format.attribute( "font-flags" ).toInt( &ok );
1688 if ( !ok )
1689 return false;
1690 m_featuresSet |= SFont;
1691 m_featuresSet |= SFontFlag;
1692 }
1693
1694 if ( format.hasAttribute( "brushcolor" ) )
1695 {
1696 m_backGroundBrush.setColor( TQColor( format.attribute( "brushcolor" ) ) );
1697 // It is not necessary to set this feature just because the color changes.
1698 // FIXME: Or is it?
1699 //m_featuresSet |= SBackgroundBrush;
1700 }
1701
1702 if ( format.hasAttribute( "brushstyle" ) )
1703 {
1704 m_backGroundBrush.setStyle( (TQt::BrushStyle) format.attribute( "brushstyle" ).toInt( &ok ) );
1705 if ( !ok )
1706 return false;
1707
1708 if ( m_backGroundBrush.style() != TQt::NoBrush )
1709 m_featuresSet |= SBackgroundBrush;
1710 }
1711
1712 TQDomElement pen = format.namedItem( "pen" ).toElement();
1713 if ( !pen.isNull() )
1714 {
1715 m_textPen = util_toPen( pen );
1716 if ( m_textPen.style() != TQt::NoPen )
1717 m_featuresSet |= STextPen;
1718 }
1719
1720 TQDomElement left = format.namedItem( "left-border" ).toElement();
1721 if ( !left.isNull() )
1722 {
1723 TQDomElement pen = left.namedItem( "pen" ).toElement();
1724 if ( !pen.isNull() )
1725 {
1726 m_leftBorderPen = util_toPen( pen );
1727 if ( m_leftBorderPen.style() != TQt::NoPen )
1728 m_featuresSet |= SLeftBorder;
1729 }
1730 }
1731
1732 TQDomElement top = format.namedItem( "top-border" ).toElement();
1733 if ( !top.isNull() )
1734 {
1735 TQDomElement pen = top.namedItem( "pen" ).toElement();
1736 if ( !pen.isNull() )
1737 {
1738 m_topBorderPen = util_toPen( pen );
1739 if ( m_topBorderPen.style() != TQt::NoPen )
1740 m_featuresSet |= STopBorder;
1741 }
1742 }
1743
1744 TQDomElement right = format.namedItem( "right-border" ).toElement();
1745 if ( !right.isNull() )
1746 {
1747 TQDomElement pen = right.namedItem( "pen" ).toElement();
1748 if ( !pen.isNull() )
1749 {
1750 m_rightBorderPen = util_toPen( pen );
1751 if ( m_rightBorderPen.style() != TQt::NoPen )
1752 m_featuresSet |= SRightBorder;
1753 }
1754 }
1755
1756 TQDomElement bottom = format.namedItem( "bottom-border" ).toElement();
1757 if ( !bottom.isNull() )
1758 {
1759 TQDomElement pen = bottom.namedItem( "pen" ).toElement();
1760 if ( !pen.isNull() )
1761 {
1762 m_bottomBorderPen = util_toPen( pen );
1763 if ( m_bottomBorderPen.style() != TQt::NoPen )
1764 m_featuresSet |= SBottomBorder;
1765 }
1766 }
1767
1768 TQDomElement fallDiagonal = format.namedItem( "fall-diagonal" ).toElement();
1769 if ( !fallDiagonal.isNull() )
1770 {
1771 TQDomElement pen = fallDiagonal.namedItem( "pen" ).toElement();
1772 if ( !pen.isNull() )
1773 {
1774 m_fallDiagonalPen = util_toPen( pen );
1775 if ( m_fallDiagonalPen.style() != TQt::NoPen )
1776 m_featuresSet |= SFallDiagonal;
1777 }
1778 }
1779
1780 TQDomElement goUpDiagonal = format.namedItem( "up-diagonal" ).toElement();
1781 if ( !goUpDiagonal.isNull() )
1782 {
1783 TQDomElement pen = goUpDiagonal.namedItem( "pen" ).toElement();
1784 if ( !pen.isNull() )
1785 {
1786 m_goUpDiagonalPen = util_toPen( pen );
1787 if ( m_goUpDiagonalPen.style() != TQt::NoPen )
1788 m_featuresSet |= SGoUpDiagonal;
1789 }
1790 }
1791
1792 if ( format.hasAttribute( "prefix" ) )
1793 {
1794 m_prefix = format.attribute( "prefix" );
1795 m_featuresSet |= SPrefix;
1796 }
1797 if ( format.hasAttribute( "postfix" ) )
1798 {
1799 m_postfix = format.attribute( "postfix" );
1800 m_featuresSet |= SPostfix;
1801 }
1802
1803 return true;
1804}
1805
1806void Style::setParent( CustomStyle * parent )
1807{
1808 m_parent = parent;
1809 if ( m_parent )
1810 m_parentName = m_parent->name();
1811}
1812
1813CustomStyle * Style::parent() const
1814{
1815 return m_parent;
1816}
1817
1819{
1820 --m_usageCount;
1821
1822 if ( m_type == CUSTOM || m_type == BUILTIN )
1823 return false; // never delete builtin styles...
1824
1825 if ( m_usageCount < 1 )
1826 return true;
1827
1828 return false;
1829}
1830
1832{
1833 ++m_usageCount;
1834}
1835
1836bool Style::hasProperty( Properties p ) const
1837{
1838 FlagsSet f;
1839 switch( p )
1840 {
1841 case PDontPrintText:
1842 f = SDontPrintText;
1843 break;
1844 case PCustomFormat:
1845 f = SCustomFormat;
1846 break;
1847 case PNotProtected:
1848 f = SNotProtected;
1849 break;
1850 case PHideAll:
1851 f = SHideAll;
1852 break;
1853 case PHideFormula:
1854 f = SHideFormula;
1855 break;
1856 case PMultiRow:
1857 f = SMultiRow;
1858 break;
1859 case PVerticalText:
1860 f = SVerticalText;
1861 break;
1862 default:
1863 kdWarning() << "Unhandled property" << endl;
1864 return ( m_properties & (uint) p );
1865 }
1866
1867 return ( !m_parent || featureSet( f ) ? ( m_properties & (uint) p ) : m_parent->hasProperty( p ) );
1868}
1869
1870bool Style::hasFeature( FlagsSet f, bool withoutParent ) const
1871{
1872 bool b = ( m_featuresSet & (uint) f );
1873
1874 // check if feature is defined here or at parent level
1875 if ( m_parent && !withoutParent )
1876 b = ( m_parent->hasFeature( f, withoutParent ) ? true : b );
1877
1878 return b;
1879}
1880
1881void Style::clearFeature( FlagsSet f )
1882{
1883 m_featuresSet &= ~(uint)f;
1884}
1885
1886TQFont Style::font() const
1887{
1888 TQString family = fontFamily();
1889 int size = fontSize();
1890 uint ff = fontFlags();
1891
1892 TQFont f( family, size );
1893 if ( ff & (uint) FBold )
1894 f.setBold( true );
1895 if ( ff & (uint) FItalic )
1896 f.setItalic( true );
1897 if ( ff & (uint) FUnderline )
1898 f.setUnderline( true );
1899 if ( ff & (uint) FStrike )
1900 f.setStrikeOut( true );
1901
1902 return f;
1903}
1904
1905TQString const & Style::fontFamily() const
1906{
1907 return ( !m_parent || featureSet( SFontFamily ) ? m_fontFamily : m_parent->fontFamily() );
1908}
1909
1910uint Style::fontFlags() const
1911{
1912 return ( !m_parent || featureSet( SFontFlag ) ? m_fontFlags : m_parent->fontFlags() );
1913}
1914
1915int Style::fontSize() const
1916{
1917 return ( !m_parent || featureSet( SFontSize ) ? m_fontSize : m_parent->fontSize() );
1918}
1919
1920TQPen const & Style::pen() const
1921{
1922 return ( !m_parent || featureSet( STextPen ) ? m_textPen : m_parent->pen() );
1923}
1924
1925TQColor const & Style::bgColor() const
1926{
1927 return ( !m_parent || featureSet( SBackgroundColor ) ? m_bgColor : m_parent->bgColor() );
1928}
1929
1930TQPen const & Style::rightBorderPen() const
1931{
1932 return ( !m_parent || featureSet( SRightBorder ) ? m_rightBorderPen : m_parent->rightBorderPen() );
1933}
1934
1935TQPen const & Style::bottomBorderPen() const
1936{
1937 return ( !m_parent || featureSet( SBottomBorder ) ? m_bottomBorderPen : m_parent->bottomBorderPen() );
1938}
1939
1940TQPen const & Style::leftBorderPen() const
1941{
1942 return ( !m_parent || featureSet( SLeftBorder ) ? m_leftBorderPen : m_parent->leftBorderPen() );
1943}
1944
1945TQPen const & Style::topBorderPen() const
1946{
1947 return ( !m_parent || featureSet( STopBorder ) ? m_topBorderPen : m_parent->topBorderPen() );
1948}
1949
1950TQPen const & Style::fallDiagonalPen() const
1951{
1952 return ( !m_parent || featureSet( SFallDiagonal ) ? m_fallDiagonalPen : m_parent->fallDiagonalPen() );
1953}
1954
1955TQPen const & Style::goUpDiagonalPen() const
1956{
1957 return ( !m_parent || featureSet( SGoUpDiagonal ) ? m_goUpDiagonalPen : m_parent->goUpDiagonalPen() );
1958}
1959
1960int Style::precision() const
1961{
1962 return ( !m_parent || featureSet( SPrecision ) ? m_precision : m_parent->precision() );
1963}
1964
1965int Style::rotateAngle() const
1966{
1967 return ( !m_parent || featureSet( SAngle ) ? m_rotateAngle : m_parent->rotateAngle() );
1968}
1969
1970double Style::indent() const
1971{
1972 return ( !m_parent || featureSet( SIndent ) ? m_indent : m_parent->indent() );
1973}
1974
1975TQBrush const & Style::backGroundBrush() const
1976{
1977 return ( !m_parent || featureSet( SBackgroundBrush ) ? m_backGroundBrush : m_parent->backGroundBrush() );
1978}
1979
1980Format::Align Style::alignX() const
1981{
1982 return ( !m_parent || featureSet( SAlignX ) ? m_alignX : m_parent->alignX() );
1983}
1984
1985Format::AlignY Style::alignY() const
1986{
1987 return ( !m_parent || featureSet( SAlignY ) ? m_alignY : m_parent->alignY() );
1988}
1989
1990Format::FloatFormat Style::floatFormat() const
1991{
1992 return ( !m_parent || featureSet( SFloatFormat ) ? m_floatFormat : m_parent->floatFormat() );
1993}
1994
1995Format::FloatColor Style::floatColor() const
1996{
1997 return ( !m_parent || featureSet( SFloatColor ) ? m_floatColor : m_parent->floatColor() );
1998}
1999
2000FormatType Style::formatType() const
2001{
2002 return ( !m_parent || featureSet( SFormatType ) ? m_formatType : m_parent->formatType() );
2003}
2004
2005Format::Currency const & Style::currency() const
2006{
2007 return ( !m_parent || featureSet( SFormatType ) ? m_currency : m_parent->currency() );
2008}
2009
2010TQString const & Style::strFormat() const
2011{
2012 return ( !m_parent || featureSet( SCustomFormat ) ? m_strFormat : m_parent->strFormat() );
2013}
2014
2015TQString const & Style::prefix() const
2016{
2017 return ( !m_parent || featureSet( SPrefix ) ? m_prefix : m_parent->prefix() );
2018}
2019
2020TQString const & Style::postfix() const
2021{
2022 return ( !m_parent || featureSet( SPostfix ) ? m_postfix : m_parent->postfix() );
2023}
2024
2025
2026
2027Style * Style::setAlignX( Format::Align alignX )
2028{
2029 if ( m_type != AUTO || m_usageCount > 1 )
2030 {
2031 Style * style = new Style( this );
2032 style->m_alignX = alignX;
2033 style->m_featuresSet |= SAlignX;
2034 return style;
2035 }
2036
2037 m_alignX = alignX;
2038 m_featuresSet |= SAlignX;
2039 return this;
2040}
2041
2042Style * Style::setAlignY( Format::AlignY alignY )
2043{
2044 if ( m_type != AUTO || m_usageCount > 1 )
2045 {
2046 Style * style = new Style( this );
2047 style->m_alignY = alignY;
2048 style->m_featuresSet |= SAlignY;
2049 return style;
2050 }
2051
2052 m_alignY = alignY;
2053 m_featuresSet |= SAlignY;
2054 return this;
2055}
2056
2057Style * Style::setFont( TQFont const & f )
2058{
2059 if ( m_type != AUTO || m_usageCount > 1 )
2060 {
2061 Style * style = new Style( this );
2062 if ( style->m_fontFamily != f.family() )
2063 {
2064 style->m_fontFamily = f.family();
2065 style->m_featuresSet |= SFont;
2066 style->m_featuresSet |= SFontFamily;
2067 }
2068 if ( style->m_fontSize != f.pointSize() )
2069 {
2070 style->m_fontSize = f.pointSize();
2071 style->m_featuresSet |= SFont;
2072 style->m_featuresSet |= SFontSize;
2073 }
2074 if ( f.italic() != (m_fontFlags & (uint) FItalic ) )
2075 {
2076 if ( f.italic() )
2077 style->m_fontFlags |= FItalic;
2078 else
2079 style->m_fontFlags &= ~(uint) FItalic;
2080 style->m_featuresSet |= SFont;
2081 style->m_featuresSet |= SFontFlag;
2082 }
2083 if ( f.bold() != (m_fontFlags & (uint) FBold ) )
2084 {
2085 if ( f.bold() )
2086 style->m_fontFlags |= FBold;
2087 else
2088 style->m_fontFlags &= ~(uint) FBold;
2089 style->m_featuresSet |= SFont;
2090 style->m_featuresSet |= SFontFlag;
2091 }
2092 if ( f.underline() != (m_fontFlags & (uint) FUnderline ) )
2093 {
2094 if ( f.underline() )
2095 style->m_fontFlags |= FUnderline;
2096 else
2097 style->m_fontFlags &= ~(uint) FUnderline;
2098 style->m_featuresSet |= SFont;
2099 style->m_featuresSet |= SFontFlag;
2100 }
2101 if ( f.strikeOut() != (m_fontFlags & (uint) FStrike ) )
2102 {
2103 if ( f.strikeOut() )
2104 style->m_fontFlags |= FStrike;
2105 else
2106 style->m_fontFlags &= ~(uint) FStrike;
2107 style->m_featuresSet |= SFont;
2108 style->m_featuresSet |= SFontFlag;
2109 }
2110
2111 return style;
2112 }
2113
2114 if ( m_fontFamily != f.family() )
2115 {
2116 m_fontFamily = f.family();
2117 m_featuresSet |= SFont;
2118 m_featuresSet |= SFontFamily;
2119 }
2120 if ( m_fontSize != f.pointSize() )
2121 {
2122 m_fontSize = f.pointSize();
2123 m_featuresSet |= SFont;
2124 m_featuresSet |= SFontSize;
2125 }
2126 if ( f.italic() != (m_fontFlags & (uint) FItalic ) )
2127 {
2128 if ( f.italic() )
2129 m_fontFlags |= FItalic;
2130 else
2131 m_fontFlags &= ~(uint) FItalic;
2132 m_featuresSet |= SFont;
2133 m_featuresSet |= SFontFlag;
2134 }
2135 if ( f.bold() != (m_fontFlags & (uint) FBold ) )
2136 {
2137 if ( f.bold() )
2138 m_fontFlags |= FBold;
2139 else
2140 m_fontFlags &= ~(uint) FBold;
2141 m_featuresSet |= SFont;
2142 m_featuresSet |= SFontFlag;
2143 }
2144 if ( f.underline() != (m_fontFlags & (uint) FUnderline ) )
2145 {
2146 if ( f.underline() )
2147 m_fontFlags |= FUnderline;
2148 else
2149 m_fontFlags &= ~(uint) FUnderline;
2150 m_featuresSet |= SFont;
2151 m_featuresSet |= SFontFlag;
2152 }
2153 if ( f.strikeOut() != (m_fontFlags & (uint) FStrike ) )
2154 {
2155 if ( f.strikeOut() )
2156 m_fontFlags |= FStrike;
2157 else
2158 m_fontFlags &= ~(uint) FStrike;
2159 m_featuresSet |= SFont;
2160 m_featuresSet |= SFontFlag;
2161 }
2162
2163 return this;
2164}
2165
2166Style * Style::setFontFamily( TQString const & fam )
2167{
2168 if ( m_type != AUTO || m_usageCount > 1 )
2169 {
2170 if ( m_fontFamily != fam )
2171 {
2172 Style * style = new Style( this );
2173 style->m_fontFamily = fam;
2174 style->m_featuresSet |= SFontFamily;
2175 style->m_featuresSet |= SFont;
2176 return style;
2177 }
2178 return this;
2179 }
2180
2181 m_fontFamily = fam;
2182 m_featuresSet |= SFont;
2183 m_featuresSet |= SFontFamily;
2184 return this;
2185}
2186
2187Style * Style::setFontFlags( uint flags )
2188{
2189 if ( m_type != AUTO || m_usageCount > 1 )
2190 {
2191 if ( m_fontFlags != flags )
2192 {
2193 Style * style = new Style( this );
2194 style->m_fontFlags = flags;
2195 style->m_featuresSet |= SFontFlag;
2196 style->m_featuresSet |= SFont;
2197 return style;
2198 }
2199 return this;
2200 }
2201
2202 m_fontFlags = flags;
2203 m_featuresSet |= SFont;
2204 m_featuresSet |= SFontFlag;
2205 return this;
2206}
2207
2208Style * Style::setFontSize( int size )
2209{
2210 if ( m_type != AUTO || m_usageCount > 1 )
2211 {
2212 if ( m_fontSize != size )
2213 {
2214 Style * style = new Style( this );
2215 style->m_fontSize = size;
2216 style->m_featuresSet |= SFontSize;
2217 style->m_featuresSet |= SFont;
2218 return style;
2219 }
2220 return this;
2221 }
2222
2223 m_fontSize = size;
2224 m_featuresSet |= SFont;
2225 m_featuresSet |= SFontSize;
2226 return this;
2227}
2228
2229Style * Style::setPen( TQPen const & pen )
2230{
2231 if ( m_type != AUTO || m_usageCount > 1 )
2232 {
2233 Style * style = new Style( this );
2234 style->m_textPen = pen;
2235 if ( style->m_textPen.style() != TQt::NoPen )
2236 style->m_featuresSet |= STextPen;
2237 return style;
2238 }
2239
2240 m_textPen = pen;
2241 if ( m_textPen.style() != TQt::NoPen )
2242 m_featuresSet |= STextPen;
2243 return this;
2244}
2245
2246Style * Style::setBgColor( TQColor const & color )
2247{
2248 if ( m_type != AUTO || m_usageCount > 1 )
2249 {
2250 Style * style = new Style( this );
2251 style->m_bgColor = color;
2252 if ( style->m_bgColor != TQt::white )
2253 style->m_featuresSet |= SBackgroundColor;
2254 return style;
2255 }
2256
2257 m_bgColor = color;
2258 if ( m_bgColor != TQt::white )
2259 m_featuresSet |= SBackgroundColor;
2260 return this;
2261}
2262
2263Style * Style::setRightBorderPen( TQPen const & pen )
2264{
2265 if ( m_type != AUTO || m_usageCount > 1 )
2266 {
2267 Style * style = new Style( this );
2268 style->m_rightBorderPen = pen;
2269 style->m_rightPenValue = calculateValue( pen );
2270 if ( style->m_rightBorderPen.style() != TQt::NoPen )
2271 style->m_featuresSet |= SRightBorder;
2272 return style;
2273 }
2274
2275 m_rightBorderPen = pen;
2276 m_rightPenValue = calculateValue( pen );
2277 if ( m_rightBorderPen.style() != TQt::NoPen )
2278 m_featuresSet |= SRightBorder;
2279 return this;
2280}
2281
2282Style * Style::setBottomBorderPen( TQPen const & pen )
2283{
2284 if ( m_type != AUTO || m_usageCount > 1 )
2285 {
2286 Style * style = new Style( this );
2287 style->m_bottomBorderPen = pen;
2288 style->m_bottomPenValue = calculateValue( pen );
2289 if ( style->m_bottomBorderPen.style() != TQt::NoPen )
2290 style->m_featuresSet |= SBottomBorder;
2291 return style;
2292 }
2293
2294 m_bottomBorderPen = pen;
2295 m_bottomPenValue = calculateValue( pen );
2296 if ( m_bottomBorderPen.style() != TQt::NoPen )
2297 m_featuresSet |= SBottomBorder;
2298 return this;
2299}
2300
2301Style * Style::setLeftBorderPen( TQPen const & pen )
2302{
2303 if ( m_type != AUTO || m_usageCount > 1 )
2304 {
2305 Style * style = new Style( this );
2306 style->m_leftBorderPen = pen;
2307 style->m_leftPenValue = calculateValue( pen );
2308 if ( style->m_leftBorderPen.style() != TQt::NoPen )
2309 style->m_featuresSet |= SLeftBorder;
2310 return style;
2311 }
2312
2313 m_leftBorderPen = pen;
2314 m_leftPenValue = calculateValue( pen );
2315 if ( m_leftBorderPen.style() != TQt::NoPen )
2316 m_featuresSet |= SLeftBorder;
2317 return this;
2318}
2319
2320Style * Style::setTopBorderPen( TQPen const & pen )
2321{
2322 if ( m_type != AUTO || m_usageCount > 1 )
2323 {
2324 Style * style = new Style( this );
2325 style->m_topBorderPen = pen;
2326 style->m_topPenValue = calculateValue( pen );
2327 if ( style->m_topBorderPen.style() != TQt::NoPen )
2328 style->m_featuresSet |= STopBorder;
2329 return style;
2330 }
2331
2332 m_topBorderPen = pen;
2333 m_topPenValue = calculateValue( pen );
2334 if ( m_topBorderPen.style() != TQt::NoPen )
2335 m_featuresSet |= STopBorder;
2336 return this;
2337}
2338
2339Style * Style::setFallDiagonalPen( TQPen const & pen )
2340{
2341 if ( m_type != AUTO || m_usageCount > 1 )
2342 {
2343 Style * style = new Style( this );
2344 style->m_fallDiagonalPen = pen;
2345 if ( style->m_fallDiagonalPen.style() != TQt::NoPen )
2346 style->m_featuresSet |= SFallDiagonal;
2347 return style;
2348 }
2349
2350 m_fallDiagonalPen = pen;
2351 if ( m_fallDiagonalPen.style() != TQt::NoPen )
2352 m_featuresSet |= SFallDiagonal;
2353 return this;
2354}
2355
2356Style * Style::setGoUpDiagonalPen( TQPen const & pen )
2357{
2358 if ( m_type != AUTO || m_usageCount > 1 )
2359 {
2360 Style * style = new Style( this );
2361 style->m_goUpDiagonalPen = pen;
2362 if ( style->m_goUpDiagonalPen.style() != TQt::NoPen )
2363 style->m_featuresSet |= SGoUpDiagonal;
2364 return style;
2365 }
2366
2367 m_goUpDiagonalPen = pen;
2368 if ( m_goUpDiagonalPen.style() != TQt::NoPen )
2369 m_featuresSet |= SGoUpDiagonal;
2370 return this;
2371}
2372
2373Style * Style::setRotateAngle( int angle )
2374{
2375 if ( m_type != AUTO || m_usageCount > 1 )
2376 {
2377 Style * style = new Style( this );
2378 style->m_rotateAngle = angle;
2379 style->m_featuresSet |= SAngle;
2380 return style;
2381 }
2382
2383 m_rotateAngle = angle;
2384 m_featuresSet |= SAngle;
2385 return this;
2386}
2387
2388Style * Style::setIndent( double indent )
2389{
2390 if ( m_type != AUTO || m_usageCount > 1 )
2391 {
2392 Style * style = new Style( this );
2393 style->m_indent = indent;
2394 style->m_featuresSet |= SIndent;
2395 return style;
2396 }
2397
2398 m_indent = indent;
2399 m_featuresSet |= SIndent;
2400 return this;
2401}
2402
2403Style * Style::setBackGroundBrush( TQBrush const & brush )
2404{
2405 if ( m_type != AUTO || m_usageCount > 1 )
2406 {
2407 Style * style = new Style( this );
2408 style->m_backGroundBrush = brush;
2409 if ( style->m_backGroundBrush.style() != TQt::NoBrush )
2410 style->m_featuresSet |= SBackgroundBrush;
2411 return style;
2412 }
2413
2414 m_backGroundBrush = brush;
2415 if ( m_backGroundBrush.style() != TQt::NoBrush )
2416 m_featuresSet |= SBackgroundBrush;
2417 return this;
2418}
2419
2420Style * Style::setFloatFormat( Format::FloatFormat format )
2421{
2422 if ( m_type != AUTO || m_usageCount > 1 )
2423 {
2424 Style * style = new Style( this );
2425 style->m_floatFormat = format;
2426 style->m_featuresSet |= SFloatFormat;
2427 return style;
2428 }
2429
2430 m_floatFormat = format;
2431 m_featuresSet |= SFloatFormat;
2432 return this;
2433}
2434
2435Style * Style::setFloatColor( Format::FloatColor color )
2436{
2437 if ( m_type != AUTO || m_usageCount > 1 )
2438 {
2439 Style * style = new Style( this );
2440 style->m_floatColor = color;
2441 style->m_featuresSet |= SFloatColor;
2442 return style;
2443 }
2444
2445 m_floatColor = color;
2446 m_featuresSet |= SFloatColor;
2447 return this;
2448}
2449
2450Style * Style::setStrFormat( TQString const & strFormat )
2451{
2452 if ( m_type != AUTO || m_usageCount > 1 )
2453 {
2454 Style * style = new Style( this );
2455 style->m_strFormat = strFormat;
2456 style->m_featuresSet |= SCustomFormat;
2457 return style;
2458 }
2459
2460 m_strFormat = strFormat;
2461 m_featuresSet |= SCustomFormat;
2462 return this;
2463}
2464
2465Style * Style::setPrecision( int precision )
2466{
2467 if ( m_type != AUTO || m_usageCount > 1 )
2468 {
2469 Style * style = new Style( this );
2470 style->m_precision = precision;
2471 style->m_featuresSet |= SPrecision;
2472 return style;
2473 }
2474
2475 m_precision = precision;
2476 m_featuresSet |= SPrecision;
2477 return this;
2478}
2479
2480Style * Style::setPrefix( TQString const & prefix )
2481{
2482 if ( m_type != AUTO || m_usageCount > 1 )
2483 {
2484 Style * style = new Style( this );
2485 style->m_prefix = prefix;
2486 style->m_featuresSet |= SPrefix;
2487 return style;
2488 }
2489
2490 m_prefix = prefix;
2491 m_featuresSet |= SPrefix;
2492 return this;
2493}
2494
2495Style * Style::setPostfix( TQString const & postfix )
2496{
2497 if ( m_type != AUTO || m_usageCount > 1 )
2498 {
2499 Style * style = new Style( this );
2500 style->m_postfix = postfix;
2501 style->m_featuresSet |= SPostfix;
2502 return style;
2503 }
2504
2505 m_postfix = postfix;
2506 m_featuresSet |= SPostfix;
2507 return this;
2508}
2509
2510Style * Style::setCurrency( Format::Currency const & currency )
2511{
2512 if ( m_type != AUTO || m_usageCount > 1 )
2513 {
2514 Style * style = new Style( this );
2515 style->m_currency = currency;
2516 style->m_featuresSet |= SFormatType;
2517 return style;
2518 }
2519
2520 m_currency = currency;
2521 m_featuresSet |= SFormatType;
2522 return this;
2523}
2524
2525Style * Style::setProperty( Properties p )
2526{
2527 if ( m_type != AUTO || m_usageCount > 1 )
2528 {
2529 Style * style = new Style( this );
2530 style->m_properties |= (uint) p;
2531 switch( p )
2532 {
2533 case PDontPrintText:
2534 style->m_featuresSet |= SDontPrintText;
2535 break;
2536 case PCustomFormat:
2537 style->m_featuresSet |= SCustomFormat;
2538 break;
2539 case PNotProtected:
2540 style->m_featuresSet |= SNotProtected;
2541 break;
2542 case PHideAll:
2543 style->m_featuresSet |= SHideAll;
2544 break;
2545 case PHideFormula:
2546 style->m_featuresSet |= SHideFormula;
2547 break;
2548 case PMultiRow:
2549 style->m_featuresSet |= SMultiRow;
2550 break;
2551 case PVerticalText:
2552 style->m_featuresSet |= SVerticalText;
2553 break;
2554 default:
2555 kdWarning() << "Unhandled property" << endl;
2556 }
2557 return style;
2558 }
2559
2560 m_properties |= (uint) p;
2561 switch( p )
2562 {
2563 case PDontPrintText:
2564 m_featuresSet |= SDontPrintText;
2565 break;
2566 case PCustomFormat:
2567 m_featuresSet |= SCustomFormat;
2568 break;
2569 case PNotProtected:
2570 m_featuresSet |= SNotProtected;
2571 break;
2572 case PHideAll:
2573 m_featuresSet |= SHideAll;
2574 break;
2575 case PHideFormula:
2576 m_featuresSet |= SHideFormula;
2577 break;
2578 case PMultiRow:
2579 m_featuresSet |= SMultiRow;
2580 break;
2581 case PVerticalText:
2582 m_featuresSet |= SVerticalText;
2583 break;
2584 default:
2585 kdWarning() << "Unhandled property" << endl;
2586 }
2587 return this;
2588}
2589
2590Style * Style::clearProperty( Properties p )
2591{
2592 if ( m_type != AUTO || m_usageCount > 1 )
2593 {
2594 Style * style = new Style( this );
2595 style->m_properties &= ~(uint) p;
2596 switch( p )
2597 {
2598 case PDontPrintText:
2599 style->m_featuresSet |= SDontPrintText;
2600 break;
2601 case PCustomFormat:
2602 style->m_featuresSet |= SCustomFormat;
2603 break;
2604 case PNotProtected:
2605 style->m_featuresSet |= SNotProtected;
2606 break;
2607 case PHideAll:
2608 style->m_featuresSet |= SHideAll;
2609 break;
2610 case PHideFormula:
2611 style->m_featuresSet |= SHideFormula;
2612 break;
2613 case PMultiRow:
2614 style->m_featuresSet |= SMultiRow;
2615 break;
2616 case PVerticalText:
2617 style->m_featuresSet |= SVerticalText;
2618 break;
2619 default:
2620 kdWarning() << "Unhandled property" << endl;
2621 }
2622 return style;
2623 }
2624
2625 m_properties &= ~(uint) p;
2626 switch( p )
2627 {
2628 case PDontPrintText:
2629 m_featuresSet |= SDontPrintText;
2630 break;
2631 case PCustomFormat:
2632 m_featuresSet |= SCustomFormat;
2633 break;
2634 case PNotProtected:
2635 m_featuresSet |= SNotProtected;
2636 break;
2637 case PHideAll:
2638 m_featuresSet |= SHideAll;
2639 break;
2640 case PHideFormula:
2641 m_featuresSet |= SHideFormula;
2642 break;
2643 case PMultiRow:
2644 m_featuresSet |= SMultiRow;
2645 break;
2646 case PVerticalText:
2647 m_featuresSet |= SVerticalText;
2648 break;
2649 default:
2650 kdWarning() << "Unhandled property" << endl;
2651 }
2652 return this;
2653}
2654
2655
2656Style * Style::setFormatType( FormatType format )
2657{
2658 if ( m_type != AUTO || m_usageCount > 1 )
2659 {
2660 Style * style = new Style( this );
2661 style->m_formatType = format;
2662 style->m_featuresSet |= SFormatType;
2663 return style;
2664 }
2665
2666 m_formatType = format;
2667 m_featuresSet |= SFormatType;
2668 return this;
2669}
2670
2671TQString Style::colorName( const TQColor& color )
2672{
2673 static TQMap<TQRgb , TQString> map;
2674
2675 TQRgb rgb = color.rgb();
2676
2677 if (!map.contains( rgb ))
2678 {
2679 map[rgb] = color.name();
2680 return map[rgb];
2681 }
2682 else
2683 {
2684 return map[rgb];
2685 }
2686}
2687
2694CustomStyle::CustomStyle()
2695 : Style(),
2696 m_name( "Default" )
2697{
2698 m_type = BUILTIN;
2699 m_parent = 0;
2700}
2701
2702CustomStyle::CustomStyle( Style * parent, TQString const & name )
2703 : Style(),
2704 m_name( name )
2705{
2706 m_type = CUSTOM;
2707 m_parent = 0;
2708
2709 // one to one copy
2710 if ( parent->hasProperty( PDontPrintText ) )
2711 addProperty( PDontPrintText );
2712 if ( parent->hasProperty( PCustomFormat ) )
2713 addProperty( PCustomFormat );
2714 if ( parent->hasProperty( PNotProtected ) )
2715 addProperty( PNotProtected );
2716 if ( parent->hasProperty( PHideAll ) )
2717 addProperty( PHideAll );
2718 if ( parent->hasProperty( PHideFormula ) )
2719 addProperty( PHideFormula );
2720 if ( parent->hasProperty( PMultiRow ) )
2721 addProperty( PMultiRow );
2722 if ( parent->hasProperty( PVerticalText ) )
2723 addProperty( PVerticalText );
2724
2725 changeAlignX( parent->alignX() );
2726 changeAlignY( parent->alignY() );
2727 changeFloatFormat( parent->floatFormat() );
2728 changeFloatColor( parent->floatColor() );
2729 changeFormatType( parent->formatType() );
2730 changeFontFamily( parent->fontFamily() );
2731 changeFontSize( parent->fontSize() );
2732 changeFontFlags( parent->fontFlags() );
2733 changePen( parent->pen() );
2734 changeBgColor( parent->bgColor() );
2735 changeRightBorderPen( parent->rightBorderPen() );
2736 changeBottomBorderPen( parent->bottomBorderPen() );
2737 changeLeftBorderPen( parent->leftBorderPen() );
2738 changeTopBorderPen( parent->topBorderPen() );
2739 changeFallBorderPen( parent->fallDiagonalPen() );
2740 changeGoUpBorderPen( parent->goUpDiagonalPen() );
2741 changeBackGroundBrush( parent->backGroundBrush() );
2742 changeRotateAngle( parent->rotateAngle() );
2743 changeIndent( parent->indent() );
2744 changeStrFormat( parent->strFormat() );
2745 changePrecision( parent->precision() );
2746 changePrefix( parent->prefix() );
2747 changePostfix( parent->postfix() );
2748 changeCurrency( parent->currency() );
2749}
2750
2751CustomStyle::CustomStyle( TQString const & name, CustomStyle * parent )
2752 : Style(),
2753 m_name( name )
2754{
2755 m_parent = parent;
2756 if ( m_parent )
2757 m_parentName = m_parent->name();
2758}
2759
2760CustomStyle::~CustomStyle()
2761{
2762}
2763
2764TQString CustomStyle::saveOasis( KoGenStyle& style, KoGenStyles &mainStyles )
2765{
2766 // If the type is undefined, we're called from Format
2767 // and the OASIS style is not an automatic style.
2768 // TODO: As the user styles are already created, look them up
2769 // in what way ever and return here.
2770// if ( style.type() == 0 && ( m_type == BUILTIN ) && ( m_name == "Default" ) )
2771// return "Default";
2772 if ( style.type() == 0 )
2773 style = KoGenStyle( Doc::STYLE_CELL_USER, "table-cell" );
2774
2775 if ( m_name.isEmpty() )
2776 return TQString(); // TODO fallback to Style::saveOasis() ???
2777
2778 // default style does not need display name
2779 if( type() != BUILTIN || m_name != "Default" )
2780 style.addAttribute( "style:display-name", m_name );
2781
2782 // doing the real work
2783 saveOasisStyle( style, mainStyles );
2784
2785 // The lookup is done in the calling object (Format).
2786 if ( style.type() == Doc::STYLE_CELL_AUTO )
2787 return TQString();
2788
2789 if( ( m_type == BUILTIN ) && ( m_name == "Default" ) )
2790 {
2791 style.setDefaultStyle(true);
2792 // don't i18n'ize "Default" in this case
2793 return mainStyles.lookup( style, "Default", KoGenStyles::DontForceNumbering );
2794 }
2795 else
2796 // this is a custom style
2797 return mainStyles.lookup( style, "custom-style" );
2798}
2799
2800void CustomStyle::loadOasis( KoOasisStyles& oasisStyles, const TQDomElement& style, const TQString & name )
2801{
2802 m_name = name;
2803 if ( style.hasAttributeNS( KoXmlNS::style, "parent-style-name" ) )
2804 m_parentName = style.attributeNS( KoXmlNS::style, "parent-style-name", TQString() );
2805 else if ( m_name != "Default" )
2806 m_parentName = "Default";
2807
2808 m_type = CUSTOM;
2809
2810 Style::loadOasisStyle( oasisStyles, style );
2811}
2812
2813void CustomStyle::save( TQDomDocument & doc, TQDomElement & styles )
2814{
2815 if ( m_name.isEmpty() )
2816 return;
2817
2818 TQDomElement style( doc.createElement( "style" ) );
2819 style.setAttribute( "type", (int) m_type );
2820 if ( m_parent )
2821 style.setAttribute( "parent", m_parent->name() );
2822 style.setAttribute( "name", m_name );
2823
2824 TQDomElement format( doc.createElement( "format" ) );
2825 saveXML( doc, format );
2826 style.appendChild( format );
2827
2828 styles.appendChild( style );
2829}
2830
2831bool CustomStyle::loadXML( TQDomElement const & style, TQString const & name )
2832{
2833 m_name = name;
2834
2835 if ( style.hasAttribute( "parent" ) )
2836 m_parentName = style.attribute( "parent" );
2837
2838 if ( !style.hasAttribute( "type" ) )
2839 return false;
2840
2841 bool ok = true;
2842 m_type = (StyleType) style.attribute( "type" ).toInt( &ok );
2843 if ( !ok )
2844 return false;
2845
2846 TQDomElement f( style.namedItem( "format" ).toElement() );
2847 if ( !f.isNull() )
2848 if ( !Style::loadXML( f ) )
2849 return false;
2850
2851 return true;
2852}
2853
2854void CustomStyle::setName( TQString const & name )
2855{
2856 m_name = name;
2857}
2858
2859void CustomStyle::refreshParentName()
2860{
2861 if ( m_parent )
2862 m_parentName = m_parent->name();
2863}
2864
2865bool CustomStyle::definesAll() const
2866{
2867 if ( !( m_featuresSet & (uint) SAlignX ) )
2868 return false;
2869 if ( !( m_featuresSet & (uint) SAlignY ) )
2870 return false;
2871 if ( !( m_featuresSet & (uint) SPrefix ) )
2872 return false;
2873 if ( !( m_featuresSet & (uint) SPostfix ) )
2874 return false;
2875 if ( !( m_featuresSet & (uint) SLeftBorder ) )
2876 return false;
2877 if ( !( m_featuresSet & (uint) SRightBorder ) )
2878 return false;
2879 if ( !( m_featuresSet & (uint) STopBorder ) )
2880 return false;
2881 if ( !( m_featuresSet & (uint) SBottomBorder ) )
2882 return false;
2883 if ( !( m_featuresSet & (uint) SFallDiagonal ) )
2884 return false;
2885 if ( !( m_featuresSet & (uint) SGoUpDiagonal ) )
2886 return false;
2887 if ( !( m_featuresSet & (uint) SBackgroundBrush ) )
2888 return false;
2889 if ( !( m_featuresSet & (uint) SFontFamily ) )
2890 return false;
2891 if ( !( m_featuresSet & (uint) SFontSize ) )
2892 return false;
2893 if ( !( m_featuresSet & (uint) SFontFlag ) )
2894 return false;
2895 if ( !( m_featuresSet & (uint) STextPen ) )
2896 return false;
2897 if ( !( m_featuresSet & (uint) SBackgroundColor ) )
2898 return false;
2899 if ( !( m_featuresSet & (uint) SFloatFormat ) )
2900 return false;
2901 if ( !( m_featuresSet & (uint) SFloatColor ) )
2902 return false;
2903 if ( !( m_featuresSet & (uint) SMultiRow ) )
2904 return false;
2905 if ( !( m_featuresSet & (uint) SVerticalText ) )
2906 return false;
2907 if ( !( m_featuresSet & (uint) SPrecision ) )
2908 return false;
2909 if ( !( m_featuresSet & (uint) SFormatType ) )
2910 return false;
2911 if ( !( m_featuresSet & (uint) SAngle ) )
2912 return false;
2913 if ( !( m_featuresSet & (uint) SIndent ) )
2914 return false;
2915 if ( !( m_featuresSet & (uint) SDontPrintText ) )
2916 return false;
2917 if ( !( m_featuresSet & (uint) SCustomFormat ) )
2918 return false;
2919 if ( !( m_featuresSet & (uint) SNotProtected ) )
2920 return false;
2921 if ( !( m_featuresSet & (uint) SHideAll ) )
2922 return false;
2923 if ( !( m_featuresSet & (uint) SHideFormula ) )
2924 return false;
2925
2926 return true;
2927}
2928
2929void CustomStyle::changeAlignX( Format::Align alignX )
2930{
2931 m_alignX = alignX;
2932 m_featuresSet |= SAlignX;
2933}
2934
2935void CustomStyle::changeAlignY( Format::AlignY alignY )
2936{
2937 m_alignY = alignY;
2938 m_featuresSet |= SAlignY;
2939}
2940
2941void CustomStyle::changeFont( TQFont const & f )
2942{
2943 if ( m_fontFamily != f.family() )
2944 {
2945 m_fontFamily = f.family();
2946 m_featuresSet |= SFontFamily;
2947 m_featuresSet |= SFont;
2948 }
2949 if ( m_fontSize != f.pointSize() )
2950 {
2951 m_fontSize = f.pointSize();
2952 m_featuresSet |= SFont;
2953 m_featuresSet |= SFontSize;
2954 }
2955
2956 if ( f.italic() != (m_fontFlags & (uint) FItalic ) )
2957 {
2958 if ( f.italic() )
2959 m_fontFlags |= FItalic;
2960 else
2961 m_fontFlags &= ~(uint) FItalic;
2962 m_featuresSet |= SFont;
2963 m_featuresSet |= SFontFlag;
2964 }
2965 if ( f.bold() != (m_fontFlags & (uint) FBold ) )
2966 {
2967 if ( f.bold() )
2968 m_fontFlags |= FBold;
2969 else
2970 m_fontFlags &= ~(uint) FBold;
2971 m_featuresSet |= SFont;
2972 m_featuresSet |= SFontFlag;
2973 }
2974 if ( f.underline() != (m_fontFlags & (uint) FUnderline ) )
2975 {
2976 if ( f.underline() )
2977 m_fontFlags |= FUnderline;
2978 else
2979 m_fontFlags &= ~(uint) FUnderline;
2980 m_featuresSet |= SFont;
2981 m_featuresSet |= SFontFlag;
2982 }
2983 if ( f.strikeOut() != (m_fontFlags & (uint) FStrike ) )
2984 {
2985 if ( f.strikeOut() )
2986 m_fontFlags |= FStrike;
2987 else
2988 m_fontFlags &= ~(uint) FStrike;
2989 m_featuresSet |= SFont;
2990 m_featuresSet |= SFontFlag;
2991 }
2992}
2993
2994void CustomStyle::changeFontFamily( TQString const & fam )
2995{
2996 if ( m_fontFamily != fam )
2997 {
2998 m_fontFamily = fam;
2999 m_featuresSet |= SFont;
3000 m_featuresSet |= SFontFamily;
3001 }
3002}
3003
3004void CustomStyle::changeFontSize( int size )
3005{
3006 if ( m_fontSize != size )
3007 {
3008 m_fontSize = size;
3009 m_featuresSet |= SFont;
3010 m_featuresSet |= SFontSize;
3011 }
3012}
3013
3014void CustomStyle::changeFontFlags( uint flags )
3015{
3016 if ( m_fontFlags != flags )
3017 {
3018 m_fontFlags = flags;
3019 m_featuresSet |= SFont;
3020 m_featuresSet |= SFontFlag;
3021 }
3022}
3023
3024void CustomStyle::changeTextColor( TQColor const & color )
3025{
3026 m_textPen.setColor( color );
3027 m_featuresSet |= STextPen;
3028}
3029
3030void CustomStyle::changePen( TQPen const & pen )
3031{
3032 m_textPen = pen;
3033 m_featuresSet |= STextPen;
3034}
3035
3036void CustomStyle::changeBgColor( TQColor const & color )
3037{
3038 m_bgColor = color;
3039 m_featuresSet |= SBackgroundColor;
3040}
3041
3042void CustomStyle::changeRightBorderPen( TQPen const & pen )
3043{
3044 m_rightBorderPen = pen;
3045 m_rightPenValue = calculateValue( pen );
3046 m_featuresSet |= SRightBorder;
3047}
3048
3049void CustomStyle::changeBottomBorderPen( TQPen const & pen )
3050{
3051 m_bottomBorderPen = pen;
3052 m_bottomPenValue = calculateValue( pen );
3053 m_featuresSet |= SBottomBorder;
3054}
3055
3056void CustomStyle::changeLeftBorderPen( TQPen const & pen )
3057{
3058 m_leftBorderPen = pen;
3059 m_leftPenValue = calculateValue( pen );
3060 m_featuresSet |= SLeftBorder;
3061}
3062
3063void CustomStyle::changeTopBorderPen( TQPen const & pen )
3064{
3065 m_topBorderPen = pen;
3066 m_topPenValue = calculateValue( pen );
3067 m_featuresSet |= STopBorder;
3068}
3069
3070void CustomStyle::changeFallBorderPen( TQPen const & pen )
3071{
3072 m_fallDiagonalPen = pen;
3073 m_featuresSet |= SFallDiagonal;
3074}
3075
3076void CustomStyle::changeGoUpBorderPen( TQPen const & pen )
3077{
3078 m_goUpDiagonalPen = pen;
3079 m_featuresSet |= SGoUpDiagonal;
3080}
3081
3082void CustomStyle::changeRotateAngle( int angle )
3083{
3084 m_rotateAngle = angle;
3085 m_featuresSet |= SAngle;
3086}
3087
3088void CustomStyle::changeIndent( double indent )
3089{
3090 m_indent = indent;
3091 m_featuresSet |= SIndent;
3092}
3093
3094void CustomStyle::changeBackGroundBrush( TQBrush const & brush )
3095{
3096 m_backGroundBrush = brush;
3097 m_featuresSet |= SBackgroundBrush;
3098}
3099
3100void CustomStyle::changeFloatFormat( Format::FloatFormat format )
3101{
3102 m_floatFormat = format;
3103 m_featuresSet |= SFloatFormat;
3104}
3105
3106void CustomStyle::changeFloatColor( Format::FloatColor color )
3107{
3108 m_floatColor = color;
3109 m_featuresSet |= SFloatColor;
3110}
3111
3112void CustomStyle::changeFormatType( FormatType format )
3113{
3114 m_formatType = format;
3115 m_featuresSet |= SFormatType;
3116}
3117
3118void CustomStyle::changeStrFormat( TQString const & strFormat )
3119{
3120 m_strFormat = strFormat;
3121 m_featuresSet |= SCustomFormat;
3122}
3123
3124void CustomStyle::changePrecision( int precision )
3125{
3126 m_precision = precision;
3127 m_featuresSet |= SPrecision;
3128}
3129
3130void CustomStyle::changePrefix( TQString const & prefix )
3131{
3132 m_prefix = prefix;
3133 m_featuresSet |= SPrefix;
3134}
3135
3136void CustomStyle::changePostfix( TQString const & postfix )
3137{
3138 m_postfix = postfix;
3139 m_featuresSet |= SPostfix;
3140}
3141
3142void CustomStyle::changeCurrency( Format::Currency const & currency )
3143{
3144 m_currency = currency;
3145}
3146
3147void CustomStyle::addProperty( Properties p )
3148{
3149 m_properties |= (uint) p;
3150 switch( p )
3151 {
3152 case PDontPrintText:
3153 m_featuresSet |= SDontPrintText;
3154 break;
3155 case PCustomFormat:
3156 m_featuresSet |= SCustomFormat;
3157 break;
3158 case PNotProtected:
3159 m_featuresSet |= SNotProtected;
3160 break;
3161 case PHideAll:
3162 m_featuresSet |= SHideAll;
3163 break;
3164 case PHideFormula:
3165 m_featuresSet |= SHideFormula;
3166 break;
3167 case PMultiRow:
3168 m_featuresSet |= SMultiRow;
3169 break;
3170 case PVerticalText:
3171 m_featuresSet |= SVerticalText;
3172 break;
3173 default:
3174 kdWarning() << "Unhandled property" << endl;
3175 }
3176}
3177
3178void CustomStyle::removeProperty( Properties p )
3179{
3180 m_properties &= ~(uint) p;
3181 switch( p )
3182 {
3183 case PDontPrintText:
3184 m_featuresSet &= SDontPrintText;
3185 break;
3186 case PCustomFormat:
3187 m_featuresSet &= SCustomFormat;
3188 break;
3189 case PNotProtected:
3190 m_featuresSet &= SNotProtected;
3191 break;
3192 case PHideAll:
3193 m_featuresSet &= SHideAll;
3194 break;
3195 case PHideFormula:
3196 m_featuresSet &= SHideFormula;
3197 break;
3198 case PMultiRow:
3199 m_featuresSet &= SMultiRow;
3200 break;
3201 case PVerticalText:
3202 m_featuresSet &= SVerticalText;
3203 break;
3204 default:
3205 kdWarning() << "Unhandled property" << endl;
3206 }
3207}
3208
3209bool CustomStyle::operator==( const CustomStyle& other ) const
3210{
3211 if ( m_name != other.m_name )
3212 return false;
3213 return Style::operator==( other );
3214}
Built-in or custom style defined in StyleManager dialog.
void loadOasis(KoOasisStyles &oasisStyles, const TQDomElement &style, const TQString &name)
Loads the style properties from style .
virtual TQString saveOasis(KoGenStyle &style, KoGenStyles &mainStyles)
The Style class represents a cell style.
TQBrush m_backGroundBrush
The brush used to draw the background.
TQPen m_fallDiagonalPen
The pen used to draw the diagonal.
TQString m_postfix
The postfix of a numeric value ( for example "DM" ) May be empty.
TQString m_strFormat
Format of the content, e.g.
double m_indent
Give indent.
TQPen m_bottomBorderPen
The pen used to draw the bottom border.
uint m_properties
Stores information like: DonPrint, DontShowFormula, Protected...
TQString m_fontFamily
The font used to draw the text.
void addRef()
Marks this style as used.
bool operator==(const Style &style) const
Returns true if both styles have the same properties.
bool release()
Releases this style.
TQPen m_topBorderPen
The pen used to draw the top border.
virtual TQString saveOasis(KoGenStyle &style, KoGenStyles &mainStyles)
Saves an OASIS automatic style.
TQPen m_rightBorderPen
The pen used to draw the right border.
Format::FloatColor m_floatColor
The color format of a floating point value.
Format::Currency m_currency
Currency information: about which currency from which country.
Format::AlignY m_alignY
Aligment of the text at top middle or bottom.
TQPen m_textPen
The pen used to draw the text.
virtual ~Style()
Destructor.
StyleType
The style type.
@ BUILTIN
built-in style (the default style)
@ AUTO
automatically generated on cell format changes
@ CUSTOM
custom style (defined in the StyleManager dialog)
Style()
Constructor.
Format::Align m_alignX
Alignment of the text.
TQString m_prefix
The prefix of a numeric value ( for example "$" ) May be empty.
static TQString colorName(const TQColor &color)
Returns the name of a colour.
void saveOasisStyle(KoGenStyle &style, KoGenStyles &mainStyles)
Helper function for saveOasis Does the real work by determining the used attributes.
int m_precision
The precision of the floating point representation If precision is -1, this means that no precision i...
static TQString saveOasisStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles, FormatType _style, const TQString &_prefix, const TQString &_postfix, int _precision, const TQString &symbol)
TQColor m_bgColor
The background color.
TQPen m_goUpDiagonalPen
The pen used to draw the the diagonal which go up.
TQPen m_leftBorderPen
The pen used to draw the left border.
The KSpread namespace.
Definition commands.h:39