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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
//========================================================================
//
// XpdfViewer.h
//
// Copyright 2015 Glyph & Cog, LLC
//
//========================================================================
#ifndef XPDFVIEWER_H
#define XPDFVIEWER_H
#include <aconf.h>
#include <QDialog>
#include <QIcon>
#include <QLocalServer>
#include <QMainWindow>
#include <QToolButton>
#include "gtypes.h"
#include "Error.h"
#include "XpdfWidget.h"
class GString;
class GList;
class PropertyListAnimation;
class QComboBox;
class QDialog;
class QHBoxLayout;
class QInputEvent;
class QLabel;
class QLineEdit;
class QListWidget;
class QListWidgetItem;
class QMenu;
class QModelIndex;
class QProgressDialog;
class QSignalMapper;
class QSplitter;
class QStackedLayout;
class QStackedWidget;
class QTextBrowser;
class QTimer;
class QToolBar;
class QToolButton;
class XpdfApp;
class XpdfMenuButton;
class XpdfTabInfo;
class XpdfViewer;
//------------------------------------------------------------------------
struct XpdfViewerCmd {
const char *name;
int nArgs;
GBool requiresDoc;
GBool requiresEvent;
void (XpdfViewer::*func)(GString *args[], int nArgs, QInputEvent *event);
};
//------------------------------------------------------------------------
// XpdfMenuButton
//------------------------------------------------------------------------
class XpdfMenuButton: public QToolButton {
Q_OBJECT
public:
XpdfMenuButton(QMenu *menuA);
private slots:
void btnPressed();
private:
QMenu *menu;
};
//------------------------------------------------------------------------
// XpdfErrorWindow
//------------------------------------------------------------------------
class XpdfErrorWindow: public QWidget {
Q_OBJECT
public:
XpdfErrorWindow(XpdfViewer *viewerA, int errorEventTypeA);
virtual ~XpdfErrorWindow();
virtual QSize sizeHint() const;
virtual void closeEvent(QCloseEvent *event);
virtual void keyPressEvent(QKeyEvent *event);
virtual void customEvent(QEvent *event);
private slots:
void clearBtnPressed();
private:
static void errorCbk(void *data, ErrorCategory category,
int pos, char *msg);
static void dummyErrorCbk(void *data, ErrorCategory category,
int pos, char *msg);
XpdfViewer *viewer;
int errorEventType;
QListWidget *list;
QSize lastSize;
};
//------------------------------------------------------------------------
// XpdfViewer
//------------------------------------------------------------------------
class XpdfViewer: public QMainWindow {
Q_OBJECT
public:
XpdfViewer(XpdfApp *appA, GBool fullScreen);
static XpdfViewer *create(XpdfApp *app, QString fileName, int page,
QString destName, int rot, QString password,
GBool fullScreen);
virtual ~XpdfViewer();
virtual QSize sizeHint() const;
void tweakSize();
// Open a file in the current tab. Returns a boolean indicating
// success.
GBool open(QString fileName, int page, QString destName, int rot,
QString password);
// Open a file in a new tab. Returns a boolean indicating success.
GBool openInNewTab(QString fileName, int page, QString destName,
int rot, QString password, GBool switchToTab);
// Check that [fileName] is open in the current tab -- if not, open
// it. In either case, switch to [page] or [destName]. Returns a
// boolean indicating success.
GBool checkOpen(QString fileName, int page, QString destName,
QString password);
virtual QMenu *createPopupMenu();
// Start up the remote server socket.
void startRemoteServer(const QString &remoteServerName);
// Execute a command [cmd], with [event] for context.
void execCmd(const char *cmd, QInputEvent *event);
public slots:
bool close();
private slots:
void remoteServerConnection();
void remoteServerRead();
void pdfResized();
void pdfPaintDone(bool finished);
void preLoad();
void postLoad();
void keyPress(QKeyEvent *e);
void mousePress(QMouseEvent *e);
void mouseRelease(QMouseEvent *e);
void mouseClick(QMouseEvent *e);
void mouseDoubleClick(QMouseEvent *e);
void mouseTripleClick(QMouseEvent *e);
void mouseWheel(QWheelEvent *e);
void mouseMove(QMouseEvent *e);
void pageChange(int pg);
void sidebarSplitterMoved(int pos, int index);
#if XPDFWIDGET_PRINTING
void printStatus(int nextPage, int firstPage, int lastPage);
void cancelPrint();
#endif
void openMenuAction();
void openInNewWinMenuAction();
void reloadMenuAction();
void saveAsMenuAction();
void saveImageMenuAction();
#if XPDFWIDGET_PRINTING
void printMenuAction();
#endif
void quitMenuAction();
void copyMenuAction();
void singlePageModeMenuAction();
void continuousModeMenuAction();
void sideBySideSingleModeMenuAction();
void sideBySideContinuousModeMenuAction();
void horizontalContinuousModeMenuAction();
void fullScreenMenuAction(bool checked);
void rotateClockwiseMenuAction();
void rotateCounterclockwiseMenuAction();
void zoomToSelectionMenuAction();
void toggleToolbarMenuAction(bool checked);
void toggleSidebarMenuAction(bool checked);
void viewPageLabelsMenuAction(bool checked);
void documentInfoMenuAction();
void newTabMenuAction();
void newWindowMenuAction();
void closeTabMenuAction();
void closeWindowMenuAction();
void openErrorWindowMenuAction();
void helpMenuAction();
void keyBindingsMenuAction();
void aboutMenuAction();
void popupMenuAction(int idx);
void toggleSidebarButtonPressed();
void pageNumberChanged();
void backButtonPressed();
void forwardButtonPressed();
void zoomOutButtonPressed();
void zoomInButtonPressed();
void zoomIndexChanged(int idx);
void zoomEditingFinished();
void fitWidthButtonPressed();
void fitPageButtonPressed();
void selectModeButtonPressed();
void statusIndicatorPressed();
void findTextChanged();
void findNextButtonPressed();
void findPrevButtonPressed();
void newTabButtonPressed();
void switchTab(QListWidgetItem *current, QListWidgetItem *previous);
void tabsReordered(const QModelIndex &srcParent, int srcStart, int srcEnd,
const QModelIndex &destParent, int destRow);
void infoComboBoxChanged(int idx);
void outlineItemClicked(const QModelIndex& idx);
void layerItemClicked(const QModelIndex& idx);
void attachmentSaveClicked(int idx);
void clearFindError();
private:
friend class XpdfErrorWindow;
//--- commands
int mouseX(QInputEvent *event);
int mouseY(QInputEvent *event);
void cmdAbout(GString *args[], int nArgs, QInputEvent *event);
void cmdBlockSelectMode(GString *args[], int nArgs, QInputEvent *event);
void cmdCheckOpenFile(GString *args[], int nArgs, QInputEvent *event);
void cmdCheckOpenFileAtDest(GString *args[], int nArgs, QInputEvent *event);
void cmdCheckOpenFileAtPage(GString *args[], int nArgs, QInputEvent *event);
void cmdCloseTabOrQuit(GString *args[], int nArgs, QInputEvent *event);
void cmdCloseSidebar(GString *args[], int nArgs, QInputEvent *event);
void cmdCloseSidebarMoveResizeWin(GString *args[], int nArgs, QInputEvent *event);
void cmdCloseSidebarResizeWin(GString *args[], int nArgs, QInputEvent *event);
void cmdCloseWindowOrQuit(GString *args[], int nArgs, QInputEvent *event);
void cmdContinuousMode(GString *args[], int nArgs, QInputEvent *event);
void cmdCopy(GString *args[], int nArgs, QInputEvent *event);
void cmdCopyLinkTarget(GString *args[], int nArgs, QInputEvent *event);
#if 0 // for debugging
void cmdDebug1(GString *args[], int nArgs, QInputEvent *event);
#endif
void cmdEndPan(GString *args[], int nArgs, QInputEvent *event);
void cmdEndSelection(GString *args[], int nArgs, QInputEvent *event);
void cmdExpandSidebar(GString *args[], int nArgs, QInputEvent *event);
void cmdFind(GString *args[], int nArgs, QInputEvent *event);
void cmdFindFirst(GString *args[], int nArgs, QInputEvent *event);
void cmdFindNext(GString *args[], int nArgs, QInputEvent *event);
void cmdFindPrevious(GString *args[], int nArgs, QInputEvent *event);
void cmdFocusToDocWin(GString *args[], int nArgs, QInputEvent *event);
void cmdFocusToPageNum(GString *args[], int nArgs, QInputEvent *event);
void cmdFollowLink(GString *args[], int nArgs, QInputEvent *event);
void cmdFollowLinkInNewTab(GString *args[], int nArgs, QInputEvent *event);
void cmdFollowLinkInNewTabNoSel(GString *args[], int nArgs, QInputEvent *event);
void cmdFollowLinkInNewWin(GString *args[], int nArgs, QInputEvent *event);
void cmdFollowLinkInNewWinNoSel(GString *args[], int nArgs, QInputEvent *event);
void cmdFollowLinkNoSel(GString *args[], int nArgs, QInputEvent *event);
void cmdFullScreenMode(GString *args[], int nArgs, QInputEvent *event);
void cmdGoBackward(GString *args[], int nArgs, QInputEvent *event);
void cmdGoForward(GString *args[], int nArgs, QInputEvent *event);
void cmdGotoDest(GString *args[], int nArgs, QInputEvent *event);
void cmdGotoLastPage(GString *args[], int nArgs, QInputEvent *event);
void cmdGotoPage(GString *args[], int nArgs, QInputEvent *event);
void cmdHelp(GString *args[], int nArgs, QInputEvent *event);
void cmdHideMenuBar(GString *args[], int nArgs, QInputEvent *event);
void cmdHideToolbar(GString *args[], int nArgs, QInputEvent *event);
void cmdHorizontalContinuousMode(GString *args[], int nArgs, QInputEvent *event);
void cmdLinearSelectMode(GString *args[], int nArgs, QInputEvent *event);
void cmdLoadTabState(GString *args[], int nArgs, QInputEvent *event);
void cmdNewTab(GString *args[], int nArgs, QInputEvent *event);
void cmdNewWindow(GString *args[], int nArgs, QInputEvent *event);
void cmdNextPage(GString *args[], int nArgs, QInputEvent *event);
void cmdNextPageNoScroll(GString *args[], int nArgs, QInputEvent *event);
void cmdNextTab(GString *args[], int nArgs, QInputEvent *event);
void cmdOpen(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenErrorWindow(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenFile(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenFile2(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenFileAtDest(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenFileAtDestIn(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenFileAtPage(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenFileAtPageIn(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenFileIn(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenIn(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenSidebar(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenSidebarMoveResizeWin(GString *args[], int nArgs, QInputEvent *event);
void cmdOpenSidebarResizeWin(GString *args[], int nArgs, QInputEvent *event);
void cmdPageDown(GString *args[], int nArgs, QInputEvent *event);
void cmdPageUp(GString *args[], int nArgs, QInputEvent *event);
void cmdPostPopupMenu(GString *args[], int nArgs, QInputEvent *event);
void cmdPrevPage(GString *args[], int nArgs, QInputEvent *event);
void cmdPrevPageNoScroll(GString *args[], int nArgs, QInputEvent *event);
void cmdPrevTab(GString *args[], int nArgs, QInputEvent *event);
#if XPDFWIDGET_PRINTING
void cmdPrint(GString *args[], int nArgs, QInputEvent *event);
#endif
void cmdQuit(GString *args[], int nArgs, QInputEvent *event);
void cmdRaise(GString *args[], int nArgs, QInputEvent *event);
void cmdReload(GString *args[], int nArgs, QInputEvent *event);
void cmdRotateCW(GString *args[], int nArgs, QInputEvent *event);
void cmdRotateCCW(GString *args[], int nArgs, QInputEvent *event);
void cmdRun(GString *args[], int nArgs, QInputEvent *event);
void cmdSaveAs(GString *args[], int nArgs, QInputEvent *event);
void cmdSaveImage(GString *args[], int nArgs, QInputEvent *event);
void cmdSaveTabState(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollDown(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollDownNextPage(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollLeft(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollOutlineDown(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollOutlineUp(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollRight(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollToBottomEdge(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollToBottomRight(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollToLeftEdge(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollToRightEdge(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollToTopEdge(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollToTopLeft(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollUp(GString *args[], int nArgs, QInputEvent *event);
void cmdScrollUpPrevPage(GString *args[], int nArgs, QInputEvent *event);
void cmdSelectLine(GString *args[], int nArgs, QInputEvent *event);
void cmdSelectWord(GString *args[], int nArgs, QInputEvent *event);
void cmdSetSelection(GString *args[], int nArgs, QInputEvent *event);
void cmdShowAttachmentsPane(GString *args[], int nArgs, QInputEvent *event);
void cmdShowDocumentInfo(GString *args[], int nArgs, QInputEvent *event);
void cmdShowKeyBindings(GString *args[], int nArgs, QInputEvent *event);
void cmdShowLayersPane(GString *args[], int nArgs, QInputEvent *event);
void cmdShowMenuBar(GString *args[], int nArgs, QInputEvent *event);
void cmdShowOutlinePane(GString *args[], int nArgs, QInputEvent *event);
void cmdShowToolbar(GString *args[], int nArgs, QInputEvent *event);
void cmdShrinkSidebar(GString *args[], int nArgs, QInputEvent *event);
void cmdSideBySideContinuousMode(GString *args[], int nArgs, QInputEvent *event);
void cmdSideBySideSingleMode(GString *args[], int nArgs, QInputEvent *event);
void cmdSinglePageMode(GString *args[], int nArgs, QInputEvent *event);
void cmdStartExtendedSelection(GString *args[], int nArgs, QInputEvent *event);
void cmdStartPan(GString *args[], int nArgs, QInputEvent *event);
void cmdStartSelection(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleContinuousMode(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleFullScreenMode(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleMenuBar(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleSelectMode(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleSidebar(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleSidebarMoveResizeWin(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleSidebarResizeWin(GString *args[], int nArgs, QInputEvent *event);
void cmdToggleToolbar(GString *args[], int nArgs, QInputEvent *event);
void cmdViewPageLabels(GString *args[], int nArgs, QInputEvent *event);
void cmdViewPageNumbers(GString *args[], int nArgs, QInputEvent *event);
void cmdWindowMode(GString *args[], int nArgs, QInputEvent *event);
void cmdZoomFitPage(GString *args[], int nArgs, QInputEvent *event);
void cmdZoomFitWidth(GString *args[], int nArgs, QInputEvent *event);
void cmdZoomIn(GString *args[], int nArgs, QInputEvent *event);
void cmdZoomOut(GString *args[], int nArgs, QInputEvent *event);
void cmdZoomPercent(GString *args[], int nArgs, QInputEvent *event);
void cmdZoomToSelection(GString *args[], int nArgs, QInputEvent *event);
int scaleScroll(int delta);
void followLink(QInputEvent *event, GBool onlyIfNoSel,
GBool newTab, GBool newWindow);
//--- GUI events
int getModifiers(Qt::KeyboardModifiers qtMods);
int getContext(Qt::KeyboardModifiers qtMods);
int getMouseButton(Qt::MouseButton qtBtn);
virtual void keyPressEvent(QKeyEvent *e);
virtual void dragEnterEvent(QDragEnterEvent *e);
virtual void dropEvent(QDropEvent *e);
virtual bool eventFilter(QObject *watched, QEvent *event);
//--- GUI setup
void createWindow();
void createToolBar();
QToolButton *addToolBarButton(const QIcon &icon,
const char *slot, const char *tip);
XpdfMenuButton *addToolBarMenuButton(const QIcon &icon,
const char *tip, QMenu *menu);
void addToolBarSeparator();
void addToolBarSpacing(int w);
void addToolBarStretch();
void createMainMenu();
void createXpdfPopupMenu();
QWidget *createTabPane();
QWidget *createInfoPane();
void updateInfoPane();
void destroyWindow();
void enterFullScreenMode();
void exitFullScreenMode();
void addTab();
void closeTab(XpdfTabInfo *tab);
void gotoTab(int idx);
void updateModeInfo();
void updateZoomInfo();
void updateSelectModeInfo();
void updateDocInfo();
void updatePageNumberOrLabel(int pg);
void updateOutline(int pg);
void setOutlineOpenItems(const QModelIndex &idx);
void fillAttachmentList();
void statusIndicatorStart();
void statusIndicatorStop();
void statusIndicatorOk();
void statusIndicatorError();
void showFindError();
void createDocumentInfoDialog();
void updateDocumentInfoDialog(XpdfWidget *view);
QString createDocumentInfoMetadataHTML(XpdfWidget *view);
QString createDocumentInfoFontsHTML(XpdfWidget *view);
void createKeyBindingsDialog();
QString createKeyBindingsHTML();
void createAboutDialog();
void execSaveImageDialog();
static XpdfViewerCmd cmdTab[];
XpdfApp *app;
// menu
QMenuBar *mainMenu;
QMenu *displayModeSubmenu;
QAction *fullScreenMenuItem;
QAction *toggleToolbarMenuItem;
QAction *toggleSidebarMenuItem;
QAction *viewPageLabelsMenuItem;
// popup menu
QMenu *popupMenu;
QSignalMapper *popupMenuSignalMapper;
// toolbar
int toolBarFontSize; // used for HiDPI scaling
QToolBar *toolBar;
QLineEdit *pageNumber;
QLabel *pageCount;
QComboBox *zoomComboBox;
QToolButton *fitWidthBtn;
QToolButton *fitPageBtn;
QToolButton *selectModeBtn;
PropertyListAnimation *indicatorAnimation;
QList<QVariant> indicatorIcons;
QList<QVariant> indicatorErrIcons;
QLineEdit *findEdit;
QAction *findCaseSensitiveAction;
QAction *findWholeWordsAction;
// sidebar pane
QSplitter *sidebarSplitter;
int initialSidebarWidth;
int sidebarWidth;
QListWidget *tabList;
QComboBox *infoComboBox;
QStackedLayout *infoStack;
// viewer pane
QStackedWidget *viewerStack;
QLabel *linkTargetBar;
QString linkTargetInfo;
GList *tabInfo; // [XpdfTabInfo]
XpdfTabInfo *currentTab;
XpdfTabInfo *lastOpenedTab;
double scaleFactor;
XpdfWidget::DisplayMode fullScreenPreviousDisplayMode;
double fullScreenPreviousZoom;
QTimer *findErrorTimer;
XpdfErrorWindow *errorWindow;
QDialog *documentInfoDialog;
QTextBrowser *documentInfoMetadataTab;
QTextBrowser *documentInfoFontsTab;
QDialog *keyBindingsDialog;
QDialog *aboutDialog;
#if XPDFWIDGET_PRINTING
QProgressDialog *printStatusDialog;
#endif
QString lastFileOpened;
QLocalServer *remoteServer;
};
#endif
|