1 /* 2 This is part of TeXworks, an environment for working with TeX documents 3 Copyright (C) 2007-2016 Jonathan Kew, Stefan Löffler, Charlie Sharpsteen 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 authors, 19 see <http://www.tug.org/texworks/>. 20 */ 21 22 #ifndef PDFDocument_H 23 #define PDFDocument_H 24 25 #include "TWScriptable.h" 26 27 #include <QImage> 28 #include <QLabel> 29 #include <QList> 30 #include <QCursor> 31 #include <QButtonGroup> 32 #include <QPainterPath> 33 #include <QTimer> 34 #include <QMouseEvent> 35 36 #include "TWApp.h" 37 #include "FindDialog.h" 38 #include "../modules/QtPDF/src/PDFDocumentWidget.h" 39 #include "TWSynchronizer.h" 40 41 #include "ui_PDFDocument.h" 42 43 const int kDefault_MagnifierSize = 2; 44 const bool kDefault_CircularMagnifier = true; 45 const int kDefault_PreviewScaleOption = 1; 46 const int kDefault_PreviewScale = 200; 47 const QtPDF::PDFDocumentView::PageMode kDefault_PDFPageMode = QtPDF::PDFDocumentView::PageMode_OneColumnContinuous; 48 49 const int kPDFWindowStateVersion = 1; 50 51 class QAction; 52 class QMenu; 53 class QToolBar; 54 class QScrollArea; 55 class TeXDocument; 56 class QShortcut; 57 58 class PDFDocument : public TWScriptable, private Ui::PDFDocument 59 { 60 Q_OBJECT 61 Q_PROPERTY(QString fileName READ fileName) 62 63 public: 64 PDFDocument(const QString &fileName, TeXDocument *sourceDoc = NULL); 65 virtual ~PDFDocument(); 66 67 static PDFDocument *findDocument(const QString &fileName); documentList()68 static QList<PDFDocument*> documentList() 69 { 70 return docList; 71 } 72 fileName()73 QString fileName() const 74 { return curFile; } 75 76 void zoomToRight(QWidget *otherWindow); 77 void showScale(qreal scale); 78 void showPage(int page); 79 void setResolution(const double res); 80 void resetMagnifier(); 81 void enableTypesetAction(bool enabled); 82 void updateTypesettingAction(bool processRunning); 83 void linkToSource(TeXDocument *texDoc); hasSyncData()84 bool hasSyncData() const { return _synchronizer != NULL; } 85 widget()86 QtPDF::PDFDocumentWidget * widget() { return pdfWidget; } 87 88 protected: 89 virtual void changeEvent(QEvent *event); 90 virtual bool event(QEvent *event); 91 virtual void closeEvent(QCloseEvent *event); 92 virtual void dragEnterEvent(QDragEnterEvent *event); 93 virtual void dropEvent(QDropEvent *event); 94 virtual void contextMenuEvent(QContextMenuEvent *event); 95 96 public slots: 97 void texActivated(TeXDocument * texDoc); 98 void texClosed(QObject *obj); 99 void reload(); 100 void retypeset(); 101 void interrupt(); 102 void sideBySide(); 103 void doFindDialog(); 104 void doFindAgain(bool newSearch = false); 105 void goToSource(); 106 void toggleFullScreen(); 107 void syncFromSource(const QString& sourceFile, int lineNo, int col, bool activatePreview); 108 void print(); 109 void setMouseMode(const int newMode); 110 void setPageMode(const int newMode); 111 void clearSyncHighlight(); 112 void clearSearchResultHighlight(); 113 114 private slots: 115 void changedDocument(const QWeakPointer<QtPDF::Backend::Document> newDoc); 116 void updateRecentFileActions(); 117 void updateWindowMenu(); 118 void enablePageActions(int); 119 void syncClick(int page, const QPointF& pos); 120 void invalidateSyncHighlight(); scaleLabelClick(QMouseEvent * event)121 void scaleLabelClick(QMouseEvent * event) { showScaleContextMenu(event->pos()); } 122 void showScaleContextMenu(const QPoint pos); 123 void setScaleFromContextMenu(const QString & strZoom); 124 void updateStatusBar(); 125 void updatePageMode(const QtPDF::PDFDocumentView::PageMode newMode); 126 void doPageDialog(); 127 void doScaleDialog(); 128 void jumpToSource(); 129 void searchResultHighlighted(const int pageNum, const QList<QPolygonF> region); 130 void setDefaultScale(); 131 void maybeOpenUrl(const QUrl url); 132 void maybeOpenPdf(QString filename, QtPDF::PDFDestination destination, bool newWindow); 133 134 signals: 135 void reloaded(); 136 void activatedWindow(QWidget*); 137 138 private: 139 void init(); 140 void loadFile(const QString &fileName); 141 void setCurrentFile(const QString &fileName); 142 void loadSyncData(); 143 void saveRecentFileInfo(); 144 145 QString curFile; 146 147 QtPDF::PDFDocumentWidget *pdfWidget; 148 QScrollArea *scrollArea; 149 QButtonGroup *toolButtonGroup; 150 151 QLinkedList<TeXDocument*> sourceDocList; 152 153 QLabel *pageLabel; 154 QLabel *scaleLabel; 155 QList<QAction*> recentFileActions; 156 QShortcut *exitFullscreen; 157 QSignalMapper pageModeSignalMapper; 158 159 QGraphicsItem * _syncHighlight; 160 QTimer _syncHighlightRemover; 161 162 QBrush _searchResultHighlightBrush; 163 QTimer _searchResultHighlightRemover; 164 165 bool openedManually; 166 167 static QList<PDFDocument*> docList; 168 169 TWSyncTeXSynchronizer * _synchronizer; 170 171 PDFSearchResult lastSearchResult; 172 // stores the page idx a search was started on 173 // after wrapping the search will continue only up to this page 174 int firstSearchPage; 175 }; 176 177 #endif 178