lib Library API Documentation

koGenStyles.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016    Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #ifndef KOGENSTYLES_H
00020 #define KOGENSTYLES_H
00021 
00022 #include <qdict.h>
00023 #include <qmap.h>
00024 #include <qvaluevector.h>
00025 
00026 #include <koffice_export.h>
00027 
00028 class KoXmlWriter;
00029 class KoGenStyle;
00030 
00059 class KOFFICECORE_EXPORT KoGenStyles
00060 {
00061 public:
00062     KoGenStyles();
00063     ~KoGenStyles();
00064 
00082     QString lookup( const KoGenStyle& style, const QString& name = QString::null, bool forceNumbering = true );
00083 
00084     typedef QMap<KoGenStyle, QString> StyleMap;
00089     const StyleMap& styles() const { return m_styleMap; }
00090 
00091     struct NamedStyle {
00092         const KoGenStyle* style; 
00093         QString name;
00094     };
00104     QValueList<NamedStyle> styles( int type, bool markedForStylesXml = false ) const;
00105 
00109     const KoGenStyle* style( const QString& name ) const;
00110 
00118     KoGenStyle* styleForModification( const QString& name );
00119 
00133     void markStyleForStylesXml( const QString& name );
00134 
00135 private:
00136     QString makeUniqueName( const QString& base, bool forceNumbering ) const;
00137 
00139     StyleMap m_styleMap;
00140 
00145     typedef QMap<QString, bool> NameMap;
00146     NameMap m_styleNames;
00147 
00149     typedef QValueVector<NamedStyle> StyleArray;
00150     StyleArray m_styleArray;
00151 
00152     class Private;
00153     Private *d;
00154 };
00155 
00163 class KOFFICECORE_EXPORT KoGenStyle
00164 {
00165 public:
00173     enum { STYLE_PAGELAYOUT = 0,
00174            STYLE_USER = 1,
00175            STYLE_AUTO = 2,
00176            STYLE_MASTER = 3,
00177            STYLE_LIST = 4,
00178            STYLE_AUTO_LIST = 5,
00179            // 6 is available
00180            STYLE_NUMERIC_DATE = 7,
00181        STYLE_NUMERIC_TIME = 8,
00182            STYLE_NUMERIC_FRACTION = 9,
00183            STYLE_NUMERIC_PERCENTAGE = 10,
00184            STYLE_NUMERIC_SCIENTIFIC = 11,
00185            STYLE_NUMERIC_CURRENCY = 12,
00186        STYLE_NUMERIC_TEXT = 13,
00187            STYLE_HATCH = 14,
00188            STYLE_GRAPHICAUTO = 15};
00189 
00202     explicit KoGenStyle( int type = 0, const char* familyName = 0,
00203                          const QString& parentName = QString::null )
00204         : m_type( type ), m_familyName( familyName ), m_parentName( parentName ) {}
00205 
00207     int type() const { return m_type; }
00208 
00210     const char* familyName() const { return m_familyName.data(); }
00211 
00213     QString parentName() const { return m_parentName; }
00214 
00218     enum PropertyType
00219     {
00225         DefaultType = 0,
00227         TextType,
00228         ChildElement, 
00229 
00230         ParagraphType,
00231         N_NumTypes 
00232     };
00233 
00235     void addProperty( const QString& propName, const QString& propValue, PropertyType type = DefaultType ) {
00236         m_properties[type].insert( propName, propValue );
00237     }
00239     void addProperty( const QString& propName, const char* propValue, PropertyType type = DefaultType ) {
00240         m_properties[type].insert( propName, QString::fromUtf8( propValue ), type );
00241     }
00243     void addProperty( const QString& propName, int propValue, PropertyType type = DefaultType ) {
00244         m_properties[type].insert( propName, QString::number( propValue ), type );
00245     }
00247     void addProperty( const QString& propName, bool propValue, PropertyType type = DefaultType ) {
00248         m_properties[type].insert( propName, propValue ? "true" : "false", type );
00249     }
00250 
00257     void addPropertyPt( const QString& propName, double propValue, PropertyType type = DefaultType );
00258 
00264     void addAttribute( const QString& attrName, const QString& attrValue ) {
00265         m_attributes.insert( attrName, attrValue );
00266     }
00268     void addAttribute( const QString& attrName, const char* attrValue ) {
00269         m_attributes.insert( attrName, QString::fromUtf8( attrValue ) );
00270     }
00272     void addAttribute( const QString& attrName, int attrValue ) {
00273         m_attributes.insert( attrName, QString::number( attrValue ) );
00274     }
00275 
00277     void addAttribute( const QString& attrName, bool attrValue ) {
00278         m_attributes.insert( attrName, attrValue ? "true" : "false" );
00279     }
00280 
00287     void addAttributePt( const QString& attrName, double attrValue );
00288 
00308     void addChildElement( const QString& elementName, const QString& elementContents ) {
00309         m_properties[ChildElement].insert( elementName, elementContents );
00310     }
00311 
00316     void addStyleMap( const QMap<QString, QString>& styleMap ) {
00317         m_maps.append( styleMap );
00318     }
00319 
00332     void writeStyle( KoXmlWriter* writer, KoGenStyles& styles, const char* elementName, const QString& name,
00333                      const char* propertiesElementName, bool closeElement = true, bool drawElement = false ) const;
00334 
00342     bool operator<( const KoGenStyle &other ) const;
00343 
00345     bool operator==( const KoGenStyle &other ) const;
00346 
00347 private:
00348     QString property( const QString& propName, PropertyType type ) const {
00349         QMap<QString, QString>::const_iterator it = m_properties[type].find( propName );
00350         if ( it != m_properties[type].end() )
00351             return it.data();
00352         return QString::null;
00353     }
00354 
00355     QString attribute( const QString& propName ) const {
00356         QMap<QString, QString>::const_iterator it = m_attributes.find( propName );
00357         if ( it != m_attributes.end() )
00358             return it.data();
00359         return QString::null;
00360     }
00361 
00362 #ifndef NDEBUG
00363     void printDebug() const;
00364 #endif
00365 
00366 private:
00367     // Note that the copy constructor and assignment operator are allowed.
00368     // Better not use pointers below!
00369     int m_type;
00370     QCString m_familyName;
00371     QString m_parentName;
00373     QMap<QString, QString> m_properties[N_NumTypes];
00374     QMap<QString, QString> m_attributes;
00375     typedef QMap<QString, QString> StyleMap;
00376     QValueVector<StyleMap> m_maps; // we can't really sort the maps between themselves...
00377 
00378     // For lookup
00379     friend class KoGenStyles;
00380 };
00381 
00382 #endif /* KOGENSTYLES_H */
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:01 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003