00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef KSPREAD_CELL
00036 #define KSPREAD_CELL
00037
00038 #include <qpainter.h>
00039 #include <qptrlist.h>
00040 #include <qdatetime.h>
00041
00042 #include "kspread_condition.h"
00043
00044 class KLocale;
00045 class QDomElement;
00046 class QDomDocument;
00047 class KoXmlWriter;
00048 class KoGenStyles;
00049 class KoGenStyle;
00050 class KSParseNode;
00051 class KoRect;
00052 class KoPoint;
00053 class KoOasisStyles;
00054 class KoOasisLoadingContext;
00055
00056 namespace KSpread
00057 {
00058 class Canvas;
00059 class Format;
00060 class GenValidationStyles;
00061 class Sheet;
00062 class Value;
00063 class View;
00064 class ConditionalDialog;
00065
00066 struct Validity
00067 {
00068 Validity()
00069 {
00070 valMin = 0.0;
00071 valMax = 0.0;
00072 m_cond = Conditional::None;
00073 m_action = Action::Stop;
00074 m_restriction = Restriction::None;
00075 displayMessage = true;
00076 allowEmptyCell = false;
00077 displayValidationInformation = false;
00078 };
00079
00080 bool operator==( const Validity& other ) const
00081 {
00082 if ( message == other.message &&
00083 title == other.title &&
00084 titleInfo == other.titleInfo &&
00085 messageInfo == other.messageInfo &&
00086 valMin == other.valMin &&
00087 valMax == other.valMax &&
00088 m_cond == other.m_cond &&
00089 m_action == other.m_action &&
00090 m_restriction == other.m_restriction &&
00091 timeMin == other.timeMin &&
00092 timeMax == other.timeMax &&
00093 dateMin == other.dateMin &&
00094 dateMax == other.dateMax &&
00095 displayMessage == other.displayMessage &&
00096 allowEmptyCell == other.allowEmptyCell &&
00097 displayValidationInformation == other.displayValidationInformation &&
00098 listValidity == other.listValidity )
00099 {
00100 return true;
00101 }
00102 return false;
00103 }
00104 inline bool operator!=( const Validity& other ) const { return !operator==( other ); }
00105
00106 QString message;
00107 QString title;
00108 QString titleInfo;
00109 QString messageInfo;
00110 double valMin;
00111 double valMax;
00112 Conditional::Type m_cond;
00113 Action::Type m_action;
00114 Restriction::Type m_restriction;
00115 QTime timeMin;
00116 QTime timeMax;
00117 QDate dateMin;
00118 QDate dateMax;
00119 bool displayMessage;
00120 bool allowEmptyCell;
00121 bool displayValidationInformation;
00122 QStringList listValidity;
00123 };
00124
00125 class Formula;
00126
00137 class KSPREAD_EXPORT Cell
00138 {
00139 friend class Conditions;
00140 public:
00141
00142 Cell (Sheet *_sheet, int _column, int _row);
00143 Cell (Sheet *_sheet, Style * _style, int _column, int _row);
00144
00148 ~Cell();
00149
00153 Sheet* sheet() const;
00154
00159 bool isDefault() const;
00160
00164 bool isEmpty() const;
00165
00169 int column() const;
00170
00174 int row() const;
00175
00180 QString name() const;
00181
00186 QString fullName() const;
00187
00191 QString columnName() const;
00192
00197 static QString name( int col, int row );
00198
00203 static QString fullName( const Sheet *s, int col, int row );
00204
00209 static QString columnName( uint column );
00210
00214 KLocale* locale() const;
00218 bool isFormula() const;
00219
00224 QString text() const;
00225
00226 QString strOutText() const;
00227
00228 Formula *formula () const;
00229
00231 Format* format() const;
00232
00237 const Value value() const;
00238
00242 void setValue( const Value& value );
00243
00258 void setCellValue (const Value& value, FormatType fmtType = No_format,
00259 const QString& inputText = QString::null);
00260
00261 Cell* previousCell() const;
00262 Cell* nextCell() const;
00263 void setPreviousCell( Cell* c );
00264 void setNextCell( Cell* c );
00265
00270 void move( int column, int row );
00271
00275
00276
00277
00278 void sheetDies();
00279
00295 QDomElement save( QDomDocument& doc, int _x_offset = 0, int _y_offset = 0, bool force = false, bool copy = false, bool era = false );
00296
00297 bool saveOasis( KoXmlWriter& xmlwriter, KoGenStyles& mainStyles,
00298 int row, int column, int &repeated,
00299 GenValidationStyles &valStyle );
00300
00301 void saveOasisValue (KoXmlWriter &xmlWriter);
00302
00306 QString saveOasisCellStyle( KoGenStyle ¤tCellStyle,KoGenStyles &mainStyles );
00307
00308 bool load( const QDomElement& cell, int _xshift, int _yshift, Paste::Mode pm = Paste::Normal,
00309 Paste::Operation op = Paste::OverWrite, bool paste = false );
00310
00316 bool loadOasis( const QDomElement & element, KoOasisLoadingContext &oasisContext , Style* style);
00317
00318 QTime toTime(const QDomElement &element);
00319 QDate toDate(const QDomElement &element);
00320
00326 void copyFormat( const int column, const int row );
00332 void copyFormat( const Cell* cell );
00333 void copyContent( const Cell* cell );
00341 void copyAll( Cell *cell);
00342
00343 enum BorderSides
00344 {
00345 Border_None =0x00,
00346 Border_Left =0x01,
00347 Border_Right =0x02,
00348 Border_Top =0x04,
00349 Border_Bottom =0x08,
00350 Border_SizeGrip =0x10
00351
00352
00353 };
00354
00373 void paintCell( const KoRect & rect, QPainter & painter,
00374 View * view, const KoPoint & coordinate,
00375 const QPoint & cellRef,
00376 int paintBorder,
00377 QPen & rightPen,
00378 QPen & bottomPen,
00379 QPen & leftPen,
00380 QPen & topPen,
00381 QValueList<QPoint> &mergedCellsPainted,
00382 bool drawCursor = true );
00383
00384
00392 int width( int _col = -1, const Canvas *_canvas = 0L ) const;
00393
00400 int height( int _row = -1, const Canvas *_canvas = 0L ) const;
00401
00409 double dblWidth( int _col = -1, const Canvas *_canvas = 0L ) const;
00410
00417 double dblHeight( int _row = -1, const Canvas *_canvas = 0L ) const;
00418
00422 QRect cellRect();
00423
00431 bool needsPrinting() const;
00432
00440 void incPrecision();
00448 void decPrecision();
00449
00454 void setCellText( const QString& _text, bool asString = false );
00455
00461 void setDisplayText( const QString& _text );
00462
00469 void setLink( const QString& link );
00470
00475 QString link() const;
00476
00478
00479
00480
00482
00490 const QPen & effLeftBorderPen( int col, int row ) const;
00495 const QPen & effTopBorderPen( int col, int row ) const;
00500 const QPen & effRightBorderPen( int col, int row ) const;
00505 const QPen & effBottomBorderPen( int col, int row ) const;
00512 const QPen & effGoUpDiagonalPen( int col, int row ) const;
00517 const QPen & effFallDiagonalPen( int col, int row ) const;
00518 const QColor & effTextColor( int col, int row ) const;
00519
00525 uint effBottomBorderValue( int col, int row ) const;
00531 uint effRightBorderValue( int col, int row ) const;
00537 uint effLeftBorderValue( int col, int row ) const;
00543 uint effTopBorderValue( int col, int row ) const;
00544
00548 const QPen& leftBorderPen( int col, int row ) const;
00549
00553 const QPen& topBorderPen( int col, int row ) const;
00554
00558 const QPen& rightBorderPen( int col, int row ) const;
00559
00563 const QPen& bottomBorderPen( int col, int row ) const;
00564
00568 const QColor& bgColor( int col, int row ) const;
00569
00573 const QBrush& backGroundBrush( int col, int row ) const;
00574
00576
00577
00578
00580
00584 void setLeftBorderPen( const QPen& p );
00585
00589 void setTopBorderPen( const QPen& p );
00590
00594 void setRightBorderPen( const QPen& p );
00595
00599 void setBottomBorderPen( const QPen& p );
00600
00602
00603
00604
00606
00613 FormatType formatType() const;
00614
00616 bool isDate() const;
00618 bool isTime() const;
00619
00620 void setNumber( double number );
00621
00623 double getDouble ();
00624
00626 void convertToDouble ();
00628 void convertToPercent ();
00630 void convertToMoney ();
00632 void convertToTime ();
00634 void convertToDate ();
00635
00637 double textWidth() const;
00639 double textHeight() const;
00640
00641
00648 bool updateChart(bool refresh=true);
00649
00650 QString testAnchor( int _x, int _y ) const;
00651
00660 bool calc(bool delay = true);
00661
00663 void setCalcDirtyFlag();
00665 bool calcDirtyFlag();
00666
00676 void NotifyDepending( int col, int row, Sheet* sheet, bool isDepending );
00677
00683 void setLayoutDirtyFlag( bool format = false );
00684 bool layoutDirtyFlag() const;
00685
00686 void clearDisplayDirtyFlag();
00687 void setDisplayDirtyFlag();
00688
00697 void obscure( Cell *cell, bool isForcing = false);
00703 void unobscure(Cell* cell);
00707 bool isObscured() const;
00714 bool isPartOfMerged() const;
00715
00722 Cell *ultimateObscuringCell() const;
00723
00727 QValueList<Cell*> obscuringCells() const;
00728
00729 void clearObscuringCells();
00730
00731
00743 void mergeCells( int _col, int _row, int _x, int _y );
00744
00748 bool doesMergeCells() const;
00749
00754 int mergedXCells() const;
00755
00760 int mergedYCells() const;
00761
00765 int extraXCells() const;
00766
00770 int extraYCells() const;
00771
00772 double extraWidth() const;
00773 double extraHeight() const;
00774
00784 QString encodeFormula( bool _era = false, int _col = -1, int _row = -1 ) const;
00785 QString decodeFormula( const QString &_text, int _col = -1, int _row = -1 ) const;
00786
00796 QString pasteOperation( const QString &new_text, const QString &old_text, Paste::Operation op );
00797
00802 bool hasError() const;
00803
00807 void clearAllErrors();
00808
00813 void makeLayout( QPainter &_painter, int _col, int _row );
00814
00820 bool makeFormula();
00821
00822
00823 void defaultStyle();
00824
00828 QValueList<Conditional> conditionList() const;
00829
00833 void setConditionList(const QValueList<Conditional> &newList);
00834
00835 Validity * getValidity( int newStruct = -1 );
00836
00837 void removeValidity();
00838
00843 bool testValidity() const;
00844
00849 void calculateTextParameters( QPainter &painter, int _col, int _row );
00850
00854 int defineAlignX();
00855
00856
00857
00858
00862 bool operator > ( const Cell & ) const;
00863 bool operator < ( const Cell & ) const;
00864
00865 bool operator==( const Cell& other ) const;
00866 inline bool operator!=( const Cell& other ) const { return !operator==( other ); }
00867
00868 void freeAllObscuredCells();
00869
00870
00871 enum CellFlags{
00872
00873
00874
00875 Flag_LayoutDirty = 0x00010000,
00876 Flag_CalcDirty = 0x00020000,
00877 Flag_Progress = 0x00040000,
00878 Flag_UpdatingDeps = 0x00080000,
00879 Flag_DisplayDirty = 0x00100000,
00880 Flag_Merged = 0x00200000,
00881 Flag_CellTooShortX = 0x00400000,
00882 Flag_CellTooShortY = 0x00800000,
00883 Flag_ParseError = 0x01000000,
00884 Flag_CircularCalculation = 0x02000000,
00885 Flag_DependancyError = 0x04000000,
00886 Flag_PaintingCell = 0x08000000,
00887 Flag_TextFormatDirty = 0x10000000
00888
00889 };
00890
00891 void clearFlag( CellFlags flag );
00892 void setFlag( CellFlags flag );
00893 bool testFlag( CellFlags flag ) const;
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950 protected:
00954 void applyZoomedFont( QPainter &painter, int _col, int _row );
00955
00960 void textSize( QPainter &_paint );
00961
00966 QString textDisplaying( QPainter &painter);
00967
00973 void clearFormula();
00974
00983 void checkTextInput();
00984
00989 void checkNumberFormat();
00990
00995 void loadOasisCellText( const QDomElement& parent );
00996 void loadOasisObjects( const QDomElement& e, KoOasisLoadingContext& oasisContext );
00997 void loadOasisValidation( const QString& validationName );
00998
00999 void loadOasisValidationCondition( QString &valExpression );
01000 void saveOasisAnnotation( KoXmlWriter &xmlwriter );
01001 void loadOasisConditional( QDomElement * style );
01002
01003
01004
01005 private:
01006
01007 class Extra;
01008 class Private;
01009 Private *d;
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024 void paintCellBorders( QPainter& painter, const KoRect &rect,
01025 const KoRect &cellRect,
01026 const QPoint &cellRef,
01027 bool paintBorderRight, bool paintBorderBottom,
01028 bool paintBorderLeft, bool paintBorderTop,
01029 QPen & rightPen, QPen & bottomPen,
01030 QPen & leftPen, QPen & topPen );
01031 void paintPageBorders( QPainter& painter, const KoRect &cellRect,
01032 const QPoint &cellRef,
01033 bool paintBorderRight, bool paintBorderBottom );
01034 void paintText( QPainter& painter, const KoRect &cellRect,
01035 const QPoint &cellRef );
01036 void paintMoreTextIndicator( QPainter& painter, const KoRect &cellRect,
01037 QColor &backgroundColor );
01038 void paintCommentIndicator( QPainter& painter, const KoRect &cellRect,
01039 const QPoint &cellRef, QColor &backgroundColor );
01040 void paintFormulaIndicator( QPainter& painter, const KoRect &cellRect,
01041 QColor &backgroundColor );
01042 void paintDefaultBorders( QPainter& painter, const KoRect &rect,
01043 const KoRect &cellRect, const QPoint &cellRef,
01044 bool paintBorderRight, bool paintBorderBottom,
01045 bool paintBorderLeft, bool paintBorderTop,
01046 QPen const & rightPen, QPen const & bottomPen,
01047 QPen const & leftPen, QPen const & topPen );
01048 void paintBackground( QPainter& painter, const KoRect &cellRect,
01049 const QPoint &cellRef, bool selected,
01050 QColor &backgroundColor );
01051 void paintObscuredCells( const KoRect& rect, QPainter& painter,
01052 View* view, const KoRect &cellRect,
01053 const QPoint &cellRef,
01054 bool paintBorderRight, bool paintBorderBottom,
01055 bool paintBorderLeft, bool paintBorderTop,
01056 QPen & rightPen, QPen & bottomPen,
01057 QPen & leftPen, QPen & topPen,
01058 QValueList<QPoint> &mergedCellsPainted );
01059 void paintCellDiagonalLines( QPainter& painter, const KoRect &cellRect,
01060 const QPoint &cellRef );
01061
01062
01063
01064
01067 void valueChanged ();
01068
01069
01070
01071 void setOutputText();
01072
01073
01074
01075 bool loadCellData(const QDomElement &text, Paste::Operation op);
01076 bool saveCellResult( QDomDocument& doc, QDomElement& result,
01077 QString str );
01078 void update();
01079 int effAlignX();
01080
01086 void offsetAlign( int _col, int _row );
01087
01088 void checkForNamedAreas( QString & formula ) const;
01096 QString convertFormulaToOasisFormat( const QString & formula ) const;
01097 void loadOasisValidationValue( const QStringList &listVal );
01098
01099 };
01100
01101 }
01102
01103 #endif // KSPREAD_CELL