kspread

kspread_format.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999  Torben Weis <weis@kde.org>
00003    Copyright (C) 2000 - 2003 The KSpread Team
00004                               www.koffice.org/kspread
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
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     // TODO Stefan: merge with Style::FlagsSet
00063     enum Properties{ PAlign  = 0x01,
00064              PAlignY = 0x02,
00065          //PFactor was here
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     // Loading and saving
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(/* const QDomElement& element,*/ KoOasisLoadingContext& context );
00133     bool loadOasisStyleProperties(KoStyleStack & styleStack, const KoOasisStyles& oasisStyles );
00134     bool loadFontOasisStyle( KoStyleStack & font );
00138     QString saveOasisCellStyle( KoGenStyle &currentCellStyle, KoGenStyles &mainStyle );
00139 
00141     //
00142     // Properties
00143     //
00145     uint propertiesMask() { return m_mask; } // For the cell inspector only.
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     // Flags
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                       /* reserve the bits 0xFFFF0000 for subclasses to use */
00166                     };
00167     void clearFlag( FormatFlags flag );
00168     void setFlag( FormatFlags flag );
00169     bool testFlag( FormatFlags flag ) const;
00170 
00171 
00173     //
00174     // Methods for setting format stuff.
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     // Methods for querying format stuff.
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 protected:
00397     const QPen& rightBorderPen() const;
00398     const QPen& bottomBorderPen() const;
00399 
00403     void formatChanged();
00404 
00408     virtual Format* fallbackFormat( int col, int row );
00412     virtual const Format* fallbackFormat( int col, int row ) const;
00413 
00417     virtual bool isDefault() const;
00418 
00419     Sheet * m_pSheet;
00420     Style * m_pStyle;
00421 
00422     uint m_mask;
00423 
00428     uint m_bNoFallBack;
00429 
00430     Q_UINT32 m_flagsMask;
00431 
00435     QString * m_strComment;
00436 
00437 private:
00438     void setProperty( Properties p );
00439 
00443     const QPen & leftBorderPen() const;
00444     const QPen & topBorderPen() const;
00445     const QPen & fallDiagonalPen() const;
00446     const QPen & goUpDiagonalPen() const;
00447     const QBrush & backGroundBrush() const;
00448     const QFont textFont() const;
00449     const QPen  & textPen() const;
00450 
00451     Cell* m_pCell;
00452 };
00453 
00456 class KSPREAD_EXPORT RowFormat : public Format
00457 {
00458 public:
00459     RowFormat( Sheet * _sheet, int _row );
00460     ~RowFormat();
00461 
00462     DCOPObject* dcopObject();
00463 
00464     QDomElement save( QDomDocument&, int yshift = 0, bool copy = false ) const;
00465     bool load( const QDomElement& row, int yshift = 0, Paste::Mode sp = Paste::Normal, bool paste = false );
00466     bool loadOasis( const QDomElement& row, QDomElement * rowStyle );
00467 
00473     int height( const Canvas *_canvas = 0L ) const;
00480     double dblHeight( const Canvas *_canvas = 0L ) const;
00484     double mmHeight() const;
00491     void setHeight( int _h, const Canvas *_canvas = 0L );
00499     void setDblHeight( double _h, const Canvas *_canvas = 0L );
00505     void setMMHeight( double _h );
00506 
00510     void setDefault() { m_bDefault = true; }
00514     virtual bool isDefault() const;
00515 
00521     int row() const { return m_iRow; }
00522 
00523     void setRow( int _r ) { m_iRow = _r; }
00524 
00525     void setDisplayDirtyFlag() { m_bDisplayDirtyFlag = true; }
00526     void clearDisplayDirtyFlag() { m_bDisplayDirtyFlag = false; }
00527 
00528     RowFormat* next() const { return m_next; }
00529     RowFormat* previous() const { return m_prev; }
00530     void setNext( RowFormat* c ) { m_next = c; }
00531     void setPrevious( RowFormat* c ) { m_prev = c; }
00532 
00536     const QPen& bottomBorderPen( int col, int row ) const;
00540     void setBottomBorderPen( const QPen& p );
00544     const QPen& topBorderPen( int col, int row ) const;
00548     void setTopBorderPen( const QPen& p );
00549 
00553     void setHide( bool _hide, bool repaint = true );
00554     bool isHide()const { return m_bHide;}
00555 
00556 protected:
00560     virtual Format* fallbackFormat( int col, int row );
00564     virtual const Format* fallbackFormat( int col, int row ) const;
00565 
00569     double m_fHeight;
00570 
00577     bool m_bDefault;
00584     int m_iRow;
00585 
00586     bool m_bDisplayDirtyFlag;
00587     bool m_bHide;
00588     RowFormat* m_next;
00589     RowFormat* m_prev;
00590     DCOPObject*m_dcop;
00591 };
00592 
00595 class KSPREAD_EXPORT ColumnFormat : public Format
00596 {
00597 public:
00598     ColumnFormat( Sheet *_sheet, int _column );
00599     ~ColumnFormat();
00600 
00601     QDomElement save( QDomDocument&, int xshift = 0, bool copy = false ) const;
00602     bool load( const QDomElement& row, int xshift = 0,Paste::Mode sp = Paste::Normal, bool paste = false );
00603     DCOPObject* dcopObject();
00604 
00610     int width( const Canvas *_canvas = 0L ) const;
00618     double dblWidth( const Canvas *_canvas = 0L ) const;
00622     double mmWidth() const;
00630     void setWidth( int _w, const Canvas *_canvas = 0L );
00639     void setDblWidth( double _w, const Canvas *_canvas = 0L );
00645     void setMMWidth( double _w );
00646 
00650     void setDefault() { m_bDefault = true; }
00654     virtual bool isDefault() const;
00655 
00661     int column() const { return m_iColumn; }
00662 
00663     void setColumn( int _c ) { m_iColumn = _c; }
00664 
00665     void setDisplayDirtyFlag() { m_bDisplayDirtyFlag = true; }
00666     void clearDisplayDirtyFlag() { m_bDisplayDirtyFlag = false; }
00667 
00668     ColumnFormat* next() const { return m_next; }
00669     ColumnFormat* previous() const { return m_prev; }
00670     void setNext( ColumnFormat* c ) { m_next = c; }
00671     void setPrevious( ColumnFormat* c ) { m_prev = c; }
00672 
00676     virtual const QPen& rightBorderPen( int col, int row ) const;
00680     virtual void setRightBorderPen( const QPen& p );
00684     virtual const QPen& leftBorderPen( int col, int row ) const;
00688     virtual void setLeftBorderPen( const QPen& p );
00689 
00690     void setHide( bool _hide );
00691     bool isHide()const { return m_bHide;}
00692 
00693 
00694 protected:
00698     Format* fallbackFormat( int col, int row );
00702     const Format* fallbackFormat( int col, int row ) const;
00703 
00707     double m_fWidth;
00708 
00715     bool m_bDefault;
00722     int m_iColumn;
00723 
00724     bool m_bDisplayDirtyFlag;
00725 
00726     bool m_bHide;
00727 
00728     ColumnFormat* m_next;
00729     ColumnFormat* m_prev;
00730     DCOPObject*m_dcop;
00731 };
00732 
00733 class KSPREAD_EXPORT Currency
00734 {
00735  public:
00736 
00737   enum currencyFormat { Gnumeric, OpenCalc, ApplixSpread,
00738                         GobeProductiveSpread, HancomSheet };
00739 
00740   Currency();
00741   ~Currency();
00742 
00743   Currency(int index);
00744 
00748   Currency(int index, QString const & code);
00749 
00756   Currency(QString const & code, currencyFormat format);
00757   Currency & operator=(int type);
00758   Currency & operator=(char const * code);
00759   bool operator==(Currency const & cur) const;
00760   bool operator==(int type) const;
00761   operator int() const;
00762 
00763   QString getCode() const;
00764   QString getCountry() const;
00765   QString getName() const;
00766   QString getDisplayCode() const;
00767   int     getIndex() const;
00768 
00769   static QString getChooseString(int type, bool & ok);
00770   static QString getDisplaySymbol(int type);
00771   static QString getCurrencyCode( int type);
00772 
00776   QString getExportCode(currencyFormat format) const;
00777 
00778  private:
00779   int     m_type;
00780   QString m_code;
00781 };
00782 
00783 } // namespace KSpread
00784 
00785 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys