00001
00002
00003
00004
00005
00006
00007
00008
00014
00016
00017 #ifndef XPDFWIDGET_H
00018 #define XPDFWIDGET_H
00019
00020 #include <aconf.h>
00021
00022 #ifdef USE_GCC_PRAGMAS
00023 #pragma interface
00024 #endif
00025
00026 #include <QAbstractScrollArea>
00027
00028 class QMutex;
00029
00030 class GString;
00031 class QtPDFCore;
00032
00033
00034
00036 typedef void *XpdfOutlineHandle;
00037
00039 typedef void *XpdfLayerHandle;
00040
00041
00042
00044 class XpdfWidget: public QAbstractScrollArea {
00045 Q_OBJECT
00046
00047 public:
00048
00050 enum ErrorCode {
00051 pdfOk = 0,
00052 pdfErrOpenFile = 1,
00053 pdfErrBadCatalog = 2,
00054 pdfErrDamaged = 3,
00055
00056 pdfErrEncrypted = 4,
00057
00058 pdfErrHighlightFile = 5,
00059 pdfErrBadPrinter = 6,
00060 pdfErrPrinting = 7,
00061 pdfErrPermission = 8,
00062 pdfErrBadPageNum = 9,
00063 pdfErrFileIO = 10,
00064 pdfErrNoHandle = 1001,
00065 pdfErrOutOfMemory = 1002,
00066 pdfErrBusy = 1003,
00067 pdfErrBadArg = 1004
00068 };
00069
00072
00073 static const int zoomToPage = -1;
00074 static const int zoomToWidth = -2;
00075
00076
00079
00080
00081 static const int findBackward = 0x00000001;
00083 static const int findCaseSensitive = 0x00000002;
00085 static const int findNext = 0x00000004;
00087 static const int findOnePageOnly = 0x00000008;
00089
00100 static void init(const QString &configFileName = QString());
00101
00104 static void setConfig(const QString &command);
00105
00113 XpdfWidget(const QColor &paperColor = QColor(0xff, 0xff, 0xff),
00114 const QColor &matteColor = QColor(0x80, 0x80, 0x80),
00115 bool reverseVideo = false, QWidget *parentA = 0);
00116
00118 virtual ~XpdfWidget();
00119
00124 void enableHyperlinks(bool on);
00125
00131 void enableSelect(bool on);
00132
00137 void enablePan(bool on);
00138
00143 void setKeyPassthrough(bool on) { keyPassthrough = on; }
00144
00150 void showPasswordDialog(bool showDlg);
00151
00154 void setMatteColor(const QColor &matteColor);
00155
00157 void setReverseVideo(bool reverse);
00158
00164 ErrorCode loadFile(const QString &fileName,
00165 const QString &password = "");
00166
00173 ErrorCode loadMem(const char *buffer, unsigned int bufferLength,
00174 const QString &password = "");
00175
00180 void closeFile();
00181
00185 ErrorCode saveAs(const QString &fileName);
00186
00188 QString getFileName();
00189
00192 int getNumPages();
00193
00196 int getCurrentPage();
00197
00199 void gotoPage(int pageNum);
00200
00205 void gotoFirstPage();
00206
00211 void gotoLastPage();
00212
00214 void gotoNextPage();
00215
00217 void gotoPreviousPage();
00218
00220 bool gotoNamedDestination(const QString &dest);
00221
00223 void goForward();
00224
00226 void goBackward();
00227
00229 void scrollPageUp();
00230
00232 void scrollPageDown();
00233
00236 void scrollTo(int xx, int yy);
00237
00242 void scrollBy(int dx, int dy);
00243
00245 int getScrollX();
00246
00248 int getScrollY();
00249
00253 void setZoom(double zoom);
00254
00258 double getZoom();
00259
00263 double getZoomPercent();
00264
00270 void zoomToRect(int page, double xMin, double yMin,
00271 double xMax, double yMax);
00272
00275 void zoomCentered(double zoom);
00276
00279 void zoomToCurrentWidth();
00280
00283 void setRotate(int rotate);
00284
00287 int getRotate();
00288
00292 void setContinuousMode(bool continuous);
00293
00296 bool getContinuousMode();
00297
00301 bool onLink(int page, double xx, double yy);
00302
00305 void gotoLinkAt(int page, double xx, double yy);
00306
00308 void convertWindowToPDFCoords(int winX, int winY,
00309 int *page, double *pdfX, double *pdfY);
00310
00312 void convertPDFToWindowCoords(int page, double pdfX, double pdfY,
00313 int *winX, int *winY);
00314
00318 void enableRedraw(bool enable);
00319
00330 void getPageBox(int page, const QString &box,
00331 double *xMin, double *yMin, double *xMax, double *yMax);
00332
00336 double getPageWidth(int page);
00337
00341 double getPageHeight(int page);
00342
00346 int getPageRotation(int page);
00347
00353 bool getCurrentSelection(int *page, double *x0, double *y0,
00354 double *x1, double *y1);
00355
00359 void setCurrentSelection(int page, double x0, double y0,
00360 double x1, double y1);
00361
00366 QImage *convertPageToImage(int page, double dpi);
00367
00374 QImage *convertRegionToImage(int page, double x0, double y0,
00375 double x1, double y1, double dpi);
00376
00385 bool okToExtractText();
00386
00395 void setTextEncoding(const QString &encodingName);
00396
00404 QString extractText(int page, double x0, double y0,
00405 double x1, double y1);
00406
00408 void copySelection();
00409
00422 bool find(const QString &text, int flags = 0);
00423
00427 int getOutlineNumChildren(XpdfOutlineHandle outline);
00428
00432 XpdfOutlineHandle getOutlineChild(XpdfOutlineHandle outline, int idx);
00433
00436 QString getOutlineTitle(XpdfOutlineHandle outline);
00437
00439 bool getOutlineStartsOpen(XpdfOutlineHandle outline);
00440
00442 int getOutlineTargetPage(XpdfOutlineHandle outline);
00443
00445 void gotoOutlineTarget(XpdfOutlineHandle outline);
00446
00449 int getNumLayers();
00450
00453 XpdfLayerHandle getLayer(int idx);
00454
00457 QString getLayerName(XpdfLayerHandle layer);
00458
00461 bool getLayerVisibility(XpdfLayerHandle layer);
00462
00467 void setLayerVisibility(XpdfLayerHandle layer, bool visibility);
00468
00474 int getLayerViewState(XpdfLayerHandle layer);
00475
00481 int getLayerPrintState(XpdfLayerHandle layer);
00482
00483 signals:
00484
00489 void pageChange(int pageNum);
00490
00496 void midPageChange(int pageNum);
00497
00499 void keyPress(QKeyEvent *e);
00500
00502 void mousePress(QMouseEvent *e);
00503
00505 void mouseRelease(QMouseEvent *e);
00506
00508 void mouseMove(QMouseEvent *e);
00509
00526 void linkClick(const QString &linkType, const QString &dest, int page);
00527
00530 void selectDone();
00531
00532 protected:
00533
00535
00536 virtual void paintEvent(QPaintEvent *eventA);
00537 virtual void resizeEvent(QResizeEvent *eventA);
00538 virtual void scrollContentsBy(int dx, int dy);
00539 virtual void keyPressEvent(QKeyEvent *e);
00540 virtual void mousePressEvent(QMouseEvent *e);
00541 virtual void mouseReleaseEvent(QMouseEvent *e);
00542 virtual void mouseMoveEvent(QMouseEvent *e);
00543
00545
00546 private:
00547
00548 static void updateCbk(void *data, GString *fileName,
00549 int pageNum, int numPages, char *linkLabel);
00550 static void midPageChangedCbk(void *data, int pageNum);
00551 static void linkCbk(void *data, char *type, char *dest, int page);
00552 static void selectDoneCbk(void *data);
00553
00554
00555 static QMutex initMutex;
00556
00557 QtPDFCore *core;
00558
00559 bool keyPassthrough;
00560 };
00561
00562 #endif