KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3215 lines
91KB

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