summaryrefslogtreecommitdiffstats
path: root/kio/kio/kscan.h
blob: 5306156ac4d0b007fbf7d24282b8aaf6882aa410 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/* This file is part of the KDE libraries
    Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#ifndef KSCAN_H
#define KSCAN_H

#include <kdialogbase.h>
#include <kinstance.h>
#include <klibloader.h>

class TQImage;

/**
 * This is a base class for scanning dialogs. You can derive from this class
 * and implement your own dialog. An implementation is available in
 * tdegraphics/libkscan.
 *
 * Application developers that wish to add scanning support to their program
 * can use the static method @p KScanDialog::getScanDialog() to get an instance
 * of the user's preferred scanning dialog.
 *
 * Typical usage looks like this (e.g. in a slotShowScanDialog() method):
 *
 * \code
 * if ( !m_scanDialog ) {
 *     m_scanDialog = KScanDialog::getScanDialog( this, "scandialog" );
 *     if ( !m_scanDialog ) // no scanning support installed?
 *         return;
 *
 *     connect( m_scanDialog, TQT_SIGNAL( finalImage( const TQImage&, int )),
 *              TQT_SLOT( slotScanned( const TQImage&, int ) ));
 * }
 *
 * if ( m_scanDialog->setup() ) // only if scanner configured/available
 *     m_scanDialog->show();
 * \endcode
 *
 * This will create and show a non-modal scanning dialog. Connect to more
 * signals if you like.
 *
 * If you implement an own scan-dialog, you also have to implement a
 * KScanDialogFactory.
 *
 * @short A baseclass and accessor for Scanning Dialogs
 * @author Carsten Pfeiffer <pfeiffer@kde.org>
 */
class KIO_EXPORT KScanDialog : public KDialogBase
{
    Q_OBJECT

public:
    /**
     * Creates the user's preferred scanning dialog and returns it,
     * or 0L if no scan-support
     * is available. Pass a suitable @p parent widget, if you like. If you
     * don't you have to 'delete' the returned pointer yourself.
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     * @param modal if true the dialog is model
     * @return the KScanDialog, or 0 if the function failed
     */
    static KScanDialog * getScanDialog( TQWidget *parent=0L,
					const char *name=0, bool modal=false );
    /**
     * Destructs the scan dialog.
     */
    ~KScanDialog();

    /**
     * Reimplement this if you need to set up some things, before showing the
     * dialog, e.g. to ask the user for the scanner device to use. If you
     * return false (e.g. there is no device available or the user aborted
     * device selection), the dialog will not be shown.
     *
     * @return true by default.
     */
    virtual bool setup();

protected:
    /**
     * Constructs the scan dialog. If you implement an own dialog, you can
     * customize it with the usual KDialogBase flags.
     *
     * @param dialogFace the KDialogBase::DialogType
     * @param buttonMask a ORed mask of all buttons (see
     * KDialogBase::ButtonCode)
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     * @param modal if true the dialog is model
     * @see KDialogBase
     */
    KScanDialog( int dialogFace=Tabbed, int buttonMask = Close|Help,
		 TQWidget *parent=0L, const char *name=0, bool modal=false );

    /**
     * Returns the current id for an image. You can use that in your subclass
     * for the signals. The id is used in the signals to let people know
     * which preview and which text-recognition belongs to which scan.
     *
     * @return the current id for the image
     * @see nextId
     * @see finalImage
     * @see preview
     * @see textRecognized
     */
    int id() const { return m_currentId; }

    /**
     * Returns the id for the next image. You can use that in your subclass
     * for the signals.
     *
     * @return the id for the next image
     * @see id
     * @see finalImage
     * @see preview
     * @see textRecognized
     *
     */
    int nextId() { return ++m_currentId; }

signals:
    /**
     * Informs you that an image has been previewed.
     * @param img the image
     * @param id the image's id
     */
    void preview( const TQImage &img, int id );

    /**
     * Informs you that an image has scanned. @p id is the same as in the
     * @p preview() signal, if this image had been previewed before.
     *
     * Note, that those id's may not be properly implemented in the current
     * libkscan.
     * @param img the image
     * @param id the image's id
     */
    void finalImage( const TQImage &img, int id );

    /**
     * Informs you that the image with the id @p id has been run through
     * text-recognition. The text is in the TQString parameter. In the future,
     * a compound document, using rich text will be used instead.
     *
     * @param text the text that has been recognized
     * @param id the id of the image
     */
    void textRecognized( const TQString &text, int id );

private:
    int m_currentId;

protected:
    virtual void virtual_hook( int id, void* data );
private:
    class KScanDialogPrivate;
    KScanDialogPrivate *d;
};


/**
 * A factory for creating a KScanDialog. You need to reimplement
 * createDialog().
 * @short Factory for creating KScanDialogs
 */
