File indexing completed on 2024-04-28 12:07:04
0001 /************************************************************************ 0002 * * 0003 * This file is part of Kooka, a scanning/OCR application using * 0004 * Qt <http://www.qt.io> and KDE Frameworks <http://www.kde.org>. * 0005 * * 0006 * Copyright (C) 1999-2016 Klaas Freitag <freitag@suse.de> * 0007 * Jonathan Marten <jjm@keelhaul.me.uk> * 0008 * * 0009 * Kooka is free software; you can redistribute it and/or modify it * 0010 * under the terms of the GNU Library General Public License as * 0011 * published by the Free Software Foundation and appearing in the * 0012 * file COPYING included in the packaging of this file; either * 0013 * version 2 of the License, or (at your option) any later version. * 0014 * * 0015 * As a special exception, permission is given to link this program * 0016 * with any version of the KADMOS OCR/ICR engine (a product of * 0017 * reRecognition GmbH, Kreuzlingen), and distribute the resulting * 0018 * executable without including the source code for KADMOS in the * 0019 * source distribution. * 0020 * * 0021 * This program is distributed in the hope that it will be useful, * 0022 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0024 * GNU General Public License for more details. * 0025 * * 0026 * You should have received a copy of the GNU General Public * 0027 * License along with this program; see the file COPYING. If * 0028 * not, see <http://www.gnu.org/licenses/>. * 0029 * * 0030 ************************************************************************/ 0031 0032 #ifndef KOOKAPRINT_H 0033 #define KOOKAPRINT_H 0034 0035 #include <qprinter.h> 0036 0037 #include "kookacore_export.h" 0038 0039 class QPainter; 0040 // For rigorousness, the image to be printed should be passed to us and 0041 // stored as a ScanImage::Ptr (a QSharedPointer to a ScanImage). Unfortunately, 0042 // having such a pointer as a member would need to include "scanimage.h", which 0043 // in turn means that the KCFG settings (which needs to include "kookaprint.h" 0044 // but then cannot find "scanimage.h") will not build. 0045 // 0046 // Since KookaPrint only uses the image for printing and does not need to copy 0047 // or modify it, it should be safe to store a pointer to the image here. 0048 class QImage; 0049 0050 0051 class KOOKACORE_EXPORT KookaPrint : public QPrinter 0052 { 0053 public: 0054 explicit KookaPrint(); 0055 0056 enum ScaleOption 0057 { 0058 ScaleScreen, ///< As seen on screen 0059 ScaleScan, ///< From scan resolution 0060 ScaleCustom, ///< Custom size 0061 ScaleFitPage ///< Fit to page 0062 }; 0063 0064 enum CutMarksOption 0065 { 0066 CutMarksNone, ///< No cut marks 0067 CutMarksMultiple, ///< Cut marks if multiple pages 0068 CutMarksAlways ///< Always cut marks 0069 }; 0070 0071 void recalculatePrintParameters(); 0072 void printImage(); 0073 0074 void setImage(const QImage *img) { m_image = img; } 0075 void setCopyMode(bool on); 0076 bool isCopyMode() const { return (m_copyMode); } 0077 0078 void setScaleOption(KookaPrint::ScaleOption opt) { m_scaleOption = opt; } 0079 KookaPrint::ScaleOption scaleOption() const { return (m_scaleOption); } 0080 0081 void setPrintSize(const QSize &opt) { m_printSize = opt; } 0082 QSize printSize() const { return (m_printSize); } 0083 0084 void setMaintainAspect(bool opt) { m_maintainAspect = opt; } 0085 bool maintainAspect() const { return (m_maintainAspect); } 0086 0087 void setLowResDraft(bool opt) { m_lowResDraft = opt; } 0088 bool lowResDraft() const { return (m_lowResDraft); } 0089 0090 void setScreenResolution(int res) { m_screenResolution = res; } 0091 int screenResolution() const { return (m_screenResolution); } 0092 0093 void setScanResolution(int res) { m_scanResolution = res; } 0094 int scanResolution() const { return (m_scanResolution); } 0095 0096 void setCutMarks(KookaPrint::CutMarksOption opt) { m_cutsOption = opt; } 0097 KookaPrint::CutMarksOption cutMarksOption() const { return (m_cutsOption); } 0098 0099 QSize availablePageArea() const { return (QSize(qRound(mPageWidthAdjustedMm), qRound(mPageHeightAdjustedMm))); } 0100 QSize imagePrintArea() const { return (QSize(qRound(mPrintWidthMm), qRound(mPrintHeightMm))); } 0101 QSize pageCount() const { return (QSize(mPrintColumns, mPrintRows)); } 0102 0103 protected: 0104 void drawMarkerAroundPoint(QPainter *painter, const QPoint &p); 0105 void drawCutSign(QPainter *painter, const QPoint &p, int num, Qt::Corner dir); 0106 void drawCornerMarkers(QPainter *painter, const QRect &targetRect, int row, int col, int maxRows, int maxCols); 0107 0108 private: 0109 const QImage *m_image; 0110 0111 KookaPrint::ScaleOption m_scaleOption; 0112 KookaPrint::CutMarksOption m_cutsOption; 0113 QSize m_printSize; 0114 bool m_maintainAspect; 0115 bool m_lowResDraft; 0116 int m_screenResolution; 0117 int m_scanResolution; 0118 0119 int mImageWidthPix; // pixel size of the image 0120 int mImageHeightPix; 0121 double mPrintWidthMm; // print size of the image 0122 double mPrintHeightMm; 0123 double mPageWidthMm; // print area available on page 0124 double mPageHeightMm; 0125 double mPageWidthAdjustedMm; // print area used on page 0126 double mPageHeightAdjustedMm; 0127 int mPrintRows; // rows/columns required 0128 int mPrintColumns; 0129 int mPrintTopPix; // pixel position of origin 0130 int mPrintLeftPix; 0131 0132 int mPrintResolution; // printer resolution 0133 0134 bool m_copyMode; 0135 }; 0136 0137 #endif // KOOKAPRINT_H