1 /* This file is part of the KDE project
2    Copyright 2008 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 
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 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17    Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef CALLIGRA_SHEETS_PAGE_MANAGER
21 #define CALLIGRA_SHEETS_PAGE_MANAGER
22 
23 #include <Qt>
24 
25 #include "sheets_common_export.h"
26 
27 class QRect;
28 class QSizeF;
29 
30 namespace Calligra
31 {
32 namespace Sheets
33 {
34 class PrintSettings;
35 class Sheet;
36 
37 /**
38  * Manages the layouting of pages.
39  * Contains shared functionality between PrintManager, which layouts pages for
40  * printing, and TablePageManager, which does the same for the table shape in
41  * page based hosting apps.
42  */
43 class CALLIGRA_SHEETS_COMMON_EXPORT PageManager
44 {
45 public:
46     /**
47      * Constructor.
48      */
49     explicit PageManager(Sheet *sheet);
50 
51     /**
52      * Destructor.
53      */
54     virtual ~PageManager();
55 
56     /**
57      * Layouts the pages.
58      * Splits the used cell range, so that it fits on several pages.
59      */
60     void layoutPages();
61 
62     /**
63      * Sets the print settings.
64      * If the settings differ from the existing ones, the pages are recreated.
65      * \param settings the print settings
66      * \param force forces a recreation of the pages, if \c true
67      */
68     void setPrintSettings(const PrintSettings& settings, bool force = false);
69 
70     /**
71      * Number of pages.
72      */
73     int pageCount() const;
74 
75     /**
76      * Return the cell range of the requested page.
77      * \param page the page number
78      * \return the page's cell range
79      */
80     QRect cellRange(int page) const;
81 
82     /**
83      * Return the visible size, the page size decreased by the borders, of the requested page.
84      * \param page the page number
85      * \return the page's visible size
86      */
87     virtual QSizeF size(int page) const;
88 
89 protected:
90     Sheet* sheet() const;
91     const PrintSettings& printSettings() const;
92     virtual void clearPages();
93     virtual bool pageNeedsPrinting(const QRect& cellRange) const;
94     virtual void insertPage(int page);
95     virtual void preparePage(int page);
96 
97 private:
98     Q_DISABLE_COPY(PageManager)
99 
100     class Private;
101     Private * const d;
102 };
103 
104 } // namespace Sheets
105 } // namespace Calligra
106 
107 #endif // CALLIGRA_SHEETS_PAGE_MANAGER
108