File indexing completed on 2025-01-19 12:59:19
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) 2000-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 PREVIEWER_H 0033 #define PREVIEWER_H 0034 0035 #include "kookascan_export.h" 0036 0037 #include <qvector.h> 0038 #include <qframe.h> 0039 0040 #include <kruler.h> 0041 0042 #include "scanimage.h" 0043 0044 /** 0045 *@author Klaas Freitag 0046 */ 0047 0048 class KScanDevice; 0049 0050 class ImageCanvas; 0051 class AutoSelectBar; 0052 0053 0054 class KOOKASCAN_EXPORT Previewer : public QFrame 0055 { 0056 Q_OBJECT 0057 0058 public: 0059 explicit Previewer(QWidget *parent = nullptr); 0060 virtual ~Previewer() = default; 0061 0062 ImageCanvas *getImageCanvas() const { return (mCanvas); } 0063 0064 bool setPreviewImage(ScanImage::Ptr image); 0065 void newImage(ScanImage::Ptr image); 0066 void setScannerBedSize(int w, int h); 0067 void setDisplayUnit(KRuler::MetricStyle unit); 0068 void connectScanner(KScanDevice *scan); 0069 0070 static QString previewInfoString(double widthMm, double heightMm, int resX, int resY); 0071 0072 public slots: 0073 void slotNewAreaSelected(const QRectF &rect); 0074 void slotNewScanResolutions(int xres, int yres); 0075 void slotNewScanMode(int bytes_per_pix); 0076 void slotSetAutoSelThresh(int); 0077 void slotAutoSelToggled(bool); 0078 0079 void slotNewCustomScanSize(const QRect &rect); 0080 0081 protected slots: 0082 void slotAutoSelectSettingsChanged(int margin, bool bgIsWhite, int dustsize); 0083 0084 signals: 0085 void newPreviewRect(const QRect &rect); 0086 void autoSelectStateChanged(bool isAvailable, bool isOn); 0087 void previewDimsChanged(const QString &dims); 0088 void previewFileSizeChanged(long size); 0089 0090 private: 0091 bool checkForScannerBg(); 0092 0093 void updateSelectionDims(); 0094 0095 void resetAutoSelection(); 0096 void setAutoSelection(bool on); 0097 bool imagePiece(const QVector<long> &src, int *start, int *end); 0098 0099 private slots: 0100 void slotNotifyAutoSelectChanged(); 0101 void slotFindAutoSelection(); 0102 0103 private: 0104 ImageCanvas *mCanvas; 0105 AutoSelectBar *mAutoSelectBar; 0106 KScanDevice *mScanDevice; 0107 0108 int mBedWidth, mBedHeight; 0109 int mScanResX, mScanResY; 0110 int mBytesPerPix; 0111 double mSelectionWidthMm, mSelectionHeightMm; 0112 KRuler::MetricStyle mDisplayUnit; 0113 0114 bool mDoAutoSelection; 0115 int mAutoSelMargin; 0116 int mAutoSelThresh; 0117 int mAutoSelDustsize; 0118 bool mBgIsWhite; 0119 0120 QVector<long> mHeightSum; 0121 QVector<long> mWidthSum; 0122 }; 0123 0124 #endif // PREVIEWER_H