"Fossies" - the Fresh Open Source Software Archive

Member "xpdf-4.02/xpdf-qt/XpdfWidget.h" (25 Sep 2019, 35730 Bytes) of package /linux/misc/xpdf-4.02.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "XpdfWidget.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.01.01_vs_4.02.

    1 //========================================================================
    2 //
    3 // XpdfWidget.h
    4 //
    5 // Copyright 2009-2019 Glyph & Cog, LLC
    6 //
    7 //========================================================================
    8 
    9 //! \mainpage
   10 //!
   11 //! XpdfWidget is a PDF viewer widget class for Qt.
   12 //! <br><br>
   13 //! <a href="changes.html">Change history</a>
   14 //! <br><br>
   15 //! Copyright 2009-2019 Glyph & Cog, LLC
   16 
   17 //! \file
   18 
   19 #ifndef XPDFWIDGET_H
   20 #define XPDFWIDGET_H
   21 
   22 #include <aconf.h>
   23 
   24 #ifdef USE_GCC_PRAGMAS
   25 #pragma interface
   26 #endif
   27 
   28 #include <QAbstractScrollArea>
   29 
   30 class QMutex;
   31 class QTimer;
   32 #if XPDFWIDGET_PRINTING
   33 class QPrinter;
   34 class QPrintDialog;
   35 #endif
   36 
   37 class GString;
   38 class PDFDoc;
   39 class QtPDFCore;
   40 
   41 //------------------------------------------------------------------------
   42 
   43 
   44 /*! Opaque handle used to represent an outline node. */
   45 typedef void *XpdfOutlineHandle;
   46 
   47 /*! Opaque handle used to represent a layer. */
   48 typedef void *XpdfLayerHandle;
   49 
   50 /*! Opaque handle used to represent a layer display order tree node. */
   51 typedef void *XpdfLayerOrderHandle;
   52 
   53 /*! Opaque handle used to represent an annotation. */
   54 typedef void *XpdfAnnotHandle;
   55 
   56 /*! Opaque handle used to represent a form field. */
   57 typedef void *XpdfFormFieldHandle;
   58 
   59 /*! Opaque handle used to represent a PDF document. */
   60 typedef void *XpdfDocHandle;
   61 
   62 //------------------------------------------------------------------------
   63 
   64 //! A PDF viewer widget class for Qt.
   65 class XpdfWidget: public QAbstractScrollArea {
   66   Q_OBJECT
   67 
   68 public:
   69 
   70   //! Error codes returned by certain XpdfViewer functions.
   71   enum ErrorCode {
   72     pdfOk               =    0, //!< no error
   73     pdfErrOpenFile      =    1, //!< couldn't open the PDF file
   74     pdfErrBadCatalog    =    2, //!< couldn't read the page catalog
   75     pdfErrDamaged       =    3, //!< PDF file was damaged and couldn't be
   76                 //!<   repaired
   77     pdfErrEncrypted     =    4, //!< file was encrypted and password was
   78                 //!<   incorrect or not supplied
   79     pdfErrHighlightFile =    5, //!< nonexistent or invalid highlight file
   80     pdfErrBadPrinter    =    6, //!< invalid printer
   81     pdfErrPrinting      =    7, //!< error during printing
   82     pdfErrPermission    =    8, //!< PDF file doesn't allow that operation
   83     pdfErrBadPageNum    =    9, //!< invalid page number
   84     pdfErrFileIO        =   10, //!< file I/O error
   85     pdfErrNoHandle      = 1001, //!< NULL object handle
   86     pdfErrOutOfMemory   = 1002, //!< out of memory
   87     pdfErrBusy          = 1003, //!< PDF component is busy
   88     pdfErrBadArg        = 1004  //!< invalid argument
   89   };
   90 
   91   //! Display modes, to be passed to XpdfWidget::setDisplayMode().
   92   enum DisplayMode {
   93     pdfDisplaySingle,           //!< single page
   94     pdfDisplayContinuous,       //!< pages stacked vertically
   95     pdfDisplaySideBySideSingle,     //!< two facing pages
   96     pdfDisplaySideBySideContinuous, //!< facing pages, stacked vertically
   97     pdfDisplayHorizontalContinuous  //!< pages stacked horizontally
   98   };
   99 
  100   //! \name Zoom values
  101   //! Special values for XpdfWidget::setZoom() / XpdfWidget::getZoom()
  102   //@{
  103   static const int zoomToPage  = -1;    //!< zoom to fit whole page
  104   static const int zoomToWidth = -2;    //!< zoom to fit page width
  105   static const int zoomToHeight = -3;   //!< zoom to fit page height
  106   //@}
  107 
  108   //! \name Find flags
  109   //! Flags to be passed to XpdfWidget::find()
  110   //@{
  111   //! search backward from the starting point
  112   static const int findBackward      = 0x00000001;
  113   //! perform a case-sensitive search (default is case-insensitive)
  114   static const int findCaseSensitive = 0x00000002;
  115   //! start searching from the previous search result
  116   static const int findNext          = 0x00000004;
  117   //! limit the search to the current page
  118   static const int findOnePageOnly   = 0x00000008;
  119   //! limit the search to whole words
  120   static const int findWholeWord     = 0x00000010;
  121   //@}
  122 
  123   //! Initialize the XpdfWidget class, reading a configuration file.
  124   //! If \a configFileName is non-empty, the specified file is
  125   //! tried first.  If \a configFileName is empty, or the file
  126   //! doesn't exist, the default location is tried (\c <exe-dir>/xpdfrc
  127   //! on Windows; \c ~/\c .xpdfrc on Unix).
  128   //!
  129   //! This function must be called before any other XpdfWidget functions
  130   //! (including the constructor).  It will be called automatically
  131   //! (with a NULL \a configFileName) if it hasn't already been
  132   //! called when the first XpdfWidget function is used.
  133   static void init(const QString &configFileName = QString());
  134 
  135   //! Process a configuration command, i.e., one line of an xpdfrc file.
  136   //! Note that this applies globally to all XpdfWidget instances.
  137   static void setConfig(const QString &command);
  138 
  139   //! The XpdfWidget constructor.
  140   //! \param paperColor the paper background color (which should generally
  141   //!        be left as white)
  142   //! \param matteColor the matte color displayed between pages, and around
  143   //!        pages that are smaller than the window
  144   //! \param reverseVideo sets reverse video at startup
  145   //! \param parentA the parent QWidget
  146   XpdfWidget(const QColor &paperColor = QColor(0xff, 0xff, 0xff),
  147          const QColor &matteColor = QColor(0x80, 0x80, 0x80),
  148          bool reverseVideo = false, QWidget *parentA = 0);
  149 
  150   //! The XpdfWidget constructor.
  151   //! \param paperColor the paper background color (which should generally
  152   //!        be left as white)
  153   //! \param matteColor the matte color displayed between pages, and around
  154   //!        pages that are smaller than the window
  155   //! \param reverseVideo sets reverse video at startup
  156   //! \param parentA the parent QWidget
  157   //! This version has the \a parent argument first so it works correctly
  158   //! with Qt Designer.
  159   XpdfWidget(QWidget *parentA,
  160          const QColor &paperColor = QColor(0xff, 0xff, 0xff),
  161          const QColor &matteColor = QColor(0x80, 0x80, 0x80),
  162          bool reverseVideo = false);
  163 
  164   //! Destroys the XpdfWidget.
  165   virtual ~XpdfWidget();
  166 
  167   //! Control handling of hyperlinks.
  168   //! If enabled, the viewer will follow hyperlinks when clicked with the
  169   //! left mouse button.  If disabled, the viewer will ignore left mouse
  170   //! button clicks on hyperlinks.  The default is enabled.
  171   void enableHyperlinks(bool on);
  172 
  173   //! Control handling of text selection.
  174   //! If enabled, the viewer will allow the user to select rectangular
  175   //! regions of text when the user drags with the left mouse button.  If
  176   //! disabled, dragging with the left mouse button is ignored.  The
  177   //! default is enabled.
  178   void enableSelect(bool on);
  179 
  180   //! Control mouse panning.
  181   //! If enabled, dragging with the middle mouse button pressed will pan
  182   //! the page.  If disabled, the middle button is ignored.  The default
  183   //! is enabled.
  184   void enablePan(bool on);
  185 
  186   //! Control touchscreen panning.
  187   //! If enabled, QPanGestures are recognized and used to pan the PDF
  188   //! view.
  189   void enableTouchPan(bool on);
  190 
  191   //! Control touchscreen zooming.
  192   //! If enabled QPinchGestures are recognized and used to pinch-zoom
  193   //! the PDF view.
  194   void enableTouchZoom(bool on);
  195 
  196   //! Control keypress passthrough.
  197   //! If enabled, XpdfWidget will pass keypress events through to the
  198   //! keyPress signal, with no other processing.  If disabled, XpdfWidget
  199   //! will implement some built-in key bindings.  The default is disabled.
  200   void setKeyPassthrough(bool on) { keyPassthrough = on; }
  201 
  202   //! Control mouse event passthrough.
  203   //! If enabled, XpdfWidget will pass mouse events through to the
  204   //! mousePress/mouseRelease signals, with no other processing.  If
  205   //! disabled, XpdfWidget will implement some built-in mouse handling
  206   //! (in addition to sending the signals).  The default is disabled.
  207   void setMousePassthrough(bool on) { mousePassthrough = on; }
  208 
  209   //! Control the password dialog.
  210   //! If enabled, the viewer will show a password dialog for encrypted
  211   //! files; if disabled, it will simply return \c pdfErrEncrypted unless
  212   //! the correct password is passed to \c pdfLoadFileWithPassword.  The
  213   //! default is enabled.
  214   void showPasswordDialog(bool showDlg);
  215 
  216   //! Set the matte color, i.e., the color used for background outside
  217   //! the actual page area.  The default is a medium gray.
  218   void setMatteColor(const QColor &matteColor);
  219 
  220   //! Turn reverse video mode on/off.  The default is off.
  221   void setReverseVideo(bool reverse);
  222 
  223   //! Set the cursor.  The requested cursor will only be displayed in
  224   //! the viewport (not in the scrollbars).
  225   void setCursor(const QCursor &cursor);
  226 
  227   //! Reset to the default cursor.
  228   void unsetCursor();
  229 
  230   //! Load a PDF file and display its first page.
  231   //! \param fileName the PDF file to load
  232   //! \param password a string to be tried first as the owner password
  233   //!        and then as the user password
  234   //! \return \c pdfOk if successful; an error code, otherwise
  235   ErrorCode loadFile(const QString &fileName,
  236              const QString &password = "");
  237 
  238   //! Load a PDF file from a memory buffer and display its first page.
  239   //! \param buffer the PDF file in memory
  240   //! \param bufferLength length of \a buffer
  241   //! \param password a string to be tried first as the owner password
  242   //!        and then as the user password
  243   //! \return \c pdfOk if successful; an error code otherwise
  244   ErrorCode loadMem(const char *buffer, unsigned int bufferLength,
  245             const QString &password = "");
  246 
  247   //! Load a PDF file and return a handle.
  248 
  249   //! This function can be safely called from a non-GUI thread.  Use
  250   //! XpdfWidget::loadDoc (on the GUI thread) to load the document
  251   //! handle into the viewer.  The handle returned in *\c docPtr
  252   //! should be passed to either XpdfWidget::loadDoc or
  253   //! XpdfWidget::freeDoc.
  254   //!
  255   //! Calling XpdfWidget::readDoc + XpdfWidget::loadDoc is equivalent
  256   //! to calling XpdfWidget::loadFile.  The difference is that readDoc
  257   //! can be called on a background thread to avoid stalling the user
  258   //! interface.
  259   //! \param docPtr the PDF document handle will be returned her
  260   //! \param fileName the PDF file to load
  261   //! \param password a string to be tried first as the owner password
  262   //!        and then as the user password
  263   //! \return \c pdfOk if successful; an error code, otherwise
  264   ErrorCode readDoc(XpdfDocHandle *docPtr,
  265             const QString &fileName,
  266             const QString &password = "");
  267 
  268   //! Load a PDF document and display its first page.
  269   //! This function displays a PDF document handle created by
  270   //! XpdfWidget::readDoc.  The document handle should not be used for
  271   //! anything else after calling this function.
  272   //! \return \c pdfOk if successful; an error code, otherwise
  273   ErrorCode loadDoc(XpdfDocHandle doc);
  274 
  275   //! Free a PDF document.
  276   //! This function frees a PDF document handle created by
  277   //! XpdfWidget::readDoc.  It should only be called if the document
  278   //! is not going to be displayed.  That is: after calling
  279   //! XpdfWidget::readDoc, you should call either XpdfWidget::loadDoc
  280   //! or XpdfWidget::freeDoc.  The document handle should not be used
  281   //! for anything else after calling this function.
  282   void freeDoc(XpdfDocHandle doc);
  283 
  284   //! Reload the current PDF file.
  285   //! This reloads the current PDF file, maintaining the zoom and
  286   //! scroll position (if possible).  This only works if the PDF file
  287   //! was loaded from a file (i.e., with XpdfWidget::loadFile, not
  288   //! with XpdfWidget::loadMem).
  289   //! \return \c pdfOk if successful; an error code otherwise
  290   ErrorCode reload();
  291 
  292   //! Close the currently open PDF file (if any).
  293   //! Calling this function is optional - the current PDF file will be
  294   //! automatically closed if XpdfWidget::loadFile or XpdfWidget::loadMem
  295   //! is called.
  296   void closeFile();
  297 
  298   //! Save the PDF file with another name.
  299   //! \param fileName the file to be written
  300   //! \return \c pdfOk if successful; an error code otherwise
  301   ErrorCode saveAs(const QString &fileName);
  302 
  303   //! Get the file name of the currently open PDF file.
  304   QString getFileName() const;
  305 
  306   //! Returns true if there is currently a PDF file open.
  307   bool hasOpenDocument() const;
  308 
  309   //! Return the number of pages in the currently open PDF file.
  310   //! Returns -1 if no file is open.
  311   int getNumPages() const;
  312 
  313   //! Return the currently displayed page number.
  314   //! Returns -1 if no file is open.
  315   int getCurrentPage() const;
  316 
  317   //! Return the page number corresponding to the middle of the
  318   //! window.
  319   int getMidPage() const;
  320 
  321   //! Display the specified page.
  322   void gotoPage(int pageNum);
  323 
  324   //! Display the first page.
  325   //! This is equivalent to \code
  326   //!     gotoPage(1)
  327   //! \endcode
  328   void gotoFirstPage();
  329 
  330   //! Display the last page.
  331   //! This is equivalent to \code
  332   //!     gotoPage(getNumPages())
  333   //! \endcode
  334   void gotoLastPage();
  335 
  336   //! Display the next page.
  337   void gotoNextPage(bool scrollToTop = true);
  338 
  339   //! Display the previous page.
  340   void gotoPreviousPage(bool scrollToTop = true);
  341 
  342   //! Go to a named destination.
  343   bool gotoNamedDestination(const QString &dest);
  344 
  345   //! Go forward along the history list.
  346   void goForward();
  347 
  348   //! Go backward along the history list.
  349   void goBackward();
  350 
  351   //! Scroll one screen up.
  352   void scrollPageUp();
  353 
  354   //! Scroll one screen down.
  355   void scrollPageDown();
  356 
  357   //! Scroll the page so that the top-left corner of the window is
  358   //! (\a xx,\a yy) pixels from the top-left corner of the PDF page.
  359   void scrollTo(int xx, int yy);
  360 
  361   //! Scroll the page by (\a dx,\a dy) pixels.  If \a dx is positive,
  362   //! scrolls right; if \a dx is negative, scrolls left.  Similarly,
  363   //! positive and negative values of \a dy scroll down and up,
  364   //! respectively.
  365   void scrollBy(int dx, int dy);
  366 
  367   //! Return the current scroll position x coordinate.
  368   int getScrollX() const;
  369 
  370   //! Return the current scroll position y coordinate.
  371   int getScrollY() const;
  372 
  373   //! Change the zoom factor.
  374   //! This can be a percentage factor (where 100 means 72 dpi) or one of
  375   //! the special values, XpdfWidget::zoomToPage or XpdfWidget::zoomToWidth.
  376   void setZoom(double zoom);
  377 
  378   //! Return the current zoom factor.
  379   //! This can be a percentage factor or one of the special values,
  380   //! XpdfWidget::zoomToPage or XpdfWidget::zoomToWidth.
  381   double getZoom() const;
  382 
  383   //! Return the current zoom factor as a percentage.
  384   //! If the zoom is set to XpdfWidget::zoomToPage or
  385   //! XpdfWidget::zoomToWidth, returns the computed zoom percentage
  386   //! for the specified page, based on the current window size.
  387   double getZoomPercent(int page = 1) const;
  388 
  389   //! Zoom in to the specified rectangle.
  390   //! The coordinate system is the same one used by
  391   //! XpdfWidget::getCurrentSelection.  This function will set the zoom
  392   //! factor and scroll position so that the specified rectangle just fits
  393   //! in the window.
  394   void zoomToRect(int page, double xMin, double yMin,
  395           double xMax, double yMax);
  396 
  397   //! Set the zoom factor, while maintaining the current center.
  398   //! Accepts the same zoom values as XpdfWidget::setZoom.
  399   void zoomCentered(double zoom);
  400 
  401   //! Zoom so that the current page(s) fill the window width.
  402   //! Maintains the vertical center.
  403   void zoomToCurrentWidth();
  404 
  405   //! Change the page rotation.
  406   //! \param rotate rotation angle in degrees - must be 0, 90, 180, or 270
  407   void setRotate(int rotate);
  408 
  409   //! Return the current page rotation.
  410   //! The angle can be 0, 90, 180, or 270.
  411   int getRotate() const;
  412 
  413   //! Set continuous or single-page view mode.
  414   //! Deprecated: this is equivalent to calling setDisplayMode() with
  415   //! pdfDisplaySingle or pdfDisplayContinuous.
  416   //! \param continuous true for continous view mode, false for single-page
  417   //!        view mode
  418   void setContinuousMode(bool continuous);
  419 
  420   //! Return true if the viewer is in continuous view mode, or false
  421   //! if it is in any other mode.  Deprecated: see getDisplayMode().
  422   bool getContinuousMode() const;
  423 
  424   //! Set the display mode.
  425   void setDisplayMode(DisplayMode mode);
  426 
  427   //! Return the current display mode.
  428   DisplayMode getDisplayMode();
  429 
  430   //! Returns true if the mouse is currently over a hyperlink.
  431   bool mouseOverLink();
  432 
  433   //! Returns true if the specified coordinates are inside a
  434   //! hyperlink.  Note: This function expects PDF coordinates, not window
  435   //! coordinates.
  436   bool onLink(int page, double xx, double yy);
  437 
  438   //! Get destination information for the hyperlink at the specified
  439   //! page and coordinates.  If there is a link at the specified
  440   //! point, returns a string suitable for displaying to a user;
  441   //! otherwise returns an empty string.  Note: This function expects
  442   //! PDF coordinates, not window coordinates.
  443   QString getLinkInfo(int page, double xx, double yy);
  444 
  445   //! Get destination information for the hyperlink under the mouse.
  446   //! If the mouse is currently over a hyperlink, return an info
  447   //! string (same as with getLinkInfo()); otherwise return an empty
  448   //! string.
  449   QString getMouseLinkInfo();
  450 
  451   //! Activate the link (if any) at the specified page and coordinates.
  452   //! Returns true if successful.  Note: This function expects PDF
  453   //! coordinates, not window coordinates.
  454   bool gotoLinkAt(int page, double xx, double yy);
  455 
  456   //! Check for an annotation containing the specified point.
  457   //! Returns NULL if there is no annotation at this point.  Note:
  458   //! This function expects PDF coordinates, not window coordinates.
  459   XpdfAnnotHandle onAnnot(int page, double xx, double yy);
  460 
  461   //! Get the annotation type.
  462   QString getAnnotType(XpdfAnnotHandle annot);
  463 
  464   //! Get the annotation's content.
  465   //! Usage of this depends on the annotation type.
  466   QString getAnnotContent(XpdfAnnotHandle annot);
  467 
  468   //! Check for a form field containing the specified point.
  469   //! Returns NULL if there is no annotation at this point.  Note:
  470   //! This function expects PDF coordinates, not window coordinates.
  471   XpdfFormFieldHandle onFormField(int page, double xx, double yy);
  472 
  473   //! Get the form field's type.
  474   QString getFormFieldType(XpdfFormFieldHandle field);
  475 
  476   //! Get the form field's name.
  477   QString getFormFieldName(XpdfFormFieldHandle field);
  478 
  479   //! Get the form field's content.
  480   //! Usage of this depends on the field type.
  481   QString getFormFieldValue(XpdfFormFieldHandle field);
  482 
  483   //! Get the form field's bounding box.
  484   void getFormFieldBBox(XpdfFormFieldHandle field, int *pageNum,
  485             double *xMin, double *yMin,
  486             double *xMax, double *yMax);
  487 
  488   //! Convert window coordinates to PDF coordinates.  Returns true if
  489   //! successful, i.e., if the specified point falls on a PDF page.
  490   bool convertWindowToPDFCoords(int winX, int winY,
  491                 int *page, double *pdfX, double *pdfY);
  492 
  493   //! Convert PDF coordinates to window coordinates.
  494   void convertPDFToWindowCoords(int page, double pdfX, double pdfY,
  495                 int *winX, int *winY);
  496 
  497   //! Enable or disable window redraws.
  498   //! This is useful, e.g., for avoiding extra redraws during window
  499   //! resizing.  Deprecated -- this just calls setUpdatesEnabled().
  500   void enableRedraw(bool enable);
  501 
  502   //! Return the coordinates of the specified page box.
  503   //! \param page the page number
  504   //! \param box the requested page box - one of "media", "crop",
  505   //!        "bleed", "trim", or "art" (\a box is not case-sensitive)
  506   //! \param *xMin returns the minimum x coordinate of the box
  507   //! \param *yMin returns the minimum y coordinate of the box
  508   //! \param *xMax returns the maximum x coordinate of the box
  509   //! \param *yMax returns the maximum y coordinate of the box
  510   //!
  511   //! All coordinates are in points (1 point = 1/72 inch).
  512   void getPageBox(int page, const QString &box,
  513           double *xMin, double *yMin, double *xMax, double *yMax) const;
  514 
  515   //! Return the width of the specified page.
  516   //! This function returns the crop box width, measured in points
  517   //! (1 point = 1/72 inch).
  518   double getPageWidth(int page) const;
  519 
  520   //! Return the height of the specified page.
  521   //! This function returns the crop box height, measured in points
  522   //! (1 point = 1/72 inch).
  523   double getPageHeight(int page) const;
  524 
  525   //! Get the default rotation for the specified page.
  526   //! This is the default viewing rotation specified in the PDF file -
  527   //! it will be one of 0, 90, 180, or 270.
  528   int getPageRotation(int page) const;
  529 
  530   //! Check to see if there is a selection.
  531   //! Returns true if there is a currently active selection.
  532   bool hasSelection();
  533 
  534   //! Returns the current selection.
  535   //! If there is a currently active selection, sets *\a page, (*\a x0,*\a y0),
  536   //! and (*\a x1,*\a y1) to the page number and upper-left and lower-right
  537   //! coordinates, respectively, and returns true.  If there is no selection,
  538   //! returns false.
  539   bool getCurrentSelection(int *page, double *x0, double *y0,
  540                double *x1, double *y1) const;
  541 
  542   //! Set the selection.
  543   //! Sets the current selection to the rectangle with upper-left corner
  544   //! (\a x0,\a y0) and lower-right corner (\a x1,\a y1) on \a page.
  545   void setCurrentSelection(int page, double x0, double y0,
  546                double x1, double y1);
  547 
  548   //! Clear the selection.
  549   void clearSelection();
  550 
  551   //! Check for block selection mode.
  552   //! Returns true if the current selection mode is block.
  553   bool isBlockSelectMode();
  554 
  555   //! Check for linear selection mode.
  556   //! Returns true if the current selection mode is linear.
  557   bool isLinearSelectMode();
  558 
  559   //! Set block selection mode.
  560   //! In this mode, the selection is a simple rectangle.  Any part of
  561   //! the page can be selected, regardless of the content on the page.
  562   void setBlockSelectMode();
  563 
  564   //! Set linear selection mode.
  565   //! In this mode, the selection follows text.  Non-text regions
  566   //! cannot be selected.
  567   void setLinearSelectMode();
  568 
  569   //! Set the selection color.
  570   void setSelectionColor(const QColor &selectionColor);
  571 
  572 
  573   //! Force a complete redraw.
  574   void forceRedraw();
  575 
  576 #if XPDFWIDGET_PRINTING
  577   //! Checks to see if printing is allowed.
  578   //! This function returns false if the currently displayed PDF file
  579   //! is encrypted and does not allow printing (or if no PDF file is
  580   //! currently open).  The owner password can be used to circumvent
  581   //! this: if a valid owner password was supplied to
  582   //! XpdfWidget::loadFile, this function will always return true.  If
  583   //! this function returns false, the printing functions will return
  584   //! an error.
  585   bool okToPrint() const;
  586 
  587   //! Print the currently displayed PDF file.
  588   //! Prints the currently displayed PDF file.  If \a showDialog is
  589   //! true, displays the Qt print dialog, and uses the printer
  590   //! selected by the user.  If \a showDialog is false, prints to the
  591   //! default printer without showing any dialogs.
  592   ErrorCode print(bool showDialog);
  593 
  594   //! Print the currently displayed PDF file.
  595   //! Prints the currently displayed PDF file to \a prt.
  596   ErrorCode print(QPrinter *prt);
  597 
  598   //! Cancel an in-progress print job.  This should be called in
  599   //! response to a printStatus signal.
  600   void cancelPrint() { printCanceled = true; }
  601 
  602   void updatePrintStatus(int nextPage, int firstPage, int lastPage);
  603   bool isPrintCanceled() { return printCanceled; }
  604 
  605   //! Set the horizontal and vertical print resolution, in dots per
  606   //! inch (DPI).  The horizontal and vertical resolutions are
  607   //! typically the same.  (There are exceptions, such as some chart
  608   //! printers.)
  609   void setPrintDPI(int hDPI, int vDPI);
  610 #endif // XPDFWIDGET_PRINTING
  611 
  612   //! Convert a page to a color image.
  613   //! This function converts the page number \a page to a 24-bit RGB
  614   //! bitmap, at a resolution of \a dpi dots per inch.
  615   QImage convertPageToImage(int page, double dpi);
  616 
  617   //! Convert a rectangular region of a page to a color image.
  618   //! This function converts a rectangular region, defined by
  619   //! corners (\a x0,\a y0) and (\a x1,\a y1), of page number \a page
  620   //! to a 24-bit RGB bitmap, at a resolution of \a dpi dots per inch.
  621   QImage convertRegionToImage(int page, double x0, double y0,
  622                   double x1, double y1, double dpi);
  623 
  624   //! Retrieve an embedded thumbnail image.
  625   //! This function returns the embedded thumbnail image for the
  626   //! specified page, or a null image if there is no embedded
  627   //! thumbnail.  This function does not do any rasterization -- it
  628   //! only returns a non-null image if there is an embedded thumbnail
  629   //! in the PDF file.
  630   QImage getThumbnail(int page);
  631 
  632   //! Checks to see if text extraction is allowed.
  633   //! This function returns false if the currently displayed PDF file
  634   //! is encrypted and does not allow extraction of text (or if no PDF
  635   //! file is currently open).  The owner password can be used to
  636   //! circumvent this: if a valid owner password was supplied to
  637   //! XpdfWidget::loadFile, this function will always return true.
  638   //! If this function returns false, the text extraction functions will
  639   //! not return any text.
  640   bool okToExtractText() const;
  641 
  642   //! Set the encoding to use for text extraction.
  643   //! The following encodings are predefined:
  644   //!   - \c "Latin1": ISO-8859-1 (this is the default value)
  645   //!   - \c "ASCII7": 7-bit ASCII
  646   //!   - \c "UTF-8": Unicode in UTF-8 format
  647   //!   - \c "UCS-2": Unicode in UCS-2 format
  648   //!
  649   //! Additional encodings can be defined via the xpdfrc config file.
  650   void setTextEncoding(const QString &encodingName);
  651 
  652   //! Extract text from a region of a page.
  653   //! This function extracts and returns text from the rectangular
  654   //! region, defined by corners (\a x0,\a y0) and (\a x1,\a y1), of
  655   //! page number \a page.  The coordinates returned by
  656   //! XpdfWidget::getCurrentSelection may be passed directly to this
  657   //! function.  Returns an empty string if no file is open or if
  658   //! text extraction is not allowed.
  659   QString extractText(int page, double x0, double y0,
  660               double x1, double y1);
  661 
  662   //! Get the currently selected text.
  663   //! Returns an empty string if there is no selection (or if there is
  664   //! no text in the selected region).
  665   QString getSelectedText();
  666 
  667   //! Copy the current selection to the clipboard.
  668   void copySelection();
  669 
  670   //! Find a text string.
  671   //! This function searches for a Unicode text string.  Starts
  672   //! searching after (before, if searching backward) the current
  673   //! selection (if there is a selection), or at the top (bottom,
  674   //! if searching backward) of the current page (if there is no
  675   //! selection).  The \a flags argument consists of zero or more
  676   //! of the following, or-ed together:
  677   //!   - \c findBackward - search backward from the starting point
  678   //!   - \c findCaseSensitive - perform a case-sensitive search
  679   //!     (default is case-insensitive)
  680   //!   - \c findNext - start searching from the previous search result
  681   //!   - \c findOnePageOnly - limit the search to the current page
  682   //!   - \c findWholeWord - limit the search to whole words
  683   bool find(const QString &text, int flags = 0);
  684 
  685   //! Return the number of children of an outline tree node.
  686   //! This function returns the number of children of node \a outline,
  687   //! or the number of root outline entries if \a outline is \c NULL.
  688   int getOutlineNumChildren(XpdfOutlineHandle outline);
  689 
  690   //! Return a child of an outline tree node.
  691   //! This function returns the \a idx 'th child of node \a outline,
  692   //! or the \a idx 'th root entry if \a outline is \c NULL.
  693   XpdfOutlineHandle getOutlineChild(XpdfOutlineHandle outline, int idx);
  694 
  695   //! Return the parent of an outline tree node.
  696   //! This function returns the parent of node \a outline, or NULL if
  697   //! \a outline is a root item.
  698   XpdfOutlineHandle getOutlineParent(XpdfOutlineHandle outline);
  699 
  700   //! Get the title of an outline tree node.
  701   //! This function returns the title of node \a outline.
  702   QString getOutlineTitle(XpdfOutlineHandle outline);
  703 
  704   //! Return true if the specified outline entry starts open.
  705   bool getOutlineStartsOpen(XpdfOutlineHandle outline);
  706 
  707   //! Return the target page number for the specified outline entry.
  708   int getOutlineTargetPage(XpdfOutlineHandle outline);
  709 
  710   //! Jump to the target of the specified outline entry.
  711   void gotoOutlineTarget(XpdfOutlineHandle outline);
  712 
  713   //! Return the number of layers in the PDF file.
  714   //! Note that a PDF file can have zero or more layers.
  715   int getNumLayers() const;
  716 
  717   //! Get a layer handle.
  718   //! This function returns a handle for the \a idx 'th layer.
  719   XpdfLayerHandle getLayer(int idx) const;
  720 
  721   //! Get the name of a layer.
  722   //! This function returns the title of \a layer.
  723   QString getLayerName(XpdfLayerHandle layer) const;
  724 
  725   //! Get the visibility state of a layer.
  726   //! Returns true if the layer is currently visible, false if not.
  727   bool getLayerVisibility(XpdfLayerHandle layer) const;
  728 
  729   //! Set the visibility state of a layer.
  730   //! \param layer the layer handle
  731   //! \param visibility the new state - true for visible, false for not
  732   //!        visible
  733   void setLayerVisibility(XpdfLayerHandle layer, bool visibility);
  734 
  735   //! Get the suggested state for this layer in viewing mode.
  736   //! This function returns one of:
  737   //!   -  1: on
  738   //!   -  0: off
  739   //!   - -1: unset
  740   int getLayerViewState(XpdfLayerHandle layer) const;
  741 
  742   //! Get the suggested state for this layer in printing mode.
  743   //! This function returns one of:
  744   //!   -  1: on
  745   //!   -  0: off
  746   //!   - -1: unset
  747   int getLayerPrintState(XpdfLayerHandle layer) const;
  748 
  749   //! Get the root of the layer display order tree.
  750   XpdfLayerOrderHandle getLayerOrderRoot() const;
  751 
  752   //! Check the type of a layer display order tree node.
  753   //! Returns true if the specified node of the layer display order
  754   //! tree is a name; false if the node is a layer.
  755   bool getLayerOrderIsName(XpdfLayerOrderHandle order) const;
  756 
  757   //! Get the name of a layer display order tree node.
  758   //! This should only be called if getLayerOrderIsName returns true.
  759   QString getLayerOrderName(XpdfLayerOrderHandle order) const;
  760 
  761   //! Get the layer associated with a layer display order tree node.
  762   XpdfLayerHandle getLayerOrderLayer(XpdfLayerOrderHandle order);
  763 
  764   //! Returns the number of children attached to a layer display order
  765   //! tree node.
  766   int getLayerOrderNumChildren(XpdfLayerOrderHandle order);
  767 
  768   //! Returns the \a idx 'th child of a layer display order tree node.
  769   XpdfLayerOrderHandle getLayerOrderChild(XpdfLayerOrderHandle order, int idx);
  770 
  771   //! Return the parent of a layer display order tree node.
  772   //! This function returns the parent of node \a order, or NULL if \a
  773   //! order is the root node.
  774   XpdfLayerOrderHandle getLayerOrderParent(XpdfLayerOrderHandle order);
  775 
  776   //! Return the number of embedded files in the current PDF file.
  777   int getNumEmbeddedFiles();
  778 
  779   //! Return the name of the \a idx 'th embedded file.
  780   QString getEmbeddedFileName(int idx);
  781 
  782   //! Save the \a idx 'th embedded file with the specified file name.
  783   //! Returns true if successful.
  784   bool saveEmbeddedFile(int idx, QString fileName);
  785 
  786   //--- for internal use
  787 
  788   //! \cond
  789 
  790   virtual QSize sizeHint() const;
  791   QtPDFCore *getCore() { return core; }
  792 
  793   //! \endcond
  794 
  795 signals:
  796 
  797   //! This signal is emitted whenever the viewer displays a new page.
  798   //! It can be triggered by user actions (e.g., the PageDown button),
  799   //! or program control (e.g., the gotoNextPage function).
  800   //! \param pageNum - the new page number
  801   void pageChange(int pageNum);
  802 
  803   //! This signal is emitted whenever the page shown at the middle of
  804   //! the window changes.
  805   //! It is similar to XpdfWidget::pageChange, except that it reflects
  806   //! the page shown at the middle of the window (instead of the page
  807   //! at the top of the window).
  808   void midPageChange(int pageNum);
  809 
  810   //! This signal is emitted just before a PDF file is loaded.
  811   void preLoad();
  812 
  813   //! This signal is emitted just after a PDF file is loaded.
  814   void postLoad();
  815 
  816   //! This signal is emitted whenever a key is pressed.
  817   void keyPress(QKeyEvent *e);
  818 
  819   //! This signal is emitted whenever a mouse button is pressed.
  820   void mousePress(QMouseEvent *e);
  821 
  822   //! This signal is emitted whenever a mouse button is released.
  823   void mouseRelease(QMouseEvent *e);
  824 
  825   //! This signal is emitted whenever the mouse pointer is moved.
  826   void mouseMove(QMouseEvent *e);
  827 
  828   //! This signal is emitted whenever a mouse wheel is clicked.
  829   void mouseWheel(QWheelEvent *e);
  830 
  831   //! This signal is emitted whenever the user clicks on a hyperlink.
  832   //! \param linkType the type of link - one of:
  833   //!          - \c "goto": a link to another page in the same PDF
  834   //!            file - \a dest is empty; \a page is the destination
  835   //!            page number
  836   //!          - \c "pdf": a link to another PDF file - \a dest is the
  837   //!            target PDF file; \a page is 0
  838   //!          - \c "launch": an arbitrary command to be run - \a dest
  839   //!            is the command; \a page is 0
  840   //!          - \c "url": a URL link - \a dest is the URL; \a page is 0
  841   //!          - \c "named": a "named action" link - \a dest is the
  842   //!            action (see the PDF spec for details); \a page is 0
  843   //!          - \c "unknown": an unknown link type - \a dest is empty;
  844   //!            \a page is 0
  845   //! \param dest destination string
  846   //! \param page destination page number
  847   void linkClick(const QString &linkType, const QString &dest, int page);
  848 
  849   //! This signal is emitted when the user selects an area.
  850   //! Use XpdfWidget::getCurrentSelection to retrieve the selection.
  851   void selectDone();
  852 
  853   //! This signal is emitted whenever the widget is repainted.  \a
  854   //! finished is true if the painted view is complete, or false if
  855   //! this was an incremental update, i.e., if the view is still being
  856   //! rendered.
  857   void paintDone(bool finished);
  858 
  859   //! This signal is emitted when the widget is resized.
  860   void resized();
  861 
  862 
  863 #if XPDFWIDGET_PRINTING
  864   //! This signal is called before each page is spooled, and after the
  865   //! last page is spooled.  It is typically used to update a print
  866   //! status dialog.  \a nextPage is the next page to be printed.
  867   //! \a firstPage and \a lastPage specify the range of pages being
  868   //! printed.
  869   void printStatus(int nextPage, int firstPage, int lastPage);
  870 #endif
  871 
  872   //! \cond PROTECTED
  873 
  874   void tileDone();
  875 
  876   //! \endcond
  877 
  878 protected:
  879 
  880   //! \cond PROTECTED
  881 
  882   virtual void paintEvent(QPaintEvent *eventA);
  883   virtual void resizeEvent(QResizeEvent *eventA);
  884   virtual void scrollContentsBy(int dx, int dy);
  885   virtual void keyPressEvent(QKeyEvent *e);
  886   virtual void mousePressEvent(QMouseEvent *e);
  887   virtual void mouseReleaseEvent(QMouseEvent *e);
  888   virtual void mouseMoveEvent(QMouseEvent *e);
  889   virtual void wheelEvent(QWheelEvent *e);
  890   virtual bool eventFilter(QObject *obj, QEvent *event);
  891 
  892   //! \endcond
  893 
  894 private slots:
  895 
  896   void tick();
  897 
  898 private:
  899 
  900   void setup(const QColor &paperColor, const QColor &matteColor,
  901          bool reverseVideo);
  902   static void updateCbk(void *data, GString *fileName,
  903             int pageNum, int numPages,
  904             const char *linkLabel);
  905   static void midPageChangedCbk(void *data, int pageNum);
  906   static void preLoadCbk(void *data);
  907   static void postLoadCbk(void *data);
  908   static void linkCbk(void *data, const char *type,
  909               const char *dest, int page);
  910   static void selectDoneCbk(void *data);
  911   static void paintDoneCbk(void *data, bool finished);
  912   static void tileDoneCbk(void *data);
  913 
  914   friend class XpdfViewer;
  915   bool getLinkTarget(int page, double xx, double yy,
  916              QString &targetFileName, int &targetPage,
  917              QString &targetDest);
  918 
  919 #if XPDFWIDGET_PRINTING
  920   QPrinter *printerForDialog;
  921   QPrintDialog *printDialog;
  922   int printHDPI, printVDPI;
  923   bool printCanceled;
  924 #endif
  925 
  926   static QMutex initMutex;
  927 
  928   QtPDFCore *core;
  929   double scaleFactor;
  930 
  931   bool keyPassthrough;
  932   bool mousePassthrough;
  933 
  934   bool touchPanEnabled;
  935   bool touchZoomEnabled;
  936   double pinchZoomStart;
  937 
  938   QTimer *tickTimer;
  939 };
  940 
  941 #endif