kspread

kspread_style.h
1/* This file is part of the KDE project
2 Copyright (C) 2003 Norbert Andres, nandres@web.de
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef __kspread_style__
21#define __kspread_style__
22
23#include <tqbrush.h>
24#include <tqcolor.h>
25#include <tqfont.h>
26#include <tqpen.h>
27
28#include "kspread_format.h"
29
30class TQDomDocument;
31class TQDomElement;
32class KoGenStyles;
33class KoOasisStyles;
34
35namespace KSpread
36{
37class CustomStyle;
38
45class Style
46{
47public:
50 {
54 TENTATIVE
55 };
56
57 enum FontFlags
58 {
59 FBold = 0x01,
60 FUnderline = 0x02,
61 FItalic = 0x04,
62 FStrike = 0x08
63 };
64
67 {
68 PDontPrintText = 0x01,
69 PCustomFormat = 0x02,
70 PNotProtected = 0x04,
71 PHideAll = 0x08,
72 PHideFormula = 0x10,
73 PMultiRow = 0x20,
74 PVerticalText = 0x40
75 };
76
77 // TODO Stefan: merge with Format::Properties
80 {
81 SAlignX = 0x01,
82 SAlignY = 0x02,
83 //SFactor was here
84 SPrefix = 0x08,
85 SPostfix = 0x10,
86 SLeftBorder = 0x20,
87 SRightBorder = 0x40,
88 STopBorder = 0x80,
89 SBottomBorder = 0x100,
90 SFallDiagonal = 0x200,
91 SGoUpDiagonal = 0x400,
92 SBackgroundBrush = 0x800,
93 SFont = 0x1000,
94 STextPen = 0x2000,
95 SBackgroundColor = 0x4000,
96 SFloatFormat = 0x8000,
97 SFloatColor = 0x10000,
98 SMultiRow = 0x20000,
99 SVerticalText = 0x40000,
100 SPrecision = 0x80000,
101 SFormatType = 0x100000,
102 SAngle = 0x200000,
103 //SComment = 0x400000,
104 SIndent = 0x800000,
105 SDontPrintText = 0x1000000,
106 SCustomFormat = 0x2000000,
107 SNotProtected = 0x4000000,
108 SHideAll = 0x8000000,
109 SHideFormula = 0x10000000,
110 SFontSize = 0x20000000,
111 SFontFlag = 0x40000000,
112 SFontFamily = 0x80000000
113 };
114
119 Style();
127 Style( Style* style );
128
132 virtual ~Style();
133
135 bool operator == (const Style& style) const;
136 inline bool operator!=( const Style& other ) const { return !operator==( other ); }
137
138 static FormatType dateType( const TQString &_format );
139 static FormatType timeType( const TQString &_format );
140 static FormatType fractionType( const TQString &_format );
141
146 static TQString saveOasisStyleNumeric( KoGenStyle &style, KoGenStyles &mainStyles, FormatType _style,
147 const TQString &_prefix, const TQString &_postfix, int _precision, const TQString& symbol );
148 static TQString saveOasisStyleNumericDate( KoGenStyles &mainStyles, FormatType _style,
149 const TQString &_prefix, const TQString &_suffix );
150 static TQString saveOasisStyleNumericFraction( KoGenStyles &mainStyles, FormatType _style,
151 const TQString &_prefix, const TQString _suffix );
152 static TQString saveOasisStyleNumericTime( KoGenStyles& mainStyles, FormatType _style,
153 const TQString &_prefix, const TQString &_suffix );
154 static TQString saveOasisStyleNumericCustom( KoGenStyles&mainStyles, FormatType _style,
155 const TQString &_prefix, const TQString &_suffix );
156 static TQString saveOasisStyleNumericScientific( KoGenStyles&mainStyles, FormatType _style,
157 const TQString &_prefix, const TQString _suffix, int _precision );
158 static TQString saveOasisStyleNumericPercentage( KoGenStyles&mainStyles, FormatType _style, int _precision,
159 const TQString &_prefix, const TQString &_suffix );
160 static TQString saveOasisStyleNumericMoney( KoGenStyles&mainStyles, FormatType _style,
161 const TQString& symbol, int _precision,
162 const TQString &_prefix, const TQString &_suffix );
163 static TQString saveOasisStyleNumericText( KoGenStyles&mainStyles, FormatType _style, int _precision,
164 const TQString &_prefix, const TQString &_suffix );
165 static TQString saveOasisStyleNumericNumber( KoGenStyles&mainStyles, FormatType _style, int _precision,
166 const TQString &_prefix, const TQString &_suffix );
167
168
169 StyleType type() const { return m_type; }
170
171 void saveXML( TQDomDocument & doc, TQDomElement & format ) const;
172 bool loadXML( TQDomElement & format );
173
179 virtual TQString saveOasis( KoGenStyle& style, KoGenStyles& mainStyles);
180 void loadOasisStyle( KoOasisStyles& oasisStyles, const TQDomElement & element );
181 static TQString saveOasisBackgroundStyle( KoGenStyles &mainStyles, const TQBrush &brush );
182
187 bool release();
191 void addRef();
195 int usage() const { return m_usageCount; }
196
197 bool hasProperty( Properties p ) const;
198 bool hasFeature( FlagsSet f, bool withoutParent ) const;
199 void clearFeature( FlagsSet f );
200 uint features() const { return m_featuresSet; }
201
202 uint bottomPenValue() const { return m_bottomPenValue; }
203 uint rightPenValue() const { return m_rightPenValue; }
204 uint leftPenValue() const { return m_leftPenValue; }
205 uint topPenValue() const { return m_topPenValue; }
206
207 TQPen const & pen() const;
208 TQColor const & bgColor() const;
209 TQPen const & rightBorderPen() const;
210 TQPen const & bottomBorderPen() const;
211 TQPen const & leftBorderPen() const;
212 TQPen const & topBorderPen() const;
213 TQPen const & fallDiagonalPen() const;
214 TQPen const & goUpDiagonalPen() const;
215 TQBrush const & backGroundBrush() const;
216 TQString const & strFormat() const;
217 TQString const & prefix() const;
218 TQString const & postfix() const;
219 TQString const & fontFamily() const;
220
221 Format::Align alignX() const;
222 Format::AlignY alignY() const;
223 Format::FloatFormat floatFormat() const;
224 Format::FloatColor floatColor() const;
225 FormatType formatType() const;
226
227 Format::Currency const & currency() const;
228
229 TQFont font() const;
230 uint fontFlags() const;
231 int fontSize() const;
232 int precision() const;
233 int rotateAngle() const;
234 double indent() const;
235
236 Style * setAlignX( Format::Align alignX );
237 Style * setAlignY( Format::AlignY alignY );
238 Style * setFont( TQFont const & f );
239 Style * setFontFamily( TQString const & fam );
240 Style * setFontFlags( uint flags );
241 Style * setFontSize( int size );
242 Style * setPen( TQPen const & pen );
243 Style * setBgColor( TQColor const & color );
244 Style * setRightBorderPen( TQPen const & pen );
245 Style * setBottomBorderPen( TQPen const & pen );
246 Style * setLeftBorderPen( TQPen const & pen );
247 Style * setTopBorderPen( TQPen const & pen );
248 Style * setFallDiagonalPen( TQPen const & pen );
249 Style * setGoUpDiagonalPen( TQPen const & pen );
250 Style * setRotateAngle( int angle );
251 Style * setIndent( double indent );
252 Style * setBackGroundBrush( TQBrush const & brush );
253 Style * setFloatFormat( Format::FloatFormat format );
254 Style * setFloatColor( Format::FloatColor color );
255 Style * setFormatType( FormatType format );
256 Style * setStrFormat( TQString const & strFormat );
257 Style * setPrecision( int precision );
258 Style * setPrefix( TQString const & prefix );
259 Style * setPostfix( TQString const & postfix );
260 Style * setCurrency( Format::Currency const & currency );
261 Style * setProperty( Properties p );
262 Style * clearProperty( Properties p );
263
264 CustomStyle * parent() const;
265 TQString const & parentName() const { return m_parentName; }
266 void setParent( CustomStyle * parent );
267
272 static TQString colorName( const TQColor& color );
273
274protected:
279 void saveOasisStyle( KoGenStyle &style, KoGenStyles &mainStyles );
280
281 void loadOasisDataStyle( KoOasisStyles& oasisStyles, const TQDomElement& styleStack );
282 void loadOasisParagraphProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack );
283 void loadOasisTableCellProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack );
284 void loadOasisTextProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack );
285
286 CustomStyle * m_parent;
287 TQString m_parentName;
288 StyleType m_type;
289 uint m_usageCount;
290 uint m_featuresSet;
291
295 Format::Align m_alignX;
299 Format::AlignY m_alignY;
300
301 Format::FloatFormat m_floatFormat;
305 Format::FloatColor m_floatColor;
306
307 FormatType m_formatType;
308
312 TQString m_fontFamily;
313 uint m_fontFlags;
314 int m_fontSize;
315
323 TQColor m_bgColor;
324
329
334
339
344
353
358
359 int m_rotateAngle;
363 double m_indent;
367 TQString m_strFormat;
377 TQString m_prefix;
382 TQString m_postfix;
387 Format::Currency m_currency;
388
393
394 uint m_bottomPenValue;
395 uint m_rightPenValue;
396 uint m_leftPenValue;
397 uint m_topPenValue;
398
399 bool featureSet( FlagsSet f ) const { return ( !m_parent || ( m_featuresSet & (uint) f ) ); }
400};
401
405class CustomStyle : public Style
406{
407public:
414 CustomStyle( Style * style, TQString const & name );
415 CustomStyle( TQString const & name, CustomStyle * parent );
416 ~CustomStyle();
417
418 TQString const & name() const { return m_name; }
419
420 void save( TQDomDocument & doc, TQDomElement & styles );
426 virtual TQString saveOasis( KoGenStyle& style, KoGenStyles &mainStyles );
434 void loadOasis( KoOasisStyles& oasisStyles, const TQDomElement & style, const TQString & name );
435
436 bool loadXML( TQDomElement const & style, TQString const & name );
437
438 void setType( StyleType type ) { m_type = type; }
439
440 void setName( TQString const & name );
441 void refreshParentName();
442 bool definesAll() const;
443
444 void changeAlignX( Format::Align alignX );
445 void changeAlignY( Format::AlignY alignY );
446 void changeFont( TQFont const & f );
447 void changeFontFamily( TQString const & fam );
448 void changeFontSize( int size );
449 void changeFontFlags( uint flags );
450 void changePen( TQPen const & pen );
451 void changeTextColor( TQColor const & color );
452 void changeBgColor( TQColor const & color );
453 void changeRightBorderPen( TQPen const & pen );
454 void changeBottomBorderPen( TQPen const & pen );
455 void changeLeftBorderPen( TQPen const & pen );
456 void changeTopBorderPen( TQPen const & pen );
457 void changeFallBorderPen( TQPen const & pen );
458 void changeGoUpBorderPen( TQPen const & pen );
459 void changeRotateAngle( int angle );
460 void changeIndent( double indent );
461 void changeBackGroundBrush( TQBrush const & brush );
462 void changeFloatFormat( Format::FloatFormat format );
463 void changeFloatColor( Format::FloatColor color );
464 void changeFormatType( FormatType format );
465 void changeStrFormat( TQString const & strFormat );
466 void changePrecision( int precision );
467 void changePrefix( TQString const & prefix );
468 void changePostfix( TQString const & postfix );
469 void changeCurrency( Format::Currency const & currency );
470
471 void addProperty( Properties p );
472 void removeProperty( Properties p );
473
474 bool operator==( const CustomStyle& other ) const;
475 inline bool operator!=( const CustomStyle& other ) const { return !operator==( other ); }
476
477 private:
478 friend class StyleManager;
479
480 TQString m_name;
481
486 CustomStyle();
487};
488
489} // namespace KSpread
490
491#endif
Built-in or custom style defined in StyleManager dialog.
CustomStyle(Style *style, TQString const &name)
Constructor.
void loadOasis(KoOasisStyles &oasisStyles, const TQDomElement &style, const TQString &name)
Loads the style properties from style .
virtual TQString saveOasis(KoGenStyle &style, KoGenStyles &mainStyles)
The Style class represents a cell style.
TQBrush m_backGroundBrush
The brush used to draw the background.
TQPen m_fallDiagonalPen
The pen used to draw the diagonal.
TQString m_postfix
The postfix of a numeric value ( for example "DM" ) May be empty.
TQString m_strFormat
Format of the content, e.g.
double m_indent
Give indent.
TQPen m_bottomBorderPen
The pen used to draw the bottom border.
uint m_properties
Stores information like: DonPrint, DontShowFormula, Protected...
TQString m_fontFamily
The font used to draw the text.
void addRef()
Marks this style as used.
bool operator==(const Style &style) const
Returns true if both styles have the same properties.
bool release()
Releases this style.
TQPen m_topBorderPen
The pen used to draw the top border.
virtual TQString saveOasis(KoGenStyle &style, KoGenStyles &mainStyles)
Saves an OASIS automatic style.
TQPen m_rightBorderPen
The pen used to draw the right border.
Format::FloatColor m_floatColor
The color format of a floating point value.
Format::Currency m_currency
Currency information: about which currency from which country.
Format::AlignY m_alignY
Aligment of the text at top middle or bottom.
TQPen m_textPen
The pen used to draw the text.
virtual ~Style()
Destructor.
StyleType
The style type.
@ BUILTIN
built-in style (the default style)
@ AUTO
automatically generated on cell format changes
@ CUSTOM
custom style (defined in the StyleManager dialog)
Style()
Constructor.
Format::Align m_alignX
Alignment of the text.
TQString m_prefix
The prefix of a numeric value ( for example "$" ) May be empty.
static TQString colorName(const TQColor &color)
Returns the name of a colour.
void saveOasisStyle(KoGenStyle &style, KoGenStyles &mainStyles)
Helper function for saveOasis Does the real work by determining the used attributes.
int m_precision
The precision of the floating point representation If precision is -1, this means that no precision i...
int usage() const
static TQString saveOasisStyleNumeric(KoGenStyle &style, KoGenStyles &mainStyles, FormatType _style, const TQString &_prefix, const TQString &_postfix, int _precision, const TQString &symbol)
TQColor m_bgColor
The background color.
TQPen m_goUpDiagonalPen
The pen used to draw the the diagonal which go up.
TQPen m_leftBorderPen
The pen used to draw the left border.
The KSpread namespace.
Definition commands.h:39