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 #ifndef KSPREAD_CELL
00035 #define KSPREAD_CELL
00036
00037 #include <qpainter.h>
00038 #include <qptrlist.h>
00039 #include <qdatetime.h>
00040
00041 #include "kspread_condition.h"
00042
00043 class KLocale;
00044 class QDomElement;
00045 class QDomDocument;
00046 class KoXmlWriter;
00047 class KoGenStyles;
00048 class KoGenStyle;
00049 class KSParseNode;
00050 class KoRect;
00051 class KoPoint;
00052 class KoOasisStyles;
00053 class KoOasisLoadingContext;
00054
00055 namespace KSpread
00056 {
00057 class Canvas;
00058 class Format;
00059 class GenValidationStyles;
00060 class Sheet;
00061 class Value;
00062 class View;
00063 class ConditionalDialog;
00064
00065 struct Validity
00066 {
00067 Validity()
00068 {
00069 valMin = 0.0;
00070 valMax = 0.0;
00071 m_cond = Conditional::None;
00072 m_action = Action::Stop;
00073 m_restriction = Restriction::None;
00074 displayMessage = true;
00075 allowEmptyCell = false;
00076 displayValidationInformation = false;
00077 };
00078
00079 QString message;
00080 QString title;
00081 QString titleInfo;
00082 QString messageInfo;
00083 double valMin;
00084 double valMax;
00085 Conditional::Type m_cond;
00086 Action::Type m_action;
00087 Restriction::Type m_restriction;
00088 QTime timeMin;
00089 QTime timeMax;
00090 QDate dateMin;
00091 QDate dateMax;
00092 bool displayMessage;
00093 bool allowEmptyCell;
00094 bool displayValidationInformation;
00095 QStringList listValidity;
00096 };
00097
00098 class Formula;
00099
00110 class KSPREAD_EXPORT Cell
00111 {
00112 friend class Conditions;
00113 public:
00114
00115 Cell (Sheet *_sheet, int _column, int _row);
00116 Cell (Sheet *_sheet, Style * _style, int _column, int _row);
00117
00121 ~Cell();
00122
00126 Sheet* sheet() const;
00127
00132 bool isDefault() const;
00133
00137 bool isEmpty() const;
00138
00142 int column() const;
00143
00147 int row() const;
00148
00153 QString name() const;
00154
00159 QString fullName() const;
00160
00164 QString columnName() const;
00165
00170 static QString name( int col, int row );
00171
00176 static QString fullName( const Sheet *s, int col, int row );
00177
00182 static QString columnName( uint column );
00183
00187 KLocale* locale() const;
00191 bool isFormula() const;
00192
00197 QString text() const;
00198
00199 QString strOutText() const;
00200
00201 Formula *formula () const;
00202
00204 Format* format() const;
00205
00210 const Value value() const;
00211
00215 void setValue( const Value& value );
00218 void setCellValue (const Value &v, FormatType fmtType = No_format,
00219 const QString &txt = QString::null);
00220
00221 Cell* previousCell() const;
00222 Cell* nextCell() const;
00223 void setPreviousCell( Cell* c );
00224 void setNextCell( Cell* c );
00225
00230 void move( int column, int row );
00231
00235
00236
00237
00238 void sheetDies();
00239
00255 QDomElement save( QDomDocument& doc, int _x_offset = 0, int _y_offset = 0, bool force = false, bool copy = false, bool era = false );
00256
00257 virtual bool saveOasis( KoXmlWriter& xmlwriter , KoGenStyles &mainStyles, int row, int column, int maxCol, int &repeated, GenValidationStyles &valStyle );
00258
00259 void saveOasisValue (KoXmlWriter &xmlWriter);
00260
00264 QString saveOasisCellStyle( KoGenStyle ¤tCellStyle,KoGenStyles &mainStyles );
00265
00266 bool load( const QDomElement& cell, int _xshift, int _yshift, Paste::Mode pm = Paste::Normal,
00267 Paste::Operation op = Paste::OverWrite, bool paste = false );
00268
00274 bool loadOasis( const QDomElement & element, KoOasisLoadingContext &oasisContext , Style* style);
00275
00276 QTime toTime(const QDomElement &element);
00277 QDate toDate(const QDomElement &element);
00278
00284 void copyFormat( const int column, const int row );
00290 void copyFormat( const Cell* cell );
00291 void copyContent( const Cell* cell );
00299 void copyAll( Cell *cell);
00300
00301 enum BorderSides
00302 {
00303 Border_None =0x00,
00304 Border_Left =0x01,
00305 Border_Right =0x02,
00306 Border_Top =0x04,
00307 Border_Bottom =0x08,
00308 Border_SizeGrip =0x10
00309
00310
00311 };
00312
00331 void paintCell( const KoRect & rect, QPainter & painter,
00332 View * view, const KoPoint & coordinate,
00333 const QPoint & cellRef,
00334 int paintBorder,
00335 QPen & rightPen,
00336 QPen & bottomPen,
00337 QPen & leftPen,
00338 QPen & topPen,
00339 QValueList<QPoint> &mergedCellsPainted,
00340 bool drawCursor = true );
00341
00342
00350 int width( int _col = -1, const Canvas *_canvas = 0L ) const;
00351
00358 int height( int _row = -1, const Canvas *_canvas = 0L ) const;
00359
00367 double dblWidth( int _col = -1, const Canvas *_canvas = 0L ) const;
00368
00375 double dblHeight( int _row = -1, const Canvas *_canvas = 0L ) const;
00376
00380 QRect cellRect();
00381
00389 bool needsPrinting() const;
00390
00398 void incPrecision();
00406 void decPrecision();
00407
00412 void setCellText( const QString& _text, bool asString = false );
00413
00419 void setDisplayText( const QString& _text );
00420
00427 void setLink( const QString& link );
00428
00433 QString link() const;
00434
00436
00437
00438
00440
00448 const QPen & effLeftBorderPen( int col, int row ) const;
00453 const QPen & effTopBorderPen( int col, int row ) const;
00458 const QPen & effRightBorderPen( int col, int row ) const;
00463 const QPen & effBottomBorderPen( int col, int row ) const;
00470 const QPen & effGoUpDiagonalPen( int col, int row ) const;
00475 const QPen & effFallDiagonalPen( int col, int row ) const;
00476 const QColor & effTextColor( int col, int row ) const;
00477
00483 uint effBottomBorderValue( int col, int row ) const;
00489 uint effRightBorderValue( int col, int row ) const;
00495 uint effLeftBorderValue( int col, int row ) const;
00501 uint effTopBorderValue( int col, int row ) const;
00502
00506 const QPen& leftBorderPen( int col, int row ) const;
00507
00511 const QPen& topBorderPen( int col, int row ) const;
00512
00516 const QPen& rightBorderPen( int col, int row ) const;
00517
00521 const QPen& bottomBorderPen( int col, int row ) const;
00522
00526 const QColor& bgColor( int col, int row ) const;
00527
00531 const QBrush& backGroundBrush( int col, int row ) const;
00532
00534
00535
00536
00538
00542 void setLeftBorderPen( const QPen& p );
00543
00547 void setTopBorderPen( const QPen& p );
00548
00552 void setRightBorderPen( const QPen& p );
00553
00557 void setBottomBorderPen( const QPen& p );
00558
00560
00561
00562
00564
00571 FormatType formatType() const;
00572
00574 bool isDate() const;
00576 bool isTime() const;
00577
00578 void setNumber( double number );
00579
00581 double getDouble ();
00582
00584 void convertToDouble ();
00586 void convertToPercent ();
00588 void convertToMoney ();
00590 void convertToTime ();
00592 void convertToDate ();
00593
00595 double textWidth() const;
00597 double textHeight() const;
00598
00599
00606 bool updateChart(bool refresh=true);
00607
00608 QString testAnchor( int _x, int _y ) const;
00609
00618 bool calc(bool delay = true);
00619
00621 void setCalcDirtyFlag();
00623 bool calcDirtyFlag();
00624
00634 void NotifyDepending( int col, int row, Sheet* sheet, bool isDepending );
00635
00641 virtual void setLayoutDirtyFlag( bool format = false );
00642 bool layoutDirtyFlag() const;
00643
00644 void clearDisplayDirtyFlag();
00645 void setDisplayDirtyFlag();
00646
00655 void obscure( Cell *cell, bool isForcing = false);
00661 void unobscure(Cell* cell);
00665 bool isObscured() const;
00672 bool isPartOfMerged() const;
00673
00680 Cell *ultimateObscuringCell() const;
00681
00685 QValueList<Cell*> obscuringCells() const;
00686
00687 void clearObscuringCells();
00688
00689
00701 void mergeCells( int _col, int _row, int _x, int _y );
00702
00706 bool doesMergeCells() const;
00707
00712 int mergedXCells() const;
00713
00718 int mergedYCells() const;
00719
00723 int extraXCells() const;
00724
00728 int extraYCells() const;
00729
00730 double extraWidth() const;
00731 double extraHeight() const;
00732
00742 QString encodeFormula( bool _era = false, int _col = -1, int _row = -1 ) const;
00743 QString decodeFormula( const QString &_text, int _col = -1, int _row = -1 ) const;
00744
00754 QString pasteOperation( const QString &new_text, const QString &old_text, Paste::Operation op );
00755
00760 bool hasError() const;
00761
00765 void clearAllErrors();
00766
00771 void makeLayout( QPainter &_painter, int _col, int _row );
00772
00778 bool makeFormula();
00779
00780
00781 void defaultStyle();
00782
00786 QValueList<Conditional> conditionList() const;
00787
00791 void setConditionList(const QValueList<Conditional> &newList);
00792
00793 Validity * getValidity( int newStruct = -1 );
00794
00795 void removeValidity();
00796
00801 bool testValidity() const;
00802
00807 void calculateTextParameters( QPainter &painter, int _col, int _row );
00808
00812 int defineAlignX();
00813
00814
00815
00816
00820 bool operator > ( const Cell & ) const;
00821 bool operator < ( const Cell & ) const;
00822
00823 void freeAllObscuredCells();
00824
00825
00826 enum CellFlags{
00827
00828
00829
00830 Flag_LayoutDirty = 0x00010000,
00831 Flag_CalcDirty = 0x00020000,
00832 Flag_Progress = 0x00040000,
00833 Flag_UpdatingDeps = 0x00080000,
00834 Flag_DisplayDirty = 0x00100000,
00835 Flag_Merged = 0x00200000,
00836 Flag_CellTooShortX = 0x00400000,
00837 Flag_CellTooShortY = 0x00800000,
00838 Flag_ParseError = 0x01000000,
00839 Flag_CircularCalculation = 0x02000000,
00840 Flag_DependancyError = 0x04000000,
00841 Flag_PaintingCell = 0x08000000,
00842 Flag_TextFormatDirty = 0x10000000
00843
00844 };
00845
00846 void clearFlag( CellFlags flag );
00847 void setFlag( CellFlags flag );
00848 bool testFlag( CellFlags flag ) const;
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905 protected:
00909 void applyZoomedFont( QPainter &painter, int _col, int _row );
00910
00915 void textSize( QPainter &_paint );
00916
00921 QString textDisplaying( QPainter &painter);
00922
00928 void clearFormula();
00929
00938 void checkTextInput();
00939
00944 void checkNumberFormat();
00945
00950 void loadOasisCellText( const QDomElement& parent );
00951 void loadOasisObjects( const QDomElement& e, KoOasisLoadingContext& oasisContext );
00952 void loadOasisValidation( const QString& validationName );
00953
00954 void loadOasisValidationCondition( QString &valExpression );
00955 void saveOasisAnnotation( KoXmlWriter &xmlwriter );
00956 void loadOasisConditional( QDomElement * style );
00957
00958
00959
00960 private:
00961
00962 class Extra;
00963 class Private;
00964 Private *d;
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979 void paintCellBorders( QPainter& painter, const KoRect &rect,
00980 const KoRect &cellRect,
00981 const QPoint &cellRef,
00982 bool paintBorderRight, bool paintBorderBottom,
00983 bool paintBorderLeft, bool paintBorderTop,
00984 QPen & rightPen, QPen & bottomPen,
00985 QPen & leftPen, QPen & topPen );
00986 void paintPageBorders( QPainter& painter, const KoRect &cellRect,
00987 const QPoint &cellRef,
00988 bool paintBorderRight, bool paintBorderBottom );
00989 void paintText( QPainter& painter, const KoRect &cellRect,
00990 const QPoint &cellRef );
00991 void paintMoreTextIndicator( QPainter& painter, const KoRect &cellRect,
00992 QColor &backgroundColor );
00993 void paintCommentIndicator( QPainter& painter, const KoRect &cellRect,
00994 const QPoint &cellRef, QColor &backgroundColor );
00995 void paintFormulaIndicator( QPainter& painter, const KoRect &cellRect,
00996 QColor &backgroundColor );
00997 void paintDefaultBorders( QPainter& painter, const KoRect &rect,
00998 const KoRect &cellRect, const QPoint &cellRef,
00999 bool paintBorderRight, bool paintBorderBottom,
01000 bool paintBorderLeft, bool paintBorderTop,
01001 QPen const & rightPen, QPen const & bottomPen,
01002 QPen const & leftPen, QPen const & topPen );
01003 void paintBackground( QPainter& painter, const KoRect &cellRect,
01004 const QPoint &cellRef, bool selected,
01005 QColor &backgroundColor );
01006 void paintObscuredCells( const KoRect& rect, QPainter& painter,
01007 View* view, const KoRect &cellRect,
01008 const QPoint &cellRef,
01009 bool paintBorderRight, bool paintBorderBottom,
01010 bool paintBorderLeft, bool paintBorderTop,
01011 QPen & rightPen, QPen & bottomPen,
01012 QPen & leftPen, QPen & topPen,
01013 QValueList<QPoint> &mergedCellsPainted );
01014 void paintCellDiagonalLines( QPainter& painter, const KoRect &cellRect,
01015 const QPoint &cellRef );
01016
01017
01018
01019
01022 void valueChanged ();
01023
01024
01025
01026 void setOutputText();
01027
01028
01029
01030 bool loadCellData(const QDomElement &text, Paste::Operation op);
01031 bool saveCellResult( QDomDocument& doc, QDomElement& result,
01032 QString str );
01033 void update();
01034 int effAlignX();
01035
01041 void offsetAlign( int _col, int _row );
01042
01043 void checkForNamedAreas( QString & formula ) const;
01051 QString convertFormulaToOasisFormat( const QString & formula ) const;
01052 void loadOasisValidationValue( const QStringList &listVal );
01053
01054 };
01055
01056 }
01057
01058 #endif // KSPREAD_CELL