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