File indexing completed on 2025-01-19 12:59:20
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 SCANPARAMS_H 0033 #define SCANPARAMS_H 0034 0035 #include "kookascan_export.h" 0036 0037 #include <qwidget.h> 0038 0039 #include "kscandevice.h" 0040 //#include "scansourcedialog.h" 0041 0042 class QProgressDialog; 0043 class QPushButton; 0044 class QLabel; 0045 class QTabWidget; 0046 0047 class KScanOption; 0048 class KGammaTable; 0049 class KLed; 0050 class KMessageWidget; 0051 class KLocalizedString; 0052 0053 class ScanParamsPage; 0054 class ScanSizeSelector; 0055 0056 /** 0057 * @short Scanner settings GUI. 0058 * 0059 * The most well-known and important scanner options are placed in a 0060 * "Basic" tab. These are settings such as the scan mode and resolution, 0061 * area and document source. 0062 * 0063 * Other scanner options are placed either in an "Other" or "Advanced" tab, 0064 * depending on how they are classified by the SANE backend. 0065 * 0066 * The scanner name/description and the operation LED appear above the 0067 * scanner settings, and the "Preview" and "Scan" action buttons below. 0068 * 0069 * This class controls the scanner operation (via its @c KScanDevice) and 0070 * the popup scanning progress dialogue. 0071 * 0072 * @author Klaas Freitag 0073 * @author Jonathan Marten 0074 **/ 0075 0076 class KOOKASCAN_EXPORT ScanParams : public QWidget 0077 { 0078 Q_OBJECT 0079 0080 public: 0081 /** 0082 * Create the scanner options container widget. The GUI for the 0083 * scanner settings is not actually created until the scanner device is 0084 * specified with @c connectDevice(). 0085 * 0086 * @param parent The parent widget 0087 **/ 0088 explicit ScanParams(QWidget *parent); 0089 0090 /** 0091 * Destructor. 0092 **/ 0093 virtual ~ScanParams(); 0094 0095 /** 0096 * Specify a scanner device and create the GUI for its settings. 0097 * 0098 * @param newScanDevice The scan device to use, or @c nullptr if no 0099 * scanner device is to be used. 0100 * @param galleryMode If this is @c true, then a @c nullptr value for 0101 * the @p newScanDevice will be allowed and a message will be 0102 * displayed in place of the scanner settings. This message will 0103 * be as created by @c messageScannerNotSelected(). If this 0104 * parameter is @c false and the @p newScanDevice parameter is 0105 * @c nullptr, the message as created by @c messageScannerProblem() 0106 * will be displayed. 0107 * @return @c true in all cases. 0108 **/ 0109 bool connectDevice(KScanDevice *newScanDevice, bool galleryMode = false); 0110 0111 /** 0112 * Get the operation "LED" widget. 0113 * 0114 * @return The widget, or @c nullptr if it has not been created yet. 0115 * Do not delete this, it is owned by the @c ScanParams object. 0116 **/ 0117 KLed *operationLED() const; 0118 0119 /** 0120 * Set the scan destination to be displayed in the progress dialogue. 0121 * 0122 * @param dest Destination to be shown 0123 **/ 0124 void setScanDestination(const KLocalizedString &dest); 0125 0126 public slots: 0127 /** 0128 * Start to acquire a scan preview. This is internally connected 0129 * and called when the "Preview" button is clicked. 0130 * 0131 * @see slotStartScan 0132 **/ 0133 void slotAcquirePreview(); 0134 0135 /** 0136 * Start to acquire a scan. This is internally connected and called 0137 * when the "Start Scan" button is clicked. 0138 * 0139 * @see slotAcquirePreview 0140 **/ 0141 void slotStartScan(); 0142 0143 /** 0144 * A new scan area has been drawn on or auto-selected by the previewer. 0145 * 0146 * @param rect The new scan area. 0147 **/ 0148 void slotNewPreviewRect(const QRect &rect); 0149 0150 protected: 0151 /** 0152 * Create a widget (for example, a QLabel showing an appropriate message) 0153 * which is displayed if no scanner is selected. This happens if 0154 * the @c newScanDevice parameter to @c connectDevice() is @c nullptr and 0155 * the @c galleryMode parameter is @c true. 0156 * 0157 * @return the created widget 0158 * 0159 * @note The returned widget is added to the GUI, so it will be deleted 0160 * when the @c ScanParams object is deleted. 0161 * 0162 * @see messageScannerProblem 0163 **/ 0164 virtual QWidget *messageScannerNotSelected(); 0165 0166 /** 0167 * Create a widget (for example, a QLabel showing an appropriate message) 0168 * which is displayed if a scanner is selected but there is an error 0169 * opening or connecting to it. This happens if the @c newScanDevice 0170 * parameter to @c connectDevice() is @c nullptr but the @c galleryMode 0171 * parameter is @c false (the default). 0172 * 0173 * @return the created widget 0174 * 0175 * @note The returned widget is added to the GUI, so it will be deleted 0176 * when the @c ScanParams object is deleted. 0177 * 0178 * @see messageScannerNotSelected 0179 **/ 0180 virtual QWidget *messageScannerProblem(); 0181 0182 /** 0183 * Create a GUI to display the application's "Scan Destination" 0184 * selector and further controls as appropriate. 0185 * 0186 * @param frame the page to add the widgets to 0187 * 0188 * @note Any widgets created should be children of the @p frame page, 0189 * so they will be deleted along with the @c ScanParams object. 0190 * @see @c ScanParamsPage 0191 **/ 0192 virtual void createScanDestinationGUI(ScanParamsPage *frame) { } 0193 0194 /** 0195 * Check whether a scan device is present and configured. 0196 * 0197 * @return @c true if there is a scan device. 0198 **/ 0199 bool hasScanDevice() const { return (mSaneDevice!=nullptr); } 0200 0201 protected slots: 0202 /** 0203 * Open the source selection dialogue. Internally connected 0204 * to the GUI button, if one is present. 0205 **/ 0206 void slotSourceSelect(); 0207 0208 /** 0209 * Change the virtual scan mode. Internally connected to the 0210 * GUI radio button group, if this setting is present. 0211 * 0212 * @param but The activated button index within the group. 0213 **/ 0214 void slotVirtScanModeSelect(int but); 0215 0216 /** 0217 * Open the gamma table edit dialogue. Internally connected 0218 * to the GUI button, if one is present. 0219 **/ 0220 void slotEditCustGamma(); 0221 0222 /** 0223 * The setting of one of the scanner controls has changed. 0224 * Inform the scanner device and check whether any other options 0225 * are affected. 0226 * 0227 * @param so The option that has changed. 0228 **/ 0229 void slotOptionChanged(KScanOption *so); 0230 0231 /** 0232 * The gamma table has been edited via the gamma table edit dialogue. 0233 * Send the new gamma table to the scanner. 0234 * 0235 * @param gt The new gamma table. 0236 **/ 0237 void slotApplyGamma(const KGammaTable *gt); 0238 0239 /** 0240 * The setting for the X or Y, or both, resolutions has changed. 0241 * Calculate the new resolution and emit the @c scanResolutionChanged() 0242 * signal. 0243 * 0244 * @param so The option that has changed. 0245 * 0246 * @see scanResolutionChanged 0247 **/ 0248 void slotNewResolution(KScanOption *so); 0249 0250 /** 0251 * The setting for the scan mode (colour, greyscale etc.) has changed. 0252 * Calculate the new bit depth and emit the @c scanModeChanged() 0253 * signal. 0254 * 0255 * @see scanModeChanged 0256 **/ 0257 void slotNewScanMode(); 0258 0259 /** 0260 * A new preset scan size or orientation has been chosen by the user. 0261 * Calculate the new scan area and emit the @c newCustomScanSize() 0262 * signal. 0263 * 0264 * @param rect The new scan area, or a null rectangle (@c QRect()) 0265 * for the default maximum scan area. 0266 * 0267 * @see newCustomScanSize 0268 **/ 0269 void slotScanSizeSelected(const QRect &rect); 0270 0271 signals: 0272 /** 0273 * Indicates that the resolution setting has changed. 0274 * 0275 * @param xres The new X resolution. 0276 * @param yres The new Y resolution. 0277 * 0278 * @see slotNewResolution 0279 **/ 0280 void scanResolutionChanged(int xres, int yres); 0281 0282 /** 0283 * Indicates that the scan mode setting has changed. 0284 * 0285 * @param bytes_per_pix The new pixel depth. This is the number 0286 * of bytes per pixel, or @c 0 for a black/white (1 bit per pixel) 0287 * image. 0288 * 0289 * @see slotNewScanMode 0290 **/ 0291 void scanModeChanged(int bytes_per_pix); 0292 0293 /** 0294 * The scan area or its size has changed, either by the user selecting 0295 * a preset scan area or by drawing an area on the previewer, or by 0296 * the previewer auto-selection. 0297 * 0298 * @param rect The new scan area. 0299 * @see slotScanSizeSelected 0300 **/ 0301 void newCustomScanSize(const QRect &rect); 0302 0303 private slots: 0304 void slotScanProgress(int value); 0305 0306 private: 0307 0308 enum ScanMode { // order fixed by GUI buttons 0309 SaneDebugMode = 0, 0310 VirtualScannerMode = 1, 0311 NormalMode = 2 0312 }; 0313 0314 KScanDevice::Status prepareScan(QString *vfp); 0315 KScanDevice::Status performADFScan(); 0316 0317 void createNoScannerMsg(bool galleryMode); 0318 void initStartupArea(bool dontRestore); 0319 void setEditCustomGammaTableState(); 0320 0321 QWidget *createScannerParams(); 0322 ScanParamsPage *createTab(QTabWidget *tw, const QString &title, const char *name = nullptr); 0323 0324 void applyRect(const QRect &rect); 0325 void setMaximalScanSize(); 0326 0327 bool getGammaTableFrom(const QByteArray &opt, KGammaTable *gt); 0328 bool setGammaTableTo(const QByteArray &opt, const KGammaTable *gt); 0329 0330 KScanDevice *mSaneDevice; 0331 KScanOption *mVirtualFile; 0332 0333 QPushButton *mGammaEditButt; 0334 QProgressDialog *mProgressDialog; 0335 KLed *mLed; 0336 0337 // AdfBehaviour adf; 0338 ScanParams::ScanMode mScanMode; 0339 ScanSizeSelector *mAreaSelect; 0340 0341 KScanOption *mResolutionBind; 0342 KScanOption *mSourceSelect; 0343 0344 KMessageWidget *mProblemMessage; 0345 KMessageWidget *mNoScannerMessage; 0346 }; 0347 0348 #endif // SCANPARAMS_H