1 /************************************************************************ 2 * * 3 * This file is part of Kooka, a scanning/OCR application using * 4 * Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>. * 5 * * 6 * Copyright (C) 1999-2016 Klaas Freitag <freitag@suse.de> * 7 * Jonathan Marten <jjm@keelhaul.me.uk> * 8 * * 9 * Kooka is free software; you can redistribute it and/or modify it * 10 * under the terms of the GNU Library General Public License as * 11 * published by the Free Software Foundation and appearing in the * 12 * file COPYING included in the packaging of this file; either * 13 * version 2 of the License, or (at your option) any later version. * 14 * * 15 * As a special exception, permission is given to link this program * 16 * with any version of the KADMOS OCR/ICR engine (a product of * 17 * reRecognition GmbH, Kreuzlingen), and distribute the resulting * 18 * executable without including the source code for KADMOS in the * 19 * source distribution. * 20 * * 21 * This program is distributed in the hope that it will be useful, * 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 24 * GNU General Public License for more details. * 25 * * 26 * You should have received a copy of the GNU General Public * 27 * License along with this program; see the file COPYING. If * 28 * not, see <http://www.gnu.org/licenses/>. * 29 * * 30 ************************************************************************/ 31 32 #ifndef KOOKAPRINT_H 33 #define KOOKAPRINT_H 34 35 #include <qprinter.h> 36 37 class QPainter; 38 class KookaImage; 39 40 41 class KookaPrint : public QPrinter 42 { 43 public: 44 explicit KookaPrint(); 45 46 enum ScaleOption 47 { 48 ScaleScreen, ///< As seen on screen 49 ScaleScan, ///< From scan resolution 50 ScaleCustom, ///< Custom size 51 ScaleFitPage ///< Fit to page 52 }; 53 54 enum CutMarksOption 55 { 56 CutMarksNone, ///< No cut marks 57 CutMarksMultiple, ///< Cut marks if multiple pages 58 CutMarksAlways ///< Always cut marks 59 }; 60 61 void recalculatePrintParameters(); 62 void printImage(); 63 setImage(const KookaImage * img)64 void setImage(const KookaImage *img) { m_image = img; } image()65 const KookaImage *image() const { return (m_image); } 66 setScaleOption(KookaPrint::ScaleOption opt)67 void setScaleOption(KookaPrint::ScaleOption opt) { m_scaleOption = opt; } scaleOption()68 KookaPrint::ScaleOption scaleOption() const { return (m_scaleOption); } 69 setPrintSize(const QSize & opt)70 void setPrintSize(const QSize &opt) { m_printSize = opt; } printSize()71 QSize printSize() const { return (m_printSize); } 72 setMaintainAspect(bool opt)73 void setMaintainAspect(bool opt) { m_maintainAspect = opt; } maintainAspect()74 bool maintainAspect() const { return (m_maintainAspect); } 75 setLowResDraft(bool opt)76 void setLowResDraft(bool opt) { m_lowResDraft = opt; } lowResDraft()77 bool lowResDraft() const { return (m_lowResDraft); } 78 setScreenResolution(int res)79 void setScreenResolution(int res) { m_screenResolution = res; } screenResolution()80 int screenResolution() const { return (m_screenResolution); } 81 setScanResolution(int res)82 void setScanResolution(int res) { m_scanResolution = res; } scanResolution()83 int scanResolution() const { return (m_scanResolution); } 84 setCutMarks(KookaPrint::CutMarksOption opt)85 void setCutMarks(KookaPrint::CutMarksOption opt) { m_cutsOption = opt; } cutMarksOption()86 KookaPrint::CutMarksOption cutMarksOption() const { return (m_cutsOption); } 87 availablePageArea()88 QSize availablePageArea() const { return (QSize(qRound(mPageWidthAdjustedMm), qRound(mPageHeightAdjustedMm))); } imagePrintArea()89 QSize imagePrintArea() const { return (QSize(qRound(mPrintWidthMm), qRound(mPrintHeightMm))); } pageCount()90 QSize pageCount() const { return (QSize(mPrintColumns, mPrintRows)); } 91 92 protected: 93 void drawMarkerAroundPoint(QPainter *painter, const QPoint &p); 94 void drawCutSign(QPainter *painter, const QPoint &p, int num, Qt::Corner dir); 95 void drawCornerMarkers(QPainter *painter, const QRect &targetRect, int row, int col, int maxRows, int maxCols); 96 97 private: 98 const KookaImage *m_image; 99 100 KookaPrint::ScaleOption m_scaleOption; 101 KookaPrint::CutMarksOption m_cutsOption; 102 QSize m_printSize; 103 bool m_maintainAspect; 104 bool m_lowResDraft; 105 int m_screenResolution; 106 int m_scanResolution; 107 108 int mImageWidthPix; // pixel size of the image 109 int mImageHeightPix; 110 double mPrintWidthMm; // print size of the image 111 double mPrintHeightMm; 112 double mPageWidthMm; // print area available on page 113 double mPageHeightMm; 114 double mPageWidthAdjustedMm; // print area used on page 115 double mPageHeightAdjustedMm; 116 int mPrintRows; // rows/columns required 117 int mPrintColumns; 118 int mPrintTopPix; // pixel position of origin 119 int mPrintLeftPix; 120 121 int mPrintResolution; // printer resolution 122 }; 123 124 #endif // KOOKAPRINT_H 125