File: PDFViewer.h

package info (click to toggle)
texworks 0.6.10%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 24,600 kB
  • sloc: cpp: 32,035; ansic: 8,252; javascript: 972; xml: 344; python: 208; sh: 157; makefile: 24
file content (114 lines) | stat: -rw-r--r-- 2,740 bytes parent folder | download | duplicates (3)
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
/**
 * Copyright (C) 2013-2021  Charlie Sharpsteen, Stefan Löffler
 *
 * 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, 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.
 */

#include "PDFDocumentWidget.h"

#include <QtGui/QtGui>

class PageCounter;
class ZoomTracker;
class SearchLineEdit;

class PDFViewer : public QMainWindow {
  Q_OBJECT

  PageCounter * _counter;
  ZoomTracker * _zoomWdgt;
  SearchLineEdit * _search;
  QToolBar * _toolBar;

  static QTranslator * _translator;
  static QString _translatorLanguage;

public:
  PDFViewer(const QString & pdf_doc = QString(), QWidget * parent = Q_NULLPTR, Qt::WindowFlags flags = {});

public slots:
  void open();

private slots:
  void openUrl(const QUrl url) const;
  void openPdf(QString filename, QtPDF::PDFDestination destination, bool newWindow) const;
  void syncFromPdf(const int page, const QPointF pos);
  void searchProgressChanged(int percent, int occurrences);
  void documentChanged(const QWeakPointer<QtPDF::Backend::Document> newDoc);

#ifdef DEBUG
  // TODO: Make this more general or remove it altogether
  void setGermanLocale() { switchInterfaceLocale(QLocale(QLocale::German)); }
  void setEnglishLocale() { switchInterfaceLocale(QLocale(QLocale::C)); }
#endif
  void switchInterfaceLocale(const QLocale & newLocale);
};


class SearchLineEdit : public QLineEdit
{
  Q_OBJECT

public:
  SearchLineEdit(QWidget * parent = Q_NULLPTR);

protected:
  void resizeEvent(QResizeEvent *) override;

private:
  QToolButton *nextResultButton, *previousResultButton, *clearButton;

signals:
  void searchRequested(QString searchText);
  void gotoNextResult();
  void gotoPreviousResult();
  void searchCleared();

private slots:
  void prepareSearch();
  void clearSearch();
  void handleNextResult();
  void handlePreviousResult();

};


class PageCounter : public QLabel {
  Q_OBJECT
  typedef QLabel super;
  int currentPage{1}, lastPage{-1};

public:
  PageCounter(QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = {});

public slots:
  void setLastPage(int page);
  void setCurrentPage(int page);

private:
  void refreshText();
};


class ZoomTracker : public QLabel {
  Q_OBJECT
  typedef QLabel super;
  qreal zoom{1.0};

public:
  ZoomTracker(QWidget * parent = Q_NULLPTR, Qt::WindowFlags f = {});

public slots:
  void setZoom(qreal newZoom);

private:
  void refreshText();
};