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.

765 lines
24KB

  1. /* -*- Mode: C++ -*-
  2. $Id: KDGanttXMLTools.cpp 523435 2006-03-28 08:01:15Z mlaurent $
  3. KDGantt - a multi-platform charting engine
  4. */
  5. /****************************************************************************
  6. ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
  7. **
  8. ** This file is part of the KDGantt library.
  9. **
  10. ** This file may be distributed and/or modified under the terms of the
  11. ** GNU General Public License version 2 as published by the Free Software
  12. ** Foundation and appearing in the file LICENSE.GPL included in the
  13. ** packaging of this file.
  14. **
  15. ** Licensees holding valid commercial KDGantt licenses may use this file in
  16. ** accordance with the KDGantt Commercial License Agreement provided with
  17. ** the Software.
  18. **
  19. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. **
  22. ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
  23. ** information about KDGantt Commercial License Agreements.
  24. **
  25. ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
  26. ** licensing are not clear to you.
  27. **
  28. ** As a special exception, permission is given to link this program
  29. ** with any edition of TQt, and distribute the resulting executable,
  30. ** without including the source code for TQt in the source distribution.
  31. **
  32. **********************************************************************/
  33. #include "KDGanttXMLTools.h"
  34. #include <tqbrush.h>
  35. #include <tqbuffer.h>
  36. #include <tqimage.h>
  37. #include <zlib.h>
  38. namespace KDGanttXML {
  39. void createBoolNode( TQDomDocument& doc, TQDomNode& parent,
  40. const TQString& elementName, bool value )
  41. {
  42. TQDomElement newElement =
  43. doc.createElement( elementName );
  44. parent.appendChild( newElement );
  45. TQDomText elementContent =
  46. doc.createTextNode( value ? "true" : "false" );
  47. newElement.appendChild( elementContent );
  48. }
  49. void createSizeNode( TQDomDocument& doc, TQDomNode& parent,
  50. const TQString& elementName, const TQSize& value )
  51. {
  52. TQDomElement newElement =
  53. doc.createElement( elementName );
  54. parent.appendChild( newElement );
  55. newElement.setAttribute( "Width", value.width() );
  56. newElement.setAttribute( "Height", value.height() );
  57. }
  58. void createIntNode( TQDomDocument& doc, TQDomNode& parent,
  59. const TQString& elementName, int value )
  60. {
  61. TQDomElement newElement =
  62. doc.createElement( elementName );
  63. parent.appendChild( newElement );
  64. TQDomText elementContent =
  65. doc.createTextNode( TQString::number( value ) );
  66. newElement.appendChild( elementContent );
  67. }
  68. void createDoubleNode( TQDomDocument& doc, TQDomNode& parent,
  69. const TQString& elementName, double value )
  70. {
  71. TQDomElement newElement =
  72. doc.createElement( elementName );
  73. parent.appendChild( newElement );
  74. TQDomText elementContent =
  75. doc.createTextNode( TQString::number( value ) );
  76. newElement.appendChild( elementContent );
  77. }
  78. void createStringNode( TQDomDocument& doc, TQDomNode& parent,
  79. const TQString& elementName,
  80. const TQString& text )
  81. {
  82. TQDomElement newElement =
  83. doc.createElement( elementName );
  84. parent.appendChild( newElement );
  85. TQDomText elementContent =
  86. doc.createTextNode( text );
  87. newElement.appendChild( elementContent );
  88. }
  89. void createColorNode( TQDomDocument& doc, TQDomNode& parent,
  90. const TQString& elementName, const TQColor& color )
  91. {
  92. TQDomElement colorElement = doc.createElement( elementName );
  93. parent.appendChild( colorElement );
  94. colorElement.setAttribute( "Red",
  95. TQString::number( color.red() ) );
  96. colorElement.setAttribute( "Green",
  97. TQString::number( color.green() ) );
  98. colorElement.setAttribute( "Blue",
  99. TQString::number( color.blue() ) );
  100. }
  101. void createBrushNode( TQDomDocument& doc, TQDomNode& parent,
  102. const TQString& elementName, const TQBrush& brush )
  103. {
  104. TQDomElement brushElement = doc.createElement( elementName );
  105. parent.appendChild( brushElement );
  106. createColorNode( doc, brushElement, "Color", brush.color() );
  107. createStringNode( doc, brushElement, "Style",
  108. KDGanttXML::brushStyleToString( brush.style() ) );
  109. if( brush.style() == TQt::CustomPattern && brush.pixmap() )
  110. createPixmapNode( doc, brushElement, "Pixmap", *brush.pixmap() );
  111. }
  112. void createPixmapNode( TQDomDocument& doc, TQDomNode& parent,
  113. const TQString& elementName, const TQPixmap& pixmap )
  114. {
  115. TQDomElement pixmapElement = doc.createElement( elementName );
  116. parent.appendChild( pixmapElement );
  117. // Convert the pixmap to an image, save that image to an in-memory
  118. // XPM representation and compress this representation. This
  119. // conforms to the file format TQt Designer uses.
  120. TQByteArray ba;
  121. TQBuffer buffer( ba );
  122. buffer.open( IO_WriteOnly );
  123. TQImageIO imgio( &buffer, "XPM" );
  124. TQImage image = pixmap.convertToImage();
  125. imgio.setImage( image );
  126. imgio.write();
  127. buffer.close();
  128. ulong len = ba.size() * 2;
  129. TQByteArray bazip( len );
  130. ::compress( (uchar*) bazip.data(), &len, (uchar*) ba.data(), ba.size() );
  131. TQString dataString;
  132. static const char hexchars[] = "0123456789abcdef";
  133. for ( int i = 0; i < (int)len; ++i ) {
  134. uchar c = (uchar) bazip[i];
  135. dataString += hexchars[c >> 4];
  136. dataString += hexchars[c & 0x0f];
  137. }
  138. createStringNode( doc, pixmapElement, "Format", "XPM.GZ" );
  139. createIntNode( doc, pixmapElement, "Length", ba.size() );
  140. createStringNode( doc, pixmapElement, "Data", dataString );
  141. }
  142. void createRectNode( TQDomDocument& doc, TQDomNode& parent,
  143. const TQString& elementName, const TQRect& rect )
  144. {
  145. TQDomElement rectElement = doc.createElement( elementName );
  146. parent.appendChild( rectElement );
  147. TQDomElement xElement = doc.createElement( "X" );
  148. rectElement.appendChild( xElement );
  149. TQDomText xContent = doc.createTextNode( TQString::number( rect.x() ) );
  150. xElement.appendChild( xContent );
  151. TQDomElement yElement = doc.createElement( "Y" );
  152. rectElement.appendChild( yElement );
  153. TQDomText yContent = doc.createTextNode( TQString::number( rect.y() ) );
  154. yElement.appendChild( yContent );
  155. TQDomElement widthElement = doc.createElement( "Width" );
  156. rectElement.appendChild( widthElement );
  157. TQDomText widthContent = doc.createTextNode( TQString::number( rect.width() ) );
  158. widthElement.appendChild( widthContent );
  159. TQDomElement heightElement = doc.createElement( "Height" );
  160. rectElement.appendChild( heightElement );
  161. TQDomText heightContent = doc.createTextNode( TQString::number( rect.height() ) );
  162. heightElement.appendChild( heightContent );
  163. }
  164. void createStringListNodes( TQDomDocument& doc, TQDomNode& parent,
  165. const TQString& elementName,
  166. const TQStringList* list )
  167. {
  168. if( !list )
  169. return;
  170. for( TQStringList::ConstIterator it = list->begin();
  171. it != list->end(); ++it ) {
  172. TQDomElement element = doc.createElement( elementName );
  173. parent.appendChild( element );
  174. TQDomText elementContent = doc.createTextNode( *it );
  175. element.appendChild( elementContent );
  176. }
  177. }
  178. void createFontNode( TQDomDocument& doc, TQDomNode& parent,
  179. const TQString& elementName, const TQFont& font )
  180. {
  181. TQDomElement fontElement = doc.createElement( elementName );
  182. parent.appendChild( fontElement );
  183. createStringNode( doc, fontElement, "Family", font.family() );
  184. createIntNode( doc, fontElement, "PointSize", font.pointSize() );
  185. createIntNode( doc, fontElement, "PixelSize", font.pixelSize() );
  186. createIntNode( doc, fontElement, "Weight", font.weight() );
  187. createBoolNode( doc, fontElement, "Italic", font.italic() );
  188. }
  189. void createPenNode( TQDomDocument& doc, TQDomNode& parent,
  190. const TQString& elementName, const TQPen& pen )
  191. {
  192. TQDomElement penElement = doc.createElement( elementName );
  193. parent.appendChild( penElement );
  194. createIntNode( doc, penElement, "Width", pen.width() );
  195. createColorNode( doc, penElement, "Color", pen.color() );
  196. createStringNode( doc, penElement, "Style", penStyleToString( pen.style() ) );
  197. }
  198. void createDateTimeNode( TQDomDocument& doc, TQDomNode& parent,
  199. const TQString& elementName,
  200. const TQDateTime& datetime )
  201. {
  202. TQDomElement dateTimeElement = doc.createElement( elementName );
  203. parent.appendChild( dateTimeElement );
  204. createDateNode( doc, dateTimeElement, "Date", datetime.date() );
  205. createTimeNode( doc, dateTimeElement, "Time", datetime.time() );
  206. }
  207. void createDateNode( TQDomDocument& doc, TQDomNode& parent,
  208. const TQString& elementName, const TQDate& date )
  209. {
  210. TQDomElement dateElement = doc.createElement( elementName );
  211. parent.appendChild( dateElement );
  212. dateElement.setAttribute( "Year", TQString::number( date.year() ) );
  213. dateElement.setAttribute( "Month", TQString::number( date.month() ) );
  214. dateElement.setAttribute( "Day", TQString::number( date.day() ) );
  215. }
  216. void createTimeNode( TQDomDocument& doc, TQDomNode& parent,
  217. const TQString& elementName, const TQTime& time )
  218. {
  219. TQDomElement timeElement = doc.createElement( elementName );
  220. parent.appendChild( timeElement );
  221. timeElement.setAttribute( "Hour",
  222. TQString::number( time.hour() ) );
  223. timeElement.setAttribute( "Minute",
  224. TQString::number( time.minute() ) );
  225. timeElement.setAttribute( "Second",
  226. TQString::number( time.second() ) );
  227. timeElement.setAttribute( "Millisecond",
  228. TQString::number( time.msec() ) );
  229. }
  230. TQString penStyleToString( Qt::PenStyle style )
  231. {
  232. switch( style ) {
  233. case Qt::NoPen:
  234. return "NoPen";
  235. case Qt::SolidLine:
  236. return "SolidLine";
  237. case Qt::DashLine:
  238. return "DashLine";
  239. case Qt::DotLine:
  240. return "DotLine";
  241. case Qt::DashDotLine:
  242. return "DashDotLine";
  243. case Qt::DashDotDotLine:
  244. return "DashDotDotLine";
  245. default: // should not happen
  246. return "SolidLine";
  247. }
  248. }
  249. TQString brushStyleToString( Qt::BrushStyle style )
  250. {
  251. // PENDING(kalle) Support custom patterns
  252. switch( style ) {
  253. case Qt::NoBrush:
  254. return "NoBrush";
  255. case Qt::SolidPattern:
  256. return "SolidPattern";
  257. case Qt::Dense1Pattern:
  258. return "Dense1Pattern";
  259. case Qt::Dense2Pattern:
  260. return "Dense2Pattern";
  261. case Qt::Dense3Pattern:
  262. return "Dense3Pattern";
  263. case Qt::Dense4Pattern:
  264. return "Dense4Pattern";
  265. case Qt::Dense5Pattern:
  266. return "Dense5Pattern";
  267. case Qt::Dense6Pattern:
  268. return "Dense6Pattern";
  269. case Qt::Dense7Pattern:
  270. return "Dense7Pattern";
  271. case Qt::HorPattern:
  272. return "HorPattern";
  273. case Qt::VerPattern:
  274. return "VerPattern";
  275. case Qt::CrossPattern:
  276. return "CrossPattern";
  277. case Qt::BDiagPattern:
  278. return "BDiagPattern";
  279. case Qt::FDiagPattern:
  280. return "FDiagPattern";
  281. case Qt::DiagCrossPattern:
  282. return "DiagCrossPattern";
  283. default: // should not happen (but can for a custom pattern)
  284. return "SolidPattern";
  285. }
  286. }
  287. bool readStringNode( const TQDomElement& element, TQString& value )
  288. {
  289. value = element.text();
  290. return true;
  291. }
  292. bool readIntNode( const TQDomElement& element, int& value )
  293. {
  294. bool ok = false;
  295. int temp = element.text().toInt( &ok );
  296. if( ok )
  297. value = temp;
  298. return ok;
  299. }
  300. bool readDoubleNode( const TQDomElement& element, double& value )
  301. {
  302. bool ok = false;
  303. double temp = element.text().toDouble( &ok );
  304. if( ok )
  305. value = temp;
  306. return ok;
  307. }
  308. bool readBoolNode( const TQDomElement& element, bool& value )
  309. {
  310. if( element.text() == "true" ) {
  311. value = true;
  312. return true;
  313. } else if( element.text() == "false" ) {
  314. value = false;
  315. return true;
  316. } else
  317. return false;
  318. }
  319. bool readColorNode( const TQDomElement& element, TQColor& value )
  320. {
  321. bool ok = true;
  322. int red, green, blue;
  323. if( element.hasAttribute( "Red" ) ) {
  324. bool redOk = false;
  325. red = element.attribute( "Red" ).toInt( &redOk );
  326. ok = ok & redOk;
  327. }
  328. if( element.hasAttribute( "Green" ) ) {
  329. bool greenOk = false;
  330. green = element.attribute( "Green" ).toInt( &greenOk );
  331. ok = ok & greenOk;
  332. }
  333. if( element.hasAttribute( "Blue" ) ) {
  334. bool blueOk = false;
  335. blue = element.attribute( "Blue" ).toInt( &blueOk );
  336. ok = ok & blueOk;
  337. }
  338. if( ok )
  339. value.setRgb( red, green, blue );
  340. return ok;
  341. }
  342. bool readBrushNode( const TQDomElement& element, TQBrush& brush )
  343. {
  344. bool ok = true;
  345. TQColor tempColor;
  346. Qt::BrushStyle tempStyle;
  347. TQPixmap tempPixmap;
  348. TQDomNode node = element.firstChild();
  349. while( !node.isNull() ) {
  350. TQDomElement element = node.toElement();
  351. if( !element.isNull() ) { // was really an element
  352. TQString tagName = element.tagName();
  353. if( tagName == "Color" ) {
  354. ok = ok & readColorNode( element, tempColor );
  355. } else if( tagName == "Style" ) {
  356. TQString value;
  357. ok = ok & readStringNode( element, value );
  358. tempStyle = stringToBrushStyle( value );
  359. } else if( tagName == "Pixmap" ) {
  360. ok = ok & readPixmapNode( element, tempPixmap );
  361. } else {
  362. tqDebug( "Unknown tag in brush" );
  363. }
  364. }
  365. node = node.nextSibling();
  366. }
  367. if( ok ) {
  368. brush.setColor( tempColor );
  369. brush.setStyle( tempStyle );
  370. if( !tempPixmap.isNull() )
  371. brush.setPixmap( tempPixmap );
  372. }
  373. return ok;
  374. }
  375. bool readPixmapNode( const TQDomElement& element, TQPixmap& pixmap )
  376. {
  377. bool ok = true;
  378. int tempLengthi;
  379. TQString tempData;
  380. TQDomNode node = element.firstChild();
  381. while( !node.isNull() ) {
  382. TQDomElement element = node.toElement();
  383. if( !element.isNull() ) { // was really an element
  384. TQString tagName = element.tagName();
  385. if( tagName == "Format" ) {
  386. TQString formatName;
  387. ok = ok & readStringNode( element, formatName );
  388. #ifndef NDEBUG
  389. if( formatName != "XPM.GZ" )
  390. tqDebug( "Unsupported pixmap format in XML file" );
  391. #endif
  392. } else if( tagName == "Length" ) {
  393. ok = ok & readIntNode( element, tempLengthi );
  394. } else if( tagName == "Data" ) {
  395. ok = ok & readStringNode( element, tempData );
  396. } else {
  397. tqDebug( "Unknown tag in Pixmap" );
  398. }
  399. }
  400. node = node.nextSibling();
  401. }
  402. if( ok ) {
  403. if( 0 < tempLengthi ) {
  404. // Decode the image file format in the same way TQt Designer does.
  405. char *ba = new char[ tempData.length() / 2 ];
  406. for ( int i = 0; i < (int)tempData.length() / 2; ++i ) {
  407. char h = tempData[ 2 * i ].latin1();
  408. char l = tempData[ 2 * i + 1 ].latin1();
  409. uchar r = 0;
  410. if ( h <= '9' )
  411. r += h - '0';
  412. else
  413. r += h - 'a' + 10;
  414. r = r << 4;
  415. if ( l <= '9' )
  416. r += l - '0';
  417. else
  418. r += l - 'a' + 10;
  419. ba[ i ] = r;
  420. }
  421. if( tempLengthi < (int)tempData.length() * 5 )
  422. tempLengthi = tempData.length() * 5;
  423. unsigned long tempLength = tempLengthi;
  424. TQByteArray baunzip( tempLength );
  425. ::uncompress( (uchar*) baunzip.data(), &tempLength,
  426. (uchar*) ba, tempData.length()/2 );
  427. TQImage image;
  428. image.loadFromData( (const uchar*)baunzip.data(), tempLength, "XPM" );
  429. if( image.isNull() )
  430. pixmap.resize( 0, 0 ); // This is _not_ an error, we just read a NULL pixmap!
  431. else
  432. ok = ok & pixmap.convertFromImage( image, 0 );
  433. } else
  434. pixmap.resize( 0, 0 ); // This is _not_ an error, we just read a empty pixmap!
  435. }
  436. return ok;
  437. }
  438. bool readPenNode( const TQDomElement& element, TQPen& pen )
  439. {
  440. bool ok = true;
  441. int tempWidth;
  442. TQColor tempColor;
  443. Qt::PenStyle tempStyle;
  444. TQDomNode node = element.firstChild();
  445. while( !node.isNull() ) {
  446. TQDomElement element = node.toElement();
  447. if( !element.isNull() ) { // was really an element
  448. TQString tagName = element.tagName();
  449. if( tagName == "Width" ) {
  450. ok = ok & readIntNode( element, tempWidth );
  451. } else if( tagName == "Color" ) {
  452. ok = ok & readColorNode( element, tempColor );
  453. } else if( tagName == "Style" ) {
  454. TQString value;
  455. ok = ok & readStringNode( element, value );
  456. tempStyle = stringToPenStyle( value );
  457. } else {
  458. tqDebug( "Unknown tag in brush" );
  459. }
  460. }
  461. node = node.nextSibling();
  462. }
  463. if( ok ) {
  464. pen.setWidth( tempWidth );
  465. pen.setColor( tempColor );
  466. pen.setStyle( tempStyle );
  467. }
  468. return ok;
  469. }
  470. bool readFontNode( const TQDomElement& element, TQFont& font )
  471. {
  472. bool ok = true;
  473. TQString family;
  474. int pointSize, pixelSize, weight;
  475. bool italic;
  476. int charSet;
  477. TQDomNode node = element.firstChild();
  478. while( !node.isNull() ) {
  479. TQDomElement element = node.toElement();
  480. if( !element.isNull() ) { // was really an element
  481. TQString tagName = element.tagName();
  482. if( tagName == "Family" ) {
  483. ok = ok & readStringNode( element, family );
  484. } else if( tagName == "PointSize" ) {
  485. ok = ok & readIntNode( element, pointSize );
  486. } else if( tagName == "PixelSize" ) {
  487. ok = ok & readIntNode( element, pixelSize );
  488. } else if( tagName == "Weight" ) {
  489. ok = ok & readIntNode( element, weight );
  490. } else if( tagName == "Italic" ) {
  491. ok = ok & readBoolNode( element, italic );
  492. } else if( tagName == "CharSet" ) {
  493. ok = ok & readIntNode( element, charSet );
  494. } else {
  495. tqDebug( "Unknown tag in color map" );
  496. }
  497. }
  498. node = node.nextSibling();
  499. }
  500. if( ok ) {
  501. font.setFamily( family );
  502. if ( pointSize > 0 ) font.setPointSize( pointSize );
  503. if ( pixelSize > 0 ) font.setPixelSize( pixelSize );
  504. font.setWeight( weight );
  505. font.setItalic( italic );
  506. }
  507. return ok;
  508. }
  509. bool readRectNode( const TQDomElement& element, TQRect& value )
  510. {
  511. bool ok = true;
  512. int width, height, x, y;
  513. TQDomNode node = element.firstChild();
  514. while( !node.isNull() ) {
  515. TQDomElement element = node.toElement();
  516. if( !element.isNull() ) { // was really an element
  517. TQString tagName = element.tagName();
  518. if( tagName == "Width" ) {
  519. ok = ok & readIntNode( element, width );
  520. } else if( tagName == "Height" ) {
  521. ok = ok & readIntNode( element, height );
  522. } else if( tagName == "X" ) {
  523. ok = ok & readIntNode( element, x );
  524. } else if( tagName == "Y" ) {
  525. ok = ok & readIntNode( element, y );
  526. } else {
  527. tqDebug( "Unknown tag in rect" );
  528. }
  529. }
  530. node = node.nextSibling();
  531. }
  532. if( ok ) {
  533. value.setX( x );
  534. value.setY( y );
  535. value.setWidth( width );
  536. value.setHeight( height );
  537. }
  538. return ok;
  539. }
  540. bool readDateTimeNode( const TQDomElement& element, TQDateTime& datetime )
  541. {
  542. bool ok = true;
  543. TQDate tempDate;
  544. TQTime tempTime;
  545. TQDomNode node = element.firstChild();
  546. while( !node.isNull() ) {
  547. TQDomElement element = node.toElement();
  548. if( !element.isNull() ) { // was really an element
  549. TQString tagName = element.tagName();
  550. if( tagName == "Date" ) {
  551. ok = ok & readDateNode( element, tempDate );
  552. } else if( tagName == "Time" ) {
  553. ok = ok & readTimeNode( element, tempTime );
  554. } else {
  555. tqDebug( "Unknown tag in datetime" );
  556. }
  557. }
  558. node = node.nextSibling();
  559. }
  560. if( ok ) {
  561. datetime.setDate( tempDate );
  562. datetime.setTime( tempTime );
  563. }
  564. return ok;
  565. }
  566. bool readDateNode( const TQDomElement& element, TQDate& value )
  567. {
  568. bool ok = true;
  569. int year, month, day;
  570. if( element.hasAttribute( "Year" ) ) {
  571. bool yearOk = false;
  572. year = element.attribute( "Year" ).toInt( &yearOk );
  573. ok = ok & yearOk;
  574. }
  575. if( element.hasAttribute( "Month" ) ) {
  576. bool monthOk = false;
  577. month = element.attribute( "Month" ).toInt( &monthOk );
  578. ok = ok & monthOk;
  579. }
  580. if( element.hasAttribute( "Day" ) ) {
  581. bool dayOk = false;
  582. day = element.attribute( "Day" ).toInt( &dayOk );
  583. ok = ok & dayOk;
  584. }
  585. if( ok )
  586. value.setYMD( year, month, day );
  587. return ok;
  588. }
  589. bool readTimeNode( const TQDomElement& element, TQTime& value )
  590. {
  591. bool ok = true;
  592. int hour, minute, second, msec;
  593. if( element.hasAttribute( "Hour" ) ) {
  594. bool hourOk = false;
  595. hour = element.attribute( "Hour" ).toInt( &hourOk );
  596. ok = ok & hourOk;
  597. }
  598. if( element.hasAttribute( "Minute" ) ) {
  599. bool minuteOk = false;
  600. minute = element.attribute( "Minute" ).toInt( &minuteOk );
  601. ok = ok & minuteOk;
  602. }
  603. if( element.hasAttribute( "Second" ) ) {
  604. bool secondOk = false;
  605. second = element.attribute( "Second" ).toInt( &secondOk );
  606. ok = ok & secondOk;
  607. }
  608. if( element.hasAttribute( "Millisecond" ) ) {
  609. bool msecOk = false;
  610. msec = element.attribute( "Millisecond" ).toInt( &msecOk );
  611. ok = ok & msecOk;
  612. }
  613. if( ok )
  614. value.setHMS( hour, minute, second, msec );
  615. return ok;
  616. }
  617. Qt::PenStyle stringToPenStyle( const TQString& style )
  618. {
  619. if( style == "NoPen" )
  620. return Qt::NoPen;
  621. else if( style == "SolidLine" )
  622. return Qt::SolidLine;
  623. else if( style == "DashLine" )
  624. return Qt::DashLine;
  625. else if( style == "DotLine" )
  626. return Qt::DotLine;
  627. else if( style == "DashDotLine" )
  628. return Qt::DashDotLine;
  629. else if( style == "DashDotDotLine" )
  630. return Qt::DashDotDotLine;
  631. else // should not happen
  632. return Qt::SolidLine;
  633. }
  634. Qt::BrushStyle stringToBrushStyle( const TQString& style )
  635. {
  636. // PENDING(kalle) Support custom patterns
  637. if( style == "NoBrush" )
  638. return Qt::NoBrush;
  639. else if( style == "SolidPattern" )
  640. return Qt::SolidPattern;
  641. else if( style == "Dense1Pattern" )
  642. return Qt::Dense1Pattern;
  643. else if( style == "Dense2Pattern" )
  644. return Qt::Dense2Pattern;
  645. else if( style == "Dense3Pattern" )
  646. return Qt::Dense3Pattern;
  647. else if( style == "Dense4Pattern" )
  648. return Qt::Dense4Pattern;
  649. else if( style == "Dense5Pattern" )
  650. return Qt::Dense5Pattern;
  651. else if( style == "Dense6Pattern" )
  652. return Qt::Dense6Pattern;
  653. else if( style == "Dense7Pattern" )
  654. return Qt::Dense7Pattern;
  655. else if( style == "HorPattern" )
  656. return Qt::HorPattern;
  657. else if( style == "VerPattern" )
  658. return Qt::VerPattern;
  659. else if( style == "CrossPattern" )
  660. return Qt::CrossPattern;
  661. else if( style == "BDiagPattern" )
  662. return Qt::BDiagPattern;
  663. else if( style == "FDiagPattern" )
  664. return Qt::FDiagPattern;
  665. else if( style == "DiagCrossPattern" )
  666. return Qt::DiagCrossPattern;
  667. else // should not happen (but can with custom patterns)
  668. return Qt::SolidPattern;
  669. }
  670. }