1 // xlsxformat.h
2 
3 #ifndef QXLSX_FORMAT_H
4 #define QXLSX_FORMAT_H
5 
6 #include <QFont>
7 #include <QColor>
8 #include <QByteArray>
9 #include <QList>
10 #include <QExplicitlySharedDataPointer>
11 #include <QVariant>
12 
13 #include "xlsxglobal.h"
14 
15 class FormatTest;
16 
17 QT_BEGIN_NAMESPACE_XLSX
18 
19 class Styles;
20 class Worksheet;
21 class WorksheetPrivate;
22 class RichStringPrivate;
23 class SharedStrings;
24 
25 class FormatPrivate;
26 
27 class Format
28 {
29 public:
30     enum FontScript
31     {
32         FontScriptNormal,
33         FontScriptSuper,
34         FontScriptSub
35     };
36 
37     enum FontUnderline
38     {
39         FontUnderlineNone,
40         FontUnderlineSingle,
41         FontUnderlineDouble,
42         FontUnderlineSingleAccounting,
43         FontUnderlineDoubleAccounting
44     };
45 
46     enum HorizontalAlignment
47     {
48         AlignHGeneral,
49         AlignLeft,
50         AlignHCenter,
51         AlignRight,
52         AlignHFill,
53         AlignHJustify,
54         AlignHMerge,
55         AlignHDistributed
56     };
57 
58     enum VerticalAlignment
59     {
60         AlignTop,
61         AlignVCenter,
62         AlignBottom,
63         AlignVJustify,
64         AlignVDistributed
65     };
66 
67     enum BorderStyle
68     {
69         BorderNone,
70         BorderThin,
71         BorderMedium,
72         BorderDashed,
73         BorderDotted,
74         BorderThick,
75         BorderDouble,
76         BorderHair,
77         BorderMediumDashed,
78         BorderDashDot,
79         BorderMediumDashDot,
80         BorderDashDotDot,
81         BorderMediumDashDotDot,
82         BorderSlantDashDot
83     };
84 
85     enum DiagonalBorderType
86     {
87         DiagonalBorderNone,
88         DiagonalBorderDown,
89         DiagonalBorderUp,
90         DiagnoalBorderBoth
91     };
92 
93     enum FillPattern
94     {
95         PatternNone,
96         PatternSolid,
97         PatternMediumGray,
98         PatternDarkGray,
99         PatternLightGray,
100         PatternDarkHorizontal,
101         PatternDarkVertical,
102         PatternDarkDown,
103         PatternDarkUp,
104         PatternDarkGrid,
105         PatternDarkTrellis,
106         PatternLightHorizontal,
107         PatternLightVertical,
108         PatternLightDown,
109         PatternLightUp,
110         PatternLightTrellis,
111         PatternGray125,
112         PatternGray0625,
113         PatternLightGrid
114     };
115 
116     Format();
117     Format(const Format &other);
118     Format &operator=(const Format &rhs);
119     ~Format();
120 
121     int numberFormatIndex() const;
122     void setNumberFormatIndex(int format);
123     QString numberFormat() const;
124     void setNumberFormat(const QString &format);
125     void setNumberFormat(int id, const QString &format);
126     bool isDateTimeFormat() const;
127 
128     int fontSize() const;
129     void setFontSize(int size);
130     bool fontItalic() const;
131     void setFontItalic(bool italic);
132     bool fontStrikeOut() const;
133     void setFontStrikeOut(bool);
134     QColor fontColor() const;
135     void setFontColor(const QColor &);
136     bool fontBold() const;
137     void setFontBold(bool bold);
138     FontScript fontScript() const;
139     void setFontScript(FontScript);
140     FontUnderline fontUnderline() const;
141     void setFontUnderline(FontUnderline);
142     bool fontOutline() const;
143     void setFontOutline(bool outline);
144     QString fontName() const;
145     void setFontName(const QString &);
146     QFont font() const;
147     void setFont(const QFont &font);
148 
149     HorizontalAlignment horizontalAlignment() const;
150     void setHorizontalAlignment(HorizontalAlignment align);
151     VerticalAlignment verticalAlignment() const;
152     void setVerticalAlignment(VerticalAlignment align);
153     bool textWrap() const;
154     void setTextWrap(bool textWrap);
155     int rotation() const;
156     void setRotation(int rotation);
157     int indent() const;
158     void setIndent(int indent);
159     bool shrinkToFit() const;
160     void setShrinkToFit(bool shink);
161 
162     void setBorderStyle(BorderStyle style);
163     void setBorderColor(const QColor &color);
164     BorderStyle leftBorderStyle() const;
165     void setLeftBorderStyle(BorderStyle style);
166     QColor leftBorderColor() const;
167     void setLeftBorderColor(const QColor &color);
168     BorderStyle rightBorderStyle() const;
169     void setRightBorderStyle(BorderStyle style);
170     QColor rightBorderColor() const;
171     void setRightBorderColor(const QColor &color);
172     BorderStyle topBorderStyle() const;
173     void setTopBorderStyle(BorderStyle style);
174     QColor topBorderColor() const;
175     void setTopBorderColor(const QColor &color);
176     BorderStyle bottomBorderStyle() const;
177     void setBottomBorderStyle(BorderStyle style);
178     QColor bottomBorderColor() const;
179     void setBottomBorderColor(const QColor &color);
180     BorderStyle diagonalBorderStyle() const;
181     void setDiagonalBorderStyle(BorderStyle style);
182     DiagonalBorderType diagonalBorderType() const;
183     void setDiagonalBorderType(DiagonalBorderType style);
184     QColor diagonalBorderColor() const;
185     void setDiagonalBorderColor(const QColor &color);
186 
187     FillPattern fillPattern() const;
188     void setFillPattern(FillPattern pattern);
189     QColor patternForegroundColor() const;
190     void setPatternForegroundColor(const QColor &color);
191     QColor patternBackgroundColor() const;
192     void setPatternBackgroundColor(const QColor &color);
193 
194     bool locked() const;
195     void setLocked(bool locked);
196     bool hidden() const;
197     void setHidden(bool hidden);
198 
199     void mergeFormat(const Format &modifier);
200     bool isValid() const;
201     bool isEmpty() const;
202 
203     bool operator == (const Format &format) const;
204     bool operator != (const Format &format) const;
205 
206     QVariant property(int propertyId, const QVariant &defaultValue=QVariant()) const;
207     void setProperty(int propertyId, const QVariant &value, const QVariant &clearValue=QVariant(), bool detach=true);
208     void clearProperty(int propertyId);
209     bool hasProperty(int propertyId) const;
210 
211     bool boolProperty(int propertyId, bool defaultValue=false) const;
212     int intProperty(int propertyId, int defaultValue=0) const;
213     double doubleProperty(int propertyId, double defaultValue = 0.0) const;
214     QString stringProperty(int propertyId, const QString &defaultValue = QString()) const;
215     QColor colorProperty(int propertyId, const QColor &defaultValue = QColor()) const;
216 
217     bool hasNumFmtData() const;
218     bool hasFontData() const;
219     bool hasFillData() const;
220     bool hasBorderData() const;
221     bool hasAlignmentData() const;
222     bool hasProtectionData() const;
223 
224     bool fontIndexValid() const;
225     int fontIndex() const;
226     QByteArray fontKey() const;
227     bool borderIndexValid() const;
228     QByteArray borderKey() const;
229     int borderIndex() const;
230     bool fillIndexValid() const;
231     QByteArray fillKey() const;
232     int fillIndex() const;
233 
234     QByteArray formatKey() const;
235     bool xfIndexValid() const;
236     int xfIndex() const;
237     bool dxfIndexValid() const;
238     int dxfIndex() const;
239 
240     void fixNumberFormat(int id, const QString &format);
241     void setFontIndex(int index);
242     void setBorderIndex(int index);
243     void setFillIndex(int index);
244     void setXfIndex(int index);
245     void setDxfIndex(int index);
246 private:
247     friend class Styles;
248     friend class ::FormatTest;
249     friend   QDebug operator<<(QDebug, const Format &f);
250 
251     int theme() const;
252 
253     QExplicitlySharedDataPointer<FormatPrivate> d;
254 };
255 
256 #ifndef QT_NO_DEBUG_STREAM
257   QDebug operator<<(QDebug dbg, const Format &f);
258 #endif
259 
260 QT_END_NAMESPACE_XLSX
261 
262 #endif // QXLSX_FORMAT_H
263