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 bool saveOasis( KoXmlWriter& xmlwriter, KoGenStyles& mainStyles,
00258 int row, int column, int &repeated,
00259 GenValidationStyles &valStyle );
00260
00261 void saveOasisValue (KoXmlWriter &xmlWriter);
00262
00266 QString saveOasisCellStyle( KoGenStyle ¤tCellStyle,KoGenStyles &mainStyles );
00267
00268 bool load( const QDomElement& cell, int _xshift, int _yshift, Paste::Mode pm = Paste::Normal,
00269 Paste::Operation op = Paste::OverWrite, bool paste = false );
00270
00276 bool loadOasis( const QDomElement & element, KoOasisLoadingContext &oasisContext , Style* style);
00277
00278 QTime toTime(const QDomElement &element);
00279 QDate toDate(const QDomElement &element);
00280
00286 void copyFormat( const int column, const int row );
00292 void copyFormat( const Cell* cell );
00293 void copyContent( const Cell* cell );
00301 void copyAll( Cell *cell);
00302
00303 enum BorderSides
00304 {
00305 Border_None =0x00,
00306 Border_Left =0x01,
00307 Border_Right =0x02,
00308 Border_Top =0x04,
00309 Border_Bottom =0x08,
00310 Border_SizeGrip =0x10
00311
00312
00313 };
00314
00333 void paintCell( const KoRect & rect, QPainter & painter,
00334 View * view, const KoPoint & coordinate,
00335 const QPoint & cellRef,
00336 int paintBorder,
00337 QPen & rightPen,
00338 QPen & bottomPen,
00339 QPen & leftPen,
00340 QPen & topPen,
00341 QValueList<QPoint> &mergedCellsPainted,
00342 bool drawCursor = true );
00343
00344
00352 int width( int _col = -1, const Canvas *_canvas = 0L ) const;
00353
00360 int height( int _row = -1, const Canvas *_canvas = 0L ) const;
00361
00369 double dblWidth( int _col = -1, const Canvas *_canvas = 0L ) const;
00370
00377 double dblHeight( int _row = -1, const Canvas *_canvas = 0L ) const;
00378
00382 QRect cellRect();
00383
00391 bool needsPrinting() const;
00392
00400 void incPrecision();
00408 void decPrecision();
00409
00414 void setCellText( const QString& _text, bool asString = false );
00415
00421 void setDisplayText( const QString& _text );
00422
00429 void setLink( const QString& link );
00430
00435 QString link() const;
00436
00438
00439
00440
00442
00450 const QPen & effLeftBorderPen( int col, int row ) const;
00455 const QPen & effTopBorderPen( int col, int row ) const;
00460 const QPen & effRightBorderPen( int col, int row ) const;
00465 const QPen & effBottomBorderPen( int col, int row ) const;
00472 const QPen & effGoUpDiagonalPen( int col, int row ) const;
00477 const QPen & effFallDiagonalPen( int col, int row ) const;
00478 const QColor & effTextColor( int col, int row ) const;
00479
00485 uint effBottomBorderValue( int col, int row ) const;
00491 uint effRightBorderValue( int col, int row ) const;
00497 uint effLeftBorderValue( int col, int row ) const;
00503 uint effTopBorderValue( int col, int row ) const;
00504
00508 const QPen& leftBorderPen( int col, int row ) const;
00509
00513 const QPen& topBorderPen( int col, int row ) const;
00514
00518 const QPen& rightBorderPen( int col, int row ) const;
00519
00523 const QPen& bottomBorderPen( int col, int row ) const;
00524
00528 const QColor& bgColor( int col, int row ) const;
00529
00533 const QBrush& backGroundBrush( int col, int row ) const;
00534
00536
00537
00538
00540
00544 void setLeftBorderPen( const QPen& p );
00545
00549 void setTopBorderPen( const QPen& p );
00550
00554 void setRightBorderPen( const QPen& p );
00555
00559 void setBottomBorderPen( const QPen& p );
00560
00562
00563
00564
00566
00573 FormatType formatType() const;
00574
00576 bool isDate() const;
00578 bool isTime() const;
00579
00580 void setNumber( double number );
00581
00583 double getDouble ();
00584
00586 void convertToDouble ();
00588 void convertToPercent ();
00590 void convertToMoney ();
00592 void convertToTime ();
00594 void convertToDate ();
00595
00597 double textWidth() const;
00599 double textHeight() const;
00600
00601
00608 bool updateChart(bool refresh=true);
00609
00610 QString testAnchor( int _x, int _y ) const;
00611
00620 bool calc(bool delay = true);
00621
00623 void setCalcDirtyFlag();
00625 bool calcDirtyFlag();
00626
00636 void NotifyDepending( int col, int row, Sheet* sheet, bool isDepending );
00637
00643 void setLayoutDirtyFlag( bool format = false );
00644 bool layoutDirtyFlag() const;
00645
00646 void clearDisplayDirtyFlag();
00647 void setDisplayDirtyFlag();
00648
00657 void obscure( Cell *cell, bool isForcing = false);
00663 void unobscure(Cell* cell);
00667 bool isObscured() const;
00674 bool isPartOfMerged() const;
00675
00682 Cell *ultimateObscuringCell() const;
00683
00687 QValueList<Cell*> obscuringCells() const;
00688
00689 void clearObscuringCells();
00690
00691
00703 void mergeCells( int _col, int _row, int _x, int _y );
00704
00708 bool doesMergeCells() const;
00709
00714 int mergedXCells() const;
00715
00720 int mergedYCells() const;
00721
00725 int extraXCells() const;
00726
00730 int extraYCells() const;
00731
00732 double extraWidth() const;
00733 double extraHeight() const;
00734
00744 QString encodeFormula( bool _era = false, int _col = -1, int _row = -1 ) const;
00745 QString decodeFormula( const QString &_text, int _col = -1, int _row = -1 ) const;
00746
00756 QString pasteOperation( const QString &new_text, const QString &old_text, Paste::Operation op );
00757
00762 bool hasError() const;
00763
00767 void clearAllErrors();
00768
00773 void makeLayout( QPainter &_painter, int _col, int _row );
00774
00780 bool makeFormula();
00781
00782
00783 void defaultStyle();
00784
00788 QValueList<Conditional> conditionList() const;
00789
00793 void setConditionList(const QValueList<Conditional> &newList);
00794
00795 Validity * getValidity( int newStruct = -1 );
00796
00797 void removeValidity();
00798
00803 bool testValidity() const;
00804
00809 void calculateTextParameters( QPainter &painter, int _col, int _row );
00810
00814 int defineAlignX();
00815
00816
00817
00818
00822 bool operator > ( const Cell & ) const;
00823 bool operator < ( const Cell & ) const;
00824
00825 void freeAllObscuredCells();
00826
00827
00828 enum CellFlags{
00829
00830
00831
00832 Flag_LayoutDirty = 0x00010000,
00833 Flag_CalcDirty = 0x00020000,
00834 Flag_Progress = 0x00040000,
00835 Flag_UpdatingDeps = 0x00080000,
00836 Flag_DisplayDirty = 0x00100000,
00837 Flag_Merged = 0x00200000,
00838 Flag_CellTooShortX = 0x00400000,
00839 Flag_CellTooShortY = 0x00800000,
00840 Flag_ParseError = 0x01000000,
00841 Flag_CircularCalculation = 0x02000000,
00842 Flag_DependancyError = 0x04000000,
00843 Flag_PaintingCell = 0x08000000,
00844 Flag_TextFormatDirty = 0x10000000
00845
00846 };
00847
00848 void clearFlag( CellFlags flag );
00849 void setFlag( CellFlags flag );
00850 bool testFlag( CellFlags flag ) const;
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
00906
00907 protected:
00911 void applyZoomedFont( QPainter &painter, int _col, int _row );
00912
00917 void textSize( QPainter &_paint );
00918
00923 QString textDisplaying( QPainter &painter);
00924
00930 void clearFormula();
00931
00940 void checkTextInput();
00941
00946 void checkNumberFormat();
00947
00952 void loadOasisCellText( const QDomElement& parent );
00953 void loadOasisObjects( const QDomElement& e, KoOasisLoadingContext& oasisContext );
00954 void loadOasisValidation( const QString& validationName );
00955
00956 void loadOasisValidationCondition( QString &valExpression );
00957 void saveOasisAnnotation( KoXmlWriter &xmlwriter );
00958 void loadOasisConditional( QDomElement * style );
00959
00960
00961
00962 private:
00963
00964 class Extra;
00965 class Private;
00966 Private *d;
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981 void paintCellBorders( QPainter& painter, const KoRect &rect,
00982 const KoRect &cellRect,
00983 const QPoint &cellRef,
00984 bool paintBorderRight, bool paintBorderBottom,
00985 bool paintBorderLeft, bool paintBorderTop,
00986 QPen & rightPen, QPen & bottomPen,
00987 QPen & leftPen, QPen & topPen );
00988 void paintPageBorders( QPainter& painter, const KoRect &cellRect,
00989 const QPoint &cellRef,
00990 bool paintBorderRight, bool paintBorderBottom );
00991 void paintText( QPainter& painter, const KoRect &cellRect,
00992 const QPoint &cellRef );
00993 void paintMoreTextIndicator( QPainter& painter, const KoRect &cellRect,
00994 QColor &backgroundColor );
00995 void paintCommentIndicator( QPainter& painter, const KoRect &cellRect,
00996 const QPoint &cellRef, QColor &backgroundColor );
00997 void paintFormulaIndicator( QPainter& painter, const KoRect &cellRect,
00998 QColor &backgroundColor );
00999 void paintDefaultBorders( QPainter& painter, const KoRect &rect,
01000 const KoRect &cellRect, const QPoint &cellRef,
01001 bool paintBorderRight, bool paintBorderBottom,
01002 bool paintBorderLeft, bool paintBorderTop,
01003 QPen const & rightPen, QPen const & bottomPen,
01004 QPen const & leftPen, QPen const & topPen );
01005 void paintBackground( QPainter& painter, const KoRect &cellRect,
01006 const QPoint &cellRef, bool selected,
01007 QColor &backgroundColor );
01008 void paintObscuredCells( const KoRect& rect, QPainter& painter,
01009 View* view, const KoRect &cellRect,
01010 const QPoint &cellRef,
01011 bool paintBorderRight, bool paintBorderBottom,
01012 bool paintBorderLeft, bool paintBorderTop,
01013 QPen & rightPen, QPen & bottomPen,
01014 QPen & leftPen, QPen & topPen,
01015 QValueList<QPoint> &mergedCellsPainted );
01016 void paintCellDiagonalLines( QPainter& painter, const KoRect &cellRect,
01017 const QPoint &cellRef );
01018
01019
01020
01021
01024 void valueChanged ();
01025
01026
01027
01028 void setOutputText();
01029
01030
01031
01032 bool loadCellData(const QDomElement &text, Paste::Operation op);
01033 bool saveCellResult( QDomDocument& doc, QDomElement& result,
01034 QString str );
01035 void update();
01036 int effAlignX();
01037
01043 void offsetAlign( int _col, int _row );
01044
01045 void checkForNamedAreas( QString & formula ) const;
01053 QString convertFormulaToOasisFormat( const QString & formula ) const;
01054 void loadOasisValidationValue( const QStringList &listVal );
01055
01056 };
01057
01058 }
01059
01060 #endif // KSPREAD_CELL