00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef KOGENSTYLE_H
00020 #define KOGENSTYLE_H
00021
00022 #include <QMap>
00023 #include <q3valuevector.h>
00024 #include <QString>
00025 #include <koffice_export.h>
00026
00027 class KoGenStyles;
00028 class KoXmlWriter;
00029
00037 class KOFFICECORE_EXPORT KoGenStyle
00038 {
00039 public:
00047 enum { STYLE_PAGELAYOUT = 0,
00048 STYLE_USER = 1,
00049 STYLE_AUTO = 2,
00050 STYLE_MASTER = 3,
00051 STYLE_LIST = 4,
00052 STYLE_AUTO_LIST = 5,
00053 STYLE_NUMERIC_NUMBER = 6,
00054 STYLE_NUMERIC_DATE = 7,
00055 STYLE_NUMERIC_TIME = 8,
00056 STYLE_NUMERIC_FRACTION = 9,
00057 STYLE_NUMERIC_PERCENTAGE = 10,
00058 STYLE_NUMERIC_SCIENTIFIC = 11,
00059 STYLE_NUMERIC_CURRENCY = 12,
00060 STYLE_NUMERIC_TEXT = 13,
00061 STYLE_HATCH = 14,
00062 STYLE_GRAPHICAUTO = 15};
00063
00076 explicit KoGenStyle( int type = 0, const char* familyName = 0,
00077 const QString& parentName = QString::null );
00078 ~KoGenStyle();
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 void setAutoStyleInStylesDotXml( bool b ) { m_autoStyleInStylesDotXml = b; }
00090 bool autoStyleInStylesDotXml() const { return m_autoStyleInStylesDotXml; }
00091
00092
00093
00094
00095
00096
00097 void setDefaultStyle( bool b ) { m_defaultStyle = b; }
00099 bool isDefaultStyle() const { return m_defaultStyle; }
00100
00102 int type() const { return m_type; }
00103
00105 const char* familyName() const { return m_familyName.data(); }
00106
00108 QString parentName() const { return m_parentName; }
00109
00128 enum PropertyType
00129 {
00135 DefaultType = 0,
00137 TextType,
00139 ParagraphType,
00141 GraphicType,
00142 Reserved1,
00143 Reserved2,
00144 ChildElement,
00145 N_NumTypes
00146 };
00147
00149 void addProperty( const QString& propName, const QString& propValue, PropertyType type = DefaultType ) {
00150 m_properties[type].insert( propName, propValue );
00151 }
00153 void addProperty( const QString& propName, const char* propValue, PropertyType type = DefaultType ) {
00154 m_properties[type].insert( propName, QString::fromUtf8( propValue ) );
00155 }
00157 void addProperty( const QString& propName, int propValue, PropertyType type = DefaultType ) {
00158 m_properties[type].insert( propName, QString::number( propValue ) );
00159 }
00161 void addProperty( const QString& propName, bool propValue, PropertyType type = DefaultType ) {
00162 m_properties[type].insert( propName, propValue ? "true" : "false" );
00163 }
00164
00171 void addPropertyPt( const QString& propName, double propValue, PropertyType type = DefaultType );
00172
00178 void addAttribute( const QString& attrName, const QString& attrValue ) {
00179 m_attributes.insert( attrName, attrValue );
00180 }
00182 void addAttribute( const QString& attrName, const char* attrValue ) {
00183 m_attributes.insert( attrName, QString::fromUtf8( attrValue ) );
00184 }
00186 void addAttribute( const QString& attrName, int attrValue ) {
00187 m_attributes.insert( attrName, QString::number( attrValue ) );
00188 }
00189
00191 void addAttribute( const QString& attrName, bool attrValue ) {
00192 m_attributes.insert( attrName, attrValue ? "true" : "false" );
00193 }
00194
00201 void addAttributePt( const QString& attrName, double attrValue );
00202
00222 void addChildElement( const QString& elementName, const QString& elementContents ) {
00223 m_properties[ChildElement].insert( elementName, elementContents );
00224 }
00225
00230 void addStyleMap( const QMap<QString, QString>& styleMap ) {
00231 m_maps.append( styleMap );
00232 }
00233
00239 bool isEmpty() const {
00240 if ( !m_attributes.isEmpty() || ! m_maps.isEmpty() )
00241 return false;
00242 for ( uint i = 0 ; i < N_NumTypes ; ++i )
00243 if ( ! m_properties[i].isEmpty() )
00244 return false;
00245 return true;
00246 }
00247
00261 void writeStyle( KoXmlWriter* writer, KoGenStyles& styles, const char* elementName, const QString& name,
00262 const char* propertiesElementName, bool closeElement = true, bool drawElement = false ) const;
00263
00271 bool operator<( const KoGenStyle &other ) const;
00272
00274 bool operator==( const KoGenStyle &other ) const;
00275
00276 private:
00277 QString property( const QString& propName, PropertyType type ) const {
00278 QMap<QString, QString>::const_iterator it = m_properties[type].find( propName );
00279 if ( it != m_properties[type].end() )
00280 return it.value();
00281 return QString();
00282 }
00283
00284 QString attribute( const QString& propName ) const {
00285 QMap<QString, QString>::const_iterator it = m_attributes.find( propName );
00286 if ( it != m_attributes.end() )
00287 return it.value();
00288 return QString();
00289 }
00290
00291 void writeStyleProperties( KoXmlWriter* writer, PropertyType i,
00292 const char* elementName, const KoGenStyle* parentStyle ) const;
00293
00294 #ifndef NDEBUG
00295 void printDebug() const;
00296 #endif
00297
00298 private:
00299
00300
00301 int m_type;
00302 QByteArray m_familyName;
00303 QString m_parentName;
00305 QMap<QString, QString> m_properties[N_NumTypes];
00306 QMap<QString, QString> m_attributes;
00307 typedef QMap<QString, QString> StyleMap;
00308 Q3ValueVector<StyleMap> m_maps;
00309
00310 bool m_autoStyleInStylesDotXml;
00311 bool m_defaultStyle;
00312 short m_unused2;
00313
00314
00315 friend class KoGenStyles;
00316 };
00317
00318 #endif