00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00074 enum Flags {
00075 NoFlag = 0,
00076 ForceNumbering = 0,
00077 DontForceNumbering = 1
00078 };
00079
00080
00097 QString lookup( const KoGenStyle& style, const QString& name = QString::null, int flags = NoFlag );
00098
00099 typedef QMap<KoGenStyle, QString> StyleMap;
00104 const StyleMap& styles() const { return m_styleMap; }
00105
00106 struct NamedStyle {
00107 const KoGenStyle* style;
00108 QString name;
00109 };
00119 QValueList<NamedStyle> styles( int type, bool markedForStylesXml = false ) const;
00120
00124 const KoGenStyle* style( const QString& name ) const;
00125
00133 KoGenStyle* styleForModification( const QString& name );
00134
00147 void markStyleForStylesXml( const QString& name );
00148
00152 void dump();
00153
00154 private:
00155 QString makeUniqueName( const QString& base, int flags ) const;
00156
00158 StyleMap m_styleMap;
00159
00163 typedef QMap<QString, bool> NameMap;
00164 NameMap m_styleNames;
00165 NameMap m_autoStylesInStylesDotXml;
00166
00168 typedef QValueVector<NamedStyle> StyleArray;
00169 StyleArray m_styleArray;
00170
00171 class Private;
00172 Private *d;
00173 };
00174
00182 class KOFFICECORE_EXPORT KoGenStyle
00183 {
00184 public:
00192 enum { STYLE_PAGELAYOUT = 0,
00193 STYLE_USER = 1,
00194 STYLE_AUTO = 2,
00195 STYLE_MASTER = 3,
00196 STYLE_LIST = 4,
00197 STYLE_AUTO_LIST = 5,
00198
00199 STYLE_NUMERIC_DATE = 7,
00200 STYLE_NUMERIC_TIME = 8,
00201 STYLE_NUMERIC_FRACTION = 9,
00202 STYLE_NUMERIC_PERCENTAGE = 10,
00203 STYLE_NUMERIC_SCIENTIFIC = 11,
00204 STYLE_NUMERIC_CURRENCY = 12,
00205 STYLE_NUMERIC_TEXT = 13,
00206 STYLE_HATCH = 14,
00207 STYLE_GRAPHICAUTO = 15};
00208
00221 explicit KoGenStyle( int type = 0, const char* familyName = 0,
00222 const QString& parentName = QString::null );
00223 ~KoGenStyle();
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 void setAutoStyleInStylesDotXml( bool b ) { m_autoStyleInStylesDotXml = b; }
00235 bool autoStyleInStylesDotXml() const { return m_autoStyleInStylesDotXml; }
00236
00237
00238
00239
00240
00241
00242 void setDefaultStyle( bool b ) { m_defaultStyle = b; }
00244 bool isDefaultStyle() const { return m_defaultStyle; }
00245
00247 int type() const { return m_type; }
00248
00250 const char* familyName() const { return m_familyName.data(); }
00251
00253 QString parentName() const { return m_parentName; }
00254
00273 enum PropertyType
00274 {
00280 DefaultType = 0,
00282 TextType,
00284 ParagraphType,
00286 GraphicType,
00287 Reserved1,
00288 Reserved2,
00289 ChildElement,
00290 N_NumTypes
00291 };
00292
00294 void addProperty( const QString& propName, const QString& propValue, PropertyType type = DefaultType ) {
00295 m_properties[type].insert( propName, propValue );
00296 }
00298 void addProperty( const QString& propName, const char* propValue, PropertyType type = DefaultType ) {
00299 m_properties[type].insert( propName, QString::fromUtf8( propValue ) );
00300 }
00302 void addProperty( const QString& propName, int propValue, PropertyType type = DefaultType ) {
00303 m_properties[type].insert( propName, QString::number( propValue ) );
00304 }
00306 void addProperty( const QString& propName, bool propValue, PropertyType type = DefaultType ) {
00307 m_properties[type].insert( propName, propValue ? "true" : "false" );
00308 }
00309
00316 void addPropertyPt( const QString& propName, double propValue, PropertyType type = DefaultType );
00317
00323 void addAttribute( const QString& attrName, const QString& attrValue ) {
00324 m_attributes.insert( attrName, attrValue );
00325 }
00327 void addAttribute( const QString& attrName, const char* attrValue ) {
00328 m_attributes.insert( attrName, QString::fromUtf8( attrValue ) );
00329 }
00331 void addAttribute( const QString& attrName, int attrValue ) {
00332 m_attributes.insert( attrName, QString::number( attrValue ) );
00333 }
00334
00336 void addAttribute( const QString& attrName, bool attrValue ) {
00337 m_attributes.insert( attrName, attrValue ? "true" : "false" );
00338 }
00339
00346 void addAttributePt( const QString& attrName, double attrValue );
00347
00367 void addChildElement( const QString& elementName, const QString& elementContents ) {
00368 m_properties[ChildElement].insert( elementName, elementContents );
00369 }
00370
00375 void addStyleMap( const QMap<QString, QString>& styleMap ) {
00376 m_maps.append( styleMap );
00377 }
00378
00384 bool isEmpty() const {
00385 if ( !m_attributes.isEmpty() || ! m_maps.isEmpty() )
00386 return false;
00387 for ( uint i = 0 ; i < N_NumTypes ; ++i )
00388 if ( ! m_properties[i].isEmpty() )
00389 return false;
00390 return true;
00391 }
00392
00406 void writeStyle( KoXmlWriter* writer, KoGenStyles& styles, const char* elementName, const QString& name,
00407 const char* propertiesElementName, bool closeElement = true, bool drawElement = false ) const;
00408
00416 bool operator<( const KoGenStyle &other ) const;
00417
00419 bool operator==( const KoGenStyle &other ) const;
00420
00421 private:
00422 QString property( const QString& propName, PropertyType type ) const {
00423 QMap<QString, QString>::const_iterator it = m_properties[type].find( propName );
00424 if ( it != m_properties[type].end() )
00425 return it.data();
00426 return QString::null;
00427 }
00428
00429 QString attribute( const QString& propName ) const {
00430 QMap<QString, QString>::const_iterator it = m_attributes.find( propName );
00431 if ( it != m_attributes.end() )
00432 return it.data();
00433 return QString::null;
00434 }
00435
00436 void writeStyleProperties( KoXmlWriter* writer, PropertyType i,
00437 const char* elementName, const KoGenStyle* parentStyle ) const;
00438
00439 #ifndef NDEBUG
00440 void printDebug() const;
00441 #endif
00442
00443 private:
00444
00445
00446 int m_type;
00447 QCString m_familyName;
00448 QString m_parentName;
00450 QMap<QString, QString> m_properties[N_NumTypes];
00451 QMap<QString, QString> m_attributes;
00452 typedef QMap<QString, QString> StyleMap;
00453 QValueVector<StyleMap> m_maps;
00454
00455 bool m_autoStyleInStylesDotXml;
00456 bool m_defaultStyle;
00457 short m_unused2;
00458
00459
00460 friend class KoGenStyles;
00461 };
00462
00463 #endif