1 /***************************************************************************
2  *   Copyright (C) 2015 by Jens Nissen jens-chessx@gmx.net                 *
3  *   Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org>                   *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10 
11 #ifndef OOO_FORMATPROPERTY_H
12 #define OOO_FORMATPROPERTY_H
13 
14 #include <QVector>
15 #include <QColor>
16 #include <QTextListFormat>
17 
18 #define USETODONEXT Q_UNUSED
19 
20 #define POINT_TO_CM(cm) ((cm)/28.3465058)
21 #define POINT_TO_MM(mm) ((mm)/2.83465058)     ////////  0.352777778
22 #define POINT_TO_DM(dm) ((dm)/283.465058)
23 #define POINT_TO_INCH(inch) ((inch)/72.0)
24 #define POINT_TO_PI(pi) ((pi)/12)
25 #define POINT_TO_DD(dd) ((dd)/154.08124)
26 #define POINT_TO_CC(cc) ((cc)/12.840103)
27 
28 #define MM_TO_POINT(mm) ((mm)*2.83465058)
29 #define CM_TO_POINT(cm) ((cm)*28.3465058)     ///// 28.346456693
30 #define DM_TO_POINT(dm) ((dm)*283.465058)
31 #define INCH_TO_POINT(inch) ((inch)*72.0)
32 #define PI_TO_POINT(pi) ((pi)*12)
33 #define DD_TO_POINT(dd) ((dd)*154.08124)
34 #define CC_TO_POINT(cc) ((cc)*12.840103)
35 
36 class QTextBlockFormat;
37 class QTextCharFormat;
38 class QTextFormat;
39 class QTextTableFormat;
40 
41 namespace OOO {
42 
43 class StyleInformation;
44 
45 class FontFormatProperty
46 {
47   public:
48     FontFormatProperty();
49 
50     void apply( QTextFormat *format ) const;
51 
52     void setFamily( const QString &name );
53 
54   private:
55     QString m_Family;
56 };
57 
58 class ParagraphFormatProperty
59 {
60   public:
61     enum WritingMode
62     {
63       LRTB,
64       RLTB,
65       TBRL,
66       TBLR,
67       LR,
68       RL,
69       TB,
70       PAGE
71     };
72 
73     ParagraphFormatProperty();
74 
75     void apply( QTextFormat *format ) const;
76 
77     void setPageNumber( int number );
78     void setWritingMode( WritingMode mode );
79     void setTextAlignment( Qt::Alignment alignment );
80     void setBackgroundColor( const QColor &color );
81     void setLeftMargin( const qreal margin );
82 
83     bool writingModeIsRightToLeft() const;
84 
85   private:
86     int m_PageNumber;
87     WritingMode m_WritingMode;
88     Qt::Alignment m_Alignment;
89     bool m_HasAlignment;
90     QColor m_BackgroundColor;
91     bool m_HasLeftMargin;
92     qreal m_LeftMargin;
93 };
94 
95 class TextFormatProperty
96 {
97   public:
98     TextFormatProperty();
99     TextFormatProperty( const StyleInformation *information );
100 
101     void apply( QTextCharFormat *format ) const;
102 
103     void setFontSize( int size );
104     void setFontName( const QString &name );
105     void setFontWeight( int weight );
106     void setFontStyle( int style );
107     void setTextPosition( int position );
108     void setColor( const QColor &color );
109     void setBackgroundColor( const QColor &color );
110     void setUnderline(bool underline);
111 
112   private:
113     const StyleInformation *m_StyleInformation;
114     int m_FontSize;
115     bool m_HasFontSize;
116     int m_FontWeight;
117     QString m_FontName;
118     int m_FontStyle;
119     int m_TextPosition;
120     QColor m_Color;
121     QColor m_BackgroundColor;
122     bool m_underline;
123 };
124 
125 class PageFormatProperty
126 {
127   public:
128     enum PageUsage
129     {
130       All,
131       Left,
132       Right,
133       Mirrored
134     };
135 
136     enum PrintOrientation
137     {
138       Portrait,
139       Landscape
140     };
141 
142     PageFormatProperty();
143 
144     void apply( QTextFormat *format ) const;
145 
146     void setPageUsage( PageUsage usage );
147     void setBottomMargin( double margin );
148     void setLeftMargin( double margin );
149     void setTopMargin( double margin );
150     void setRightMargin( double margin );
151     void setHeight( double height );
152     void setWidth( double width );
153     void setPrintOrientation( PrintOrientation orientation );
154 
155     double width() const;
156     double height() const;
157     double margin() const;
158 
159   private:
160     PageUsage m_PageUsage;
161     double m_BottomMargin;
162     double m_LeftMargin;
163     double m_TopMargin;
164     double m_RightMargin;
165     double m_Height;
166     double m_Width;
167     PrintOrientation m_PrintOrientation;
168 };
169 
170 class ListFormatProperty
171 {
172   public:
173     enum Type
174     {
175       Number,
176       Bullet
177     };
178 
179     ListFormatProperty();
180 
181     void apply(QTextListFormat *format) const;
182 
183     void addItem( int level, double indent = 0 );
184     void setType(QTextListFormat::Style type);
185 
186   private:
187     QTextListFormat::Style m_Type;
188     QVector<double> m_Indents;
189     QColor m_BackgroundColor;
190 };
191 
192 class TableColumnFormatProperty
193 {
194   public:
195     TableColumnFormatProperty();
196 
197     void apply( QTextTableFormat *format ) const;
198 
199     void setWidth( double width );
200 
201   private:
202     double m_Width;
203     bool isValid;
204 };
205 
206 class TableCellFormatProperty
207 {
208   public:
209     TableCellFormatProperty();
210 
211     void apply( QTextBlockFormat *format ) const;
212 
213     void setBackgroundColor( const QColor &color );
214     void setPadding( double padding );
215     void setAlignment( Qt::Alignment alignment );
216 
217   private:
218     double m_Padding;
219     Qt::Alignment m_Alignment;
220     bool m_HasAlignment;
221     QColor m_BackgroundColor;
222 
223 };
224 
225 class StyleFormatProperty
226 {
227   public:
228     StyleFormatProperty();
229     StyleFormatProperty( const StyleInformation *information );
230 
231     void applyBlock( QTextBlockFormat *format ) const;
232     void applyText( QTextCharFormat *format ) const;
233     void applyTableColumn( QTextTableFormat *format ) const;
234     void applyTableCell( QTextBlockFormat *format ) const;
235 
236     void setParentStyleName( const QString &parentStyleName );
237     QString parentStyleName() const;
238 
239     void setFamily( const QString &family );
240     void setDefaultStyle( bool defaultStyle );
241 
242     void setMasterPageName( const QString &masterPageName );
243 
244     void setParagraphFormat( const ParagraphFormatProperty &format );
245     void setTextFormat( const TextFormatProperty &format );
246     void setTableColumnFormat( const TableColumnFormatProperty &format );
247     void setTableCellFormat( const TableCellFormatProperty &format );
248 
249   private:
250     QString m_ParentStyleName;
251     QString m_Family;
252     QString m_MasterPageName;
253     ParagraphFormatProperty m_ParagraphFormat;
254     TextFormatProperty m_TextFormat;
255     TableColumnFormatProperty m_TableColumnFormat;
256     TableCellFormatProperty m_TableCellFormat;
257     const StyleInformation *m_StyleInformation;
258     bool m_DefaultStyle;
259 };
260 
261 }
262 
263 #endif
264