00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __kspread_style__
00021 #define __kspread_style__
00022
00023 #include <qbrush.h>
00024 #include <qcolor.h>
00025 #include <qfont.h>
00026 #include <qpen.h>
00027
00028 #include "kspread_format.h"
00029
00030 class QDomDocument;
00031 class QDomElement;
00032 class KoGenStyles;
00033 class KoOasisStyles;
00034
00035 namespace KSpread
00036 {
00037 class CustomStyle;
00038
00045 class Style
00046 {
00047 public:
00049 enum StyleType
00050 {
00051 BUILTIN,
00052 CUSTOM,
00053 AUTO,
00054 TENTATIVE
00055 };
00056
00057 enum FontFlags
00058 {
00059 FBold = 0x01,
00060 FUnderline = 0x02,
00061 FItalic = 0x04,
00062 FStrike = 0x08
00063 };
00064
00066 enum Properties
00067 {
00068 PDontPrintText = 0x01,
00069 PCustomFormat = 0x02,
00070 PNotProtected = 0x04,
00071 PHideAll = 0x08,
00072 PHideFormula = 0x10,
00073 PMultiRow = 0x20,
00074 PVerticalText = 0x40
00075 };
00076
00077
00079 enum FlagsSet
00080 {
00081 SAlignX = 0x01,
00082 SAlignY = 0x02,
00083
00084 SPrefix = 0x08,
00085 SPostfix = 0x10,
00086 SLeftBorder = 0x20,
00087 SRightBorder = 0x40,
00088 STopBorder = 0x80,
00089 SBottomBorder = 0x100,
00090 SFallDiagonal = 0x200,
00091 SGoUpDiagonal = 0x400,
00092 SBackgroundBrush = 0x800,
00093 SFont = 0x1000,
00094 STextPen = 0x2000,
00095 SBackgroundColor = 0x4000,
00096 SFloatFormat = 0x8000,
00097 SFloatColor = 0x10000,
00098 SMultiRow = 0x20000,
00099 SVerticalText = 0x40000,
00100 SPrecision = 0x80000,
00101 SFormatType = 0x100000,
00102 SAngle = 0x200000,
00103
00104 SIndent = 0x800000,
00105 SDontPrintText = 0x1000000,
00106 SCustomFormat = 0x2000000,
00107 SNotProtected = 0x4000000,
00108 SHideAll = 0x8000000,
00109 SHideFormula = 0x10000000,
00110 SFontSize = 0x20000000,
00111 SFontFlag = 0x40000000,
00112 SFontFamily = 0x80000000
00113 };
00114
00119 Style();
00127 Style( Style* style );
00128
00132 virtual ~Style();
00133
00135 bool operator == (const Style& style) const;
00136 inline bool operator!=( const Style& other ) const { return !operator==( other ); }
00137
00138 static FormatType dateType( const QString &_format );
00139 static FormatType timeType( const QString &_format );
00140 static FormatType fractionType( const QString &_format );
00141
00146 static QString saveOasisStyleNumeric( KoGenStyle &style, KoGenStyles &mainStyles, FormatType _style,
00147 const QString &_prefix, const QString &_postfix, int _precision, const QString& symbol );
00148 static QString saveOasisStyleNumericDate( KoGenStyles &mainStyles, FormatType _style,
00149 const QString &_prefix, const QString &_suffix );
00150 static QString saveOasisStyleNumericFraction( KoGenStyles &mainStyles, FormatType _style,
00151 const QString &_prefix, const QString _suffix );
00152 static QString saveOasisStyleNumericTime( KoGenStyles& mainStyles, FormatType _style,
00153 const QString &_prefix, const QString &_suffix );
00154 static QString saveOasisStyleNumericCustom( KoGenStyles&mainStyles, FormatType _style,
00155 const QString &_prefix, const QString &_suffix );
00156 static QString saveOasisStyleNumericScientific( KoGenStyles&mainStyles, FormatType _style,
00157 const QString &_prefix, const QString _suffix, int _precision );
00158 static QString saveOasisStyleNumericPercentage( KoGenStyles&mainStyles, FormatType _style, int _precision,
00159 const QString &_prefix, const QString &_suffix );
00160 static QString saveOasisStyleNumericMoney( KoGenStyles&mainStyles, FormatType _style,
00161 const QString& symbol, int _precision,
00162 const QString &_prefix, const QString &_suffix );
00163 static QString saveOasisStyleNumericText( KoGenStyles&mainStyles, FormatType _style, int _precision,
00164 const QString &_prefix, const QString &_suffix );
00165 static QString saveOasisStyleNumericNumber( KoGenStyles&mainStyles, FormatType _style, int _precision,
00166 const QString &_prefix, const QString &_suffix );
00167
00168
00169 StyleType type() const { return m_type; }
00170
00171 void saveXML( QDomDocument & doc, QDomElement & format ) const;
00172 bool loadXML( QDomElement & format );
00173
00179 virtual QString saveOasis( KoGenStyle& style, KoGenStyles& mainStyles);
00180 void loadOasisStyle( KoOasisStyles& oasisStyles, const QDomElement & element );
00181 static QString saveOasisBackgroundStyle( KoGenStyles &mainStyles, const QBrush &brush );
00182
00187 bool release();
00191 void addRef();
00195 int usage() const { return m_usageCount; }
00196
00197 bool hasProperty( Properties p ) const;
00198 bool hasFeature( FlagsSet f, bool withoutParent ) const;
00199 void clearFeature( FlagsSet f );
00200 uint features() const { return m_featuresSet; }
00201
00202 uint bottomPenValue() const { return m_bottomPenValue; }
00203 uint rightPenValue() const { return m_rightPenValue; }
00204 uint leftPenValue() const { return m_leftPenValue; }
00205 uint topPenValue() const { return m_topPenValue; }
00206
00207 QPen const & pen() const;
00208 QColor const & bgColor() const;
00209 QPen const & rightBorderPen() const;
00210 QPen const & bottomBorderPen() const;
00211 QPen const & leftBorderPen() const;
00212 QPen const & topBorderPen() const;
00213 QPen const & fallDiagonalPen() const;
00214 QPen const & goUpDiagonalPen() const;
00215 QBrush const & backGroundBrush() const;
00216 QString const & strFormat() const;
00217 QString const & prefix() const;
00218 QString const & postfix() const;
00219 QString const & fontFamily() const;
00220
00221 Format::Align alignX() const;
00222 Format::AlignY alignY() const;
00223 Format::FloatFormat floatFormat() const;
00224 Format::FloatColor floatColor() const;
00225 FormatType formatType() const;
00226
00227 Format::Currency const & currency() const;
00228
00229 QFont font() const;
00230 uint fontFlags() const;
00231 int fontSize() const;
00232 int precision() const;
00233 int rotateAngle() const;
00234 double indent() const;
00235
00236 Style * setAlignX( Format::Align alignX );
00237 Style * setAlignY( Format::AlignY alignY );
00238 Style * setFont( QFont const & f );
00239 Style * setFontFamily( QString const & fam );
00240 Style * setFontFlags( uint flags );
00241 Style * setFontSize( int size );
00242 Style * setPen( QPen const & pen );
00243 Style * setBgColor( QColor const & color );
00244 Style * setRightBorderPen( QPen const & pen );
00245 Style * setBottomBorderPen( QPen const & pen );
00246 Style * setLeftBorderPen( QPen const & pen );
00247 Style * setTopBorderPen( QPen const & pen );
00248 Style * setFallDiagonalPen( QPen const & pen );
00249 Style * setGoUpDiagonalPen( QPen const & pen );
00250 Style * setRotateAngle( int angle );
00251 Style * setIndent( double indent );
00252 Style * setBackGroundBrush( QBrush const & brush );
00253 Style * setFloatFormat( Format::FloatFormat format );
00254 Style * setFloatColor( Format::FloatColor color );
00255 Style * setFormatType( FormatType format );
00256 Style * setStrFormat( QString const & strFormat );
00257 Style * setPrecision( int precision );
00258 Style * setPrefix( QString const & prefix );
00259 Style * setPostfix( QString const & postfix );
00260 Style * setCurrency( Format::Currency const & currency );
00261 Style * setProperty( Properties p );
00262 Style * clearProperty( Properties p );
00263
00264 CustomStyle * parent() const;
00265 QString const & parentName() const { return m_parentName; }
00266 void setParent( CustomStyle * parent );
00267
00272 static QString colorName( const QColor& color );
00273
00274 protected:
00279 void saveOasisStyle( KoGenStyle &style, KoGenStyles &mainStyles );
00280
00281 void loadOasisDataStyle( KoOasisStyles& oasisStyles, const QDomElement& styleStack );
00282 void loadOasisParagraphProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack );
00283 void loadOasisTableCellProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack );
00284 void loadOasisTextProperties( KoOasisStyles& oasisStyles, const KoStyleStack& styleStack );
00285
00286 CustomStyle * m_parent;
00287 QString m_parentName;
00288 StyleType m_type;
00289 uint m_usageCount;
00290 uint m_featuresSet;
00291
00295 Format::Align m_alignX;
00299 Format::AlignY m_alignY;
00300
00301 Format::FloatFormat m_floatFormat;
00305 Format::FloatColor m_floatColor;
00306
00307 FormatType m_formatType;
00308
00312 QString m_fontFamily;
00313 uint m_fontFlags;
00314 int m_fontSize;
00315
00319 QPen m_textPen;
00323 QColor m_bgColor;
00324
00328 QPen m_rightBorderPen;
00329
00333 QPen m_bottomBorderPen;
00334
00338 QPen m_leftBorderPen;
00339
00343 QPen m_topBorderPen;
00344
00348 QPen m_fallDiagonalPen;
00352 QPen m_goUpDiagonalPen;
00353
00357 QBrush m_backGroundBrush;
00358
00359 int m_rotateAngle;
00363 double m_indent;
00367 QString m_strFormat;
00372 int m_precision;
00377 QString m_prefix;
00382 QString m_postfix;
00387 Format::Currency m_currency;
00388
00392 uint m_properties;
00393
00394 uint m_bottomPenValue;
00395 uint m_rightPenValue;
00396 uint m_leftPenValue;
00397 uint m_topPenValue;
00398
00399 bool featureSet( FlagsSet f ) const { return ( !m_parent || ( m_featuresSet & (uint) f ) ); }
00400 };
00401
00405 class CustomStyle : public Style
00406 {
00407 public:
00414 CustomStyle( Style * style, QString const & name );
00415 CustomStyle( QString const & name, CustomStyle * parent );
00416 ~CustomStyle();
00417
00418 QString const & name() const { return m_name; }
00419
00420 void save( QDomDocument & doc, QDomElement & styles );
00426 virtual QString saveOasis( KoGenStyle& style, KoGenStyles &mainStyles );
00434 void loadOasis( KoOasisStyles& oasisStyles, const QDomElement & style, const QString & name );
00435
00436 bool loadXML( QDomElement const & style, QString const & name );
00437
00438 void setType( StyleType type ) { m_type = type; }
00439
00440 void setName( QString const & name );
00441 void refreshParentName();
00442 bool definesAll() const;
00443
00444 void changeAlignX( Format::Align alignX );
00445 void changeAlignY( Format::AlignY alignY );
00446 void changeFont( QFont const & f );
00447 void changeFontFamily( QString const & fam );
00448 void changeFontSize( int size );
00449 void changeFontFlags( uint flags );
00450 void changePen( QPen const & pen );
00451 void changeTextColor( QColor const & color );
00452 void changeBgColor( QColor const & color );
00453 void changeRightBorderPen( QPen const & pen );
00454 void changeBottomBorderPen( QPen const & pen );
00455 void changeLeftBorderPen( QPen const & pen );
00456 void changeTopBorderPen( QPen const & pen );
00457 void changeFallBorderPen( QPen const & pen );
00458 void changeGoUpBorderPen( QPen const & pen );
00459 void changeRotateAngle( int angle );
00460 void changeIndent( double indent );
00461 void changeBackGroundBrush( QBrush const & brush );
00462 void changeFloatFormat( Format::FloatFormat format );
00463 void changeFloatColor( Format::FloatColor color );
00464 void changeFormatType( FormatType format );
00465 void changeStrFormat( QString const & strFormat );
00466 void changePrecision( int precision );
00467 void changePrefix( QString const & prefix );
00468 void changePostfix( QString const & postfix );
00469 void changeCurrency( Format::Currency const & currency );
00470
00471 void addProperty( Properties p );
00472 void removeProperty( Properties p );
00473
00474 bool operator==( const CustomStyle& other ) const;
00475 inline bool operator!=( const CustomStyle& other ) const { return !operator==( other ); }
00476
00477 private:
00478 friend class StyleManager;
00479
00480 QString m_name;
00481
00486 CustomStyle();
00487 };
00488
00489 }
00490
00491 #endif