📄 pdfwidget.h
字号:
#include <qscrollview.h>#include <poppler/poppler-qt.h>#include <qstring.h>#include <qrect.h>class QPixmap;class QImage;class QPainter;class QWidget;class QKeyEvent;class QMouseEvent;class QLabel;class QPoint;class RenderThread;/** This is the id of the QCustomEvent with which the renderer thread notifies * the pdfWidget that it is ready and a new pixmap is available. */enum { PageReady = 1001, PagePreview };#define FIT_TO_PAGE 0#define FIT_TO_WIDTH 1// used for the navigation stackclass PageNum { public: PageNum() {}; PageNum(int p) : _page(p) { }; int getPageNum() { return _page; }; private: int _page;};enum { Up = 0, Down, Left, Right};enum { Back = 0, Forward };class PDFWidget : public QScrollView { Q_OBJECTpublic: PDFWidget( Poppler::Document *d = 0, QWidget *parent = 0, const char* name = 0, bool helpViewer = false); ~PDFWidget(); void setDocument( Poppler::Document *d, int scale = 72); /** return the current page number. It starts with one. */ int getPageNumber(); int getNumPages(); bool arePagesInHistory(); void invalidatePixmap(void); bool rendererRunning(void); void setHotspot(QSize s);public slots: void nextPage(); void prevPage(); void lastPage(); void firstPage(); void jumpToPage(int page); void redisplay(); void scrollUp(int factor); void scrollDown(int factor); void scrollLeft(int factor); void scrollRight(int factor); void zoomIn(); void zoomOut(); bool zoomIsUpperBound(); bool zoomIsLowerBound(); bool zoomIsDefault(); void moveBack(); void followLink(); void setFitToPage(); void setFitToWidth();signals: void rendererRunning(bool running); /** Emited when we display or leave the last page */ void isLastPage(bool last); /** Emited when we display or leave the last page. */ void isFirstPage(bool first); /** Emited when the current page isn't completly rendered because the user aborted the renderer. */ void currentPageIsAborted(); void zoomChanged(); void pagesInHistory(bool pages); void hotspot(void);protected: void drawContents( QPainter *painter, int, int, int, int ); void viewportMousePressEvent ( QMouseEvent * e); void viewportMouseReleaseEvent ( QMouseEvent * e); void viewportMouseMoveEvent ( QMouseEvent * e); void customEvent(QCustomEvent *e); void resizeEvent(QResizeEvent *);private slots: void pageReady(void*); void pagePreview(void* d);private: void display(); void prevPagePanning(); void viewportMousePressEventPanning(QMouseEvent *e); void viewportMouseReleaseEventPanning(QMouseEvent *e); void viewportMouseMoveEventPanning(QMouseEvent * e); void setZoom(unsigned int dpi); int fitToPageDpi() const; int fitToWidthDpi() const; int fitToPagePercent() const; int dpiToPercent(int dpi) const; void recalcZoomAndDisplay(); int getPageWidth() const; int getPageHeight() const; void drawLinks(QPixmap *pixmap, int selectedLink); /** When switching to a new page we have to reposition the ScrollViewContents. Rendering the page costs time so we do it in another thread and wait till it's finished. Based on the method which requested the new page we wan't the content positioned differently. So a method can use this to request a new position for the new page. The values are used when the page is ready*/ void scheduleContentsPosUpdate(int x, int y); void emitNavSignals(); unsigned int m_scale; int currentPage; QPixmap *pixmap; int borderWidth; Poppler::Document *doc; Poppler::Page *page; RenderThread *renderThread; bool m_panning; QPoint* m_panningPos; int zoomLevel; static int maxZoomLevel; int scheduledContentsPosX, scheduledContentsPosY; bool firstPreview; int selectedLink; bool m_linkSelected; QPoint *m_LinkPos; int x_origin, y_origin; QValueList<PageNum> navStack; void updateViewRect(); int selectLink(); int selectNextLink(int direction, int currentLink); QRect viewRect; int direction; QSize m_hotspot;};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -