File: pdfrendermanager.h

package info (click to toggle)
texstudio 2.11.2%2Bdebian-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 41,292 kB
  • ctags: 12,405
  • sloc: cpp: 93,072; xml: 10,217; ansic: 4,153; sh: 145; makefile: 56
file content (131 lines) | stat: -rw-r--r-- 2,596 bytes parent folder | download | duplicates (2)
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
#ifndef PDFRENDERMANAGER_H
#define PDFRENDERMANAGER_H

#include "mostQtHeaders.h"

#ifndef NO_POPPLER_PREVIEW

#include <QCache>
#include <QImage>

#include "pdfrenderengine.h"

class RecInfo
{
public:
	QObject *obj;
	const char *slot;
	int x, y, w, h;
	int pageNr;
	qreal xres;
	bool cache;
	bool priority;
};


class CachePixmap: public QPixmap
{
public:
	CachePixmap(const QPixmap &pixmap);
	CachePixmap();
	void setRes(qreal res, int x, int y);
	qreal getRes()
	{
		return resolution;
	}
	QPoint getCoord()
	{
		return QPoint(x, y);
	}

private:
	qreal resolution;
	int x, y;
};


class PDFQueue : public QObject
{
public:
	explicit PDFQueue(QObject *parent = 0);

	inline void ref()
	{
		m_ref.ref();
	}
	void deref();
	int getRef()
	{
		return m_ref.fetchAndAddRelaxed(0);;
	}

	QQueue<RenderCommand> mCommands;
	QSemaphore mCommandsAvailable;
	QMutex mQueueLock;
	bool stopped;

	QMutex mPriorityLock;

	int num_renderQueues;

	QList<PDFRenderEngine *>renderQueues;

	QByteArray documentData;

private:
#if QT_VERSION < 0x040400
	QBasicAtomic m_ref;
#else
	QAtomicInt m_ref;
#endif
};


class PDFRenderManager : public QObject
{
	Q_OBJECT

public:
	explicit PDFRenderManager(QObject *parent, int limitQueues = -1);
	~PDFRenderManager();

	static const int BufferedLoad = 0;
	static const int DirectLoad = 1;
	static const int HybridLoad = 2;
	enum Error {NoError, FileOpenFailed, PopplerError, PopplerErrorBadAlloc, PopplerErrorException, FileLocked, FileIncomplete };

	QPixmap renderToImage(int pageNr, QObject *obj, const char *rec, double xres = 72.0, double yres = 72.0, int x = -1, int y = -1, int w = -1, int h = -1, bool cache = true, bool priority = false, Poppler::Page::Rotation rotate = Poppler::Page::Rotate0);
	QSharedPointer<Poppler::Document> loadDocument(const QString &fileName, Error &error, const QString &userPasswordStr,  bool foreceLoad = false);
	void stopRendering();
	void setCacheSize(int megabyte);
	void fillCache(int pg = -1);
	qreal getResLimit();
	void setLoadStrategy(int strategy);

public slots:
	void addToCache(QImage img, int pageNr, int ticket);

private:
	friend class PDFRenderEngine;
	bool checkDuplicate(int &ticket, RecInfo &info);
	void enqueue(RenderCommand cmd, bool priority);

	void reduceCacheFilling(double fraction);

	QSharedPointer<Poppler::Document> document;
	int cachedNumPages;

	QCache<int, CachePixmap> renderedPages;
	QMultiMap<int, RecInfo> lstOfReceivers;
	int currentTicket;

	QMap<int, RecInfo> lstForThumbs;
	PDFQueue *queueAdministration;
	bool mFillCacheMode;

	int loadStrategy;
};

#endif // PDFRENDERMANAGER_H

#endif