class KIO_EXPORT KScanDialogFactory : public KLibFactory
{
public:
    virtual ~KScanDialogFactory();

    /**
     * Your library should reimplement this method to return your KScanDialog
     * derived dialog.
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     * @param modal if true the dialog is model
     */
    virtual KScanDialog * createDialog( TQWidget *parent=0, const char *name=0,
					bool modal=false ) = 0;

protected:
    /**
     * Creates a new KScanDialogFactory.
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     */
    KScanDialogFactory( TQObject *parent=0, const char *name=0 );

    virtual TQObject* createObject( TQObject* parent = 0, const char* name = 0,
                                   const char* classname = TQOBJECT_OBJECT_NAME_STRING,
                                   const TQStringList &args = TQStringList() );


    /**
     * Creates a new instance with the given name.
     * @param instanceName the name of the instance
     */
    void setName( const TQCString& instanceName ) {
	delete m_instance;
	m_instance = new KInstance( instanceName );
    }

    /**
     * Returns the instance.
     * @return the KInstance
     */
    KInstance *instance() const { return m_instance; }

private:
    KInstance *m_instance;
protected:
    virtual void virtual_hook( int id, void* data );
private:
    class KScanDialogFactoryPrivate* d;
};

/**
 * Base class for OCR Dialogs.
 */
class KIO_EXPORT KOCRDialog : public KDialogBase
{
    Q_OBJECT

public:
    /**
     * Creates the user's preferred OCR dialog and returns it,
     * or 0L if no OCR-support
     * is available. Pass a suitable @p parent widget, if you like. If you
     * don't you have to 'delete' the returned pointer yourself.
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     * @param modal if true the dialog is model
     * @return the KOCRDialog, or 0 if the function failed
     */
    static KOCRDialog * getOCRDialog( TQWidget *parent=0L,
					const char *name=0, bool modal=false );
    ~KOCRDialog();

protected:
    /**
     * Constructs the OCR dialog. If you implement an own dialog, you can
     * customize it with the usual KDialogBase flags.
     *
     * @param dialogFace the KDialogBase::DialogType
     * @param buttonMask a ORed mask of all buttons (see
     * KDialogBase::ButtonCode)
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     * @param modal if true the dialog is model
     */
    KOCRDialog( int dialogFace=Tabbed, int buttonMask = Close|Help,
		 TQWidget *parent=0L, const char *name=0, bool modal=false );

    /**
     * Returns the current id for an image. You can use that in your subclass
     * for the signals. The id is used in the signals to let people know
     * which text-recognition belongs to which scan.
     *
     * @return the current id for the image
     * @see nextId
     * @see textRecognized
     */
    int id() const { return m_currentId; }

    /**
     * Returns the id for the next image. You can use that in your subclass
     * for the signals.
     *
     * @return the id for the next image
     * @see id
     * @see textRecognized
     */
    int nextId() { return ++m_currentId; }

signals:
    /**
     * Informs you that the image with the id @p id has been run through
     * text-recognition. The text is in the TQString parameter. In the future,
     * a compound document, using rich text will be used instead.
     *
     * @param text the text that has been recognized
     * @param id the id of the image
     */
    void textRecognized( const TQString &text, int id );

private:
    int m_currentId;

protected:
    virtual void virtual_hook( int id, void* data );
private:
    class KOCRDialogPrivate;
    KOCRDialogPrivate *d;
};


/**
 * A factory for creating a KOCRDialog. You need to reimplement
 * createDialog().
 * @short Factory for creating KScanDialogs
 */
class KIO_EXPORT KOCRDialogFactory : public KLibFactory
{
public:
    virtual ~KOCRDialogFactory();

    /**
     * Your library should reimplement this method to return your KOCRDialog
     * derived dialog.
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     * @param modal if true the dialog is model
     */
    virtual KOCRDialog * createDialog( TQWidget *parent=0, const char *name=0,
					bool modal=false ) = 0;

protected:
    /**
     * Creates a new KScanDialogFactory.
     * @param parent the QWidget's parent, or 0
     * @param name the name of the TQObject, can be 0
     */
    KOCRDialogFactory( TQObject *parent=0, const char *name=0 );

    virtual TQObject* createObject( TQObject* parent = 0, const char* name = 0,
                                   const char* className = TQOBJECT_OBJECT_NAME_STRING,
                                   const TQStringList &args = TQStringList() );


    /**
     * Creates a new instance with the given name.
     * @param instanceName the name of the instance
     */
    void setName( const TQCString& instanceName ) {
	delete m_instance;
	m_instance = new KInstance( instanceName );
    }

    /**
     * Returns the instance.
     * @return the KInstance
     */
    KInstance *instance() const { return m_instance; }

private:
    KInstance *m_instance;
protected:
    virtual void virtual_hook( int id, void* data );
private:
    class KOCRDialogFactory* d;
};


#endif // KSCAN_H