kspread

kspread_style.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Norbert Andres, nandres@web.de
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
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     // TODO Stefan: merge with Format::Properties
00079     enum FlagsSet
00080     {
00081       SAlignX          = 0x01,
00082       SAlignY          = 0x02,
00083       //SFactor was here
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       //SComment         = 0x400000,
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 
00137     static FormatType formatType( const QString &_format );
00138 
00143     static QString saveOasisStyleNumeric( KoGenStyle &style, KoGenStyles &mainStyles, FormatType _style, const QString &_prefix, const QString &_postfix, int _precision, const QString& symbol );
00144     static QString saveOasisStyleNumericDate( KoGenStyles &mainStyles, FormatType _style );
00145     static QString saveOasisStyleNumericFraction( KoGenStyles &mainStyles, FormatType _style, const QString &_prefix, const QString _suffix );
00146     static QString saveOasisStyleNumericTime( KoGenStyles& mainStyles, FormatType _style );
00147     static QString saveOasisStyleNumericCustom( KoGenStyles&mainStyles, FormatType _style );
00148     static QString saveOasisStyleNumericScientific( KoGenStyles&mainStyles, FormatType _style, const QString &_prefix, const QString _suffix, int _precision );
00149     static QString saveOasisStyleNumericPercentage( KoGenStyles&mainStyles, FormatType _style, int _precision );
00150     static QString saveOasisStyleNumericMoney( KoGenStyles&mainStyles, FormatType _style, int _precision );
00151     static QString saveOasisStyleNumericText( KoGenStyles&mainStyles, FormatType _style, int _precision );
00152     static QString saveOasisStyleNumericNumber( KoGenStyles&mainStyles, FormatType _style, int _precision );
00153 
00154 
00155   StyleType type() const { return m_type; }
00156 
00157   void saveXML( QDomDocument & doc, QDomElement & format ) const;
00158   bool loadXML( QDomElement & format );
00159 
00165   virtual QString saveOasis( KoGenStyle& style, KoGenStyles& mainStyles);
00166   void loadOasisStyle( KoOasisStyles& oasisStyles, const QDomElement & element );
00167   static QString saveOasisBackgroundStyle( KoGenStyles &mainStyles, const QBrush &brush );
00168 
00173   bool release();
00177   void addRef();
00181   int usage() const { return m_usageCount; }
00182 
00183   bool   hasProperty( Properties p ) const;
00184   bool   hasFeature( FlagsSet f, bool withoutParent ) const;
00185   uint   features() const { return m_featuresSet; }
00186 
00187   uint bottomPenValue() const { return m_bottomPenValue; }
00188   uint rightPenValue() const { return m_rightPenValue; }
00189   uint leftPenValue() const { return m_leftPenValue; }
00190   uint topPenValue() const { return m_topPenValue; }
00191 
00192   QPen    const & pen()             const;
00193   QColor  const & bgColor()         const;
00194   QPen    const & rightBorderPen()  const;
00195   QPen    const & bottomBorderPen() const;
00196   QPen    const & leftBorderPen()   const;
00197   QPen    const & topBorderPen()    const;
00198   QPen    const & fallDiagonalPen() const;
00199   QPen    const & goUpDiagonalPen() const;
00200   QBrush  const & backGroundBrush() const;
00201   QString const & strFormat()       const;
00202   QString const & prefix()          const;
00203   QString const & postfix()         const;
00204   QString const & fontFamily()      const;
00205 
00206   Format::Align       alignX()      const;
00207   Format::AlignY      alignY()      const;
00208   Format::FloatFormat floatFormat() const;
00209   Format::FloatColor  floatColor()  const;
00210   FormatType  formatType()  const;
00211 
00212   Format::Currency const & currency() const;
00213 
00214   QFont  font()        const;
00215   uint   fontFlags()   const;
00216   int    fontSize()    const;
00217   int    precision()   const;
00218   int    rotateAngle() const;
00219   double indent()      const;
00220 
00221   Style * setAlignX( Format::Align  alignX );
00222   Style * setAlignY( Format::AlignY alignY );
00223   Style * setFont( QFont const & f );
00224   Style * setFontFamily( QString const & fam );
00225   Style * setFontFlags( uint flags );
00226   Style * setFontSize( int size );
00227   Style * setPen( QPen const & pen );
00228   Style * setBgColor( QColor const & color );
00229   Style * setRightBorderPen( QPen const & pen );
00230   Style * setBottomBorderPen( QPen const & pen );
00231   Style * setLeftBorderPen( QPen const & pen );
00232   Style * setTopBorderPen( QPen const & pen );
00233   Style * setFallDiagonalPen( QPen const & pen );
00234   Style * setGoUpDiagonalPen( QPen const & pen );
00235   Style * setRotateAngle( int angle );
00236   Style * setIndent( double indent );
00237   Style * setBackGroundBrush( QBrush const & brush );
00238   Style * setFloatFormat( Format::FloatFormat format );
00239   Style * setFloatColor( Format::FloatColor color );
00240   Style * setFormatType( FormatType format );
00241   Style * setStrFormat( QString const & strFormat );
00242   Style * setPrecision( int precision );
00243   Style * setPrefix( QString const & prefix );
00244   Style * setPostfix( QString const & postfix );
00245   Style * setCurrency( Format::Currency const & currency );
00246   Style * setProperty( Properties p );
00247   Style * clearProperty( Properties p );
00248 
00249   CustomStyle * parent() const;
00250   QString const & parentName() const { return m_parentName; }
00251   void setParent( CustomStyle * parent );
00252 
00257   static QString colorName( const QColor& color );
00258 
00259 protected:
00264   void saveOasisStyle( KoGenStyle &style, KoGenStyles &mainStyles );
00265 
00266 
00267   CustomStyle * m_parent;
00268   QString        m_parentName;
00269   StyleType      m_type;
00270   uint           m_usageCount;
00271   uint           m_featuresSet;
00272 
00276   Format::Align m_alignX;
00280   Format::AlignY m_alignY;
00281 
00282   Format::FloatFormat m_floatFormat;
00286   Format::FloatColor m_floatColor;
00287 
00288   FormatType m_formatType;
00289 
00293   QString   m_fontFamily;
00294   uint      m_fontFlags;
00295   int       m_fontSize;
00296 
00300   QPen m_textPen;
00304   QColor m_bgColor;
00305 
00309   QPen m_rightBorderPen;
00310 
00314   QPen m_bottomBorderPen;
00315 
00319   QPen m_leftBorderPen;
00320 
00324   QPen m_topBorderPen;
00325 
00329   QPen m_fallDiagonalPen;
00333   QPen m_goUpDiagonalPen;
00334 
00338   QBrush m_backGroundBrush;
00339 
00340   int m_rotateAngle;
00344   double m_indent;
00348   QString m_strFormat;
00353   int m_precision;
00358   QString m_prefix;
00363   QString m_postfix;
00368   Format::Currency m_currency;
00369 
00373   uint m_properties;
00374 
00375   uint m_bottomPenValue;
00376   uint m_rightPenValue;
00377   uint m_leftPenValue;
00378   uint m_topPenValue;
00379 
00380   bool featureSet( FlagsSet f ) const { return ( !m_parent || ( m_featuresSet & (uint) f ) ); }
00381 };
00382 
00386 class CustomStyle : public Style
00387 {
00388 public:
00395   CustomStyle( Style * style, QString const & name );
00396   CustomStyle( QString const & name, CustomStyle * parent );
00397   ~CustomStyle();
00398 
00399   QString const & name() const { return m_name; }
00400 
00401   void save( QDomDocument & doc, QDomElement & styles );
00407   virtual QString saveOasis( KoGenStyle& style, KoGenStyles &mainStyles );
00415   void loadOasis( KoOasisStyles& oasisStyles, const QDomElement & style, const QString & name );
00416 
00417   bool loadXML( QDomElement const & style, QString const & name );
00418 
00419   void setType( StyleType type ) { m_type = type; }
00420 
00421   void setName( QString const & name );
00422   void refreshParentName();
00423   bool definesAll() const;
00424 
00425   void changeAlignX( Format::Align  alignX );
00426   void changeAlignY( Format::AlignY alignY );
00427   void changeFont( QFont const & f );
00428   void changeFontFamily( QString const & fam );
00429   void changeFontSize( int size );
00430   void changeFontFlags( uint flags );
00431   void changePen( QPen const & pen );
00432   void changeTextColor( QColor const & color );
00433   void changeBgColor( QColor const & color );
00434   void changeRightBorderPen( QPen const & pen );
00435   void changeBottomBorderPen( QPen const & pen );
00436   void changeLeftBorderPen( QPen const & pen );
00437   void changeTopBorderPen( QPen const & pen );
00438   void changeFallBorderPen( QPen const & pen );
00439   void changeGoUpBorderPen( QPen const & pen );
00440   void changeRotateAngle( int angle );
00441   void changeIndent( double indent );
00442   void changeBackGroundBrush( QBrush const & brush );
00443   void changeFloatFormat( Format::FloatFormat format );
00444   void changeFloatColor( Format::FloatColor color );
00445   void changeFormatType( FormatType format );
00446   void changeStrFormat( QString const & strFormat );
00447   void changePrecision( int precision );
00448   void changePrefix( QString const & prefix );
00449   void changePostfix( QString const & postfix );
00450   void changeCurrency( Format::Currency const & currency );
00451 
00452   void addProperty( Properties p );
00453   void removeProperty( Properties p );
00454 
00455  private:
00456   friend class StyleManager;
00457 
00458   QString              m_name;
00459 
00464   CustomStyle();
00465 };
00466 
00467 } // namespace KSpread
00468 
00469 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys