stylereader.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef STYLEREADER_H
00028 #define STYLEREADER_H
00029
00030 #include "scconfig.h"
00031
00032 #ifdef HAVE_XML26
00033 #include <libxml/SAX2.h>
00034 #else
00035 #include <libxml/SAX.h>
00036 #endif
00037 #include <QMap>
00038 #include <QXmlAttributes>
00039 #include <gtstyle.h>
00040 #include <gtwriter.h>
00041
00042
00043 enum BulletType {
00044 Bullet,
00045 Number,
00046 LowerRoman,
00047 UpperRoman,
00048 LowerAlpha,
00049 UpperAlpha,
00050 Graphic
00051 };
00052
00053 class ListLevel
00054 {
00055 public:
00056 ListLevel(uint level,
00057 BulletType btype,
00058 const QString &prefix,
00059 const QString &suffix,
00060 const QString &bullet,
00061 uint displayLevels = 1,
00062 uint startValue = 0);
00063 ~ListLevel();
00064 QString bulletString();
00065 QString bullet();
00066 QString prefix();
00067 QString suffix();
00068 void advance();
00069 void reset();
00070 uint level();
00071 uint displayLevels();
00072 private:
00073 uint m_level;
00074 BulletType m_btype;
00075 QString m_prefix;
00076 QString m_suffix;
00077 QString m_bullet;
00078 uint m_displayLevels;
00079 uint m_next;
00080 static const QString lowerUnits[10];
00081 static const QString lowerTens[10];
00082 static const QString lowerHundreds[10];
00083 static const QString lowerThousands[4];
00084 static const QString upperUnits[10];
00085 static const QString upperTens[10];
00086 static const QString upperHundreds[10];
00087 static const QString upperThousands[4];
00088 static const QString lowerAlphabets[27];
00089 static const QString upperAlphabets[27];
00090 QString lowerRoman(uint n);
00091 QString upperRoman(uint n);
00092 QString lowerAlpha(uint n);
00093 QString upperAlpha(uint n);
00094 };
00095
00096 class ListStyle
00097 {
00098 public:
00099 ListStyle(const QString &name, bool consecutiveNumbering = false, uint currentLevel = 1);
00100 ~ListStyle();
00101 void addLevel(uint level, ListLevel *llevel);
00102 QString bullet();
00103 void advance();
00104 void setLevel(uint level);
00105 void resetLevel();
00106 QString& name();
00107 private:
00108 QString m_name;
00109 bool m_consecutiveNumbering;
00110 uint m_currentLevel;
00111 uint m_count;
00112 ListLevel* levels[11];
00113 };
00114
00115 typedef QMap<QString, gtStyle*> StyleMap;
00116 typedef QMap<QString, QString> FontMap;
00117 typedef QMap<QString, int> CounterMap;
00118 typedef QMap<QString, ListStyle*> ListMap;
00119
00120 class StyleReader
00121 {
00122 private:
00123 static StyleReader *sreader;
00124 gtWriter *writer;
00125 bool importTextOnly;
00126 bool usePrefix;
00127 bool packStyles;
00128 bool readProperties;
00129 QString docname;
00130 StyleMap styles;
00131 StyleMap listParents;
00132 StyleMap attrsStyles;
00133 CounterMap pstyleCounts;
00134 FontMap fonts;
00135 ListMap lists;
00136 gtStyle* currentStyle;
00137 gtStyle* parentStyle;
00138 bool inList;
00139 QString currentList;
00140 ListStyle *currentListStyle;
00141 bool defaultStyleCreated;
00142 double getSize(QString s, double parentSize = -1);
00143 void styleProperties(const QXmlAttributes& attrs);
00144 void defaultStyle(const QXmlAttributes& attrs);
00145 void styleStyle(const QXmlAttributes& attrs);
00146 void tabStop(const QXmlAttributes& attrs);
00147 void setupFrameStyle();
00148 public:
00149 StyleReader(QString documentName, gtWriter *wr, bool textOnly, bool prefix, bool combineStyles = true);
00150 ~StyleReader();
00151 bool updateStyle(gtStyle* style, gtStyle* parent2Style, const QString& key, const QString& value);
00152 static void startElement(void *user_data, const xmlChar * fullname, const xmlChar ** atts);
00153 static void endElement(void *user_data, const xmlChar * name);
00154 bool startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs);
00155 bool endElement(const QString&, const QString&, const QString &name);
00156 void parse(QString fileName);
00157 gtStyle* getDefaultStyle(void);
00158 gtStyle* getStyle(const QString& name);
00159 void setStyle(const QString& name, gtStyle* style);
00160 QString getFont(const QString& key);
00161 ListStyle *getList(const QString &name);
00162 };
00163
00164 #endif