1 /* This file is part of the KDE project
2 Copyright 2008 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3 Copyright 2005 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
4 Copyright 2003 Philipp Müller <philipp.mueller@gmx.de>
5 Copyright 1998, 1999 Torben Weis <weis@kde.org>
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 // Local
24 #include "PrintSettings.h"
25
26 // Sheets
27 #include "calligra_sheets_limits.h"
28 #include "Region.h"
29
30 // Calligra
31 #include <KoPageLayout.h>
32 #include <KoUnit.h>
33
34 // Qt
35 #include <QSize>
36
37 using namespace Calligra::Sheets;
38
39 class Q_DECL_HIDDEN PrintSettings::Private
40 {
41 public:
42 KoPageLayout pageLayout;
43 bool printGrid : 1;
44 bool printCharts : 1;
45 bool printObjects : 1;
46 bool printGraphics : 1;
47 bool printCommentIndicator : 1;
48 bool printFormulaIndicator : 1;
49 bool printHeaders : 1;
50 bool printZeroValues : 1;
51 bool centerHorizontally : 1;
52 bool centerVertically : 1;
53 PageOrder pageOrder;
54 Region printRegion;
55 double zoom;
56 QSize pageLimits;
57 QPair<int, int> repeatedColumns;
58 QPair<int, int> repeatedRows;
59
60 public:
61 void calculatePageDimensions();
62 };
63
calculatePageDimensions()64 void PrintSettings::Private::calculatePageDimensions()
65 {
66 if (pageLayout.format != KoPageFormat::CustomSize) {
67 pageLayout.width = MM_TO_POINT(KoPageFormat::width(pageLayout.format, pageLayout.orientation));
68 pageLayout.height = MM_TO_POINT(KoPageFormat::height(pageLayout.format, pageLayout.orientation));
69 }
70 }
71
PrintSettings()72 PrintSettings::PrintSettings()
73 : d(new Private)
74 {
75 d->printGrid = false;
76 d->printCharts = true;
77 d->printObjects = true;
78 d->printGraphics = true;
79 d->printCommentIndicator = false;
80 d->printFormulaIndicator = false;
81 d->printHeaders = true;
82 d->printZeroValues = false;
83 d->centerHorizontally = false;
84 d->centerVertically = false;
85 d->pageOrder = LeftToRight;
86 d->printRegion = Region(1, 1, KS_colMax, KS_rowMax);
87 d->zoom = 1.0;
88 }
89
PrintSettings(const PrintSettings & other)90 PrintSettings::PrintSettings(const PrintSettings& other)
91 : d(new Private)
92 {
93 d->pageLayout = other.d->pageLayout;
94 d->printGrid = other.d->printGrid;
95 d->printCharts = other.d->printCharts;
96 d->printObjects = other.d->printObjects;
97 d->printGraphics = other.d->printGraphics;
98 d->printCommentIndicator = other.d->printCommentIndicator;
99 d->printFormulaIndicator = other.d->printFormulaIndicator;
100 d->printHeaders = other.d->printHeaders;
101 d->printZeroValues = other.d->printZeroValues;
102 d->centerHorizontally = other.d->centerHorizontally;
103 d->centerVertically = other.d->centerVertically;
104 d->pageOrder = other.d->pageOrder;
105 d->printRegion = other.d->printRegion;
106 d->zoom = other.d->zoom;
107 d->pageLimits = other.d->pageLimits;
108 d->repeatedColumns = other.d->repeatedColumns;
109 d->repeatedRows = other.d->repeatedRows;
110 }
111
~PrintSettings()112 PrintSettings::~PrintSettings()
113 {
114 delete d;
115 }
116
pageLayout() const117 const KoPageLayout& PrintSettings::pageLayout() const
118 {
119 return d->pageLayout;
120 }
121
setPageLayout(const KoPageLayout & pageLayout)122 void PrintSettings::setPageLayout(const KoPageLayout& pageLayout)
123 {
124 d->pageLayout = pageLayout;
125 }
126
setPageFormat(KoPageFormat::Format format)127 void PrintSettings::setPageFormat(KoPageFormat::Format format)
128 {
129 d->pageLayout.format = format;
130 d->calculatePageDimensions();
131 }
132
setPageOrientation(KoPageFormat::Orientation orientation)133 void PrintSettings::setPageOrientation(KoPageFormat::Orientation orientation)
134 {
135 d->pageLayout.orientation = orientation;
136 d->calculatePageDimensions();
137 }
138
paperFormatString() const139 QString PrintSettings::paperFormatString() const
140 {
141 if (d->pageLayout.format == KoPageFormat::CustomSize) {
142 QString tmp;
143 tmp.sprintf("%fx%f", d->pageLayout.width, d->pageLayout.height);
144 return tmp;
145 }
146 return KoPageFormat::formatString(d->pageLayout.format);
147 }
148
orientationString() const149 QString PrintSettings::orientationString() const
150 {
151 switch (d->pageLayout.orientation) {
152 case QPrinter::Portrait:
153 default:
154 return "Portrait";
155 case QPrinter::Landscape:
156 return "Landscape";
157 }
158 }
159
printWidth() const160 double PrintSettings::printWidth() const
161 {
162 return d->pageLayout.width - d->pageLayout.leftMargin - d->pageLayout.rightMargin;
163 }
164
printHeight() const165 double PrintSettings::printHeight() const
166 {
167 return d->pageLayout.height - d->pageLayout.topMargin - d->pageLayout.bottomMargin;
168 }
169
pageOrder() const170 PrintSettings::PageOrder PrintSettings::pageOrder() const
171 {
172 return d->pageOrder;
173 }
174
setPageOrder(PageOrder order)175 void PrintSettings::setPageOrder(PageOrder order)
176 {
177 d->pageOrder = order;
178 }
179
printGrid() const180 bool PrintSettings::printGrid() const
181 {
182 return d->printGrid;
183 }
184
setPrintGrid(bool printGrid)185 void PrintSettings::setPrintGrid(bool printGrid)
186 {
187 d->printGrid = printGrid;
188 }
189
printCharts() const190 bool PrintSettings::printCharts() const
191 {
192 return d->printCharts;
193 }
194
setPrintCharts(bool printCharts)195 void PrintSettings::setPrintCharts(bool printCharts)
196 {
197 d->printCharts = printCharts;
198 }
199
printObjects() const200 bool PrintSettings::printObjects() const
201 {
202 return d->printObjects;
203 }
204
setPrintObjects(bool printObjects)205 void PrintSettings::setPrintObjects(bool printObjects)
206 {
207 d->printObjects = printObjects;
208 }
209
printGraphics() const210 bool PrintSettings::printGraphics() const
211 {
212 return d->printGraphics;
213 }
214
setPrintGraphics(bool printGraphics)215 void PrintSettings::setPrintGraphics(bool printGraphics)
216 {
217 d->printGraphics = printGraphics;
218 }
219
printCommentIndicator() const220 bool PrintSettings::printCommentIndicator() const
221 {
222 return d->printCommentIndicator;
223 }
224
setPrintCommentIndicator(bool printCommentIndicator)225 void PrintSettings::setPrintCommentIndicator(bool printCommentIndicator)
226 {
227 d->printCommentIndicator = printCommentIndicator;
228 }
229
printFormulaIndicator() const230 bool PrintSettings::printFormulaIndicator() const
231 {
232 return d->printFormulaIndicator;
233 }
234
setPrintFormulaIndicator(bool printFormulaIndicator)235 void PrintSettings::setPrintFormulaIndicator(bool printFormulaIndicator)
236 {
237 d->printFormulaIndicator = printFormulaIndicator;
238 }
239
printHeaders() const240 bool PrintSettings::printHeaders() const
241 {
242 return d->printHeaders;
243 }
244
setPrintHeaders(bool printHeaders)245 void PrintSettings::setPrintHeaders(bool printHeaders)
246 {
247 d->printHeaders = printHeaders;
248 }
249
printZeroValues() const250 bool PrintSettings::printZeroValues() const
251 {
252 return d->printZeroValues;
253 }
254
setPrintZeroValues(bool printZeroValues)255 void PrintSettings::setPrintZeroValues(bool printZeroValues)
256 {
257 d->printZeroValues = printZeroValues;
258 }
259
centerHorizontally() const260 bool PrintSettings::centerHorizontally() const
261 {
262 return d->centerHorizontally;
263 }
264
setCenterHorizontally(bool center)265 void PrintSettings::setCenterHorizontally(bool center)
266 {
267 d->centerHorizontally = center;
268 }
269
centerVertically() const270 bool PrintSettings::centerVertically() const
271 {
272 return d->centerVertically;
273 }
274
setCenterVertically(bool center)275 void PrintSettings::setCenterVertically(bool center)
276 {
277 d->centerVertically = center;
278 }
279
printRegion() const280 const Calligra::Sheets::Region& PrintSettings::printRegion() const
281 {
282 return d->printRegion;
283 }
284
setPrintRegion(const Region & region)285 void PrintSettings::setPrintRegion(const Region& region)
286 {
287 d->printRegion = region;
288 }
289
addPrintRange(const QRect & range)290 void PrintSettings::addPrintRange(const QRect& range)
291 {
292 d->printRegion.add(range);
293 }
294
removePrintRange(const QRect & range)295 void PrintSettings::removePrintRange(const QRect& range)
296 {
297 d->printRegion.sub(range, 0);
298 }
299
zoom() const300 double PrintSettings::zoom() const
301 {
302 return d->zoom;
303 }
304
setZoom(double zoom)305 void PrintSettings::setZoom(double zoom)
306 {
307 d->zoom = zoom;
308 }
309
pageLimits() const310 const QSize& PrintSettings::pageLimits() const
311 {
312 return d->pageLimits;
313 }
314
setPageLimits(const QSize & pageLimits)315 void PrintSettings::setPageLimits(const QSize& pageLimits)
316 {
317 d->pageLimits = pageLimits;
318 }
319
repeatedColumns() const320 const QPair<int, int>& PrintSettings::repeatedColumns() const
321 {
322 return d->repeatedColumns;
323 }
324
setRepeatedColumns(const QPair<int,int> & repeatedColumns)325 void PrintSettings::setRepeatedColumns(const QPair<int, int>& repeatedColumns)
326 {
327 d->repeatedColumns = repeatedColumns;
328 debugSheets << repeatedColumns;
329 }
330
repeatedRows() const331 const QPair<int, int>& PrintSettings::repeatedRows() const
332 {
333 return d->repeatedRows;
334 }
335
setRepeatedRows(const QPair<int,int> & repeatedRows)336 void PrintSettings::setRepeatedRows(const QPair<int, int>& repeatedRows)
337 {
338 d->repeatedRows = repeatedRows;
339 }
340
operator =(const PrintSettings & other)341 void PrintSettings::operator=(const PrintSettings & other)
342 {
343 d->pageLayout = other.d->pageLayout;
344 d->printGrid = other.d->printGrid;
345 d->printCharts = other.d->printCharts;
346 d->printObjects = other.d->printObjects;
347 d->printGraphics = other.d->printGraphics;
348 d->printCommentIndicator = other.d->printCommentIndicator;
349 d->printFormulaIndicator = other.d->printFormulaIndicator;
350 d->printHeaders = other.d->printHeaders;
351 d->printZeroValues = other.d->printZeroValues;
352 d->centerHorizontally = other.d->centerHorizontally;
353 d->centerVertically = other.d->centerVertically;
354 d->pageOrder = other.d->pageOrder;
355 d->printRegion = other.d->printRegion;
356 d->zoom = other.d->zoom;
357 d->pageLimits = other.d->pageLimits;
358 d->repeatedColumns = other.d->repeatedColumns;
359 d->repeatedRows = other.d->repeatedRows;
360 }
361
operator ==(const PrintSettings & other) const362 bool PrintSettings::operator==(const PrintSettings& other) const
363 {
364 if (d->pageLayout != other.d->pageLayout)
365 return false;
366 if (d->printGrid != other.d->printGrid)
367 return false;
368 if (d->printCharts != other.d->printCharts)
369 return false;
370 if (d->printObjects != other.d->printObjects)
371 return false;
372 if (d->printGraphics != other.d->printGraphics)
373 return false;
374 if (d->printCommentIndicator != other.d->printCommentIndicator)
375 return false;
376 if (d->printFormulaIndicator != other.d->printFormulaIndicator)
377 return false;
378 if (d->printHeaders != other.d->printHeaders)
379 return false;
380 if (d->printZeroValues != other.d->printZeroValues)
381 return false;
382 if (d->centerHorizontally != other.d->centerHorizontally)
383 return false;
384 if (d->centerVertically != other.d->centerVertically)
385 return false;
386 if (d->pageOrder != other.d->pageOrder)
387 return false;
388 if (d->printRegion != other.d->printRegion)
389 return false;
390 if (d->zoom != other.d->zoom)
391 return false;
392 if (d->pageLimits != other.d->pageLimits)
393 return false;
394 if (d->repeatedColumns != other.d->repeatedColumns)
395 return false;
396 if (d->repeatedRows != other.d->repeatedRows)
397 return false;
398 return true;
399 }
400