-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnsrreadercore.h
411 lines (351 loc) · 9.58 KB
/
nsrreadercore.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
#ifndef __NSRREADERCORE_H__
#define __NSRREADERCORE_H__
/**
* @file nsrreadercore.h
* @author Alexander Saprykin
* @brief Rendering engine API
*/
#include "interfaces/insrsettings.h"
#include "interfaces/insrthumbnailer.h"
#include "nsrabstractdocument.h"
#include "nsrrenderthread.h"
#include "nsrrenderrequest.h"
#include "nsrpagescache.h"
#include "nsrcroppadscache.h"
#include "nsrsession.h"
#include "nsrtocentry.h"
#include "nsrreadercore_global.h"
#include <QObject.h>
/**
* @class NSRReaderCore nsrreadercore.h
* @brief Main render class
*/
class NSRREADERCORE_SHARED NSRReaderCore: public QObject
{
Q_OBJECT
Q_ENUMS (PageLoad)
public:
/** Page load direction */
enum PageLoad {
PAGE_LOAD_PREV = 0, /**< Previous page */
PAGE_LOAD_NEXT = 1, /**< Next page */
PAGE_LOAD_CUSTOM = 2 /**< Custom page */
};
/** Rotation direction */
enum RotateDirection {
ROTATE_DIRECTION_RIGHT = 0, /**< 90 degrees cw */
ROTATE_DIRECTION_LEFT = 1 /**< 90 degrees ccw */
};
/**
* @brief Constructor with parameters
* @param settings #INSRSettings implementation.
* @param thumbnailer #INSRThumbnailer implementation.
* @param parent Parent object.
*/
NSRReaderCore (const INSRSettings * settings,
INSRThumbnailer * thumbnailer,
QObject * parent = 0);
/**
* @brief Destructor
*/
virtual ~NSRReaderCore ();
/**
* @brief Prepares engine object for destruction
*
* Stops all rendering threads and tries to minimize resources
* usage as soon as possible.
*/
void prepareForDestruction ();
/**
* @brief Checks whether engine object is preparing for
* destruction
* @return True if engine object is preparing for destruction,
* false otherwise.
*/
inline bool isDestructing () const {
return _isDestructing;
}
/**
* @brief Gets engine version
* @return Engine version.
*/
static QString getVersion ();
/**
* @brief Loads file session
* @param session Session to load.
*/
void loadSession (const NSRSession *session);
/**
* @brief Resets loaded session.
*/
void resetSession ();
/**
* @brief Checks whether session currently is loaded
* @return True is session is loaded, false otherwise.
*/
bool isSessionLoaded () const;
/**
* @brief Gets file path of loaded session
* @return File path of loaded session.
*/
QString getSessionFile () const;
/**
* @brief Reloads rendering settings
*
* Initiates page re-rendering if need.
*/
void reloadSettings ();
/**
* @brief Gets pages count
* @return Pages count if session is loaded, 0 otherwise.
*/
int getPagesCount () const;
/**
* @brief Gets last rendered page of loaded session
* @return Last rendered page of loaded session.
*/
NSRRenderedPage getCurrentPage () const;
/**
* @brief Navigates to selected page
* @param dir Page load direction.
* @param pageNumber Page number if need.
*/
void navigateToPage (PageLoad dir, int pageNumber = 0);
/**
* @brief Checks whether page is currently rendering
* @return True if page is rendering, false otherwise.
*/
bool isPageRendering () const;
/**
* @brief Sets device screen width
* @param width Screen width, in px.
*/
void setScreenWidth (int width);
/**
* @brief Checks whether pages are rendering fitted to screen width
* @return True if pages are rendering fitted to screen width, false
* otherwise.
* @note Use setZoom() to activate fit to width.
*/
bool isFitToWidth () const;
/**
* @brief Gets zoom value
* @return Zoom value, in %.
*/
double getZoom () const;
/**
* @brief Sets zoom for current session
* @param zoom Zoom value, in %.
* @param reason Rendering reason.
*/
void setZoom (double zoom, NSRRenderRequest::NSRRenderReason reason);
/**
* @brief Gets rotation for current session
* @return Rotation for current session.
*/
NSRAbstractDocument::NSRDocumentRotation getRotation () const;
/**
* @brief Rotates pages for current session
* @param dir Rotation direction.
*/
void rotate (RotateDirection dir);
/**
* @brief Saves current page scrolling positions
* @param pos Image position.
* @param textPos Text view position.
*/
void saveCurrentPagePositions (const QPointF& pos,
const QPointF& textPos);
/**
* @brief Checks whether text reflow is enabled
* @return True if text reflow is enabled, false otherwise.
*/
bool isTextReflow () const;
/**
* @brief Checks whether text reflow is supported for current
* session
* @return True if text reflow is supported, false otherwise.
*/
bool isTextReflowSwitchSupported () const;
/**
* @brief Switches text reflow for current session
*/
void switchTextReflow ();
/**
* @brief Checks whether file is password protected
* @param file Path to file.
* @return True if file is password protected, false
* otherwise.
*/
bool isPasswordProtected (const QString& file) const;
/**
* @brief Checks whether current session has inverted colors
* @return True if session has inverted colors, false otherwise.
*/
bool isInvertedColors () const;
/**
* @brief Switches inverted colors for current session
*/
void switchInvertedColors ();
/**
* @brief Gets pages limit engine can load
* @return Pages limit engine can load.
*
* It defines maximum page number engine can load. It is useful
* for evaluation version.
*/
inline int getPagesLimit () const {
return _pagesLimit;
}
/**
* @brief Sets pages limit engine can load
* @param limit Pages limit engine can load.
*/
inline void setPagesLimit (int limit) {
_pagesLimit = limit;
}
/**
* @brief Gets pages cache size
* @return Pages cache size, bytes.
* @since 1.4.3
*/
qint64 getCacheSize () const;
/**
* @brief Sets pages cache size
* @param cacheSize Pages cache size, bytes.
* @since 1.4.3
*/
void setCacheSize (qint64 cacheSize);
/**
* @brief Gets file TOC if any
* @return TOC in case of success, NULL otherwise.
* @since 1.5.2
*
* Caller takes ownership of the returned object.
*/
NSRTocEntry * getToc () const;
Q_SIGNALS:
/**
* @brief Page rendered
* @param number Page number.
*/
void pageRendered (int number);
/**
* @brief Session thumbnail rendered
*/
void thumbnailRendered ();
/**
* @brief Possible long async action is performing
* @param enabled Whether to show indicator for UI.
*/
void needIndicator (bool enabled);
/**
* @brief Error while opening file
* @param error Error.
*/
void errorWhileOpening (NSRAbstractDocument::NSRDocumentError error);
/**
* @brief Session file opened
* @param file Path to file.
*/
void sessionFileOpened (const QString& file);
/**
* @brief Session file closed
* @param file Path to file.
*/
void sessionFileClosed (const QString& file);
/**
* @brief Engine detected attempt to pass pages limit
*/
void pagesLimitPassed ();
private Q_SLOTS:
/**
* @brief On page rendering finished
*/
void onRenderDone ();
/**
* @brief On page zooming finished
*/
void onZoomRenderDone ();
/**
* @brief On page preloading finished
*/
void onPreloadRenderDone ();
/**
* @brief On zoom thread finished
*/
void onZoomThreadFinished ();
/**
* @brief On preload thread finished
*/
void onPreloadThreadFinished ();
private:
/**
* @brief Opens session file
* @param path Path to file.
* @param password File password (if any).
*/
void openFile (const QString &path, const QString& password = QString ());
/**
* @brief Closes file of current session
*/
void closeFile ();
/**
* @brief Checks whether session file is opened
* @return True if session file is opened, false otherwise.
*/
bool isFileOpened () const;
/**
* @brief Loads page.
* @param dir Loading direction.
* @param reason Rendering reason.
* @param page Page number (if need), from 1.
*/
void loadPage (PageLoad dir,
NSRRenderRequest::NSRRenderReason reason,
int page = 0);
/**
* @brief Copies file handler
* @param doc File handler to copy.
* @return Copy of the given file handler in case of success,
* NULL otherwise.
*/
NSRAbstractDocument * copyFileHandler (const NSRAbstractDocument *doc);
/**
* @brief Creates file handler by path
* @param path Path to file.
* @param passwd File password if any.
* @return New file handler in case of success, NULL otherwise.
*/
NSRAbstractDocument * fileHandlerByPath (const QString& path, const QString& passwd = QString ()) const;
/**
* @brief Checks whether rendered page is still relevant
* @param page Rendered page.
* @return True if rendered page is relevant, false otherwise.
*/
bool isPageRelevant (const NSRRenderedPage& page) const;
/**
* @brief Preloads pages from current one into cache
*/
void preloadPages ();
/**
* @brief Requests thumbnail rendering for current session
*/
void requestThumbnail ();
const INSRSettings * _settings; /**< Rendering settings */
INSRThumbnailer * _thumbnailer; /**< Thumbnailer */
NSRAbstractDocument * _doc; /**< Main file handler */
NSRAbstractDocument * _zoomDoc; /**< Zoom handler */
NSRAbstractDocument * _preloadDoc; /**< Preload handler */
NSRRenderThread * _thread; /**< Main render thread */
NSRRenderThread * _zoomThread; /**< Zoom render thread */
NSRRenderThread * _preloadThread; /**< Preload render thread */
NSRPagesCache * _cache; /**< Pages cache */
NSRCropPadsCache * _cropPadsCache; /**< Page crop pads cache */
NSRRenderedPage _currentPage; /**< Last rendered page */
NSRRenderRequest _renderRequest; /**< Session rendering request */
int _pagesLimit; /**< Pages limit */
int _screenWidth; /**< Device screen width */
bool _isDestructing; /**< Destructing flag */
};
#endif /* __NSRREADERCORE_H__ */