00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __kspread_format_h__
00023 #define __kspread_format_h__
00024
00025 #include <qbrush.h>
00026 #include <qcolor.h>
00027 #include <qfont.h>
00028 #include <qpen.h>
00029
00030 #include <koffice_export.h>
00031
00032 #include "kspread_global.h"
00033
00034 class QDomElement;
00035 class QDomDocument;
00036 class DCOPObject;
00037 class KLocale;
00038 class KoGenStyle;
00039 class KoGenStyles;
00040 class KoOasisLoadingContext;
00041 class KoOasisStyles;
00042 class KoStyleStack;
00043
00044 namespace KSpread
00045 {
00046 class Canvas;
00047 class Cell;
00048 class Currency;
00049 class Sheet;
00050 class Style;
00051
00054 class KSPREAD_EXPORT Format
00055 {
00056 public:
00057 enum Align { Left = 1, Center = 2, Right = 3, Undefined = 4 };
00058 enum AlignY { Top = 1, Middle = 2, Bottom = 3, UndefinedY = 4 };
00059 enum FloatFormat { AlwaysSigned = 1, AlwaysUnsigned = 2, OnlyNegSigned = 3 };
00060 enum FloatColor { NegRed = 1, AllBlack = 2, NegBrackets = 3, NegRedBrackets = 4 };
00061
00062
00063 enum Properties{ PAlign = 0x01,
00064 PAlignY = 0x02,
00065
00066 PPrefix = 0x08,
00067 PPostfix = 0x10,
00068 PLeftBorder = 0x20,
00069 PRightBorder = 0x40,
00070 PTopBorder = 0x80,
00071 PBottomBorder = 0x100,
00072 PFallDiagonal = 0x200,
00073 PGoUpDiagonal = 0x400,
00074 PBackgroundBrush = 0x800,
00075 PFont = 0x1000,
00076 PTextPen = 0x2000,
00077 PBackgroundColor = 0x4000,
00078 PFloatFormat = 0x8000,
00079 PFloatColor = 0x10000,
00080 PMultiRow = 0x20000,
00081 PVerticalText = 0x40000,
00082 PPrecision = 0x80000,
00083 PFormatType = 0x100000,
00084 PAngle = 0x200000,
00085 PComment = 0x400000,
00086 PIndent = 0x800000,
00087 PDontPrintText = 0x1000000,
00088 PCustomFormat = 0x2000000,
00089 PNotProtected = 0x4000000,
00090 PHideAll = 0x8000000,
00091 PHideFormula = 0x10000000 };
00092
00093 struct Currency
00094 {
00095 int type;
00096 QString symbol;
00097 };
00098
00108 Format( Sheet* sheet, Style* style );
00114 virtual ~Format();
00115
00116 void copy( const Format& other );
00117
00118 void defaultStyleFormat();
00119
00121
00122
00123
00125
00126 bool load( const QDomElement & f, Paste::Mode pm, bool paste = false );
00127 bool loadFormat( const QDomElement & f, Paste::Mode pm = Paste::Normal, bool paste = false );
00128 QDomElement save( QDomDocument& doc,int _col, int _row,bool force = false, bool copy = false ) const;
00129 QDomElement saveFormat( QDomDocument& doc, bool force = false, bool copy = false ) const;
00130 QDomElement saveFormat( QDomDocument& doc, int _col, int _row, bool force = false, bool copy = false ) const;
00131
00132 void loadOasisStyle( KoOasisLoadingContext& context );
00133 bool loadOasisStyleProperties(KoStyleStack & styleStack, const KoOasisStyles& oasisStyles );
00134 bool loadFontOasisStyle( KoStyleStack & font );
00138 QString saveOasisCellStyle( KoGenStyle ¤tCellStyle, KoGenStyles &mainStyle );
00139
00141
00142
00143
00145 uint propertiesMask() { return m_mask; }
00146 void clearProperties();
00147 void clearProperty( Properties p );
00148
00149 void clearNoFallBackProperties( ) ;
00150 void clearNoFallBackProperties( Properties p ) ;
00151 void setNoFallBackProperties(Properties p);
00152 bool hasNoFallBackProperties( Properties p ) const ;
00153
00155
00156
00157
00159 enum FormatFlags{ Flag_MultiRow = 0x00000001,
00160 Flag_VerticalText = 0x00000002,
00161 Flag_DontPrintText = 0x00000004,
00162 Flag_HideAll = 0x00000008,
00163 Flag_HideFormula = 0x00000010,
00164 Flag_NotProtected = 0x00000020
00165
00166 };
00167 void clearFlag( FormatFlags flag );
00168 void setFlag( FormatFlags flag );
00169 bool testFlag( FormatFlags flag ) const;
00170
00171
00173
00174
00175
00177
00178 static void setGlobalColWidth( double width );
00179 static void setGlobalRowHeight( double height );
00180 static double globalRowHeight();
00181 static double globalColWidth();
00182
00183
00184 void setStyle( Style * style );
00185 void setCell( Cell* cell ) { m_pCell = cell; }
00186
00190 void setFormatString( QString const & format );
00191
00192 void setAlign( Align _align );
00193 void setAlignY( AlignY _alignY );
00194 void setPrefix( const QString& _prefix );
00195 void setPostfix( const QString& _postfix );
00196 void setPrecision( int _p );
00197
00198 virtual void setLeftBorderPen( const QPen& _p );
00199 void setLeftBorderStyle( Qt::PenStyle s );
00200 void setLeftBorderColor( const QColor & _c );
00201 void setLeftBorderWidth( int _w );
00202
00203 virtual void setTopBorderPen( const QPen& _p );
00204 void setTopBorderStyle( Qt::PenStyle s );
00205 void setTopBorderColor( const QColor & _c );
00206 void setTopBorderWidth( int _w );
00207
00208 virtual void setRightBorderPen( const QPen& p );
00209 void setRightBorderStyle( Qt::PenStyle _s );
00210 void setRightBorderColor( const QColor & _c );
00211 void setRightBorderWidth( int _w );
00212
00213 virtual void setBottomBorderPen( const QPen& p );
00214 void setBottomBorderStyle( Qt::PenStyle _s );
00215 void setBottomBorderColor( const QColor & _c );
00216 void setBottomBorderWidth( int _w );
00217
00218 void setFallDiagonalPen( const QPen& _p );
00219 void setFallDiagonalStyle( Qt::PenStyle s );
00220 void setFallDiagonalColor( const QColor & _c );
00221 void setFallDiagonalWidth( int _w );
00222
00223 void setGoUpDiagonalPen( const QPen& _p );
00224 void setGoUpDiagonalStyle( Qt::PenStyle s );
00225 void setGoUpDiagonalColor( const QColor & _c );
00226 void setGoUpDiagonalWidth( int _w );
00227
00228 void setBackGroundBrush( const QBrush& _p);
00229 void setBackGroundBrushStyle( Qt::BrushStyle s);
00230 void setBackGroundBrushColor( const QColor & _c);
00231
00232 void setTextFont( const QFont& _f );
00233 void setTextFontSize( int _s );
00234 void setTextFontFamily( const QString& _f );
00235 void setTextFontBold( bool _b );
00236 void setTextFontItalic( bool _i );
00237 void setTextFontUnderline( bool _i );
00238 void setTextFontStrike( bool _i );
00239
00240 void setTextPen( const QPen& _p );
00241 void setTextColor( const QColor & _c );
00242
00243 void setBgColor( const QColor & _c );
00244
00245 void setFloatFormat( FloatFormat _f );
00246 void setFloatColor( FloatColor _c );
00247
00248 void setMultiRow( bool _b );
00249
00250 void setVerticalText( bool _b );
00251
00252 void setFormatType(FormatType _format);
00253
00254 void setAngle(int _angle);
00255
00256 void setComment( const QString& c );
00257
00258 void setIndent( double _indent );
00259
00260 void setDontPrintText( bool _b );
00261 void setNotProtected( bool _b );
00262 void setHideAll( bool _b );
00263 void setHideFormula( bool _b );
00264
00265 void setCurrency( Currency const & c );
00266 void setCurrency( int type, QString const & symbol );
00267
00269
00270
00271
00273
00274 QString const & getFormatString( int col, int row ) const;
00275
00276 virtual const QPen& leftBorderPen( int col, int row ) const;
00277 int leftBorderWidth( int col, int row ) const;
00278 Qt::PenStyle leftBorderStyle( int col, int row ) const;
00279 const QColor& leftBorderColor( int col, int row ) const;
00280
00281 virtual const QPen& topBorderPen( int col, int row ) const;
00282 int topBorderWidth( int col, int row ) const;
00283 Qt::PenStyle topBorderStyle( int col, int row ) const;
00284 const QColor& topBorderColor( int col, int row ) const;
00285
00286 virtual const QPen& rightBorderPen( int col, int row ) const;
00287 int rightBorderWidth( int col, int row ) const;
00288 Qt::PenStyle rightBorderStyle( int col, int row ) const;
00289 const QColor& rightBorderColor( int col, int row ) const;
00290
00291 virtual const QPen& bottomBorderPen( int col, int row ) const;
00292 int bottomBorderWidth( int col, int row ) const;
00293 Qt::PenStyle bottomBorderStyle( int col, int row ) const;
00294 const QColor& bottomBorderColor( int col, int row ) const;
00295
00296 const QPen& fallDiagonalPen( int col, int row ) const;
00297 int fallDiagonalWidth( int col, int row ) const;
00298 Qt::PenStyle fallDiagonalStyle( int col, int row ) const;
00299 const QColor& fallDiagonalColor( int col, int row ) const;
00300
00301 const QPen& goUpDiagonalPen( int col, int row ) const;
00302 int goUpDiagonalWidth( int col, int row ) const;
00303 Qt::PenStyle goUpDiagonalStyle( int col, int row ) const;
00304 const QColor& goUpDiagonalColor( int col, int row ) const;
00305
00306 const QBrush& backGroundBrush( int col, int row ) const;
00307 Qt::BrushStyle backGroundBrushStyle( int col, int row ) const;
00308 const QColor& backGroundBrushColor(int col, int row ) const;
00309
00310 uint bottomBorderValue( int col, int row ) const;
00311 uint rightBorderValue( int col, int row ) const;
00312 uint leftBorderValue( int col, int row ) const;
00313 uint topBorderValue( int col, int row ) const;
00314
00318 int precision( int col, int row ) const;
00322 QString prefix( int col, int row ) const;
00326 QString postfix( int col, int row ) const;
00330 FloatFormat floatFormat( int col, int row ) const;
00334 FloatColor floatColor( int col, int row ) const;
00335
00336 const QPen& textPen( int col, int row ) const;
00340 const QColor& textColor( int col, int row ) const;
00341
00348 const QColor& bgColor( int col, int row ) const;
00349
00350 const QFont textFont( int col, int row ) const;
00351 int textFontSize( int col, int row ) const;
00352 QString const & textFontFamily( int col, int row ) const;
00353 bool textFontBold( int col, int row ) const;
00354 bool textFontItalic( int col, int row ) const;
00355 bool textFontUnderline( int col, int row ) const;
00356 bool textFontStrike( int col, int row ) const;
00357
00358 Align align( int col, int row ) const;
00359 AlignY alignY( int col, int row ) const;
00360
00361 bool multiRow( int col, int row ) const;
00362
00363 bool verticalText( int col, int row ) const;
00364
00365 FormatType getFormatType(int col, int row )const ;
00366
00367 int getAngle(int col, int row) const;
00368
00369 const QString* comment() const { return m_strComment; };
00370 QString comment(int col, int row) const;
00371 QString * commentP( int col, int row ) const;
00372
00373 double getIndent(int col, int row) const;
00374
00375 bool getDontprintText( int col, int row) const;
00376 bool notProtected( int col, int row) const;
00377 bool isHideAll( int col, int row) const;
00378 bool isHideFormula( int col, int row) const;
00379 bool isProtected( int col, int row ) const;
00380
00381 Style* style() const { return m_pStyle; }
00382 Sheet* sheet() { return m_pSheet; }
00383 const Sheet* sheet() const { return m_pSheet; }
00384
00385 bool hasProperty( Properties p, bool withoutParent = false ) const;
00386
00391 bool currencyInfo( Currency & currency) const;
00392
00393 QString getCurrencySymbol() const;
00394 QFont font() const;
00395
00396 bool operator==( const Format& other ) const;
00397 inline bool operator!=( const Format& other ) const { return !operator==( other ); }
00398
00399 protected:
00400 const QPen& rightBorderPen() const;
00401 const QPen& bottomBorderPen() const;
00402
00406 void formatChanged();
00407
00411 virtual Format* fallbackFormat( int col, int row );
00415 virtual const Format* fallbackFormat( int col, int row ) const;
00416
00420 virtual bool isDefault() const;
00421
00422 Sheet * m_pSheet;
00423 Style * m_pStyle;
00424
00425 uint m_mask;
00426
00431 uint m_bNoFallBack;
00432
00433 Q_UINT32 m_flagsMask;
00434
00438 QString * m_strComment;
00439
00440
00441 static double s_columnWidth;
00442 static double s_rowHeight;
00443
00444 private:
00445 void setProperty( Properties p );
00446
00450 const QPen & leftBorderPen() const;
00451 const QPen & topBorderPen() const;
00452 const QPen & fallDiagonalPen() const;
00453 const QPen & goUpDiagonalPen() const;
00454 const QBrush & backGroundBrush() const;
00455 const QFont textFont() const;
00456 const QPen & textPen() const;
00457
00458 Cell* m_pCell;
00459 };
00460
00463 class KSPREAD_EXPORT RowFormat : public Format
00464 {
00465 public:
00466 RowFormat( Sheet * _sheet, int _row );
00467 ~RowFormat();
00468
00469 DCOPObject* dcopObject();
00470
00471 QDomElement save( QDomDocument&, int yshift = 0, bool copy = false ) const;
00472 bool load( const QDomElement& row, int yshift = 0, Paste::Mode sp = Paste::Normal, bool paste = false );
00473 bool loadOasis( const QDomElement& row, QDomElement * rowStyle );
00474
00480 int height( const Canvas *_canvas = 0L ) const;
00487 double dblHeight( const Canvas *_canvas = 0L ) const;
00491 double mmHeight() const;
00498 void setHeight( int _h, const Canvas *_canvas = 0L );
00506 void setDblHeight( double _h, const Canvas *_canvas = 0L );
00512 void setMMHeight( double _h );
00513
00517 void setDefault() { m_bDefault = true; }
00521 virtual bool isDefault() const;
00522
00528 int row() const { return m_iRow; }
00529
00530 void setRow( int _r ) { m_iRow = _r; }
00531
00532 void setDisplayDirtyFlag() { m_bDisplayDirtyFlag = true; }
00533 void clearDisplayDirtyFlag() { m_bDisplayDirtyFlag = false; }
00534
00535 RowFormat* next() const { return m_next; }
00536 RowFormat* previous() const { return m_prev; }
00537 void setNext( RowFormat* c ) { m_next = c; }
00538 void setPrevious( RowFormat* c ) { m_prev = c; }
00539
00543 const QPen& bottomBorderPen( int col, int row ) const;
00547 void setBottomBorderPen( const QPen& p );
00551 const QPen& topBorderPen( int col, int row ) const;
00555 void setTopBorderPen( const QPen& p );
00556
00560 void setHide( bool _hide, bool repaint = true );
00561 bool isHide()const { return m_bHide;}
00562
00563 bool operator==( const RowFormat& other ) const;
00564 inline bool operator!=( const RowFormat& other ) const { return !operator==( other ); }
00565
00566 protected:
00570 virtual Format* fallbackFormat( int col, int row );
00574 virtual const Format* fallbackFormat( int col, int row ) const;
00575
00579 double m_fHeight;
00580
00587 bool m_bDefault;
00594 int m_iRow;
00595
00596 bool m_bDisplayDirtyFlag;
00597 bool m_bHide;
00598 RowFormat* m_next;
00599 RowFormat* m_prev;
00600 DCOPObject*m_dcop;
00601 };
00602
00605 class KSPREAD_EXPORT ColumnFormat : public Format
00606 {
00607 public:
00608 ColumnFormat( Sheet *_sheet, int _column );
00609 ~ColumnFormat();
00610
00611 QDomElement save( QDomDocument&, int xshift = 0, bool copy = false ) const;
00612 bool load( const QDomElement& row, int xshift = 0,Paste::Mode sp = Paste::Normal, bool paste = false );
00613 DCOPObject* dcopObject();
00614
00620 int width( const Canvas *_canvas = 0L ) const;
00628 double dblWidth( const Canvas *_canvas = 0L ) const;
00632 double mmWidth() const;
00640 void setWidth( int _w, const Canvas *_canvas = 0L );
00649 void setDblWidth( double _w, const Canvas *_canvas = 0L );
00655 void setMMWidth( double _w );
00656
00660 void setDefault() { m_bDefault = true; }
00664 virtual bool isDefault() const;
00665
00671 int column() const { return m_iColumn; }
00672
00673 void setColumn( int _c ) { m_iColumn = _c; }
00674
00675 void setDisplayDirtyFlag() { m_bDisplayDirtyFlag = true; }
00676 void clearDisplayDirtyFlag() { m_bDisplayDirtyFlag = false; }
00677
00678 ColumnFormat* next() const { return m_next; }
00679 ColumnFormat* previous() const { return m_prev; }
00680 void setNext( ColumnFormat* c ) { m_next = c; }
00681 void setPrevious( ColumnFormat* c ) { m_prev = c; }
00682
00686 virtual const QPen& rightBorderPen( int col, int row ) const;
00690 virtual void setRightBorderPen( const QPen& p );
00694 virtual const QPen& leftBorderPen( int col, int row ) const;
00698 virtual void setLeftBorderPen( const QPen& p );
00699
00700 void setHide( bool _hide );
00701 bool isHide()const { return m_bHide;}
00702
00703 bool operator==( const ColumnFormat& other ) const;
00704 inline bool operator!=( const ColumnFormat& other ) const { return !operator==( other ); }
00705
00706 protected:
00710 Format* fallbackFormat( int col, int row );
00714 const Format* fallbackFormat( int col, int row ) const;
00715
00719 double m_fWidth;
00720
00727 bool m_bDefault;
00734 int m_iColumn;
00735
00736 bool m_bDisplayDirtyFlag;
00737
00738 bool m_bHide;
00739
00740 ColumnFormat* m_next;
00741 ColumnFormat* m_prev;
00742 DCOPObject*m_dcop;
00743 };
00744
00745 class KSPREAD_EXPORT Currency
00746 {
00747 public:
00748
00749 enum currencyFormat { Native, Gnumeric, OpenCalc, ApplixSpread,
00750 GobeProductiveSpread, HancomSheet };
00751
00752 Currency();
00753 ~Currency();
00754
00755 Currency(int index);
00756
00760 Currency(int index, QString const & code);
00761
00768 Currency(QString const & code, currencyFormat format = Native);
00769 Currency & operator=(int type);
00770 Currency & operator=(char const * code);
00771 bool operator==(Currency const & cur) const;
00772 bool operator==(int type) const;
00773 operator int() const;
00774
00775 QString getCode() const;
00776 QString getCountry() const;
00777 QString getName() const;
00778 QString getDisplayCode() const;
00779 int getIndex() const;
00780
00781 static QString getChooseString(int type, bool & ok);
00782 static QString getDisplaySymbol(int type);
00783 static QString getCurrencyCode( int type);
00784
00788 QString getExportCode(currencyFormat format) const;
00789
00790 private:
00791 int m_type;
00792 QString m_code;
00793 };
00794
00795 }
00796
00797 #endif