00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __kspread_style__
00022 #define __kspread_style__
00023
00024 class QDomDocument;
00025 class QDomElement;
00026
00027 #include <qbrush.h>
00028 #include <qcolor.h>
00029 #include <qfont.h>
00030 #include <qpen.h>
00031
00032 #include <koOasisStyles.h>
00033
00034 #include "kspread_format.h"
00035
00036 class KSpreadCustomStyle;
00037 class KoGenStyles;
00038
00039 class KSpreadStyle
00040 {
00041 public:
00042 typedef enum E1 { BUILTIN, CUSTOM, AUTO, TENTATIVE } StyleType;
00043
00044 enum FontFlags
00045 {
00046 FBold = 0x01,
00047 FUnderline = 0x02,
00048 FItalic = 0x04,
00049 FStrike = 0x08
00050 };
00051
00052 enum Properties
00053 {
00054 PDontPrintText = 0x01,
00055 PCustomFormat = 0x02,
00056 PNotProtected = 0x04,
00057 PHideAll = 0x08,
00058 PHideFormula = 0x10,
00059 PMultiRow = 0x20,
00060 PVerticalText = 0x40
00061 };
00062
00063 enum FlagsSet
00064 {
00065 SAlignX = 0x01,
00066 SAlignY = 0x02,
00067
00068 SPrefix = 0x08,
00069 SPostfix = 0x10,
00070 SLeftBorder = 0x20,
00071 SRightBorder = 0x40,
00072 STopBorder = 0x80,
00073 SBottomBorder = 0x100,
00074 SFallDiagonal = 0x200,
00075 SGoUpDiagonal = 0x400,
00076 SBackgroundBrush = 0x800,
00077 SFont = 0x1000,
00078 STextPen = 0x2000,
00079 SBackgroundColor = 0x4000,
00080 SFloatFormat = 0x8000,
00081 SFloatColor = 0x10000,
00082 SMultiRow = 0x20000,
00083 SVerticalText = 0x40000,
00084 SPrecision = 0x80000,
00085 SFormatType = 0x100000,
00086 SAngle = 0x200000,
00087 SIndent = 0x400000,
00088 SDontPrintText = 0x800000,
00089 SCustomFormat = 0x1000000,
00090 SNotProtected = 0x2000000,
00091 SHideAll = 0x4000000,
00092 SHideFormula = 0x8000000,
00093 SFontSize = 0x10000000,
00094 SFontFlag = 0x20000000,
00095 SFontFamily = 0x40000000
00096 };
00097
00098 KSpreadStyle();
00099 KSpreadStyle( KSpreadStyle * style );
00100
00101 virtual ~KSpreadStyle();
00102
00103 static FormatType formatType( const QString &_format );
00104
00105 static QString saveOasisStyleNumeric( KoGenStyles &mainStyles, FormatType _style, const QString &_prefix, const QString &_postfix, int _precision);
00106 static QString saveOasisStyleNumericDate( KoGenStyles &mainStyles, FormatType _style );
00107 static QString saveOasisStyleNumericFraction( KoGenStyles &mainStyles, FormatType _style, const QString &_prefix, const QString _suffix );
00108 static QString saveOasisStyleNumericTime( KoGenStyles& mainStyles, FormatType _style );
00109 static QString saveOasisStyleNumericCustom( KoGenStyles&mainStyles, FormatType _style );
00110 static QString saveOasisStyleNumericScientific( KoGenStyles&mainStyles, FormatType _style, const QString &_prefix, const QString _suffix, int _precision );
00111 static QString saveOasisStyleNumericPercentage( KoGenStyles&mainStyles, FormatType _style, int _precision );
00112 static QString saveOasisStyleNumericMoney( KoGenStyles&mainStyles, FormatType _style, int _precision );
00113 static QString saveOasisStyleNumericText( KoGenStyles&mainStyles, FormatType _style, int _precision );
00114 static QString saveOasisStyleNumericNumber( KoGenStyles&mainStyles, FormatType _style, int _precision );
00115
00116
00117 StyleType type() const { return m_type; }
00118
00119 void saveXML( QDomDocument & doc, QDomElement & format ) const;
00120 bool loadXML( QDomElement & format );
00121
00122 QString saveOasisStyle( KoGenStyle &style, KoGenStyles &mainStyles );
00123 void loadOasisStyle( KoOasisStyles& oasisStyles, const QDomElement & element );
00124 static QString saveOasisBackgroundStyle( KoGenStyles &mainStyles, const QBrush &brush );
00125
00126
00127 bool release();
00128 void addRef();
00129
00130 int usage() const { return m_usageCount; }
00131
00132 bool hasProperty( Properties p ) const;
00133 bool hasFeature( FlagsSet f, bool withoutParent ) const;
00134 uint features() const { return m_featuresSet; }
00135
00136 uint bottomPenValue() const { return m_bottomPenValue; }
00137 uint rightPenValue() const { return m_rightPenValue; }
00138 uint leftPenValue() const { return m_leftPenValue; }
00139 uint topPenValue() const { return m_topPenValue; }
00140
00141 QPen const & pen() const;
00142 QColor const & bgColor() const;
00143 QPen const & rightBorderPen() const;
00144 QPen const & bottomBorderPen() const;
00145 QPen const & leftBorderPen() const;
00146 QPen const & topBorderPen() const;
00147 QPen const & fallDiagonalPen() const;
00148 QPen const & goUpDiagonalPen() const;
00149 QBrush const & backGroundBrush() const;
00150 QString const & strFormat() const;
00151 QString const & prefix() const;
00152 QString const & postfix() const;
00153 QString const & fontFamily() const;
00154
00155 KSpreadFormat::Align alignX() const;
00156 KSpreadFormat::AlignY alignY() const;
00157 KSpreadFormat::FloatFormat floatFormat() const;
00158 KSpreadFormat::FloatColor floatColor() const;
00159 FormatType formatType() const;
00160
00161 KSpreadFormat::Currency const & currency() const;
00162
00163 QFont font() const;
00164 uint fontFlags() const;
00165 int fontSize() const;
00166 int precision() const;
00167 int rotateAngle() const;
00168 double indent() const;
00169
00170 KSpreadStyle * setAlignX( KSpreadFormat::Align alignX );
00171 KSpreadStyle * setAlignY( KSpreadFormat::AlignY alignY );
00172 KSpreadStyle * setFont( QFont const & f );
00173 KSpreadStyle * setFontFamily( QString const & fam );
00174 KSpreadStyle * setFontFlags( uint flags );
00175 KSpreadStyle * setFontSize( int size );
00176 KSpreadStyle * setPen( QPen const & pen );
00177 KSpreadStyle * setBgColor( QColor const & color );
00178 KSpreadStyle * setRightBorderPen( QPen const & pen );
00179 KSpreadStyle * setBottomBorderPen( QPen const & pen );
00180 KSpreadStyle * setLeftBorderPen( QPen const & pen );
00181 KSpreadStyle * setTopBorderPen( QPen const & pen );
00182 KSpreadStyle * setFallDiagonalPen( QPen const & pen );
00183 KSpreadStyle * setGoUpDiagonalPen( QPen const & pen );
00184 KSpreadStyle * setRotateAngle( int angle );
00185 KSpreadStyle * setIndent( double indent );
00186 KSpreadStyle * setBackGroundBrush( QBrush const & brush );
00187 KSpreadStyle * setFloatFormat( KSpreadFormat::FloatFormat format );
00188 KSpreadStyle * setFloatColor( KSpreadFormat::FloatColor color );
00189 KSpreadStyle * setFormatType( FormatType format );
00190 KSpreadStyle * setStrFormat( QString const & strFormat );
00191 KSpreadStyle * setPrecision( int precision );
00192 KSpreadStyle * setPrefix( QString const & prefix );
00193 KSpreadStyle * setPostfix( QString const & postfix );
00194 KSpreadStyle * setCurrency( KSpreadFormat::Currency const & currency );
00195 KSpreadStyle * setProperty( Properties p );
00196 KSpreadStyle * clearProperty( Properties p );
00197
00198 KSpreadCustomStyle * parent() const;
00199 QString const & parentName() const { return m_parentName; }
00200 void setParent( KSpreadCustomStyle * parent );
00201
00202 protected:
00203
00204 KSpreadCustomStyle * m_parent;
00205 QString m_parentName;
00206 StyleType m_type;
00207 uint m_usageCount;
00208 uint m_featuresSet;
00209
00213 KSpreadFormat::Align m_alignX;
00217 KSpreadFormat::AlignY m_alignY;
00218
00219 KSpreadFormat::FloatFormat m_floatFormat;
00223 KSpreadFormat::FloatColor m_floatColor;
00224
00225 FormatType m_formatType;
00226
00230 QString m_fontFamily;
00231 uint m_fontFlags;
00232 int m_fontSize;
00233
00237 QPen m_textPen;
00241 QColor m_bgColor;
00242
00246 QPen m_rightBorderPen;
00247
00251 QPen m_bottomBorderPen;
00252
00256 QPen m_leftBorderPen;
00257
00261 QPen m_topBorderPen;
00262
00266 QPen m_fallDiagonalPen;
00270 QPen m_goUpDiagonalPen;
00271
00275 QBrush m_backGroundBrush;
00276
00277 int m_rotateAngle;
00281 double m_indent;
00285 QString m_strFormat;
00290 int m_precision;
00295 QString m_prefix;
00300 QString m_postfix;
00305 KSpreadFormat::Currency m_currency;
00306
00310 uint m_properties;
00311
00312 uint m_bottomPenValue;
00313 uint m_rightPenValue;
00314 uint m_leftPenValue;
00315 uint m_topPenValue;
00316
00317 bool featureSet( FlagsSet f ) const { return ( !m_parent || ( m_featuresSet & (uint) f ) ); }
00318 };
00319
00320 class KSpreadCustomStyle : public KSpreadStyle
00321 {
00322 public:
00323 KSpreadCustomStyle( KSpreadStyle * parent, QString const & name );
00324 KSpreadCustomStyle( QString const & name, KSpreadCustomStyle * parent );
00325 ~KSpreadCustomStyle();
00326
00327 QString const & name() const { return m_name; }
00328
00329 void save( QDomDocument & doc, QDomElement & styles );
00330 void saveOasis( KoGenStyles &mainStyles );
00331 void loadOasis( KoOasisStyles& oasisStyles, const QDomElement & style, const QString & name );
00332
00333 bool loadXML( QDomElement const & style, QString const & name );
00334
00335 void setType( StyleType type ) { m_type = type; }
00336
00337 void setName( QString const & name );
00338 void refreshParentName();
00339 bool definesAll() const;
00340
00341 void changeAlignX( KSpreadFormat::Align alignX );
00342 void changeAlignY( KSpreadFormat::AlignY alignY );
00343 void changeFont( QFont const & f );
00344 void changeFontFamily( QString const & fam );
00345 void changeFontSize( int size );
00346 void changeFontFlags( uint flags );
00347 void changePen( QPen const & pen );
00348 void changeTextColor( QColor const & color );
00349 void changeBgColor( QColor const & color );
00350 void changeRightBorderPen( QPen const & pen );
00351 void changeBottomBorderPen( QPen const & pen );
00352 void changeLeftBorderPen( QPen const & pen );
00353 void changeTopBorderPen( QPen const & pen );
00354 void changeFallBorderPen( QPen const & pen );
00355 void changeGoUpBorderPen( QPen const & pen );
00356 void changeRotateAngle( int angle );
00357 void changeIndent( double indent );
00358 void changeBackGroundBrush( QBrush const & brush );
00359 void changeFloatFormat( KSpreadFormat::FloatFormat format );
00360 void changeFloatColor( KSpreadFormat::FloatColor color );
00361 void changeFormatType( FormatType format );
00362 void changeStrFormat( QString const & strFormat );
00363 void changePrecision( int precision );
00364 void changePrefix( QString const & prefix );
00365 void changePostfix( QString const & postfix );
00366 void changeCurrency( KSpreadFormat::Currency const & currency );
00367
00368 void addProperty( Properties p );
00369 void removeProperty( Properties p );
00370
00371 private:
00372 friend class KSpreadStyleManager;
00373
00374 QString m_name;
00375
00376 KSpreadCustomStyle();
00377 };
00378
00379 #endif