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 class KSpreadCell;
00038 class KSpreadSheet;
00039 class KSpreadCanvas;
00040 class KSpreadView;
00041
00042 class KLocale;
00043 class QDomElement;
00044 class QDomDocument;
00045 class KoXmlWriter;
00046 class KoGenStyles;
00047 class KoGenStyle;
00048 class KSParseNode;
00049 class KSpreadGenValidationStyles;
00050
00051
00052 #include <qpainter.h>
00053 #include <qptrlist.h>
00054 #include <qdatetime.h>
00055
00056 #include "kspread_format.h"
00057 #include "kspread_global.h"
00058 #include "kspread_condition.h"
00059 #include "kspread_value.h"
00060
00061 #include <koOasisStyles.h>
00062 #include <koRect.h>
00063 struct KSpreadValidity
00064 {
00065 KSpreadValidity()
00066 {
00067 valMin = 0.0;
00068 valMax = 0.0;
00069 m_cond = None;
00070 m_action = Stop;
00071 m_allow = Allow_All;
00072 displayMessage = true;
00073 allowEmptyCell = false;
00074 displayValidationInformation = false;
00075 };
00076 QString message;
00077 QString title;
00078 QString titleInfo;
00079 QString messageInfo;
00080 double valMin;
00081 double valMax;
00082 Conditional m_cond;
00083 Action m_action;
00084 Allow m_allow;
00085 QTime timeMin;
00086 QTime timeMax;
00087 QDate dateMin;
00088 QDate dateMax;
00089 bool displayMessage;
00090 bool allowEmptyCell;
00091 bool displayValidationInformation;
00092 QStringList listValidity;
00093 };
00094
00095 class CellPrivate;
00096
00097
00108 class KSPREAD_EXPORT KSpreadCell : public KSpreadFormat
00109 {
00110 friend class SelectPrivate;
00111 friend class KSpreadConditions;
00112 public:
00113
00114 KSpreadCell (KSpreadSheet *_sheet, int _column, int _row);
00115 KSpreadCell (KSpreadSheet *_sheet, KSpreadStyle * _style, int _column, int _row);
00116
00120 ~KSpreadCell();
00121
00125 KSpreadSheet* sheet() const;
00126
00131 bool isDefault() const;
00132
00136 bool isEmpty() const;
00137
00141 int column() const;
00142
00146 int row() const;
00147
00152 QString name() const;
00153
00158 QString fullName() const;
00159
00163 QString columnName() const;
00164
00169 static QString name( int col, int row );
00170
00175 static QString fullName( const KSpreadSheet *s, int col, int row );
00176
00181 static QString columnName( uint column );
00182
00186 KLocale* locale();
00190 bool isFormula() const;
00191
00196 QString text() const;
00197
00198 QString strOutText() const;
00199
00204 const KSpreadValue value() const;
00205
00209 void setValue( const KSpreadValue& value );
00210
00211 KSpreadCell* previousCell() const;
00212 KSpreadCell* nextCell() const;
00213 void setPreviousCell( KSpreadCell* c );
00214 void setNextCell( KSpreadCell* c );
00215
00220 void move( int column, int row );
00221
00232 void sheetDies();
00233
00243 QDomElement save( QDomDocument& doc, int _x_offset = 0, int _y_offset = 0, bool force = false, bool copy = false, bool era = false );
00244
00245 virtual bool saveOasis( KoXmlWriter& xmlwriter , KoGenStyles &mainStyles, int row, int column, int maxCol, int &repeated, KSpreadGenValidationStyles &valStyle );
00246
00247 void saveOasisValue (KoXmlWriter &xmlWriter);
00248
00249 QString saveOasisCellStyle( KoGenStyle ¤tCellStyle,KoGenStyles &mainStyles, bool force = false, bool copy = false );
00250
00251 bool load( const QDomElement& cell, int _xshift, int _yshift, PasteMode pm = Normal,
00252 Operation op = OverWrite, bool paste = false );
00253
00254 bool loadOasis( const QDomElement & element, const KoOasisStyles &oasisStyles );
00255 void loadOasisValidation( const QString& validationName );
00256
00257 QTime toTime(const QDomElement &element) ;
00258 QDate toDate(const QDomElement &element);
00259
00265 void copyFormat( int _column, int _row );
00271 void copyFormat( KSpreadCell *_cell );
00272 void copyContent( KSpreadCell *_cell );
00280 void copyAll( KSpreadCell *cell);
00281
00296 void paintCell( const KoRect & rect, QPainter & painter,
00297 KSpreadView * view, const KoPoint & coordinate,
00298 const QPoint & cellRef,
00299 bool paintBorderRight,
00300 bool paintBorderBottom,
00301 bool paintBorderLeft,
00302 bool paintBorderTop,
00303 QPen & rightPen,
00304 QPen & bottomPen,
00305 QPen & leftPen,
00306 QPen & topPen,
00307 bool drawCursor = true );
00308
00315 int width( int _col = -1, const KSpreadCanvas *_canvas = 0L ) const;
00316
00322 int height( int _row = -1, const KSpreadCanvas *_canvas = 0L ) const;
00323
00330 double dblWidth( int _col = -1, const KSpreadCanvas *_canvas = 0L ) const;
00331
00337 double dblHeight( int _row = -1, const KSpreadCanvas *_canvas = 0L ) const;
00338
00342 QRect cellRect();
00343
00351 bool needsPrinting() const;
00352
00360 void incPrecision();
00368 void decPrecision();
00369
00374 void setCellText( const QString& _text, bool asString = false );
00375
00381 void setDisplayText( const QString& _text );
00382
00389 void setLink( const QString& link );
00390
00395 QString link() const;
00396
00398
00399
00400
00402
00403 const QPen & effLeftBorderPen( int col, int row ) const;
00404 const QPen & effTopBorderPen( int col, int row ) const;
00405 const QPen & effRightBorderPen( int col, int row ) const;
00406 const QPen & effBottomBorderPen( int col, int row ) const;
00407 const QPen & effGoUpDiagonalPen( int col, int row ) const;
00408 const QPen & effFallDiagonalPen( int col, int row ) const;
00409 const QColor & effTextColor( int col, int row ) const;
00410
00411 uint effBottomBorderValue( int col, int row ) const;
00412 uint effRightBorderValue( int col, int row ) const;
00413 uint effLeftBorderValue( int col, int row ) const;
00414 uint effTopBorderValue( int col, int row ) const;
00415
00419 const QPen& leftBorderPen( int col, int row ) const;
00420
00424 const QPen& topBorderPen( int col, int row ) const;
00425
00429 const QPen& rightBorderPen( int col, int row ) const;
00430
00434 const QPen& bottomBorderPen( int col, int row ) const;
00435
00439 const QColor& bgColor( int col, int row ) const;
00440
00444 const QBrush& backGroundBrush( int col, int row ) const;
00445
00447
00448
00449
00451
00455 void setLeftBorderPen( const QPen& p );
00456
00460 void setTopBorderPen( const QPen& p );
00461
00465 void setRightBorderPen( const QPen& p );
00466
00470 void setBottomBorderPen( const QPen& p );
00471
00475 virtual void setCurrency( int type, QString const & symbol );
00476
00478
00479
00480
00482
00489 FormatType formatType() const;
00490
00491 bool isDate() const;
00492 bool isTime() const;
00493
00494 void setNumber( double number );
00495
00497 double getDouble ();
00498
00499 void convertToDouble ();
00500 void convertToPercent ();
00501 void convertToMoney ();
00502 void convertToTime ();
00503 void convertToDate ();
00504
00508 double textWidth() const;
00509 double textHeight() const;
00510
00511
00518 bool updateChart(bool refresh=true);
00519
00520 QString testAnchor( int _x, int _y ) const;
00521
00526 void clicked( KSpreadCanvas *_canvas );
00527
00536 bool calc(bool delay = true);
00537
00541 void setCalcDirtyFlag();
00542
00543 bool calcDirtyFlag();
00544
00554 void NotifyDepending( int col, int row, KSpreadSheet* sheet, bool isDepending );
00555
00561 virtual void setLayoutDirtyFlag( bool format = false );
00562 bool layoutDirtyFlag() const;
00563
00564 void clearDisplayDirtyFlag();
00565 void setDisplayDirtyFlag();
00566
00575 void obscure( KSpreadCell *cell, bool isForcing = false);
00581 void unobscure(KSpreadCell* cell);
00585 bool isObscured() const;
00591 bool isObscuringForced() const;
00592
00599 KSpreadCell *ultimateObscuringCell() const;
00600
00604 QValueList<KSpreadCell*> obscuringCells() const;
00605
00606 void clearObscuringCells();
00607
00608
00619 void forceExtraCells( int _col, int _row, int _x, int _y );
00620
00624 bool isForceExtraCells() const;
00625
00630 int mergedXCells() const;
00631
00636 int mergedYCells() const;
00637
00641 int extraXCells() const;
00645 int extraYCells() const;
00646
00647 double extraWidth() const;
00648 double extraHeight() const;
00649
00657 QString encodeFormula( bool _era = false, int _col = -1, int _row = -1 );
00658 QString decodeFormula( const QString &_text, int _col = -1, int _row = -1 );
00659
00669 QString pasteOperation( const QString &new_text, const QString &old_text, Operation op );
00670
00675 bool hasError() const;
00676
00680 void clearAllErrors();
00681
00686 void makeLayout( QPainter &_painter, int _col, int _row );
00687
00693 bool makeFormula();
00694
00695
00696 void defaultStyle();
00697
00701 QValueList<KSpreadConditional> conditionList() const;
00702
00706 void setConditionList(const QValueList<KSpreadConditional> &newList);
00707
00708 KSpreadValidity * getValidity( int newStruct = -1 );
00709
00710 void removeValidity();
00711
00716 bool testValidity() const;
00717
00722 void calculateTextParameters( QPainter &painter, int _col, int _row );
00723
00727 int defineAlignX();
00728
00729
00733 bool operator > ( const KSpreadCell & ) const;
00734 bool operator < ( const KSpreadCell & ) const;
00735
00736 void freeAllObscuredCells();
00737
00738
00739 enum CellFlags{
00740
00741
00742
00743 Flag_LayoutDirty = 0x00010000,
00744 Flag_CalcDirty = 0x00020000,
00745 Flag_Progress = 0x00040000,
00746 Flag_UpdatingDeps = 0x00080000,
00747 Flag_DisplayDirty = 0x00100000,
00748 Flag_ForceExtra = 0x00200000,
00749 Flag_CellTooShortX = 0x00400000,
00750 Flag_CellTooShortY = 0x00800000,
00751 Flag_ParseError = 0x01000000,
00752 Flag_CircularCalculation = 0x02000000,
00753 Flag_DependancyError = 0x04000000,
00754 Flag_PaintingCell = 0x08000000,
00755 Flag_TextFormatDirty = 0x10000000
00756 };
00757
00758 void clearFlag( CellFlags flag );
00759 void setFlag( CellFlags flag );
00760 bool testFlag( CellFlags flag ) const;
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776
00777
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816
00817 protected:
00821 void formatChanged();
00825 KSpreadFormat* fallbackFormat( int col, int row );
00829 const KSpreadFormat* fallbackFormat( int col, int row ) const;
00830
00834 void applyZoomedFont( QPainter &painter, int _col, int _row );
00835
00840 void textSize( QPainter &_paint );
00841
00846 QString textDisplaying( QPainter &painter);
00847
00853 void clearFormula();
00854
00863 void checkTextInput();
00864
00869 void checkNumberFormat();
00870
00871 void loadOasisValidationCondition( QString &valExpression );
00872 void saveOasisAnnotation( KoXmlWriter &xmlwriter );
00873 void loadOasisConditional( QDomElement * style );
00874
00875 private:
00876
00877 CellPrivate* d;
00878
00879
00880
00881 void paintCellBorders( QPainter& painter, const KoRect &rect,
00882 const KoRect &cellRect,
00883 const QPoint &cellRef,
00884 bool paintBorderRight, bool paintBorderBottom,
00885 bool paintBorderLeft, bool paintBorderTop,
00886 QPen & rightPen, QPen & bottomPen,
00887 QPen & leftPen, QPen & topPen );
00888 void paintPageBorders( QPainter& painter, const KoRect &cellRect,
00889 const QPoint &cellRef,
00890 bool paintBorderRight, bool paintBorderBottom );
00891 void paintText( QPainter& painter, const KoRect &cellRect,
00892 const QPoint &cellRef );
00893 void paintMoreTextIndicator( QPainter& painter, const KoRect &cellRect,
00894 QColor &backgroundColor );
00895 void paintCommentIndicator( QPainter& painter, const KoRect &cellRect,
00896 const QPoint &cellRef, QColor &backgroundColor );
00897 void paintFormulaIndicator( QPainter& painter, const KoRect &cellRect,
00898 QColor &backgroundColor );
00899 void paintDefaultBorders( QPainter& painter, const KoRect &rect,
00900 const KoRect &cellRect, const QPoint &cellRef,
00901 bool paintBorderRight, bool paintBorderBottom,
00902 bool paintBorderLeft, bool paintBorderTop,
00903 QPen const & rightPen, QPen const & bottomPen,
00904 QPen const & leftPen, QPen const & topPen );
00905 void paintBackground( QPainter& painter, const KoRect &cellRect,
00906 const QPoint &cellRef, bool selected,
00907 QColor &backgroundColor );
00908 void paintObscuredCells( const KoRect& rect, QPainter& painter,
00909 KSpreadView* view, const KoRect &cellRect,
00910 const QPoint &cellRef,
00911 bool paintBorderRight, bool paintBorderBottom,
00912 bool paintBorderLeft, bool paintBorderTop,
00913 QPen & rightPen, QPen & bottomPen,
00914 QPen & leftPen, QPen & topPen );
00915 void paintCellDiagonalLines( QPainter& painter, const KoRect &cellRect,
00916 const QPoint &cellRef );
00917
00918
00919
00922 void valueChanged ();
00923
00924
00925
00926 void setOutputText();
00927
00928
00929
00930 bool loadCellData(const QDomElement &text, Operation op);
00931 bool saveCellResult( QDomDocument& doc, QDomElement& result,
00932 QString str );
00933 void update();
00934 int effAlignX();
00935
00941 void offsetAlign( int _col, int _row );
00942
00943 void checkForNamedAreas( QString & formula ) const;
00944 void convertFormula( QString & text, const QString & f ) const;
00945 QString convertFormulaToOasisFormat( const QString & formula ) const;
00946 void loadOasisValidationValue( const QStringList &listVal );
00947
00948 };
00949
00950 #endif // KSPREAD_CELL