-
Notifications
You must be signed in to change notification settings - Fork 15
/
mainwidget.h
416 lines (313 loc) · 13 KB
/
mainwidget.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
/*
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 __mainwidget_h
#define __mainwidget_h
class QTimer;
class QPrinter;
class QPrintDialog;
class QScanDialog;
class QScanner;
class Desktopmodel;
class Desktopview;
class Desktopwidget;
class Desk;
class Filepage;
class Mainwindow;
class Options;
class PPage;
class Pagewidget;
class Paperscan;
class Paperstack;
class PreviewWidget;
class Printopt;
class Pscan;
typedef struct file_info file_info;
struct err_info;
struct print_info;
#include <QModelIndex>
#include <QStackedWidget>
#include "desk.h"
#include "qwidget.h"
#include "options.h"
extern "C"
{
#include <sane/sane.h>
}
/**
* @brief Main widget
* This can display either:
* - the desktop view _desktop, with folders, stacks and preview, or
* - the page view _page, with just a single stack
*
* The swapDesktop() method switches between the two, trigger by Mainwindow,
* the parent widget, which has an actionSwap icon
*/
class Mainwidget : public QStackedWidget
{
Q_OBJECT
public:
Mainwidget (QWidget *parent, const char *name = 0);
~Mainwidget();
Desktopwidget *getDesktop (void) { return _desktop; }
Pagewidget *getPage (void) { return _page; }
Mainwindow *getMainwindow() { return _mainwindow; }
//p Desktopviewer *getViewer (void) { return _viewer; }
/** set the current operation name */
// void progress (const char *fmt, ...);
/** sets the displayed size of the scanned file so far */
void progressSize (int size);
/** set the current information text */
void info (const QString &str);
enum t_arrangeBy
{
byPosition, byName, byDate
};
// bool selectedFile (Desk * &maxdesk, file_info * &file);
struct err_info *operation (Desk::operation_t type, int ival);
// called when the main window is closing, to save window settings
void closing (void);
/**
* @brief Find folders in the current repo which match a text string
* @param text Text to match
* @param dirPath Returns the path to the root directory
* @param missing Suggestions for directories to create
* @return list of matching paths
*
* This looks for 4-digit years and 3-character months to try to guess
* which folders to put at the top of the list
*/
QStringList findFolders(const QString &text, QString& dirPath,
QStringList& missing);
/* Start a new scan using dir_ind as the destination dir in Dirmodel */
void scanInto(QModelIndex dir_ind);
//! Convert a directory path to a _model index
QModelIndex getDirIndex(const QString& dir_path);
/**
* @brief Create a new diorectory
* @param dir_path Full path of the directory to select
* @param ind Returns Dirmodel index of the created directory
* @return true if done, else false
*/
bool newDir(const QString& dir_path, QModelIndex& ind);
/**
* @brief Select a directory as the current one
* @param dir_path Full path of the directory to select
*
* The directory is selected and shown in the Dirview
*/
void selectDir(const QString& dir_path);
// Returns true if currently scanning
bool isScanning();
void setMainwindow(Mainwindow *mainwindow);
// Report an error to the user
bool complain(err_info *err);
static Mainwidget *singleton();
signals:
void newContents (QString);
//* new configuration (may affect UI settings)
void newConfig ();
public slots:
/** bring up a print dialogue and allow the user to print stacks / pages */
void print (void);
/** options have changed (e.g. some have gone) so reload them */
void slotReloadOptions(void);
/** option value has changed */
void slotSetOption(int num);
void showPage (const QModelIndex &index, bool delay_smoothing = true);
/** move left a page in the current stack */
void pageLeft (void);
/** move right a page in the current stack */
void pageRight (void);
/** move left a stack in the current stack */
void stackLeft (void);
/** move right a stack in the current stack */
void stackRight (void);
/** switch between desktop and page view */
void showDesktop ();
/** swap between desktop and page view */
void swapDesktop ();
/** scan a page or group of pages into the current directory */
void scan (void);
/** stop the scan in progress
\param cancel true to cancel the scan now (else just stops
after current page) */
void stopScan (bool cancel);
/** scan a page or group of pages under control of the pscan dialogue */
void pscan (void);
/** update buttons on the pscan dialogue */
void updatePscan (void);
/** open the options dialogue */
void options (void);
/** allow the user to select a scanner to use */
void selectScanner (void);
/** allow the user to change the scanner settings */
void scannerSettings (void);
/** ensures there is a current scanner - returns false on failure, true if ok */
bool ensureScanner (void);
/** select all items in current directory */
void selectAll (void);
/** arrange items by given type (t_arrangeBy...) */
void arrangeBy (t_arrangeBy type);
/** resize all the items in this directory */
void resizeAll ();
void rotate (int degrees);
void flip (bool horiz);
/** set whether a smooth (but slow) scaling algorithm is used */
void setSmoothing (bool smooth);
/** returns true if smoothing should be used */
bool isSmoothing (void);
/** save scanner device settings */
void saveSettings (void);
/** check the buttons on the scanner */
void checkButtons (void);
private slots:
void scanDialogClosed (void);
//! called when pending changes to the ScanDialog are complete (these happen while scanning)
void slotPendingDone (void);
void savePrintSettings (void);
void openPrintopt (void);
/** handle a new stack being started. We add it to the model with the
given name (or a default one if this is blank. From now on we expect
to get pages until the stack is complete.
\param stackName suggested stack name*/
void slotStackNew (const QString &stack_name);
/** handle the completion of scanning
\param status Sane status - will be reported if there is an error
\param msg a final message to display
\param err an error to display (normally NULL) */
void slotScanComplete (SANE_Status status, const QString &msg, const err_info *err);
/** handle a new page signal. We add the page to maxdesk and update the
display with the information given.
\param mp the new page in compressed form ready for maxdesk
\param coverageStr the page coverage
\param infoStr information about the page for the user (e.g. coverage) */
void slotStackNewPage (const Filepage *mp, const QString &coverageStr,
const QString &infoStr);
/** handle a signal that the stack is now confirmed. We tell the model
to confirm the stack */
void slotStackConfirm (void);
/** handle a signal that the stack is cancelled and should be deleted. We
pass this message on to the model */
void slotStackCancel (void);
void progress (const QString &str);
/** set the target total for the progress bar
\param total total number of bytes expected from scan
\param page the page being started */
void slotStackPageStarting (int total, const PPage *page);
/** set the current progress value
\param page the page in progress */
void slotStackPageProgress (const PPage *page);
void slotWarning (QString &str);
private:
/** print a page if it is in range
\param seq The page number of this page within the whole print job
(0 = first)
\param ind Model index of stack to print from
\param pnum Page within stack (0 = first)
\param numpages Number of pages in stack */
err_info *printPage (int seq, QModelIndex &ind, int pnum, int numpages);
//! setup the scan dialog and our _preview pointer
void setupScanDialog (void);
/** update any fields required in the scan dialog, based on config changes */
void updateScanDialog (void);
/** add a new image to the current stack */
void newImage (char *buf, int size);
/** draw some text with a background
The text is drawn either on the left, right or centre of the very
bottom of the printable area. This position is the first line,
where linenum = 0. The second line of text (linenum=1) is immediately
above this line.
The background and text colours are set by _opt->fillColour and
_opt->textColour
This function supports printing the text in two parts, with the first
being in shown in bold font.
\param flags alignment flags: Qt::AlignLeft, Qt::AlignRight, Qt::AlignHCenter
\param text text to draw
\param linenum line number to put text on (normally 0 for the first line)
\param do_bold text consists of two lines separated by \n. The first should be drawn
in bold followed by ": ", then the second immediately after it on the
same line */
void drawTextOnWhite (int flags, QString text, int linenun = 0, bool do_bold = false);
/** ensure that we have a current stack, creating a new one if necessary
\param stack_name name of stack to create
\param page_name name of page to create
\param parameters current sane parameters */
err_info *ensureStack (QString &stack_name, QString &page_name,
SANE_Parameters ¶meters);
/** connect up the scanner signals */
void connectScanner (void);
/**
* @brief Search for directories matching a string
* @param matches List of matches to update
* @param baseLen Number of characters to omit at the start of each match
* @param dirPath Directory to scan
* @param match String to match
* @param op Operation, to show progress
*
* Adds dirPath if it matches the match string, then scans directories within
* dirPath recursively.
*/
void addMatches(QStringList& matches, uint baseLen, const QString &dirPath,
const QString &match, Operation *op);
// Holds the Mainwidget
static Mainwidget *_singleton;
private:
Desktopwidget *_desktop;
Pagewidget *_page;
Desktopmodel *_contents; //!< the model for the desktop items
Desktopview *_view;
/** the current scanner being used, 0 if none */
QScanner *_scanner;
/** the current scan dialogue */
QScanDialog *_scanDialog;
/** the current pscan dialogue */
Pscan *_pscan;
/** the current options dialogue */
Options *_options;
PreviewWidget *_preview;
/** number of bytes we expect to receive for the page being scanned */
int _progressTotal;
bool _smooth; //!< sets whether smooth scaling is used or not
QTimer *_buttonTimer; //!< timer to control checking scanner buttons
bool _watchButtons; //!< true to watch buttons
//! information about a print job in progress
Printopt *_opt; //!< our print options dialogue
QModelIndexList *_list; //!< list of stacks to print
QPrinter *_printer; //!< our printer
QPrintDialog *_dialog; //!< the printer dialog (to which we add Printopt)
bool _saved; //!< true if settings were saved
int _from_page; //!< from page to print
int _to_page; //!< to page to print
bool _new_page; //!< true if we need to call newPage() before starting
QRect _body; //!< bounding rectangle for images
QRect _printable; //!< printable area of the page
QPainter *_painter; //!< our painter
int _pagecount; //!< total number of pages being printed
bool _reverse; //!< printing pages in reverse order
//! information about a scanning job in progress
bool _scanning; //!< true if scanning
bool _scan_cancelling; //!< true if cancelling the scan
// Paperstack *_stack; //!< paper stack to scan into
Paperscan *_scan; //!< the current scan in progress
Mainwindow *_mainwindow;
};
#endif