1 //C-  -*- C++ -*-
2 //C- -------------------------------------------------------------------
3 //C- DjView4
4 //C- Copyright (c) 2006-  Leon Bottou
5 //C-
6 //C- This software is subject to, and may be distributed under, the
7 //C- GNU General Public License, either version 2 of the license,
8 //C- or (at your option) any later version. The license should have
9 //C- accompanied the software or you may obtain a copy of the license
10 //C- from the Free Software Foundation at http://www.fsf.org .
11 //C-
12 //C- This program is distributed in the hope that it will be useful,
13 //C- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //C- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //C- GNU General Public License for more details.
16 //C-  ------------------------------------------------------------------
17 
18 #ifndef QDJVIEW_H
19 #define QDJVIEW_H
20 
21 #if AUTOCONF
22 # include "config.h"
23 #endif
24 
25 #include <Qt>
26 #include <QDateTime>
27 #include <QObject>
28 #include <QMainWindow>
29 #include <QMessageBox>
30 #include <QPair>
31 #include <QPointer>
32 #include <QString>
33 #include <QList>
34 #include <QUrl>
35 
36 #include <libdjvu/miniexp.h>
37 #include <libdjvu/ddjvuapi.h>
38 
39 #include "qdjvu.h"
40 #include "qdjvuwidget.h"
41 #include "qdjviewprefs.h"
42 #include "qdjviewdialogs.h"
43 
44 
45 class QAction;
46 class QActionGroup;
47 class QBoxLayout;
48 class QCloseEvent;
49 class QComboBox;
50 class QDockWidget;
51 class QDjViewOutline;
52 class QDjViewThumbnails;
53 class QDjViewFind;
54 class QDragEnterEvent;
55 class QDragMoveEvent;
56 class QDropEvent;
57 class QFileDialog;
58 class QFileSystemWatcher;
59 class QLabel;
60 class QMenu;
61 class QMenuBar;
62 class QShortcut;
63 class QSettings;
64 class QStackedLayout;
65 class QStatusBar;
66 class QStringList;
67 class QTimer;
68 class QTabWidget;
69 class QToolBar;
70 
71 
72 
73 #if DDJVUAPI_VERSION < 18
74 # error "DDJVUAPI_VERSION>=18 is required !"
75 #endif
76 
77 #if QT_VERSION < 0x40200
78 # error "QT_VERSION>=0x40200 is required !"
79 #endif
80 
81 
82 class QDjView : public QMainWindow
83 {
84   Q_OBJECT
85 
86  public:
87 
88 
89   enum ViewerMode {
90     EMBEDDED_PLUGIN       = 0,
91     FULLPAGE_PLUGIN       = 1,
92     STANDALONE            = 2,
93     STANDALONE_FULLSCREEN = 3,
94     STANDALONE_SLIDESHOW  = 4
95   };
96 
97   QDjView(QDjVuContext &context,
98           ViewerMode mode=STANDALONE,
99           QWidget *parent=0);
100 
101   ~QDjView();
102 
getDjVuContext()103   QDjVuContext       &getDjVuContext()      { return djvuContext; }
getDjVuWidget()104   QDjVuWidget        *getDjVuWidget()       { return widget; }
getErrorDialog()105   QDjViewErrorDialog *getErrorDialog()      { return errorDialog; }
getDocument()106   QDjVuDocument      *getDocument()         { return document; }
getDocumentFileName()107   QString             getDocumentFileName() { return documentFileName; }
getDocumentUrl()108   QUrl                getDocumentUrl()      { return documentUrl; }
109   QUrl                getDecoratedUrl();
110   QString             getShortFileName();
getViewerMode()111   ViewerMode          getViewerMode()       { return viewerMode; }
112 
113   QString      getArgument(QString key);
114   QStringList  parseArgument(QString key, QString val);
115   QStringList  parseArgument(QString keyEqualVal);
116   void         parseDjVuCgiArguments(QUrl url);
117   static QUrl  removeDjVuCgiArguments(QUrl url);
118 
119   int         pageNum(void);
120   QString     pageName(int pageno, bool titleonly=false);
121   int         pageNumber(QString name, int from = -1);
122   QDjView    *copyWindow(bool openDocument=true);
123   int         visibleSideBarTabs();
124   int         hiddenSideBarTabs();
125   bool        saveTextFile(QString text, QString filename=QString());
126   bool        saveImageFile(QImage image, QString filename=QString());
127   bool        startBrowser(QUrl url);
128   void        fillZoomCombo(QComboBox *zoomCombo);
129   void        fillModeCombo(QComboBox *modeCombo);
130   void        fillPageCombo(QComboBox *pageCombo);
131 
132 public slots:
133   bool  open(QString filename);
134   bool  open(QUrl url, bool inNewWindow=false, bool maybeInBrowser=false);
135   void  open(QDjVuDocument *document, QUrl url = QUrl());
136   void  closeDocument();
137   void  reloadDocument();
138   void  goToPage(int pageno);
139   void  goToPage(QString name, int from=-1);
140   void  goToPosition(QString pagename, double px, double py);
141   void  goToLink(QString link, QString target=QString(), int from=-1);
142   void  addToErrorDialog(QString message);
143   void  raiseErrorDialog(QMessageBox::Icon icon, QString caption=QString());
144   int   execErrorDialog (QMessageBox::Icon icon, QString caption=QString());
145   void  setPageLabelText(QString s = QString());
146   void  setMouseLabelText(QString s = QString());
147   void  statusMessage(QString s = QString());
148   bool  showSideBar(Qt::DockWidgetAreas areas, int tabs);
149   bool  showSideBar(QString args, QStringList &errors);
150   bool  showSideBar(bool);
151   void  showFind(void);
152   void  print(void);
153   void  saveAs(void);
154   void  exportAs(void);
155   void  find(QString find = QString());
156   void  saveSession(QSettings *s);
157   void  restoreSession(QSettings *s);
158   bool  setViewerMode(ViewerMode);
159   void  setSlideShowDelay(int delay);
160 
161 signals:
162   void  documentClosed(QDjVuDocument *doc);
163   void  documentOpened(QDjVuDocument *doc);
164   void  documentReady(QDjVuDocument *doc);
165   void  pluginStatusMessage(QString message = QString());
166   void  pluginGetUrl(QUrl url, QString target);
167   void  pluginOnChange();
168 
169 protected:
170   typedef QDjVuWidget::Position Position;
171   typedef QDjVuWidget::PageInfo PageInfo;
172   typedef QDjViewPrefs::Options Options;
173   typedef QDjViewPrefs::Tools Tools;
174   typedef QDjViewPrefs::Saved Saved;
175 
176   void     fillToolBar(QToolBar *toolBar);
177   QAction *makeAction(QString text);
178   QAction *makeAction(QString text, Qt::ShortcutContext sc);
179   QAction *makeAction(QString text, bool value);
180   void     createActions(void);
181   void     createMenus(void);
182   void     createWhatsThis(void);
183   Saved   *getSavedPrefs(void);
184   Saved   *getSavedConfig(ViewerMode mode);
185   void     enableContextMenu(bool);
186   void     enableScrollBars(bool);
187   void     applyOptions(bool remember=true);
188   void     updateOptions(void);
189   void     applySaved(Saved *saved);
190   void     updateSaved(Saved *saved);
191   void     applyPreferences(void);
192   void     updatePreferences(void);
193   void     parseToolBarOption(QString option, QStringList &errors);
194   bool     warnAboutPrintingRestrictions();
195   bool     warnAboutSavingRestrictions();
196   void     restoreRecentDocument(QUrl);
197 
198   virtual bool eventFilter(QObject *watched, QEvent *event);
199   virtual void closeEvent(QCloseEvent *event);
200   virtual void dragEnterEvent(QDragEnterEvent *event);
201   virtual void dragMoveEvent(QDragMoveEvent *event);
202   virtual void dropEvent(QDropEvent *event);
203 
204 protected slots:
205   void info(QString);
206   void error(QString, QString, int);
207   void errorCondition(int);
208   void docinfo();
209   void docinfoExtra();
210   void performPending();
211   void performPendingLater();
212   void pointerPosition(const Position &pos, const PageInfo &page);
213   void pointerEnter(const Position &pos, miniexp_t maparea);
214   void pointerLeave(const Position &pos, miniexp_t maparea);
215   void pointerClick(const Position &pos, miniexp_t maparea);
216   void pointerSelect(const QPoint &pointerPos, const QRect &rect);
217   void updateActions(void);
218   void updateActionsLater(void);
219   void updateTextLabel(void);
220   void modeComboActivated(int);
221   void zoomComboActivated(int);
222   void zoomComboEdited(void);
223   void pageComboActivated(int);
224   void pageComboEdited(void);
225   void preferencesChanged(void);
226   void performAbout(void);
227   void performNew(void);
228   void performOpen(void);
229   void performOpenLocation(void);
230   void performInformation(void);
231   void performMetadata(void);
232   void performPreferences(void);
233   void performRotation(void);
234   void performZoom(void);
235   void performSelect(bool);
236   void performViewFullScreen(bool);
237   void performViewSlideShow(bool);
238   void performEscape();
239   void performGoPage();
240   void addRecent(QUrl);
241   void fillRecent();
242   void openRecent();
243   void clearRecent();
244   void performUndo();
245   void performRedo();
246   void saveUndoData();
247   void performCopyUrl();
248   void performCopyOutline();
249   void performCopyAnnotation();
250   void maybeReloadDocument();
251   void sslWhiteList(QString why, bool &okay);
252   void authRequired(QString why, QString &user, QString &pass);
253   void slideShowTimeout(bool reset=false);
254 
255 protected:
256   // mode
257   ViewerMode   viewerMode;
258   // preferences
259   QDjViewPrefs  *prefs;
260   Options        options;
261   Tools          tools;
262   Tools          toolsCached;
263   // dialogs
264   QPointer<QDjViewErrorDialog>  errorDialog;
265   QPointer<QDjViewInfoDialog>   infoDialog;
266   QPointer<QDjViewMetaDialog>   metaDialog;
267   QPointer<QDjViewSaveDialog>   saveDialog;
268   QPointer<QDjViewExportDialog> exportDialog;
269   QPointer<QDjViewPrintDialog>  printDialog;
270   // widgets
271   QLabel             *splash;
272   QDjVuWidget        *widget;
273   QStackedLayout     *layout;
274   QMenu              *contextMenu;
275   QMenu              *recentMenu;
276   QMenuBar           *menuBar;
277   QStatusBar         *statusBar;
278   QLabel             *pageLabel;
279   QLabel             *mouseLabel;
280   QLabel             *textLabel;
281   QToolBar           *toolBar;
282   QComboBox          *modeCombo;
283   QComboBox          *zoomCombo;
284   QComboBox          *pageCombo;
285   QDjViewOutline     *outlineWidget;
286   QDockWidget        *outlineDock;
287   QDjViewThumbnails  *thumbnailWidget;
288   QDockWidget        *thumbnailDock;
289   QDjViewFind        *findWidget;
290   QDockWidget        *findDock;
291   // document data
292   QDjVuContext           &djvuContext;
293   QDjVuDocument          *document;
294   QString                 documentFileName;
295   QUrl                    documentUrl;
296   QList<ddjvu_fileinfo_t> documentPages;
297   QDateTime               documentModified;
298   bool                    hasNumericalPageTitle;
299   // delayed settings
300   typedef QPair<QString,QString> StringPair;
301   QString           pendingPage;
302   QList<double>     pendingPosition;
303   QList<StringPair> pendingHilite;
304   QString           pendingFind;
305   // delayed updates
306   bool  updateActionsScheduled;
307   bool  performPendingScheduled;
308   QTimer *textLabelTimer;
309   QRect   textLabelRect;
310   // action lists
311   QActionGroup *zoomActionGroup;
312   QActionGroup *modeActionGroup;
313   QActionGroup *rotationActionGroup;
314   // all actions
315   QObjectList allActions;
316   QAction *actionNew;
317   QAction *actionOpen;
318   QAction *actionOpenLocation;
319   QAction *actionClose;
320   QAction *actionQuit;
321   QAction *actionSave;
322   QAction *actionExport;
323   QAction *actionPrint;
324   QAction *actionFind;
325   QAction *actionFindNext;
326   QAction *actionFindPrev;
327   QAction *actionSelect;
328   QAction *actionZoomIn;
329   QAction *actionZoomOut;
330   QAction *actionZoomFitWidth;
331   QAction *actionZoomFitPage;
332   QAction *actionZoomOneToOne;
333   QAction *actionZoom300;
334   QAction *actionZoom200;
335   QAction *actionZoom150;
336   QAction *actionZoom100;
337   QAction *actionZoom75;
338   QAction *actionZoom50;
339   QAction *actionNavFirst;
340   QAction *actionNavNext;
341   QAction *actionNavPrev;
342   QAction *actionNavLast;
343   QAction *actionBack;
344   QAction *actionForw;
345   QAction *actionRotateLeft;
346   QAction *actionRotateRight;
347   QAction *actionRotate0;
348   QAction *actionRotate90;
349   QAction *actionRotate180;
350   QAction *actionRotate270;
351   QAction *actionInformation;
352   QAction *actionMetadata;
353   QAction *actionAbout;
354   QAction *actionWhatsThis;
355   QAction *actionDisplayColor;
356   QAction *actionDisplayBW;
357   QAction *actionDisplayForeground;
358   QAction *actionDisplayBackground;
359   QAction *actionDisplayHiddenText;
360   QAction *actionInvertLuminance;
361   QAction *actionPreferences;
362   QAction *actionViewToolBar;
363   QAction *actionViewSideBar;
364   QAction *actionViewStatusBar;
365   QAction *actionViewFullScreen;
366   QAction *actionViewSlideShow;
367   QAction *actionLayoutContinuous;
368   QAction *actionLayoutSideBySide;
369   QAction *actionLayoutCoverPage;
370   QAction *actionLayoutRightToLeft;
371   QShortcut *shortcutEscape;
372   QShortcut *shortcutGoPage;
373   QAction *actionCopyUrl;
374   QAction *actionCopyOutline;
375   QAction *actionCopyAnnotation;
376   // permission
377   bool printingAllowed;
378   bool savingAllowed;
379   // mode changes
380   Saved fsSavedNormal;
381   Saved fsSavedFullScreen;
382   Saved fsSavedSlideShow;
383   QByteArray savedDockState;
384   QTimer *slideShowTimer;
385   int    slideShowDelay;
386   int    slideShowCounter;
387   // undo/redo
388   class UndoRedo
389   {
390   public:
391     UndoRedo();
392     void clear();
393     void set(QDjView *djview);
394     void apply(QDjView *djview);
395     bool changed(const QDjVuWidget *widget) const;
396   protected:
397     bool valid;
398     QPoint hotSpot;
399     QDjVuWidget::Position position;
400     int rotation;
401     int zoom;
402   };
403   UndoRedo here;
404   QTimer *undoTimer;
405   QList<UndoRedo> undoList;
406   QList<UndoRedo> redoList;
407   // netopen
408   class NetOpen;
409 };
410 
411 #endif
412 
413 /* -------------------------------------------------------------
414    Local Variables:
415    c++-font-lock-extra-types: ( "\\sw+_t" "[A-Z]\\sw*[a-z]\\sw*" )
416    End:
417    ------------------------------------------------------------- */
418