KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

720 lines
21KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>,
  3. 2003 Philipp Mller <philipp.mueller@gmx.de>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. * Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef __kspread_sheetprint_h__
  18. #define __kspread_sheetprint_h__
  19. #include <tqobject.h>
  20. #include <koffice_export.h>
  21. #include <KoUnit.h>
  22. class KoGenStyles;
  23. namespace KSpread
  24. {
  25. class Doc;
  26. class Selection;
  27. class PrintNewPageEntry;
  28. class PrintObject;
  29. class KSPREAD_EXPORT SheetPrint : public TQObject
  30. {
  31. Q_OBJECT
  32. public:
  33. SheetPrint( Sheet *sheet );
  34. ~SheetPrint();
  35. TQString saveOasisSheetStyleLayout( KoGenStyles &mainStyles );
  36. /**
  37. * @return false if nothing to print.
  38. */
  39. bool print( TQPainter &painter, KPrinter *_printer );
  40. /**
  41. * @return the prinsheet width of the paper in millimeters.
  42. */
  43. float prinsheetWidth()const { return m_paperWidth - m_leftBorder - m_rightBorder; }
  44. /**
  45. * @return the prinsheet width of the paper in zoomed points.
  46. */
  47. float prinsheetWidthPts()const { return MM_TO_POINT( prinsheetWidth() / m_dZoom ); }
  48. /**
  49. * @return the prinsheet height of the paper in millimeters.
  50. */
  51. float prinsheetHeight()const { return m_paperHeight - m_topBorder - m_bottomBorder; }
  52. /**
  53. * @return the prinsheet height of the paper in zoomed points.
  54. */
  55. float prinsheetHeightPts()const { return MM_TO_POINT( prinsheetHeight() / m_dZoom ); }
  56. /**
  57. * @return the height of the paper in millimeters.
  58. */
  59. float paperHeight()const { return m_paperHeight; }
  60. /**
  61. * @return the height of the paper in zoomed points.
  62. */
  63. float paperHeightPts()const { return MM_TO_POINT( m_paperHeight / m_dZoom ); }
  64. /**
  65. * @return the width of the paper in millimeters.
  66. */
  67. float paperWidth()const { return m_paperWidth; }
  68. /**
  69. * @return the width of the paper in zoomed points.
  70. */
  71. float paperWidthPts()const { return MM_TO_POINT( m_paperWidth / m_dZoom ); }
  72. void setPaperHeight(float _val) { m_paperHeight=_val; }
  73. void setPaperWidth(float _val) { m_paperWidth=_val; }
  74. /**
  75. * @return the left border in millimeters
  76. */
  77. float leftBorder()const { return m_leftBorder; }
  78. /**
  79. * @return the left border in zoomed points
  80. */
  81. float leftBorderPts()const { return MM_TO_POINT( m_leftBorder / m_dZoom ); }
  82. /**
  83. * @return the right border in millimeters
  84. */
  85. float rightBorder()const { return m_rightBorder; }
  86. /**
  87. * @return the right border in zoomed points
  88. */
  89. float rightBorderPts()const { return MM_TO_POINT( m_rightBorder / m_dZoom ); }
  90. /**
  91. * @return the top border in millimeters
  92. */
  93. float topBorder()const { return m_topBorder; }
  94. /**
  95. * @return the top border in zoomed points
  96. */
  97. float topBorderPts()const { return MM_TO_POINT( m_topBorder / m_dZoom ); }
  98. /**
  99. * @return the bottom border in millimeters
  100. */
  101. float bottomBorder()const { return m_bottomBorder; }
  102. /**
  103. * @return the bottom border in zoomed points
  104. */
  105. float bottomBorderPts()const { return MM_TO_POINT( m_bottomBorder / m_dZoom ); }
  106. /**
  107. * @return the orientation of the paper.
  108. */
  109. KoOrientation orientation()const { return m_orientation; }
  110. /**
  111. * @return the ascii name of the paper orientation ( like Portrait, Landscape )
  112. */
  113. const char* orientationString() const;
  114. /**
  115. * @return the paper format.
  116. */
  117. KoFormat paperFormat()const { return m_paperFormat; }
  118. /**
  119. * @return the ascii name of the paper format ( like A4, Letter etc. )
  120. */
  121. TQString paperFormatString()const;
  122. void setPaperFormat(KoFormat _format) {m_paperFormat=_format;}
  123. void setPaperOrientation(KoOrientation _orient);
  124. /**
  125. * Returns the page layout
  126. */
  127. KoPageLayout paperLayout() const;
  128. /**
  129. * Changes the paper layout and repaints the currently displayed Sheet.
  130. */
  131. void setPaperLayout( float _leftBorder, float _topBorder, float _rightBorder, float _bottomBoder,
  132. KoFormat _paper, KoOrientation orientation );
  133. /**
  134. * A convenience function using a TQString as paper format and orientation.
  135. */
  136. void setPaperLayout( float _leftBorder, float _topBorder, float _rightBorder, float _bottomBoder,
  137. const TQString& _paper, const TQString& _orientation );
  138. TQString headLeft( int _p, const TQString &_t )const { if ( m_headLeft.isNull() ) return "";
  139. return completeHeading( m_headLeft, _p, _t ); }
  140. TQString headMid( int _p, const TQString &_t )const { if ( m_headMid.isNull() ) return "";
  141. return completeHeading( m_headMid, _p, _t ); }
  142. TQString headRight( int _p, const TQString &_t )const { if ( m_headRight.isNull() ) return "";
  143. return completeHeading( m_headRight, _p, _t ); }
  144. TQString footLeft( int _p, const TQString &_t )const { if ( m_footLeft.isNull() ) return "";
  145. return completeHeading( m_footLeft, _p, _t ); }
  146. TQString footMid( int _p, const TQString &_t )const { if ( m_footMid.isNull() ) return "";
  147. return completeHeading( m_footMid, _p, _t ); }
  148. TQString footRight( int _p, const TQString &_t )const { if ( m_footRight.isNull() ) return "";
  149. return completeHeading( m_footRight, _p, _t ); }
  150. TQString headLeft()const { if ( m_headLeft.isNull() ) return ""; return m_headLeft; }
  151. TQString headMid()const { if ( m_headMid.isNull() ) return ""; return m_headMid; }
  152. TQString headRight()const { if ( m_headRight.isNull() ) return ""; return m_headRight; }
  153. TQString footLeft()const { if ( m_footLeft.isNull() ) return ""; return m_footLeft; }
  154. TQString footMid()const { if ( m_footMid.isNull() ) return ""; return m_footMid; }
  155. TQString footRight()const { if ( m_footRight.isNull() ) return ""; return m_footRight; }
  156. /**
  157. * Returns the print range.
  158. * Returns ( TQPoint (1, 1), TQPoint(KS_colMax, KS_rowMax) ) if nothing is defined
  159. */
  160. TQRect printRange() const { return m_printRange; }
  161. /**
  162. * Sets the print range.
  163. * Set it to ( TQPoint (1, 1), TQPoint(KS_colMax, KS_rowMax) ) to undefine it
  164. */
  165. void setPrintRange( const TQRect &_printRange );
  166. /**
  167. * Return the page limit in X direction.
  168. * 0 means no limit
  169. */
  170. int pageLimitX() const { return m_iPageLimitX; }
  171. /**
  172. * Return the page limit in Y direction.
  173. * 0 means no limit
  174. */
  175. int pageLimitY() const { return m_iPageLimitY; }
  176. /**
  177. * Sets the page limit in X direction. The zoom factor will be adjusted,
  178. * so that there is a maximum of @arg pages pages in X direction.
  179. * 0 releases the limit
  180. */
  181. void setPageLimitX( int pages );
  182. /**
  183. * Sets the page limit in Y direction. The zoom factor will be adjusted,
  184. * so that there is a maximum of @arg pages pages in X direction.
  185. * 0 releases the limit
  186. */
  187. void setPageLimitY( int pages );
  188. /**
  189. * Calculates the zoom factor, so that the printout fits on pages in X direction.
  190. */
  191. void calculateZoomForPageLimitX();
  192. /**
  193. * Calculates the zoom factor, so that the printout fits on pages in Y direction.
  194. */
  195. void calculateZoomForPageLimitY();
  196. /**
  197. * Returns the columns, which are printed on each page.
  198. * Returns TQPair (0, 0) if nothing is defined
  199. */
  200. TQPair<int, int> printRepeatColumns() const { return m_printRepeatColumns; }
  201. /**
  202. * Sets the columns to be printed on each page.
  203. * Only the x-values of the points are used
  204. * Set it to TQPair (0, 0) to undefine it
  205. */
  206. void setPrintRepeatColumns( TQPair<int, int> _printRepeatColumns );
  207. /**
  208. * Returns the rows, which are printed on each page.
  209. * Returns TQPair (0, 0) if nothing is defined
  210. */
  211. TQPair<int, int> printRepeatRows() const { return m_printRepeatRows; }
  212. /**
  213. * Sets the rows to be printed on each page.
  214. * Only the y-values of the points are used
  215. * Set it to TQPair (0, 0) to undefine it
  216. */
  217. void setPrintRepeatRows( TQPair<int, int> _printRepeatRows );
  218. /**
  219. * Tests whether _column is the first column of a new page. In this
  220. * case the left border of this column may be drawn highlighted to show
  221. * that this is a page break.
  222. */
  223. bool isOnNewPageX( int _column );
  224. /**
  225. * Updates the new page list up to @ref _column
  226. */
  227. void updateNewPageX( int _column );
  228. /**
  229. * Tests whether _row is the first row of a new page. In this
  230. * case the top border of this row may be drawn highlighted to show
  231. * that this is a page break.
  232. */
  233. bool isOnNewPageY( int _row );
  234. /**
  235. * Updates the new page list up to @ref _row
  236. */
  237. void updateNewPageY( int _row );
  238. /**
  239. * Updates the new page list for columns starting at column @arg _col
  240. */
  241. void updateNewPageListX( int _col );
  242. /**
  243. * Updates the new page list for rows starting at row @arg _row
  244. */
  245. void updateNewPageListY( int _row );
  246. /**
  247. * Replaces in _text all _search text parts by _replace text parts.
  248. * Included is a test to not change if _search == _replace.
  249. * The arguments should not include neither the beginning "<" nor the leading ">", this is already
  250. * included internally.
  251. */
  252. void replaceHeadFootLineMacro ( TQString &_text, const TQString &_search, const TQString &_replace );
  253. /**
  254. * Replaces in _text all page macros by the i18n-version of the macros
  255. */
  256. TQString localizeHeadFootLine ( const TQString &_text );
  257. /**
  258. * Replaces in _text all i18n-versions of the page macros by the internal version of the macros
  259. */
  260. TQString delocalizeHeadFootLine ( const TQString &_text );
  261. /**
  262. * Returns the head and foot line of the print out
  263. */
  264. KoHeadFoot headFootLine() const;
  265. /**
  266. * Sets the head and foot line of the print out
  267. */
  268. void setHeadFootLine( const TQString &_headl, const TQString &_headm, const TQString &_headr,
  269. const TQString &_footl, const TQString &_footm, const TQString &_footr );
  270. /**
  271. * Returns, if the grid shall be shown on printouts
  272. */
  273. bool printGrid() const { return m_bPrintGrid; }
  274. /**
  275. * Sets, if the grid shall be shown on printouts
  276. */
  277. void setPrintGrid( bool _printGrid );
  278. /**
  279. * Returns, if the objects shall be shown on printouts
  280. */
  281. bool printObjects() const { return m_bPrintObjects; }
  282. /**
  283. * Sets, if the objects shall be shown on printouts
  284. */
  285. void setPrintObjects( bool _printObjects );
  286. /**
  287. * Returns, if the charts shall be shown on printouts
  288. */
  289. bool printCharts() const { return m_bPrintCharts; }
  290. /**
  291. * Sets, if the charts shall be shown on printouts
  292. */
  293. void setPrintCharts( bool _printCharts );
  294. /**
  295. * Returns, if the graphics shall be shown on printouts
  296. */
  297. bool printGraphics() const { return m_bPrintGraphics; }
  298. /**
  299. * Sets, if the graphics shall be shown on printouts
  300. */
  301. void setPrintGraphics( bool _printGraphics );
  302. /**
  303. * Returns, if the comment rect shall be shown on printouts
  304. */
  305. bool printCommentIndicator() const { return m_bPrintCommentIndicator; }
  306. /**
  307. * Sets, if the comment rect shall be shown on printouts
  308. */
  309. void setPrintCommentIndicator( bool _printCommentIndicator );
  310. /**
  311. * Returns, if the formula rect shall be shown on printouts
  312. */
  313. bool printFormulaIndicator() const { return m_bPrintFormulaIndicator; }
  314. /**
  315. * Sets, if the formula Rect shall be shown on printouts
  316. */
  317. void setPrintFormulaIndicator( bool _printFormulaIndicator );
  318. /**
  319. * Updates m_dPrintRepeatColumnsWidth according to the new settings
  320. */
  321. void updatePrintRepeatColumnsWidth();
  322. /**
  323. * Updates m_dPrintRepeatColumnsWidth according to the new settings
  324. */
  325. void updatePrintRepeatRowsHeight();
  326. /**
  327. * Define the print range with the current selection
  328. */
  329. void definePrintRange(Selection* selectionInfo);
  330. /**
  331. * Reset the print range to the standard definition (whole sheet)
  332. */
  333. void resetPrintRange();
  334. /**
  335. * Updates the print range, according to the inserted columns
  336. */
  337. void insertColumn( int col, int nbCol );
  338. /**
  339. * Updates the print range, according to the inserted columns
  340. */
  341. void removeColumn( int col, int nbCol );
  342. /**
  343. * Updates the print range, according to the inserted rows
  344. */
  345. void insertRow( int row, int nbRow );
  346. /**
  347. * Updates the print range, according to the inserted rows
  348. */
  349. void removeRow( int row, int nbRow );
  350. /**
  351. * Sets the zoom level of the printout to _zoom
  352. * If checkPageLimit is false, then the zoom will be set,
  353. * without checking that this zoom level fits to an availabl page limit
  354. */
  355. void setZoom( double _zoom, bool checkPageLimit = true );
  356. /**
  357. * Returns the zoom level of the printout as double
  358. */
  359. double zoom() const { return m_dZoom; }
  360. /**
  361. * Checks wether the page has content to print
  362. */
  363. bool pageNeedsPrinting( TQRect& page_range );
  364. signals:
  365. void sig_updateView( Sheet *_sheet );
  366. private:
  367. Sheet * m_pSheet;
  368. Doc * m_pDoc;
  369. /**
  370. * Prints the page specified by 'page_range'.
  371. * This for the printout it uses @ref printRect and @ref printHeaderFooter
  372. *
  373. * @return the last vertical line which was printed plus one.
  374. *
  375. * @param _page_range TQRect defines a rectangle of cells which should be
  376. * painted to the device 'prn'.
  377. *
  378. * @param view KoRect defines the sourrounding rectangle which is
  379. * the printing frame.
  380. *
  381. * @param _childOffset KoPoint used to calculate the correct position of
  382. * children, if there are repeated columns/rows.
  383. */
  384. void printPage( TQPainter &_painter, const TQRect& page_range,
  385. const KoRect& view, const KoPoint _childOffset );
  386. /**
  387. * Prints a rect of cells defined by printRect at the position topLeft.
  388. */
  389. void printRect( TQPainter &painter, const KoPoint& topLeft,
  390. const TQRect& printRect, const KoRect& view,
  391. TQRegion &clipRegion );
  392. /**
  393. * Prints the header and footer on a page
  394. */
  395. void printHeaderFooter( TQPainter &painter, int pageNo );
  396. /**
  397. * Looks at @ref #m_paperFormat and calculates @ref #m_paperWidth and @ref #m_paperHeight.
  398. */
  399. void calcPaperSize();
  400. /**
  401. * Returns the iterator for the column in the newPage list for columns
  402. */
  403. TQValueList<PrintNewPageEntry>::iterator findNewPageColumn( int col );
  404. /**
  405. * Returns the iterator for the row in the newPage list for rows
  406. */
  407. TQValueList<PrintNewPageEntry>::iterator findNewPageRow( int row );
  408. /**
  409. * Replaces macros like <name>, <file>, <date> etc. in the string and
  410. * returns the modified one.
  411. *
  412. * @param _page is the page number for which the heading is produced.
  413. * @param _Sheet is the name of the Sheet for which we generate the headings.
  414. */
  415. TQString completeHeading( const TQString &_data, int _page, const TQString &_sheet ) const ;
  416. /**
  417. * Returns a rect, which contains the cols and rows to be printed.
  418. * It respects the printrange and the children
  419. */
  420. TQRect cellsPrintRange();
  421. /**
  422. * Returns the numbers of pages in x direction
  423. */
  424. int pagesX( const TQRect& cellsPrintRange );
  425. /**
  426. * Returns the numbers of pages in y direction
  427. */
  428. int pagesY( const TQRect& cellsPrintRange );
  429. /**
  430. * The orientation of the paper.
  431. */
  432. KoOrientation m_orientation;
  433. /**
  434. * Tells about the currently seleced paper size.
  435. */
  436. KoFormat m_paperFormat;
  437. /**
  438. * The paper width in millimeters. Dont change this value, it is calculated by
  439. * @ref #calcPaperSize from the value @ref #m_paperFormat.
  440. */
  441. float m_paperWidth;
  442. /**
  443. * The paper height in millimeters. Dont change this value, it is calculated by
  444. * @ref #calcPaperSize from the value @ref #m_paperFormat.
  445. */
  446. float m_paperHeight;
  447. /**
  448. * The left border in millimeters.
  449. */
  450. float m_leftBorder;
  451. /**
  452. * The right border in millimeters.
  453. */
  454. float m_rightBorder;
  455. /**
  456. * The top border in millimeters.
  457. */
  458. float m_topBorder;
  459. /**
  460. * The right border in millimeters.
  461. */
  462. float m_bottomBorder;
  463. /**
  464. * Header string. The string may contains makros. That means
  465. * it has to be processed before printing.
  466. */
  467. TQString m_headLeft;
  468. /**
  469. * Header string. The string may contains makros. That means
  470. * it has to be processed before printing.
  471. */
  472. TQString m_headRight;
  473. /**
  474. * Header string. The string may contains makros. That means
  475. * it has to be processed before printing.
  476. */
  477. TQString m_headMid;
  478. /**
  479. * Footer string. The string may contains makros. That means
  480. * it has to be processed before printing.
  481. */
  482. TQString m_footLeft;
  483. /**
  484. * Footer string. The string may contains makros. That means
  485. * it has to be processed before printing.
  486. */
  487. TQString m_footRight;
  488. /**
  489. * Footer string. The string may contains makros. That means
  490. * it has to be processed before printing.
  491. */
  492. TQString m_footMid;
  493. /**
  494. * Number of total pages, only calculated during printing
  495. */
  496. uint m_uprintPages;
  497. /**
  498. * Defined prinsheet area
  499. */
  500. TQRect m_printRange;
  501. /**
  502. * Repeated columns on printout
  503. */
  504. TQPair<int, int> m_printRepeatColumns;
  505. /**
  506. * Repeated rows on printout
  507. */
  508. TQPair<int, int> m_printRepeatRows;
  509. /**
  510. * Show the grid when making printout
  511. */
  512. bool m_bPrintGrid;
  513. /**
  514. * Show the objects when making printout
  515. */
  516. bool m_bPrintObjects;
  517. /**
  518. * Show the charts when making printout
  519. */
  520. bool m_bPrintCharts;
  521. /**
  522. * Show the graphics when making printout
  523. */
  524. bool m_bPrintGraphics;
  525. /**
  526. * Show the formula rect when making printout
  527. */
  528. bool m_bPrintFormulaIndicator;
  529. /**
  530. * Show the comment rect when making printout
  531. */
  532. bool m_bPrintCommentIndicator;
  533. /**
  534. * Width of repeated columns in points, stored for perfomance reasons
  535. */
  536. double m_dPrintRepeatColumnsWidth;
  537. /**
  538. * Height of repeated rows in points, stored for perfomance reasons
  539. */
  540. double m_dPrintRepeatRowsHeight;
  541. /**
  542. * Stores the new page columns
  543. */
  544. TQValueList<PrintNewPageEntry> m_lnewPageListX;
  545. /**
  546. * Stores the new page columns
  547. */
  548. TQValueList<PrintNewPageEntry> m_lnewPageListY;
  549. /**
  550. * Stores internally the maximum column that was checked already
  551. */
  552. int m_maxCheckedNewPageX;
  553. /**
  554. * Stores internally the maximum row that was checked already
  555. */
  556. int m_maxCheckedNewPageY;
  557. /**
  558. * Zoom level of printout
  559. */
  560. double m_dZoom;
  561. /**
  562. * Limit of pages in X direction. 0 means no limit
  563. */
  564. int m_iPageLimitX;
  565. /**
  566. * Limit of pages in Y direction. 0 means no limit
  567. */
  568. int m_iPageLimitY;
  569. TQValueList<PrintObject*> m_printObjects;
  570. };
  571. class PrintNewPageEntry
  572. {
  573. public:
  574. PrintNewPageEntry() :
  575. m_iStartItem( 0 ), m_iEndItem( 0 ), m_dSize( 0 ),
  576. m_dOffset( 0 ){}
  577. PrintNewPageEntry( int startItem, int endItem = 0, double size = 0,
  578. double offset = 0 ) :
  579. m_iStartItem( startItem ), m_iEndItem( endItem ), m_dSize( size ),
  580. m_dOffset( offset ) {}
  581. int startItem() const { return m_iStartItem; }
  582. void setStartItem( int startItem ) { m_iStartItem = startItem; }
  583. int endItem() const { return m_iEndItem; }
  584. void setEndItem( int endItem ) { m_iEndItem = endItem; }
  585. double size() const { return m_dSize; }
  586. void setSize( double size ) { m_dSize = size; }
  587. double offset() const { return m_dOffset; }
  588. void setOffset( double offset ) { m_dOffset = offset; }
  589. bool operator==( PrintNewPageEntry const & entry ) const;
  590. private:
  591. int m_iStartItem;
  592. int m_iEndItem;
  593. double m_dSize;
  594. double m_dOffset;
  595. };
  596. class PrintObject
  597. {
  598. public:
  599. PrintObject() : obj(0), p(0) {}
  600. EmbeddedObject *obj;
  601. TQPixmap *p;
  602. };
  603. } // namespace KSpread
  604. #endif