1 /*
2 	This is part of TeXworks, an environment for working with TeX documents
3 	Copyright (C) 2007-2010  Jonathan Kew
4 
5 	This program is free software; you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation; either version 2 of the License, or
8 	(at your option) any later version.
9 
10 	This program is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 	For links to further information, or to contact the author,
19 	see <http://texworks.org/>.
20 */
21 #ifndef Header_PDF_Docks
22 #define Header_PDF_Docks
23 
24 #ifndef NO_POPPLER_PREVIEW
25 
26 
27 #include <QDockWidget>
28 #include <QTreeWidget>
29 #include <QListWidget>
30 #include <QScrollArea>
31 #include <QDateTime>
32 
33 #if QT_VERSION_MAJOR>5
34 #include "poppler-qt6.h"
35 #else
36 #include "poppler-qt5.h"
37 #endif
38 
39 #include "pdfrendermanager.h"
40 
41 class PDFDocument;
42 class QListWidget;
43 class QTableWidget;
44 class QTreeWidgetItem;
45 
46 class MessageFrame : public QFrame
47 {
48 	Q_OBJECT
49 
50 public:
51     explicit MessageFrame(QWidget *parent = nullptr);
52 	void showText(const QString &text, QList<QAction *> actions = QList<QAction *>());
53 
54 private:
55 	QLabel *label;
56 	QList<QPushButton *> buttons;
57 };
58 
59 
60 class PDFDock : public QDockWidget
61 {
62 	Q_OBJECT
63 
64 public:
65     explicit PDFDock(PDFDocument *doc = nullptr);
66 	virtual ~PDFDock();
67 
68 	void setPage(int page);
69 
70 public slots:
71 	virtual void documentLoaded();
72 	virtual void documentClosed();
73 	virtual void pageChanged(int page);
74 
75 protected:
76 	virtual void fillInfo() = 0;
77 	virtual QString getTitle() = 0;
78 	void addAction(const QString& caption, const char* slot);
79 	using QDockWidget::addAction;
80 
81 	PDFDocument *document;
82 	bool filled;
83 
84 private slots:
85 	void myVisibilityChanged(bool visible);
86 
87 protected slots:
88 	virtual void changeLanguage();
89 };
90 
91 
92 class PDFOutlineDock : public PDFDock
93 {
94 	Q_OBJECT
95 
96 public:
97     explicit PDFOutlineDock(PDFDocument *doc = nullptr);
98 	virtual ~PDFOutlineDock();
99 
100 public slots:
101 	virtual void documentClosed();
102 
103 protected:
104 	virtual void fillInfo();
getTitle()105 	virtual QString getTitle()
106 	{
107 		return tr("Contents");
108 	}
109 
110 protected slots:
111 	virtual void changeLanguage();
112 
113 	void followTocSelection();
114 
115 private:
116 	QTreeWidget *tree;
117 };
118 
119 
120 class PDFDockTreeWidget : public QTreeWidget
121 {
122 	Q_OBJECT
123 
124 public:
125 	explicit PDFDockTreeWidget(QWidget *parent);
126 	virtual ~PDFDockTreeWidget();
127 
128 	virtual QSize sizeHint() const;
129 };
130 
131 
132 class PDFInfoDock : public PDFDock
133 {
134 	Q_OBJECT
135 
136 public:
137     explicit PDFInfoDock(PDFDocument *doc = nullptr);
138 	~PDFInfoDock();
139 
140 public slots:
141 	virtual void documentClosed();
142 
143 protected:
144 	virtual void fillInfo();
getTitle()145 	virtual QString getTitle()
146 	{
147 		return tr("PDF Info");
148 	}
149 
150 private:
151 	QListWidget *list;
152 };
153 
154 
155 class PDFDockListView : public QListView
156 {
157 	Q_OBJECT
158 public:
159     explicit PDFDockListView(QWidget *parent = nullptr);
160 	virtual QSize sizeHint() const;
161 };
162 
163 
164 class PDFDockListWidget : public QListWidget
165 {
166 	Q_OBJECT
167 public:
168     explicit PDFDockListWidget(QWidget *parent = nullptr);
169 	virtual QSize sizeHint() const;
170 };
171 
172 
173 class PDFOverviewModel: public QAbstractListModel
174 {
175 	Q_OBJECT
176 public:
177     explicit PDFOverviewModel(QObject *parent = nullptr);
178 	int rowCount ( const QModelIndex &parent = QModelIndex() ) const;
179 	QVariant data ( const QModelIndex &index, int role = Qt::DisplayRole ) const;
180 	void setDocument(PDFDocument *doc);
181 
182 public slots:
183 	void updateImage(const QPixmap &pm, int page);
184 
185 private:
186 	PDFDocument *document;
187 	mutable QList<QPixmap> cache;
188 };
189 
190 
191 class PDFFontsDock : public PDFDock
192 {
193 	Q_OBJECT
194 
195 public:
196     explicit PDFFontsDock(PDFDocument *doc = nullptr);
197 	~PDFFontsDock();
198 
199 public slots:
200 	virtual void documentClosed();
201 	virtual void documentLoaded();
202 
203 protected:
204 	virtual void fillInfo();
getTitle()205 	virtual QString getTitle() { return tr("Fonts"); }
206 	void setHorizontalHeaderLabels();
207 
208 protected slots:
209 	virtual void changeLanguage();
210 
211 private:
212 	QTableWidget *table;
213 	QList<Poppler::FontInfo> fonts;
214 	bool scannedFonts;
215 };
216 
217 
218 class QToolButton;
219 class QGridLayout;
220 class QCheckBox;
221 class PDFBaseSearchDock : public QDockWidget
222 {
223 	Q_OBJECT
224 	//TODO: some how merge this with the qce search panel
225 public:
226     explicit PDFBaseSearchDock(PDFDocument *doc = nullptr);
227 
228 	QString getSearchText() const;
229 	void setSearchText(QString text);
230 	bool hasFlagCaseSensitive() const;
231 
232 	virtual void setFocus();
233 
234 signals:
235 	void search(bool backward, bool incremental);
236 
237 protected:
238 	virtual void resizeEvent(QResizeEvent *e);
239 	virtual bool eventFilter(QObject *o, QEvent *e);
240 
241 	QList<QWidget *> listOfWidget;
242 	QGridLayout *gridLayout1;
243 
244 private slots:
245 	void on_leFind_textEdited(const QString &text);
246 	void on_bNext_clicked();
247 	void on_bPrevious_clicked();
248 
249 private:
250 	PDFDocument *document;
251 
252 	int minimum_width;
253 	//QToolButton *bClose;
254 	QLineEdit *leFind;
255     QToolButton *bNext, *bPrevious;
256 	QCheckBox *cbCase;
257 	/*QCheckBox *cbWords;
258 	QCheckBox *cbRegExp;*/
259 	/*	QCheckBox *cbHighlight;
260 		QCheckBox *cbCursor;
261 		QCheckBox *cbSelection;*/
262 };
263 
264 class PDFSearchDock : public PDFBaseSearchDock
265 {
266 	Q_OBJECT
267 
268 public:
269     explicit PDFSearchDock(PDFDocument *doc = nullptr);
270 	bool hasFlagWholeWords() const;
271 	bool hasFlagSync() const;
272 
273 private:
274 	QCheckBox *cbWords;
275 	QCheckBox *cbSync;
276 };
277 
278 class PDFWidget;
279 class PDFScrollArea : public QAbstractScrollArea
280 {
281 	Q_OBJECT
282 
283 public:
284     explicit PDFScrollArea(QWidget *parent = nullptr);
285 	virtual ~PDFScrollArea();
286 	void setPDFWidget(PDFWidget *widget);
287 	void ensureVisible(int x, int y, int xmargin = 50, int ymargin = 50);
288 	void setVerticalScrollBarPolicy(Qt::ScrollBarPolicy policy);
getContinuous()289 	bool getContinuous() { return continuous; }
290 	void updateScrollBars();
291 
292 public slots:
293 	void setContinuous(bool cont);
294 	void goToPage(int page, bool sync = true);
295 	void ensureVisiblePageAbsolutePos(int page, const QPointF &pos, int xmargin = 50, int ymargin = 50);
296 
297 protected:
298 	bool event(QEvent *);
299 	bool eventFilter(QObject *, QEvent *);
300 	void wheelEvent(QWheelEvent *);
301 	void resizeEvent(QResizeEvent *event);
302 	void scrollContentsBy(int dx, int dy);
303 
304 signals:
305 	void resized();
306 
307 private:
308 	void updateWidgetPosition();
309 	bool continuous;
310 	PDFWidget *pdf;
311 	int updateWidgetPositionStackWatch, onResizeStackWatch;
312 };
313 
314 class PDFOverviewDock : public PDFDock
315 {
316 	Q_OBJECT
317 
318 public:
319     explicit PDFOverviewDock(PDFDocument *doc = nullptr);
320 	virtual ~PDFOverviewDock();
321 
322 public slots:
323 	virtual void documentClosed();
324 	virtual void pageChanged(int page);
325 
326 protected:
327 	virtual void fillInfo();
getTitle()328 	virtual QString getTitle() { return tr("Overview"); }
329 
330 protected slots:
331 	virtual void changeLanguage();
332 
333 private slots:
334 	void followTocSelection();
335 
336 private:
337 	QListView *list;
338 	int toGenerate;
339 	bool dontFollow;
340 };
341 
342 
343 class PDFClockDock: public PDFDock
344 {
345 	Q_OBJECT
346 
347 public:
348 	explicit PDFClockDock(PDFDocument *parent = nullptr);
349 	virtual ~PDFClockDock();
350 
351 protected slots:
352 	void onTimer();
353 	void restart();
354 	void setInterval();
355 	void setInterval(int interval);
356 	void setPageCount();
357 
358 protected:
359 	//virtual void pageChanged(int page);
360 	virtual void fillInfo();
361 	virtual QString getTitle();
362 	virtual void paintEvent(QPaintEvent *event);
363 
364 	int pageCount;
365 	QDateTime start, end;
366 	QTimer *timer;
367 };
368 
369 
370 #endif
371 
372 #endif
373