kdgantt

KDGanttXMLTools.cpp

00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttXMLTools.cpp 481513 2005-11-19 10:59:10Z coolo $
00003    KDGantt - a multi-platform charting engine
00004 */
00005 
00006 /****************************************************************************
00007  ** Copyright (C)  2002-2004 Klarälvdalens Datakonsult AB.  All rights reserved.
00008  **
00009  ** This file is part of the KDGantt library.
00010  **
00011  ** This file may be distributed and/or modified under the terms of the
00012  ** GNU General Public License version 2 as published by the Free Software
00013  ** Foundation and appearing in the file LICENSE.GPL included in the
00014  ** packaging of this file.
00015  **
00016  ** Licensees holding valid commercial KDGantt licenses may use this file in
00017  ** accordance with the KDGantt Commercial License Agreement provided with
00018  ** the Software.
00019  **
00020  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022  **
00023  ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
00024  **   information about KDGantt Commercial License Agreements.
00025  **
00026  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00027  ** licensing are not clear to you.
00028  **
00029  ** As a special exception, permission is given to link this program
00030  ** with any edition of Qt, and distribute the resulting executable,
00031  ** without including the source code for Qt in the source distribution.
00032  **
00033  **********************************************************************/
00034 
00035 #include "KDGanttXMLTools.h"
00036 #include <qbrush.h>
00037 #include <qbuffer.h>
00038 #include <qimage.h>
00039 #include <zlib.h>
00040 
00041 namespace KDGanttXML {
00042 
00043 void createBoolNode( QDomDocument& doc, QDomNode& parent,
00044                      const QString& elementName, bool value )
00045 {
00046     QDomElement newElement =
00047         doc.createElement( elementName );
00048     parent.appendChild( newElement );
00049     QDomText elementContent =
00050         doc.createTextNode( value ? "true" : "false" );
00051     newElement.appendChild( elementContent );
00052 }
00053 
00054 
00055 
00056 void createSizeNode( QDomDocument& doc, QDomNode& parent,
00057                      const QString& elementName, const QSize& value )
00058 {
00059     QDomElement newElement =
00060         doc.createElement( elementName );
00061     parent.appendChild( newElement );
00062     newElement.setAttribute( "Width", value.width() );
00063     newElement.setAttribute( "Height", value.height() );
00064 }
00065 
00066 
00067 void createIntNode( QDomDocument& doc, QDomNode& parent,
00068                     const QString& elementName, int value )
00069 {
00070     QDomElement newElement =
00071         doc.createElement( elementName );
00072     parent.appendChild( newElement );
00073     QDomText elementContent =
00074         doc.createTextNode( QString::number( value ) );
00075     newElement.appendChild( elementContent );
00076 }
00077 
00078 
00079 void createDoubleNode( QDomDocument& doc, QDomNode& parent,
00080                        const QString& elementName, double value )
00081 {
00082     QDomElement newElement =
00083         doc.createElement( elementName );
00084     parent.appendChild( newElement );
00085     QDomText elementContent =
00086         doc.createTextNode( QString::number( value ) );
00087     newElement.appendChild( elementContent );
00088 }
00089 
00090 
00091 void createStringNode( QDomDocument& doc, QDomNode& parent,
00092                        const QString& elementName,
00093                        const QString& text )
00094 {
00095     QDomElement newElement =
00096         doc.createElement( elementName );
00097     parent.appendChild( newElement );
00098     QDomText elementContent =
00099         doc.createTextNode( text );
00100     newElement.appendChild( elementContent );
00101 }
00102 
00103 
00104 void createColorNode( QDomDocument& doc, QDomNode& parent,
00105                       const QString& elementName, const QColor& color )
00106 {
00107     QDomElement colorElement = doc.createElement( elementName );
00108     parent.appendChild( colorElement );
00109     colorElement.setAttribute( "Red",
00110                                QString::number( color.red() ) );
00111     colorElement.setAttribute( "Green",
00112                                QString::number( color.green() ) );
00113     colorElement.setAttribute( "Blue",
00114                                QString::number( color.blue() ) );
00115 }
00116 
00117 
00118 void createBrushNode( QDomDocument& doc, QDomNode& parent,
00119                       const QString& elementName, const QBrush& brush )
00120 
00121 {
00122     QDomElement brushElement = doc.createElement( elementName );
00123     parent.appendChild( brushElement );
00124     createColorNode( doc, brushElement, "Color", brush.color() );
00125     createStringNode( doc, brushElement, "Style",
00126                       KDGanttXML::brushStyleToString( brush.style() ) );
00127     if( brush.style() == Qt::CustomPattern && brush.pixmap() )
00128         createPixmapNode( doc, brushElement, "Pixmap", *brush.pixmap() );
00129 }
00130 
00131 
00132 void createPixmapNode( QDomDocument& doc, QDomNode& parent,
00133                        const QString& elementName, const QPixmap& pixmap )
00134 {
00135     QDomElement pixmapElement = doc.createElement( elementName );
00136     parent.appendChild( pixmapElement );
00137 
00138     // Convert the pixmap to an image, save that image to an in-memory
00139     // XPM representation and compress this representation. This
00140     // conforms to the file format Qt Designer uses.
00141     QByteArray ba;
00142     QBuffer buffer( ba );
00143     buffer.open( IO_WriteOnly );
00144     QImageIO imgio( &buffer, "XPM" );
00145     QImage image = pixmap.convertToImage();
00146     imgio.setImage( image );
00147     imgio.write();
00148     buffer.close();
00149     ulong len = ba.size() * 2;
00150     QByteArray bazip( len );
00151     ::compress(  (uchar*) bazip.data(), &len, (uchar*) ba.data(), ba.size() );
00152     QString dataString;
00153     static const char hexchars[] = "0123456789abcdef";
00154     for ( int i = 0; i < (int)len; ++i ) {
00155         uchar c = (uchar) bazip[i];
00156         dataString += hexchars[c >> 4];
00157         dataString += hexchars[c & 0x0f];
00158     }
00159 
00160     createStringNode( doc, pixmapElement, "Format", "XPM.GZ" );
00161     createIntNode( doc, pixmapElement, "Length", ba.size() );
00162     createStringNode( doc, pixmapElement, "Data", dataString );
00163 }
00164 
00165 
00166 void createRectNode( QDomDocument& doc, QDomNode& parent,
00167                      const QString& elementName, const QRect& rect )
00168 {
00169     QDomElement rectElement = doc.createElement( elementName );
00170     parent.appendChild( rectElement );
00171     QDomElement xElement = doc.createElement( "X" );
00172     rectElement.appendChild( xElement );
00173     QDomText xContent = doc.createTextNode( QString::number( rect.x() ) );
00174     xElement.appendChild( xContent );
00175     QDomElement yElement = doc.createElement( "Y" );
00176     rectElement.appendChild( yElement );
00177     QDomText yContent = doc.createTextNode( QString::number( rect.y() ) );
00178     yElement.appendChild( yContent );
00179     QDomElement widthElement = doc.createElement( "Width" );
00180     rectElement.appendChild( widthElement );
00181     QDomText widthContent = doc.createTextNode( QString::number( rect.width() ) );
00182     widthElement.appendChild( widthContent );
00183     QDomElement heightElement = doc.createElement( "Height" );
00184     rectElement.appendChild( heightElement );
00185     QDomText heightContent = doc.createTextNode( QString::number( rect.height() ) );
00186     heightElement.appendChild( heightContent );
00187 }
00188 
00189 
00190 void createStringListNodes( QDomDocument& doc, QDomNode& parent,
00191                             const QString& elementName,
00192                             const QStringList* list )
00193 {
00194     if( !list )
00195         return;
00196 
00197     for( QStringList::ConstIterator it = list->begin();
00198          it != list->end(); ++it ) {
00199         QDomElement element = doc.createElement( elementName );
00200         parent.appendChild( element );
00201         QDomText elementContent = doc.createTextNode( *it );
00202         element.appendChild( elementContent );
00203     }
00204 }
00205 
00206 
00207 void createFontNode( QDomDocument& doc, QDomNode& parent,
00208                      const QString& elementName, const QFont& font )
00209 {
00210     QDomElement fontElement = doc.createElement( elementName );
00211     parent.appendChild( fontElement );
00212     createStringNode( doc, fontElement, "Family", font.family() );
00213     createIntNode( doc, fontElement, "PointSize", font.pointSize() );
00214     createIntNode( doc, fontElement, "PixelSize", font.pixelSize() );
00215     createIntNode( doc, fontElement, "Weight", font.weight() );
00216     createBoolNode( doc, fontElement, "Italic", font.italic() );
00217 #if QT_VERSION < 300
00218     // Qt 3 handles the charset internally.
00219     createIntNode( doc, fontElement, "CharSet", font.charSet() );
00220 #endif
00221 }
00222 
00223 
00224 void createPenNode( QDomDocument& doc, QDomNode& parent,
00225                     const QString& elementName, const QPen& pen )
00226 {
00227     QDomElement penElement = doc.createElement( elementName );
00228     parent.appendChild( penElement );
00229     createIntNode( doc, penElement, "Width", pen.width() );
00230     createColorNode( doc, penElement, "Color", pen.color() );
00231     createStringNode( doc, penElement, "Style", penStyleToString( pen.style() ) );
00232 }
00233 
00234 
00235 void createDateTimeNode( QDomDocument& doc, QDomNode& parent,
00236                          const QString& elementName,
00237                          const QDateTime& datetime )
00238 {
00239     QDomElement dateTimeElement = doc.createElement( elementName );
00240     parent.appendChild( dateTimeElement );
00241     createDateNode( doc, dateTimeElement, "Date", datetime.date() );
00242     createTimeNode( doc, dateTimeElement, "Time", datetime.time() );
00243 }
00244 
00245 
00246 void createDateNode( QDomDocument& doc, QDomNode& parent,
00247                      const QString& elementName, const QDate& date )
00248 {
00249     QDomElement dateElement = doc.createElement( elementName );
00250     parent.appendChild( dateElement );
00251     dateElement.setAttribute( "Year", QString::number( date.year() ) );
00252     dateElement.setAttribute( "Month", QString::number( date.month() ) );
00253     dateElement.setAttribute( "Day", QString::number( date.day() ) );
00254 }
00255 
00256 
00257 void createTimeNode( QDomDocument& doc, QDomNode& parent,
00258                       const QString& elementName, const QTime& time )
00259 {
00260     QDomElement timeElement = doc.createElement( elementName );
00261     parent.appendChild( timeElement );
00262     timeElement.setAttribute( "Hour",
00263                                QString::number( time.hour() ) );
00264     timeElement.setAttribute( "Minute",
00265                                QString::number( time.minute() ) );
00266     timeElement.setAttribute( "Second",
00267                                QString::number( time.second() ) );
00268     timeElement.setAttribute( "Millisecond",
00269                                QString::number( time.msec() ) );
00270 }
00271 
00272 
00273 QString penStyleToString( Qt::PenStyle style )
00274 {
00275     switch( style ) {
00276     case Qt::NoPen:
00277         return "NoPen";
00278     case Qt::SolidLine:
00279         return "SolidLine";
00280     case Qt::DashLine:
00281         return "DashLine";
00282     case Qt::DotLine:
00283         return "DotLine";
00284     case Qt::DashDotLine:
00285         return "DashDotLine";
00286     case Qt::DashDotDotLine:
00287         return "DashDotDotLine";
00288     default: // should not happen
00289         return "SolidLine";
00290     }
00291 }
00292 
00293 
00294 
00295 QString brushStyleToString( Qt::BrushStyle style )
00296 {
00297     // PENDING(kalle) Support custom patterns
00298     switch( style ) {
00299     case Qt::NoBrush:
00300         return "NoBrush";
00301     case Qt::SolidPattern:
00302         return "SolidPattern";
00303     case Qt::Dense1Pattern:
00304         return "Dense1Pattern";
00305     case Qt::Dense2Pattern:
00306         return "Dense2Pattern";
00307     case Qt::Dense3Pattern:
00308         return "Dense3Pattern";
00309     case Qt::Dense4Pattern:
00310         return "Dense4Pattern";
00311     case Qt::Dense5Pattern:
00312         return "Dense5Pattern";
00313     case Qt::Dense6Pattern:
00314         return "Dense6Pattern";
00315     case Qt::Dense7Pattern:
00316         return "Dense7Pattern";
00317     case Qt::HorPattern:
00318         return "HorPattern";
00319     case Qt::VerPattern:
00320         return "VerPattern";
00321     case Qt::CrossPattern:
00322         return "CrossPattern";
00323     case Qt::BDiagPattern:
00324         return "BDiagPattern";
00325     case Qt::FDiagPattern:
00326         return "FDiagPattern";
00327     case Qt::DiagCrossPattern:
00328         return "DiagCrossPattern";
00329     default: // should not happen (but can for a custom pattern)
00330         return "SolidPattern";
00331     }
00332 }
00333 
00334 
00335 bool readStringNode( const QDomElement& element, QString& value )
00336 {
00337     value = element.text();
00338     return true;
00339 }
00340 
00341 
00342 bool readIntNode( const QDomElement& element, int& value )
00343 {
00344     bool ok = false;
00345     int temp = element.text().toInt( &ok );
00346     if( ok )
00347         value = temp;
00348     return ok;
00349 }
00350 
00351 
00352 bool readDoubleNode( const QDomElement& element, double& value )
00353 {
00354     bool ok = false;
00355     double temp = element.text().toDouble( &ok );
00356     if( ok )
00357         value = temp;
00358     return ok;
00359 }
00360 
00361 
00362 bool readBoolNode( const QDomElement& element, bool& value )
00363 {
00364     if( element.text() == "true" ) {
00365         value = true;
00366         return true;
00367     } else if( element.text() == "false" ) {
00368         value = false;
00369         return true;
00370     } else
00371         return false;
00372 }
00373 
00374 
00375 bool readColorNode( const QDomElement& element, QColor& value )
00376 {
00377     bool ok = true;
00378     int red, green, blue;
00379     if( element.hasAttribute( "Red" ) ) {
00380         bool redOk = false;
00381         red = element.attribute( "Red" ).toInt( &redOk );
00382         ok = ok & redOk;
00383     }
00384     if( element.hasAttribute( "Green" ) ) {
00385         bool greenOk = false;
00386         green = element.attribute( "Green" ).toInt( &greenOk );
00387         ok = ok & greenOk;
00388     }
00389     if( element.hasAttribute( "Blue" ) ) {
00390         bool blueOk = false;
00391         blue = element.attribute( "Blue" ).toInt( &blueOk );
00392         ok = ok & blueOk;
00393     }
00394 
00395     if( ok )
00396         value.setRgb( red, green, blue );
00397 
00398     return ok;
00399 }
00400 
00401 
00402 bool readBrushNode( const QDomElement& element, QBrush& brush )
00403 {
00404     bool ok = true;
00405     QColor tempColor;
00406     Qt::BrushStyle tempStyle;
00407     QPixmap tempPixmap;
00408     QDomNode node = element.firstChild();
00409     while( !node.isNull() ) {
00410         QDomElement element = node.toElement();
00411         if( !element.isNull() ) { // was really an element
00412             QString tagName = element.tagName();
00413             if( tagName == "Color" ) {
00414                 ok = ok & readColorNode( element, tempColor );
00415             } else if( tagName == "Style" ) {
00416         QString value;
00417                 ok = ok & readStringNode( element, value );
00418         tempStyle = stringToBrushStyle( value );
00419             } else if( tagName == "Pixmap" ) {
00420                 ok = ok & readPixmapNode( element, tempPixmap );
00421             } else {
00422                 qDebug( "Unknown tag in brush" );
00423             }
00424         }
00425         node = node.nextSibling();
00426     }
00427 
00428     if( ok ) {
00429     brush.setColor( tempColor );
00430     brush.setStyle( tempStyle );
00431         if( !tempPixmap.isNull() )
00432             brush.setPixmap( tempPixmap );
00433     }
00434 
00435     return ok;
00436 }
00437 
00438 
00439 bool readPixmapNode( const QDomElement& element, QPixmap& pixmap )
00440 {
00441     bool ok = true;
00442     int tempLengthi;
00443     QString tempData;
00444     QDomNode node = element.firstChild();
00445     while( !node.isNull() ) {
00446         QDomElement element = node.toElement();
00447         if( !element.isNull() ) { // was really an element
00448             QString tagName = element.tagName();
00449             if( tagName == "Format" ) {
00450                 QString formatName;
00451                 ok = ok & readStringNode( element, formatName );
00452 #ifndef NDEBUG
00453                 if( formatName != "XPM.GZ" )
00454                     qDebug( "Unsupported pixmap format in XML file" );
00455 #endif
00456             } else if( tagName == "Length" ) {
00457                 ok = ok & readIntNode( element, tempLengthi );
00458             } else if( tagName == "Data" ) {
00459                 ok = ok & readStringNode( element, tempData );
00460             } else {
00461                 qDebug( "Unknown tag in Pixmap" );
00462             }
00463         }
00464         node = node.nextSibling();
00465     }
00466 
00467     if( ok ) {
00468     if( 0 < tempLengthi ) {
00469             // Decode the image file format in the same way Qt Designer does.
00470             char *ba = new char[ tempData.length() / 2 ];
00471             for ( int i = 0; i < (int)tempData.length() / 2; ++i ) {
00472                 char h = tempData[ 2 * i ].latin1();
00473                 char l = tempData[ 2 * i  + 1 ].latin1();
00474                 uchar r = 0;
00475                 if ( h <= '9' )
00476                     r += h - '0';
00477                 else
00478                     r += h - 'a' + 10;
00479                 r = r << 4;
00480                 if ( l <= '9' )
00481                     r += l - '0';
00482                 else
00483                     r += l - 'a' + 10;
00484                 ba[ i ] = r;
00485             }
00486 
00487             if( tempLengthi < (int)tempData.length() * 5 )
00488                 tempLengthi = tempData.length() * 5;
00489             unsigned long tempLength = tempLengthi;
00490             QByteArray baunzip( tempLength );
00491             ::uncompress( (uchar*) baunzip.data(), &tempLength,
00492                           (uchar*) ba, tempData.length()/2 );
00493             QImage image;
00494             image.loadFromData( (const uchar*)baunzip.data(), tempLength, "XPM" );
00495 
00496             if( image.isNull() )
00497                 pixmap.resize( 0, 0 ); // This is _not_ an error, we just read a NULL pixmap!
00498             else
00499                 ok = ok & pixmap.convertFromImage( image, 0 );
00500         } else
00501             pixmap.resize( 0, 0 ); // This is _not_ an error, we just read a empty pixmap!
00502     }
00503 
00504     return ok;
00505 }
00506 
00507 
00508 bool readPenNode( const QDomElement& element, QPen& pen )
00509 {
00510     bool ok = true;
00511     int tempWidth;
00512     QColor tempColor;
00513     Qt::PenStyle tempStyle;
00514     QDomNode node = element.firstChild();
00515     while( !node.isNull() ) {
00516         QDomElement element = node.toElement();
00517         if( !element.isNull() ) { // was really an element
00518             QString tagName = element.tagName();
00519             if( tagName == "Width" ) {
00520                 ok = ok & readIntNode( element, tempWidth );
00521             } else if( tagName == "Color" ) {
00522                 ok = ok & readColorNode( element, tempColor );
00523             } else if( tagName == "Style" ) {
00524         QString value;
00525                 ok = ok & readStringNode( element, value );
00526         tempStyle = stringToPenStyle( value );
00527             } else {
00528                 qDebug( "Unknown tag in brush" );
00529             }
00530         }
00531         node = node.nextSibling();
00532     }
00533 
00534     if( ok ) {
00535         pen.setWidth( tempWidth );
00536     pen.setColor( tempColor );
00537     pen.setStyle( tempStyle );
00538     }
00539 
00540     return ok;
00541 }
00542 
00543 bool readFontNode( const QDomElement& element, QFont& font )
00544 {
00545     bool ok = true;
00546     QString family;
00547     int pointSize, pixelSize, weight;
00548     bool italic;
00549     int charSet;
00550     QDomNode node = element.firstChild();
00551     while( !node.isNull() ) {
00552         QDomElement element = node.toElement();
00553         if( !element.isNull() ) { // was really an element
00554             QString tagName = element.tagName();
00555             if( tagName == "Family" ) {
00556                 ok = ok & readStringNode( element, family );
00557             } else if( tagName == "PointSize" ) {
00558                 ok = ok & readIntNode( element, pointSize );
00559             } else if( tagName == "PixelSize" ) {
00560                 ok = ok & readIntNode( element, pixelSize );
00561             } else if( tagName == "Weight" ) {
00562                 ok = ok & readIntNode( element, weight );
00563             } else if( tagName == "Italic" ) {
00564                 ok = ok & readBoolNode( element, italic );
00565             } else if( tagName == "CharSet" ) {
00566                 ok = ok & readIntNode( element, charSet );
00567             } else {
00568                 qDebug( "Unknown tag in color map" );
00569             }
00570         }
00571         node = node.nextSibling();
00572     }
00573 
00574     if( ok ) {
00575         font.setFamily( family );
00576     if ( pointSize > 0 ) font.setPointSize( pointSize );
00577     if ( pixelSize > 0 ) font.setPixelSize( pixelSize );
00578         font.setWeight( weight );
00579         font.setItalic( italic );
00580 #if QT_VERSION < 300
00581         // Qt 3 handles charsets internally.
00582         font.setCharSet( (QFont::CharSet)charSet );
00583 #endif
00584     }
00585 
00586     return ok;
00587 }
00588 
00589 bool readRectNode( const QDomElement& element, QRect& value )
00590 {
00591     bool ok = true;
00592     int width, height, x, y;
00593     QDomNode node = element.firstChild();
00594     while( !node.isNull() ) {
00595         QDomElement element = node.toElement();
00596         if( !element.isNull() ) { // was really an element
00597             QString tagName = element.tagName();
00598             if( tagName == "Width" ) {
00599                 ok = ok & readIntNode( element, width );
00600             } else if( tagName == "Height" ) {
00601                 ok = ok & readIntNode( element, height );
00602             } else if( tagName == "X" ) {
00603                 ok = ok & readIntNode( element, x );
00604             } else if( tagName == "Y" ) {
00605                 ok = ok & readIntNode( element, y );
00606             } else {
00607                 qDebug( "Unknown tag in rect" );
00608             }
00609         }
00610         node = node.nextSibling();
00611     }
00612 
00613     if( ok ) {
00614         value.setX( x );
00615         value.setY( y );
00616         value.setWidth( width );
00617         value.setHeight( height );
00618     }
00619 
00620     return ok;
00621 }
00622 
00623 
00624 
00625 bool readDateTimeNode( const QDomElement& element, QDateTime& datetime )
00626 {
00627     bool ok = true;
00628     QDate tempDate;
00629     QTime tempTime;
00630     QDomNode node = element.firstChild();
00631     while( !node.isNull() ) {
00632         QDomElement element = node.toElement();
00633         if( !element.isNull() ) { // was really an element
00634             QString tagName = element.tagName();
00635             if( tagName == "Date" ) {
00636                 ok = ok & readDateNode( element, tempDate );
00637             } else if( tagName == "Time" ) {
00638                 ok = ok & readTimeNode( element, tempTime );
00639             } else {
00640                 qDebug( "Unknown tag in datetime" );
00641             }
00642         }
00643         node = node.nextSibling();
00644     }
00645 
00646     if( ok ) {
00647         datetime.setDate( tempDate );
00648         datetime.setTime( tempTime );
00649     }
00650 
00651     return ok;
00652 }
00653 
00654 
00655 bool readDateNode( const QDomElement& element, QDate& value )
00656 {
00657     bool ok = true;
00658     int year, month, day;
00659     if( element.hasAttribute( "Year" ) ) {
00660         bool yearOk = false;
00661         year = element.attribute( "Year" ).toInt( &yearOk );
00662         ok = ok & yearOk;
00663     }
00664     if( element.hasAttribute( "Month" ) ) {
00665         bool monthOk = false;
00666         month = element.attribute( "Month" ).toInt( &monthOk );
00667         ok = ok & monthOk;
00668     }
00669     if( element.hasAttribute( "Day" ) ) {
00670         bool dayOk = false;
00671         day = element.attribute( "Day" ).toInt( &dayOk );
00672         ok = ok & dayOk;
00673     }
00674 
00675     if( ok )
00676         value.setYMD( year, month, day );
00677 
00678     return ok;
00679 }
00680 
00681 
00682 
00683 bool readTimeNode( const QDomElement& element, QTime& value )
00684 {
00685     bool ok = true;
00686     int hour, minute, second, msec;
00687     if( element.hasAttribute( "Hour" ) ) {
00688         bool hourOk = false;
00689         hour = element.attribute( "Hour" ).toInt( &hourOk );
00690         ok = ok & hourOk;
00691     }
00692     if( element.hasAttribute( "Minute" ) ) {
00693         bool minuteOk = false;
00694         minute = element.attribute( "Minute" ).toInt( &minuteOk );
00695         ok = ok & minuteOk;
00696     }
00697     if( element.hasAttribute( "Second" ) ) {
00698         bool secondOk = false;
00699         second = element.attribute( "Second" ).toInt( &secondOk );
00700         ok = ok & secondOk;
00701     }
00702     if( element.hasAttribute( "Millisecond" ) ) {
00703         bool msecOk = false;
00704         msec = element.attribute( "Millisecond" ).toInt( &msecOk );
00705         ok = ok & msecOk;
00706     }
00707 
00708     if( ok )
00709         value.setHMS( hour, minute, second, msec );
00710 
00711     return ok;
00712 }
00713 
00714 
00715 
00716 Qt::PenStyle stringToPenStyle( const QString& style )
00717 {
00718     if( style == "NoPen" )
00719         return Qt::NoPen;
00720     else if( style == "SolidLine" )
00721         return Qt::SolidLine;
00722     else if( style == "DashLine" )
00723         return Qt::DashLine;
00724     else if( style == "DotLine" )
00725         return Qt::DotLine;
00726     else if( style == "DashDotLine" )
00727         return Qt::DashDotLine;
00728     else if( style == "DashDotDotLine" )
00729         return Qt::DashDotDotLine;
00730     else // should not happen
00731         return Qt::SolidLine;
00732 }
00733 
00734 
00735 Qt::BrushStyle stringToBrushStyle( const QString& style )
00736 {
00737     // PENDING(kalle) Support custom patterns
00738     if( style == "NoBrush" )
00739         return Qt::NoBrush;
00740     else if( style == "SolidPattern" )
00741         return Qt::SolidPattern;
00742     else if( style == "Dense1Pattern" )
00743         return Qt::Dense1Pattern;
00744     else if( style == "Dense2Pattern" )
00745         return Qt::Dense2Pattern;
00746     else if( style == "Dense3Pattern" )
00747         return Qt::Dense3Pattern;
00748     else if( style == "Dense4Pattern" )
00749         return Qt::Dense4Pattern;
00750     else if( style == "Dense5Pattern" )
00751         return Qt::Dense5Pattern;
00752     else if( style == "Dense6Pattern" )
00753         return Qt::Dense6Pattern;
00754     else if( style == "Dense7Pattern" )
00755         return Qt::Dense7Pattern;
00756     else if( style == "HorPattern" )
00757         return Qt::HorPattern;
00758     else if( style == "VerPattern" )
00759         return Qt::VerPattern;
00760     else if( style == "CrossPattern" )
00761         return Qt::CrossPattern;
00762     else if( style == "BDiagPattern" )
00763         return Qt::BDiagPattern;
00764     else if( style == "FDiagPattern" )
00765         return Qt::FDiagPattern;
00766     else if( style == "DiagCrossPattern" )
00767         return Qt::DiagCrossPattern;
00768     else // should not happen (but can with custom patterns)
00769         return Qt::SolidPattern;
00770 }
00771 
00772 }
KDE Home | KDE Accessibility Home | Description of Access Keys