-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpagewidget.h
442 lines (327 loc) · 14.5 KB
/
pagewidget.h
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
/*
License: GPL-2
An electronic filing cabinet: scan, print, stack, arrange
Copyright (C) 2009 Simon Glass, [email protected]
.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
.
This program 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 General Public License for more details.
.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
X-Comment: On Debian GNU/Linux systems, the complete text of the GNU General
Public License can be found in the /usr/share/common-licenses/GPL file.
*/
#ifndef __pagewidget_h
#define __pagewidget_h
#include <QAbstractScrollArea>
#include <QModelIndex>
#include <QScrollArea>
#include <QStackedWidget>
class QAbstractModelIndex;
class QImage;
class QPixmap;
class QSplitter;
class QTextEdit;
class QTimer;
class QToolButton;
class QWidget;
class Ui_Ocrbar;
class Ui_Pageattr;
class Desktopmodelconv;
class Desk;
class Mainwidget;
class Pagedelegate;
class Pagetools;
class Pagemodel;
class Pageview;
struct file_info;
#include "qgraphicsview.h"
#include "desk.h"
struct err_info;
/* this class manages a scrolling page image. It supports scaling by holding ctrl and moving the wheel */
class MyScrollArea : public QAbstractScrollArea
{
Q_OBJECT
public:
/** constructor
\param parent the parent widget into which this draws */
MyScrollArea (QWidget *parent);
//! destructor
~MyScrollArea ();
/** set the scale of the image
\param scale the scale to set (1.0 is normal) */
void setScale (double scale);
/** set the pixmap or image to display
\param pixmap the pixmap to display
\param image the image to display (if the pixmap is too big)
\param too_big true to display the image instead of the pixmap */
void setPixmapImage (QPixmap &pixmap, QImage &image, bool too_big, int rotate);
/** set the size of the pixmap, used to set up the scrollbars correctly
\param size the pixmap size */
void setSize (QSize &size);
signals:
/* signal emitted when the user changes the scale */
void signalNewScale (double scale, bool delay_smoothing);
/* signal emitted when we paint something */
void signalPainting ();
protected:
/** called to paint the window
\param event info about paint required, including clip area */
void paintEvent (QPaintEvent * event);
/** returns the size of the pixmap being displayed, used by QT to size the widget
\returns the pixmap size */
QSize sizeHint () const;
/** handle a mouse wheel event - we use this to scroll
\param e the mouse wheel event */
void wheelEvent (QWheelEvent *e);
void mousePressEvent ( QMouseEvent * e );
void mouseMoveEvent ( QMouseEvent * e );
private:
double _scale; //!< scale of the image
QPixmap _pixmap; //!< current pixmap being displayed
QImage _image; //!< current image being displayed, for when the pixmap is too big
QSize _size; //!< size of current pixmap
bool _too_big; //!< true if the scaling is too big to use a pixmap
QPoint _scroll_origin; //!< scroll origin
QPoint _mouse_origin; //!< scroll origin
int _rotate; //!< rotation amount: 0, 90, 180, 270
};
class Pagewidget : public QWidget
{
Q_OBJECT
public:
/** which mode the viewer is in */
enum e_mode
{
Mode_select, //!< allows selection of items
Mode_move, //!< allows selection and reordering
Mode_scan, //!< allows viewing of scanning as it happens
Mode_info, //!< display stack information
Mode_none //!< mode not set
};
/** create a new page widget
\param modelconv conversion class for changing from proxy to source models
\param base base string for settings, e.g. "desktopwidget/"
\param parent parent widget */
Pagewidget (Desktopmodelconv *modelconv, QString base, QWidget *parent = 0);
~Pagewidget ();
/** init the widget - must be called immediately after creation */
void init (void);
/** convert a mode to a tool button */
QToolButton *modeToTool (e_mode mode);
/** convert a tool button to a mode */
e_mode toolToMode (QObject *tb);
/** display a page from a maxdesk. This function checks the current page in f.
\param model the model containing the file (maybe a proxy)
\param index the file index (the current page number will be shown)
\param delay_smoothing delay smoothing to allow the user to perform another action first */
// void showPage (const QAbstractItemModel *model, const QModelIndex &index,
// bool delay_smoothing = false);
/** display a set of pages from a maxdesk.
\param model the model containing the file (maybe a proxy)
\param index the file index
\param start start page (0 for first)
\param count number of pages (-1 for all)
\param across how many to show across (normally 1 or 2) */
void showPages (const QAbstractItemModel *model, const QModelIndex &index,
int start, int count, int across, bool reset = false);
void pageLeft (void);
void pageRight (void);
/** returns the index of the page currently being displayed
\param index returns the index
\param source true to return a source index, else returns whatever
model is in use (maybe a proxy) */
bool getCurrentIndex (QModelIndex &index, bool source = false);
int getCurrentPage () { return _pagenum; }
void checkSubsystem (int subsystem);
//! returns true if the page area is visible (and therefore needs redrawing)
bool isVisible (void);
enum
{
SUBSYS_pixmap, // use pixmaps am MyScrollArea
SUBSYS_gview, // use QGraphicsView
SUBSYS_opengl, // use OpenGL
};
struct err_info *operation (Desk::operation_t type, int ival);
/** redisplay the current page - can be used if the smoothing setting
has been changed, for example */
void redisplay (void);
/** set whether we are smoothing or not
\param smooth true to smooth the image */
void setSmoothing (bool smooth);
/** called when the widget is closing to save window settings */
void closing (void);
signals:
void newContents (QString);
/** indicate that the mode is changing - this allows the parent window
to save and adjust its window sizes if it wants to */
void modeChanging (int new_mode, int old_mode);
public slots:
/***************************** scanning ***************************/
/** indicates that a scan is beginning into the given stack.
This signal comes from Desktopmodel via a connect() in Desktopwidget */
void beginningScan (const QModelIndex &ind);
/** indicates that scanning into the current stack is ending
\param cancel true if the scan was cancelled, and the stack will be
deleted */
void endingScan (bool cancel);
/** indicate that a scan is complete */
void scanComplete (void);
/** handle a new page being scanned. We update our page model and store
the coverage information
This signal comes from Desktopmodel via a connect() in Desktopwidget
\param coverageStr page coverage string
\param blank true if page is marked blank */
void slotNewScannedPage (const QString &coverageStr, bool blank);
/******************************************************************/
/** handle an item being clicked
\param index item clicked
\param which which part of it was clicked (e_point) */
void slotItemClicked (const QModelIndex &index, int which);
/** show information about a page in the status bar */
void slotShowInfo (const QModelIndex &index);
/** reset the view and model so no pages are shown. Also existing page
will be committed */
void slotReset (void);
/** handle a message that the current scan stack is being committed */
void slotCommitScanStack (void);
protected:
/** update the viewport to allow a change of page or scale
\param update_scale the scale has changed, or the pixmap needs regeneration for some other reason
\param force_smoothing force smoothing regardless of the setting
\param delay_smoothing rather than setting a timer to smooth immediately after this this call,
delay it for 300ms */
void updateViewport (bool update_scale = false, bool force_smoothing = false, bool delay_smoothing = false);
/** clear the viewport so that it shows no image */
void clearViewport (void);
/** sets the page size to use for the page images. The grid size is set
to slightly larger than this also
\param size max size of each page image */
void setPagesize (QSize size);
/** revert to the mode we were in before we started scanning */
void revertMode (void);
/** change the view mode of the widget */
void setMode (e_mode mode);
/** toggle the remove flag on a page */
void toggleRemove (const QModelIndex &index);
/** commit any changes to the current stack */
void commit (void);
protected slots:
void slotNewScale (double scale, bool delay_smoothing);
void updateWindow (void);
void slotDelayedUpdate (void);
void slotZoomFit (void);
void slotZoomOrig (void);
void slotZoomIn (void);
void slotZoomOut (void);
void slotZoom (void);
void slotNewScale (int new_scale);
/** display a new page in the preview window */
void slotPreviewPage (const QModelIndex &ind);
/** called when there is a new scaled image for the page currently being
scanned
\param image image fragment
\param scaled_linenum destination start line for this fragment */
void slotNewScaledImage (const QImage &image, int scaled_linenum);
/** called when we are beginning to scan a new page. We display it and
monitor progress with calls we receive to slotNewScaledImage() */
void slotBeginningPage (void);
/** save changes to a paper stack */
void slotSave (void);
/** revert paper stack to original state */
void slotRevert (void);
/** handle a stack being changed - if it is the one we are previewing then
we need to update our view
\param from start index of stack that changed
\param to end index of stack that changed */
void slotStackChanged (const QModelIndex &from, const QModelIndex &to);
/** slot to change mode according to the sender tool button */
void slotChangeMode (bool selected);
/** slot to handle annotation text being changed. We mark the stack as
modified */
void slotAnnotChanged (void);
/** flip between horizontal and vertical view for OCR */
void ocrFlipView (void);
/** run ocr on a page. This produces some text */
void ocrPage (void);
/** clear the ocr text */
void ocrClear (void);
/** copy the ocr test to the clipboard */
void ocrCopy (void);
/** add an amount to the rotation of the current page
\param add amount to add (-90, 90, 180) */
void addRotate (int add);
/** rotate the current page image right 90 degrees */
void slotRotateRight (void);
/** rotate the current page image 180 degrees */
void slotRotate180 (void);
/** rotate the current page image left 90 degrees */
void slotRotateLeft (void);
public:
QAction *_returnToDesktop;
private:
/** update the 'enabled' status of the toolbar icons */
void updatePagetools (void);
/** update the annotation text editor with text from the stack */
void updateAttr (void);
/** update the ocr text editor with text from the current page */
void updateOcrText (void);
private:
QScrollArea *_page;
const QAbstractItemModel *_model; // model containing the stacks
QPersistentModelIndex _index; // index of current stack displayed
/* struct Desk *_desk;
struct file_info *_file;*/
QPixmap _pixmap;
QImage _image;
int _pagenum; //!< current page number being displayed
int _start; //!< start page to show
int _count; //!< number of pages to shoe
bool _smoothing; //!< true to display with smoothing
double _scale; //!< display scale
// QGraphicsScene *_scene;
// QGraphicsPixmapItem *_pitem;
// QGraphicsView *_view;
MyScrollArea *_area;
int _subsys; // display subsystem to use
bool _too_big; //!< true if the scaling is too big to use a pixmap
/** timer used to handle updates */
QTimer *_timer;
/** true if a delayed update is set - we will update when the page is visible on screen */
bool _delayed_update;
/** delayed value for update_scale */
bool _delayed_update_scale;
/** delayed value for force_smooth */
bool _delayed_force_smooth;
/** size to use for pixmap */
//QSize _pixmap_size;
Pagetools *_tools; //!< the toolbar
Desktopmodelconv *_modelconv; //!< the model converter
Pageview *_pageview; //!< page viewer
Pagemodel *_pagemodel; //!< page model
Pagedelegate *_pagedelegate; //!< page delegate
int _scale_down; //!< scale down to use 1/n
int _rotate; //!< clockwise rotation amount in degrees (0, 90, 180, 270)
QStackedWidget *_stack; //!< the stack widget which holds the splitter and text details
QSplitter *_splitter; //!< the splitter between page selector and preview
QFrame *_textframe; //!< frame containing text information
e_mode _mode; //!< which mode we are in (selection or move)
QString _settings_base; //!< base string for saving window settings
bool _modified; //!< true if we have modified the current stack
bool _scanning; //!< are we scanning?
e_mode _prescan_mode; //!< the mode we were using before we started scanning
Ui_Pageattr *_pageattr; //!< page attribute dialogue fields
QSplitter *_ocr_split; //!< ocr / image splitter
QTextEdit *_ocr_edit; //!< OCR text editor
Ui_Ocrbar *_ocr_bar; //!< OCR toolbar
bool _committing; //!< true if currently committing a stack
};
#endif