File indexing completed on 2024-04-28 16:21:26

0001 /* This file is part of the KDE project
0002    Copyright 2008 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003    Copyright 2005 Raphael Langerhorst <raphael.langerhorst@kdemail.net>
0004    Copyright 2003 Philipp Müller <philipp.mueller@gmx.de>
0005    Copyright 1998, 1999 Torben Weis <weis@kde.org>
0006 
0007    This library is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020    Boston, MA 02110-1301, USA.
0021 */
0022 
0023 // Local
0024 #include "PrintSettings.h"
0025 
0026 // Sheets
0027 #include "calligra_sheets_limits.h"
0028 #include "Region.h"
0029 
0030 // Calligra
0031 #include <KoPageLayout.h>
0032 #include <KoUnit.h>
0033 
0034 // Qt
0035 #include <QSize>
0036 
0037 using namespace Calligra::Sheets;
0038 
0039 class Q_DECL_HIDDEN PrintSettings::Private
0040 {
0041 public:
0042     KoPageLayout pageLayout;
0043     bool printGrid              : 1;
0044     bool printCharts            : 1;
0045     bool printObjects           : 1;
0046     bool printGraphics          : 1;
0047     bool printCommentIndicator  : 1;
0048     bool printFormulaIndicator  : 1;
0049     bool printHeaders           : 1;
0050     bool printZeroValues        : 1;
0051     bool centerHorizontally     : 1;
0052     bool centerVertically       : 1;
0053     PageOrder pageOrder;
0054     Region printRegion;
0055     double zoom;
0056     QSize pageLimits;
0057     QPair<int, int> repeatedColumns;
0058     QPair<int, int> repeatedRows;
0059 
0060 public:
0061     void calculatePageDimensions();
0062 };
0063 
0064 void PrintSettings::Private::calculatePageDimensions()
0065 {
0066     if (pageLayout.format != KoPageFormat::CustomSize) {
0067         pageLayout.width =  MM_TO_POINT(KoPageFormat::width(pageLayout.format, pageLayout.orientation));
0068         pageLayout.height = MM_TO_POINT(KoPageFormat::height(pageLayout.format, pageLayout.orientation));
0069     }
0070 }
0071 
0072 PrintSettings::PrintSettings()
0073         : d(new Private)
0074 {
0075     d->printGrid = false;
0076     d->printCharts = true;
0077     d->printObjects = true;
0078     d->printGraphics = true;
0079     d->printCommentIndicator = false;
0080     d->printFormulaIndicator = false;
0081     d->printHeaders = true;
0082     d->printZeroValues = false;
0083     d->centerHorizontally = false;
0084     d->centerVertically = false;
0085     d->pageOrder = LeftToRight;
0086     d->printRegion = Region(1, 1, KS_colMax, KS_rowMax);
0087     d->zoom = 1.0;
0088 }
0089 
0090 PrintSettings::PrintSettings(const PrintSettings& other)
0091         : d(new Private)
0092 {
0093     d->pageLayout = other.d->pageLayout;
0094     d->printGrid = other.d->printGrid;
0095     d->printCharts = other.d->printCharts;
0096     d->printObjects = other.d->printObjects;
0097     d->printGraphics = other.d->printGraphics;
0098     d->printCommentIndicator = other.d->printCommentIndicator;
0099     d->printFormulaIndicator = other.d->printFormulaIndicator;
0100     d->printHeaders = other.d->printHeaders;
0101     d->printZeroValues = other.d->printZeroValues;
0102     d->centerHorizontally = other.d->centerHorizontally;
0103     d->centerVertically = other.d->centerVertically;
0104     d->pageOrder = other.d->pageOrder;
0105     d->printRegion = other.d->printRegion;
0106     d->zoom = other.d->zoom;
0107     d->pageLimits = other.d->pageLimits;
0108     d->repeatedColumns = other.d->repeatedColumns;
0109     d->repeatedRows = other.d->repeatedRows;
0110 }
0111 
0112 PrintSettings::~PrintSettings()
0113 {
0114     delete d;
0115 }
0116 
0117 const KoPageLayout& PrintSettings::pageLayout() const
0118 {
0119     return d->pageLayout;
0120 }
0121 
0122 void PrintSettings::setPageLayout(const KoPageLayout& pageLayout)
0123 {
0124     d->pageLayout = pageLayout;
0125 }
0126 
0127 void PrintSettings::setPageFormat(KoPageFormat::Format format)
0128 {
0129     d->pageLayout.format = format;
0130     d->calculatePageDimensions();
0131 }
0132 
0133 void PrintSettings::setPageOrientation(KoPageFormat::Orientation orientation)
0134 {
0135     d->pageLayout.orientation = orientation;
0136     d->calculatePageDimensions();
0137 }
0138 
0139 QString PrintSettings::paperFormatString() const
0140 {
0141     if (d->pageLayout.format == KoPageFormat::CustomSize) {
0142         QString tmp;
0143         tmp.sprintf("%fx%f", d->pageLayout.width, d->pageLayout.height);
0144         return tmp;
0145     }
0146     return KoPageFormat::formatString(d->pageLayout.format);
0147 }
0148 
0149 QString PrintSettings::orientationString() const
0150 {
0151     switch (d->pageLayout.orientation) {
0152     case QPrinter::Portrait:
0153     default:
0154         return "Portrait";
0155     case QPrinter::Landscape:
0156         return "Landscape";
0157     }
0158 }
0159 
0160 double PrintSettings::printWidth() const
0161 {
0162     return d->pageLayout.width - d->pageLayout.leftMargin - d->pageLayout.rightMargin;
0163 }
0164 
0165 double PrintSettings::printHeight() const
0166 {
0167     return d->pageLayout.height - d->pageLayout.topMargin - d->pageLayout.bottomMargin;
0168 }
0169 
0170 PrintSettings::PageOrder PrintSettings::pageOrder() const
0171 {
0172     return d->pageOrder;
0173 }
0174 
0175 void PrintSettings::setPageOrder(PageOrder order)
0176 {
0177     d->pageOrder = order;
0178 }
0179 
0180 bool PrintSettings::printGrid() const
0181 {
0182     return d->printGrid;
0183 }
0184 
0185 void PrintSettings::setPrintGrid(bool printGrid)
0186 {
0187     d->printGrid = printGrid;
0188 }
0189 
0190 bool PrintSettings::printCharts() const
0191 {
0192     return d->printCharts;
0193 }
0194 
0195 void PrintSettings::setPrintCharts(bool printCharts)
0196 {
0197     d->printCharts = printCharts;
0198 }
0199 
0200 bool PrintSettings::printObjects() const
0201 {
0202     return d->printObjects;
0203 }
0204 
0205 void PrintSettings::setPrintObjects(bool printObjects)
0206 {
0207     d->printObjects = printObjects;
0208 }
0209 
0210 bool PrintSettings::printGraphics() const
0211 {
0212     return d->printGraphics;
0213 }
0214 
0215 void PrintSettings::setPrintGraphics(bool printGraphics)
0216 {
0217     d->printGraphics = printGraphics;
0218 }
0219 
0220 bool PrintSettings::printCommentIndicator() const
0221 {
0222     return d->printCommentIndicator;
0223 }
0224 
0225 void PrintSettings::setPrintCommentIndicator(bool printCommentIndicator)
0226 {
0227     d->printCommentIndicator = printCommentIndicator;
0228 }
0229 
0230 bool PrintSettings::printFormulaIndicator() const
0231 {
0232     return d->printFormulaIndicator;
0233 }
0234 
0235 void PrintSettings::setPrintFormulaIndicator(bool printFormulaIndicator)
0236 {
0237     d->printFormulaIndicator = printFormulaIndicator;
0238 }
0239 
0240 bool PrintSettings::printHeaders() const
0241 {
0242     return d->printHeaders;
0243 }
0244 
0245 void PrintSettings::setPrintHeaders(bool printHeaders)
0246 {
0247     d->printHeaders = printHeaders;
0248 }
0249 
0250 bool PrintSettings::printZeroValues() const
0251 {
0252     return d->printZeroValues;
0253 }
0254 
0255 void PrintSettings::setPrintZeroValues(bool printZeroValues)
0256 {
0257     d->printZeroValues = printZeroValues;
0258 }
0259 
0260 bool PrintSettings::centerHorizontally() const
0261 {
0262     return d->centerHorizontally;
0263 }
0264 
0265 void PrintSettings::setCenterHorizontally(bool center)
0266 {
0267     d->centerHorizontally = center;
0268 }
0269 
0270 bool PrintSettings::centerVertically() const
0271 {
0272     return d->centerVertically;
0273 }
0274 
0275 void PrintSettings::setCenterVertically(bool center)
0276 {
0277     d->centerVertically = center;
0278 }
0279 
0280 const Calligra::Sheets::Region& PrintSettings::printRegion() const
0281 {
0282     return d->printRegion;
0283 }
0284 
0285 void PrintSettings::setPrintRegion(const Region& region)
0286 {
0287     d->printRegion = region;
0288 }
0289 
0290 void PrintSettings::addPrintRange(const QRect& range)
0291 {
0292     d->printRegion.add(range);
0293 }
0294 
0295 void PrintSettings::removePrintRange(const QRect& range)
0296 {
0297     d->printRegion.sub(range, 0);
0298 }
0299 
0300 double PrintSettings::zoom() const
0301 {
0302     return d->zoom;
0303 }
0304 
0305 void PrintSettings::setZoom(double zoom)
0306 {
0307     d->zoom = zoom;
0308 }
0309 
0310 const QSize& PrintSettings::pageLimits() const
0311 {
0312     return d->pageLimits;
0313 }
0314 
0315 void PrintSettings::setPageLimits(const QSize& pageLimits)
0316 {
0317     d->pageLimits = pageLimits;
0318 }
0319 
0320 const QPair<int, int>& PrintSettings::repeatedColumns() const
0321 {
0322     return d->repeatedColumns;
0323 }
0324 
0325 void PrintSettings::setRepeatedColumns(const QPair<int, int>& repeatedColumns)
0326 {
0327     d->repeatedColumns = repeatedColumns;
0328     debugSheets << repeatedColumns;
0329 }
0330 
0331 const QPair<int, int>& PrintSettings::repeatedRows() const
0332 {
0333     return d->repeatedRows;
0334 }
0335 
0336 void PrintSettings::setRepeatedRows(const QPair<int, int>& repeatedRows)
0337 {
0338     d->repeatedRows = repeatedRows;
0339 }
0340 
0341 void PrintSettings::operator=(const PrintSettings & other)
0342 {
0343     d->pageLayout = other.d->pageLayout;
0344     d->printGrid = other.d->printGrid;
0345     d->printCharts = other.d->printCharts;
0346     d->printObjects = other.d->printObjects;
0347     d->printGraphics = other.d->printGraphics;
0348     d->printCommentIndicator = other.d->printCommentIndicator;
0349     d->printFormulaIndicator = other.d->printFormulaIndicator;
0350     d->printHeaders = other.d->printHeaders;
0351     d->printZeroValues = other.d->printZeroValues;
0352     d->centerHorizontally = other.d->centerHorizontally;
0353     d->centerVertically = other.d->centerVertically;
0354     d->pageOrder = other.d->pageOrder;
0355     d->printRegion = other.d->printRegion;
0356     d->zoom = other.d->zoom;
0357     d->pageLimits = other.d->pageLimits;
0358     d->repeatedColumns = other.d->repeatedColumns;
0359     d->repeatedRows = other.d->repeatedRows;
0360 }
0361 
0362 bool PrintSettings::operator==(const PrintSettings& other) const
0363 {
0364     if (d->pageLayout != other.d->pageLayout)
0365         return false;
0366     if (d->printGrid != other.d->printGrid)
0367         return false;
0368     if (d->printCharts != other.d->printCharts)
0369         return false;
0370     if (d->printObjects != other.d->printObjects)
0371         return false;
0372     if (d->printGraphics != other.d->printGraphics)
0373         return false;
0374     if (d->printCommentIndicator != other.d->printCommentIndicator)
0375         return false;
0376     if (d->printFormulaIndicator != other.d->printFormulaIndicator)
0377         return false;
0378     if (d->printHeaders != other.d->printHeaders)
0379         return false;
0380     if (d->printZeroValues != other.d->printZeroValues)
0381         return false;
0382     if (d->centerHorizontally != other.d->centerHorizontally)
0383         return false;
0384     if (d->centerVertically != other.d->centerVertically)
0385         return false;
0386     if (d->pageOrder != other.d->pageOrder)
0387         return false;
0388     if (d->printRegion != other.d->printRegion)
0389         return false;
0390     if (d->zoom != other.d->zoom)
0391         return false;
0392     if (d->pageLimits != other.d->pageLimits)
0393         return false;
0394     if (d->repeatedColumns != other.d->repeatedColumns)
0395         return false;
0396     if (d->repeatedRows != other.d->repeatedRows)
0397         return false;
0398     return true;
0399 }