File indexing completed on 2024-05-05 16:08:28

0001 /* This file is part of the KDE libraries
0002     Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>
0003 
0004     This library is free software; you can redistribute it and/or
0005     modify it under the terms of the GNU Library General Public
0006     License as published by the Free Software Foundation; either
0007     version 2 of the License, or (at your option) any later version.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KSCAN_H
0021 #define KSCAN_H
0022 
0023 #include <kdelibs4support_export.h>
0024 #include <kpagedialog.h>
0025 #include <QDialogButtonBox>
0026 
0027 class QByteArray;
0028 class QImage;
0029 
0030 /**
0031  * This is a base class for scanning dialogs. You can derive from this class
0032  * and implement your own dialog. An implementation is available in
0033  * kdegraphics/libkscan.
0034  *
0035  * Application developers that wish to add scanning support to their program
0036  * can use the static method @p KScanDialog::getScanDialog() to get an instance
0037  * of the user's preferred scanning dialog.
0038  *
0039  * Typical usage looks like this (e.g. in a slotShowScanDialog() method):
0040  *
0041  * \code
0042  * if ( !m_scanDialog ) {
0043  *     m_scanDialog = KScanDialog::getScanDialog( this );
0044  *     if ( !m_scanDialog ) // no scanning support installed?
0045  *         return;
0046  *
0047  *     connect( m_scanDialog, SIGNAL( finalImage( const QImage&, int )),
0048  *              SLOT( slotScanned( const QImage&, int ) ));
0049  * }
0050  *
0051  * if ( m_scanDialog->setup() ) // only if scanner configured/available
0052  *     m_scanDialog->show();
0053  * \endcode
0054  *
0055  * This will create and show a non-modal scanning dialog. Connect to more
0056  * signals if you like.
0057  *
0058  * @short A baseclass and accessor for Scanning Dialogs
0059  * @author Carsten Pfeiffer <pfeiffer@kde.org>
0060  * @deprecated since 5.0, use libksane instead
0061  */
0062 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KScanDialog : public KPageDialog
0063 {
0064     Q_OBJECT
0065 
0066 public:
0067     /**
0068      * Creates the user's preferred scanning dialog and returns it,
0069      * or 0L if no scan-support
0070      * is available. Pass a suitable @p parent widget, if you like. If you
0071      * don't you have to 'delete' the returned pointer yourself.
0072      * @param parent the QWidget's parent, or 0
0073      * @return the KScanDialog, or 0 if the function failed
0074      */
0075     static KScanDialog *getScanDialog(QWidget *parent = nullptr);
0076     /**
0077      * Destructs the scan dialog.
0078      */
0079     ~KScanDialog() override;
0080 
0081     /**
0082      * Reimplement this if you need to set up some things, before showing the
0083      * dialog, e.g. to ask the user for the scanner device to use. If you
0084      * return false (e.g. there is no device available or the user aborted
0085      * device selection), the dialog will not be shown.
0086      *
0087      * @return true by default.
0088      */
0089     virtual bool setup();
0090 
0091 protected:
0092     /**
0093      * Constructs the scan dialog. If you implement an own dialog, you can
0094      * customize it with the usual KPageDialog flags.
0095      *
0096      * @param dialogFace The KPageDialog::FaceType
0097      * @param buttonMask An ORed mask of all buttons (see
0098      * QDialogButtonBox::StandardButton)
0099      * @param parent The QWidget's parent, or 0
0100      * @see KPageDialog
0101      */
0102     KDELIBS4SUPPORT_DEPRECATED explicit KScanDialog(int dialogFace = Tabbed,
0103                          int buttonMask = QDialogButtonBox::Close | QDialogButtonBox::Help,
0104                          QWidget *parent = nullptr);
0105 
0106     /**
0107      * Returns the current id for an image. You can use that in your subclass
0108      * for the signals. The id is used in the signals to let people know
0109      * which preview and which text-recognition belongs to which scan.
0110      *
0111      * @return the current id for the image
0112      * @see nextId
0113      * @see finalImage
0114      * @see preview
0115      * @see textRecognized
0116      */
0117     int id() const;
0118 
0119     /**
0120      * Returns the id for the next image. You can use that in your subclass
0121      * for the signals.
0122      *
0123      * @return the id for the next image
0124      * @see id
0125      * @see finalImage
0126      * @see preview
0127      * @see textRecognized
0128      *
0129      */
0130     int nextId();
0131 
0132 Q_SIGNALS:
0133     /**
0134      * Informs you that an image has been previewed.
0135      * @param img the image
0136      * @param id the image's id
0137      */
0138     void preview(const QImage &img, int id);
0139 
0140     /**
0141      * Informs you that an image has scanned. @p id is the same as in the
0142      * @p preview() signal, if this image had been previewed before.
0143      *
0144      * Note, that those id's may not be properly implemented in the current
0145      * libkscan.
0146      * @param img the image
0147      * @param id the image's id
0148      */
0149     void finalImage(const QImage &img, int id);
0150 
0151     /**
0152      * Informs you that the image with the id @p id has been run through
0153      * text-recognition. The text is in the QString parameter. In the future,
0154      * a compound document, using rich text will be used instead.
0155      *
0156      * @param text the text that has been recognized
0157      * @param id the id of the image
0158      */
0159     void textRecognized(const QString &text, int id);
0160 
0161 private:
0162     class KScanDialogPrivate;
0163     KScanDialogPrivate *const d;
0164 };
0165 
0166 /**
0167  * Base class for OCR Dialogs.
0168  */
0169 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KOCRDialog : public KPageDialog
0170 {
0171     Q_OBJECT
0172 
0173 public:
0174     /**
0175      * Creates the user's preferred OCR dialog and returns it,
0176      * or 0L if no OCR-support
0177      * is available. Pass a suitable @p parent widget, if you like. If you
0178      * don't you have to 'delete' the returned pointer yourself.
0179      * @param parent the QWidget's parent, or 0
0180      * @return the KOCRDialog, or 0 if the function failed
0181      */
0182     static KOCRDialog *getOCRDialog(QWidget *parent = nullptr);
0183     ~KOCRDialog() override;
0184 
0185 protected:
0186     /**
0187      * Constructs the OCR dialog. If you implement an own dialog, you can
0188      * customize it with the usual KPageDialog flags.
0189      *
0190      * @param dialogFace the KPageDialog::FaceType
0191      * @param buttonMask a ORed mask of all buttons (see
0192      * KDialog::ButtonCode)
0193      * @param parent the QWidget's parent, or 0
0194      * @param modal if true the dialog is model
0195      */
0196     KDELIBS4SUPPORT_DEPRECATED explicit KOCRDialog(int dialogFace = Tabbed, int buttonMask = QDialogButtonBox::Close | QDialogButtonBox::Help,
0197                         QWidget *parent = nullptr, bool modal = false);
0198 
0199     /**
0200      * Returns the current id for an image. You can use that in your subclass
0201      * for the signals. The id is used in the signals to let people know
0202      * which text-recognition belongs to which scan.
0203      *
0204      * @return the current id for the image
0205      * @see nextId
0206      * @see textRecognized
0207      */
0208     int id() const;
0209 
0210     /**
0211      * Returns the id for the next image. You can use that in your subclass
0212      * for the signals.
0213      *
0214      * @return the id for the next image
0215      * @see id
0216      * @see textRecognized
0217      */
0218     int nextId();
0219 
0220 Q_SIGNALS:
0221     /**
0222      * Informs you that the image with the id @p id has been run through
0223      * text-recognition. The text is in the QString parameter. In the future,
0224      * a compound document, using rich text will be used instead.
0225      *
0226      * @param text the text that has been recognized
0227      * @param id the id of the image
0228      */
0229     void textRecognized(const QString &text, int id);
0230 
0231 private:
0232     class KOCRDialogPrivate;
0233     KOCRDialogPrivate *const d;
0234 };
0235 
0236 #endif // KSCAN_H