00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __kspread_sheetprint_h__
00022 #define __kspread_sheetprint_h__
00023
00024 #include <qobject.h>
00025
00026 #include <koffice_export.h>
00027 #include <KoUnit.h>
00028
00029 class KoGenStyles;
00030
00031 namespace KSpread
00032 {
00033 class Doc;
00034 class Selection;
00035 class PrintNewPageEntry;
00036 class PrintObject;
00037
00038 class KSPREAD_EXPORT SheetPrint : public QObject
00039 {
00040 Q_OBJECT
00041
00042 public:
00043
00044 SheetPrint( Sheet *sheet );
00045 ~SheetPrint();
00046
00047 QString saveOasisSheetStyleLayout( KoGenStyles &mainStyles );
00048
00052 bool print( QPainter &painter, KPrinter *_printer );
00053
00057 float prinsheetWidth()const { return m_paperWidth - m_leftBorder - m_rightBorder; }
00058
00062 float prinsheetWidthPts()const { return MM_TO_POINT( prinsheetWidth() / m_dZoom ); }
00063
00067 float prinsheetHeight()const { return m_paperHeight - m_topBorder - m_bottomBorder; }
00068
00072 float prinsheetHeightPts()const { return MM_TO_POINT( prinsheetHeight() / m_dZoom ); }
00073
00077 float paperHeight()const { return m_paperHeight; }
00081 float paperHeightPts()const { return MM_TO_POINT( m_paperHeight / m_dZoom ); }
00085 float paperWidth()const { return m_paperWidth; }
00089 float paperWidthPts()const { return MM_TO_POINT( m_paperWidth / m_dZoom ); }
00090
00091 void setPaperHeight(float _val) { m_paperHeight=_val; }
00092 void setPaperWidth(float _val) { m_paperWidth=_val; }
00093
00097 float leftBorder()const { return m_leftBorder; }
00101 float leftBorderPts()const { return MM_TO_POINT( m_leftBorder / m_dZoom ); }
00105 float rightBorder()const { return m_rightBorder; }
00109 float rightBorderPts()const { return MM_TO_POINT( m_rightBorder / m_dZoom ); }
00113 float topBorder()const { return m_topBorder; }
00117 float topBorderPts()const { return MM_TO_POINT( m_topBorder / m_dZoom ); }
00121 float bottomBorder()const { return m_bottomBorder; }
00125 float bottomBorderPts()const { return MM_TO_POINT( m_bottomBorder / m_dZoom ); }
00126
00130 KoOrientation orientation()const { return m_orientation; }
00134 const char* orientationString() const;
00135
00139 KoFormat paperFormat()const { return m_paperFormat; }
00143 QString paperFormatString()const;
00144
00145 void setPaperFormat(KoFormat _format) {m_paperFormat=_format;}
00146
00147 void setPaperOrientation(KoOrientation _orient);
00148
00152 KoPageLayout paperLayout() const;
00153
00157 void setPaperLayout( float _leftBorder, float _topBorder, float _rightBorder, float _bottomBoder,
00158 KoFormat _paper, KoOrientation orientation );
00162 void setPaperLayout( float _leftBorder, float _topBorder, float _rightBorder, float _bottomBoder,
00163 const QString& _paper, const QString& _orientation );
00164
00165 QString headLeft( int _p, const QString &_t )const { if ( m_headLeft.isNull() ) return "";
00166 return completeHeading( m_headLeft, _p, _t ); }
00167 QString headMid( int _p, const QString &_t )const { if ( m_headMid.isNull() ) return "";
00168 return completeHeading( m_headMid, _p, _t ); }
00169 QString headRight( int _p, const QString &_t )const { if ( m_headRight.isNull() ) return "";
00170 return completeHeading( m_headRight, _p, _t ); }
00171 QString footLeft( int _p, const QString &_t )const { if ( m_footLeft.isNull() ) return "";
00172 return completeHeading( m_footLeft, _p, _t ); }
00173 QString footMid( int _p, const QString &_t )const { if ( m_footMid.isNull() ) return "";
00174 return completeHeading( m_footMid, _p, _t ); }
00175 QString footRight( int _p, const QString &_t )const { if ( m_footRight.isNull() ) return "";
00176 return completeHeading( m_footRight, _p, _t ); }
00177
00178 QString headLeft()const { if ( m_headLeft.isNull() ) return ""; return m_headLeft; }
00179 QString headMid()const { if ( m_headMid.isNull() ) return ""; return m_headMid; }
00180 QString headRight()const { if ( m_headRight.isNull() ) return ""; return m_headRight; }
00181 QString footLeft()const { if ( m_footLeft.isNull() ) return ""; return m_footLeft; }
00182 QString footMid()const { if ( m_footMid.isNull() ) return ""; return m_footMid; }
00183 QString footRight()const { if ( m_footRight.isNull() ) return ""; return m_footRight; }
00184
00189 QRect printRange() const { return m_printRange; }
00194 void setPrintRange( const QRect &_printRange );
00195
00200 int pageLimitX() const { return m_iPageLimitX; }
00201
00206 int pageLimitY() const { return m_iPageLimitY; }
00207
00213 void setPageLimitX( int pages );
00214
00220 void setPageLimitY( int pages );
00221
00225 void calculateZoomForPageLimitX();
00226
00230 void calculateZoomForPageLimitY();
00231
00236 QPair<int, int> printRepeatColumns() const { return m_printRepeatColumns; }
00242 void setPrintRepeatColumns( QPair<int, int> _printRepeatColumns );
00243
00248 QPair<int, int> printRepeatRows() const { return m_printRepeatRows; }
00254 void setPrintRepeatRows( QPair<int, int> _printRepeatRows );
00255
00261 bool isOnNewPageX( int _column );
00262
00266 void updateNewPageX( int _column );
00267
00273 bool isOnNewPageY( int _row );
00274
00278 void updateNewPageY( int _row );
00279
00283 void updateNewPageListX( int _col );
00284
00288 void updateNewPageListY( int _row );
00289
00296 void replaceHeadFootLineMacro ( QString &_text, const QString &_search, const QString &_replace );
00300 QString localizeHeadFootLine ( const QString &_text );
00304 QString delocalizeHeadFootLine ( const QString &_text );
00305
00309 KoHeadFoot headFootLine() const;
00310
00314 void setHeadFootLine( const QString &_headl, const QString &_headm, const QString &_headr,
00315 const QString &_footl, const QString &_footm, const QString &_footr );
00316
00320 bool printGrid() const { return m_bPrintGrid; }
00321
00325 void setPrintGrid( bool _printGrid );
00326
00330 bool printObjects() const { return m_bPrintObjects; }
00331
00335 void setPrintObjects( bool _printObjects );
00336
00340 bool printCharts() const { return m_bPrintCharts; }
00341
00345 void setPrintCharts( bool _printCharts );
00346
00350 bool printGraphics() const { return m_bPrintGraphics; }
00351
00355 void setPrintGraphics( bool _printGraphics );
00356
00360 bool printCommentIndicator() const { return m_bPrintCommentIndicator; }
00361
00365 void setPrintCommentIndicator( bool _printCommentIndicator );
00366
00370 bool printFormulaIndicator() const { return m_bPrintFormulaIndicator; }
00371
00375 void setPrintFormulaIndicator( bool _printFormulaIndicator );
00376
00380 void updatePrintRepeatColumnsWidth();
00381
00385 void updatePrintRepeatRowsHeight();
00386
00390 void definePrintRange(Selection* selectionInfo);
00394 void resetPrintRange();
00395
00399 void insertColumn( int col, int nbCol );
00403 void removeColumn( int col, int nbCol );
00407 void insertRow( int row, int nbRow );
00411 void removeRow( int row, int nbRow );
00412
00418 void setZoom( double _zoom, bool checkPageLimit = true );
00419
00423 double zoom() const { return m_dZoom; }
00424
00428 bool pageNeedsPrinting( QRect& page_range );
00429
00430 signals:
00431 void sig_updateView( Sheet *_sheet );
00432
00433 private:
00434
00435 Sheet * m_pSheet;
00436 Doc * m_pDoc;
00437
00453 void printPage( QPainter &_painter, const QRect& page_range,
00454 const KoRect& view, const KoPoint _childOffset );
00455
00459 void printRect( QPainter &painter, const KoPoint& topLeft,
00460 const QRect& printRect, const KoRect& view,
00461 QRegion &clipRegion );
00462
00466 void printHeaderFooter( QPainter &painter, int pageNo );
00467
00471 void calcPaperSize();
00472
00476 QValueList<PrintNewPageEntry>::iterator findNewPageColumn( int col );
00477
00481 QValueList<PrintNewPageEntry>::iterator findNewPageRow( int row );
00482
00490 QString completeHeading( const QString &_data, int _page, const QString &_sheet ) const ;
00491
00496 QRect cellsPrintRange();
00497
00501 int pagesX( const QRect& cellsPrintRange );
00502
00506 int pagesY( const QRect& cellsPrintRange );
00507
00511 KoOrientation m_orientation;
00515 KoFormat m_paperFormat;
00520 float m_paperWidth;
00525 float m_paperHeight;
00529 float m_leftBorder;
00533 float m_rightBorder;
00537 float m_topBorder;
00541 float m_bottomBorder;
00542
00547 QString m_headLeft;
00552 QString m_headRight;
00557 QString m_headMid;
00562 QString m_footLeft;
00567 QString m_footRight;
00572 QString m_footMid;
00573
00577 uint m_uprintPages;
00578
00582 QRect m_printRange;
00583
00587 QPair<int, int> m_printRepeatColumns;
00588
00592 QPair<int, int> m_printRepeatRows;
00593
00597 bool m_bPrintGrid;
00598
00602 bool m_bPrintObjects;
00603
00607 bool m_bPrintCharts;
00608
00612 bool m_bPrintGraphics;
00613
00617 bool m_bPrintFormulaIndicator;
00618
00622 bool m_bPrintCommentIndicator;
00623
00627 double m_dPrintRepeatColumnsWidth;
00631 double m_dPrintRepeatRowsHeight;
00632
00636 QValueList<PrintNewPageEntry> m_lnewPageListX;
00637
00641 QValueList<PrintNewPageEntry> m_lnewPageListY;
00642
00646 int m_maxCheckedNewPageX;
00647
00651 int m_maxCheckedNewPageY;
00652
00656 double m_dZoom;
00657
00662 int m_iPageLimitX;
00666 int m_iPageLimitY;
00667
00668 QValueList<PrintObject*> m_printObjects;
00669 };
00670
00671
00672 class PrintNewPageEntry
00673 {
00674 public:
00675 PrintNewPageEntry() :
00676 m_iStartItem( 0 ), m_iEndItem( 0 ), m_dSize( 0 ),
00677 m_dOffset( 0 ){}
00678
00679 PrintNewPageEntry( int startItem, int endItem = 0, double size = 0,
00680 double offset = 0 ) :
00681 m_iStartItem( startItem ), m_iEndItem( endItem ), m_dSize( size ),
00682 m_dOffset( offset ) {}
00683
00684 int startItem() const { return m_iStartItem; }
00685 void setStartItem( int startItem ) { m_iStartItem = startItem; }
00686
00687 int endItem() const { return m_iEndItem; }
00688 void setEndItem( int endItem ) { m_iEndItem = endItem; }
00689
00690 double size() const { return m_dSize; }
00691 void setSize( double size ) { m_dSize = size; }
00692
00693 double offset() const { return m_dOffset; }
00694 void setOffset( double offset ) { m_dOffset = offset; }
00695
00696 bool operator==( PrintNewPageEntry const & entry ) const;
00697
00698
00699 private:
00700 int m_iStartItem;
00701 int m_iEndItem;
00702 double m_dSize;
00703 double m_dOffset;
00704 };
00705
00706 class PrintObject
00707 {
00708 public:
00709 PrintObject() : obj(0), p(0) {}
00710
00711 EmbeddedObject *obj;
00712 QPixmap *p;
00713 };
00714
00715 }
00716
00717 #endif
00718