2020-01-18 11:38:54 +01:00
|
|
|
// Copyright (C) 2018-2020 Jakub Melka
|
2019-01-27 17:55:22 +01:00
|
|
|
//
|
|
|
|
// This file is part of PdfForQt.
|
|
|
|
//
|
|
|
|
// PdfForQt is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// PdfForQt is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef PDFDRAWWIDGET_H
|
|
|
|
#define PDFDRAWWIDGET_H
|
|
|
|
|
|
|
|
#include "pdfglobal.h"
|
2019-02-24 19:42:00 +01:00
|
|
|
#include "pdfrenderer.h"
|
2019-01-27 17:55:22 +01:00
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QScrollBar>
|
2019-09-01 18:26:52 +02:00
|
|
|
#include <QOpenGLWidget>
|
2019-01-27 17:55:22 +01:00
|
|
|
|
|
|
|
namespace pdf
|
|
|
|
{
|
|
|
|
class PDFDocument;
|
2019-12-25 17:56:17 +01:00
|
|
|
class PDFCMSManager;
|
2020-01-25 17:36:25 +01:00
|
|
|
class PDFToolManager;
|
2019-01-27 17:55:22 +01:00
|
|
|
class PDFDrawWidget;
|
2020-04-26 19:43:45 +02:00
|
|
|
class PDFFormManager;
|
2019-01-27 17:55:22 +01:00
|
|
|
class PDFDrawWidgetProxy;
|
2020-04-25 14:21:06 +02:00
|
|
|
class PDFModifiedDocument;
|
2020-04-20 19:03:32 +02:00
|
|
|
class PDFWidgetAnnotationManager;
|
|
|
|
class IDrawWidgetInputInterface;
|
2019-01-27 17:55:22 +01:00
|
|
|
|
2019-09-01 18:26:52 +02:00
|
|
|
class IDrawWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~IDrawWidget() = default;
|
|
|
|
|
|
|
|
virtual QWidget* getWidget() = 0;
|
|
|
|
|
|
|
|
/// Returns page indices, which are currently displayed in the widget
|
|
|
|
virtual std::vector<PDFInteger> getCurrentPages() const = 0;
|
|
|
|
};
|
|
|
|
|
2019-01-27 17:55:22 +01:00
|
|
|
class PDFFORQTLIBSHARED_EXPORT PDFWidget : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2019-09-08 11:13:59 +02:00
|
|
|
/// Constructs new PDFWidget.
|
2019-12-25 17:56:17 +01:00
|
|
|
/// \param cmsManager Color management system manager
|
2019-09-08 11:13:59 +02:00
|
|
|
/// \param engine Rendering engine type
|
|
|
|
/// \param samplesCount Samples count for rendering engine MSAA antialiasing
|
2019-12-25 17:56:17 +01:00
|
|
|
explicit PDFWidget(const PDFCMSManager* cmsManager, RendererEngine engine, int samplesCount, QWidget* parent);
|
2019-01-27 17:55:22 +01:00
|
|
|
virtual ~PDFWidget() override;
|
|
|
|
|
2020-04-26 19:43:45 +02:00
|
|
|
virtual bool focusNextPrevChild(bool next) override;
|
|
|
|
|
2019-02-24 19:42:00 +01:00
|
|
|
using PageRenderingErrors = std::map<PDFInteger, QList<PDFRenderError>>;
|
|
|
|
|
2019-01-27 17:55:22 +01:00
|
|
|
/// Sets the document to be viewed in this widget. Document can be nullptr,
|
2019-07-04 17:52:38 +02:00
|
|
|
/// in that case, widget contents are cleared. Optional content activity can be nullptr,
|
|
|
|
/// if this occurs, no content is suppressed.
|
2019-01-27 17:55:22 +01:00
|
|
|
/// \param document Document
|
2020-04-25 14:21:06 +02:00
|
|
|
void setDocument(const PDFModifiedDocument& document);
|
2019-01-27 17:55:22 +01:00
|
|
|
|
2019-09-08 11:13:59 +02:00
|
|
|
/// Update rendering engine according the settings
|
|
|
|
/// \param engine Engine type
|
|
|
|
/// \param samplesCount Samples count for rendering engine MSAA antialiasing
|
|
|
|
void updateRenderer(RendererEngine engine, int samplesCount);
|
|
|
|
|
2019-12-15 19:28:25 +01:00
|
|
|
/// Updates cache limits
|
|
|
|
/// \param compiledPageCacheLimit Compiled page cache limit [bytes]
|
|
|
|
/// \param thumbnailsCacheLimit Thumbnail image cache limit [kB]
|
|
|
|
/// \param fontCacheLimit Font cache limit [-]
|
|
|
|
/// \param instancedFontCacheLimit Instanced font cache limit [-]
|
|
|
|
void updateCacheLimits(int compiledPageCacheLimit, int thumbnailsCacheLimit, int fontCacheLimit, int instancedFontCacheLimit);
|
|
|
|
|
2019-12-25 17:56:17 +01:00
|
|
|
const PDFCMSManager* getCMSManager() const { return m_cmsManager; }
|
2020-01-25 17:36:25 +01:00
|
|
|
PDFToolManager* getToolManager() const { return m_toolManager; }
|
2020-04-20 19:03:32 +02:00
|
|
|
PDFWidgetAnnotationManager* getAnnotationManager() const { return m_annotationManager; }
|
2019-09-01 18:26:52 +02:00
|
|
|
IDrawWidget* getDrawWidget() const { return m_drawWidget; }
|
2019-01-27 17:55:22 +01:00
|
|
|
QScrollBar* getHorizontalScrollbar() const { return m_horizontalScrollBar; }
|
|
|
|
QScrollBar* getVerticalScrollbar() const { return m_verticalScrollBar; }
|
|
|
|
PDFDrawWidgetProxy* getDrawWidgetProxy() const { return m_proxy; }
|
2019-02-24 19:42:00 +01:00
|
|
|
const PageRenderingErrors* getPageRenderingErrors() const { return &m_pageRenderingErrors; }
|
|
|
|
int getPageRenderingErrorCount() const;
|
2020-04-20 19:03:32 +02:00
|
|
|
const std::vector<IDrawWidgetInputInterface*>& getInputInterfaces() const { return m_inputInterfaces; }
|
2019-02-24 19:42:00 +01:00
|
|
|
|
2020-04-20 19:03:32 +02:00
|
|
|
void setToolManager(PDFToolManager* toolManager);
|
|
|
|
void setAnnotationManager(PDFWidgetAnnotationManager* annotationManager);
|
2020-01-25 17:36:25 +01:00
|
|
|
|
2020-04-26 19:43:45 +02:00
|
|
|
PDFFormManager* getFormManager() const;
|
|
|
|
void setFormManager(PDFFormManager* formManager);
|
|
|
|
|
2019-02-24 19:42:00 +01:00
|
|
|
signals:
|
|
|
|
void pageRenderingErrorsChanged(PDFInteger pageIndex, int errorsCount);
|
2019-01-27 17:55:22 +01:00
|
|
|
|
|
|
|
private:
|
2019-12-15 16:45:49 +01:00
|
|
|
void updateRendererImpl();
|
2019-02-24 19:42:00 +01:00
|
|
|
void onRenderingError(PDFInteger pageIndex, const QList<PDFRenderError>& errors);
|
2019-12-14 19:09:34 +01:00
|
|
|
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
|
2019-02-24 19:42:00 +01:00
|
|
|
|
2019-09-08 11:13:59 +02:00
|
|
|
IDrawWidget* createDrawWidget(RendererEngine rendererEngine, int samplesCount);
|
|
|
|
|
2020-04-20 19:03:32 +02:00
|
|
|
void removeInputInterface(IDrawWidgetInputInterface* inputInterface);
|
|
|
|
void addInputInterface(IDrawWidgetInputInterface* inputInterface);
|
|
|
|
|
2019-12-25 17:56:17 +01:00
|
|
|
const PDFCMSManager* m_cmsManager;
|
2020-01-25 17:36:25 +01:00
|
|
|
PDFToolManager* m_toolManager;
|
2020-04-20 19:03:32 +02:00
|
|
|
PDFWidgetAnnotationManager* m_annotationManager;
|
2020-04-26 19:43:45 +02:00
|
|
|
PDFFormManager* m_formManager;
|
2019-09-01 18:26:52 +02:00
|
|
|
IDrawWidget* m_drawWidget;
|
2019-01-27 17:55:22 +01:00
|
|
|
QScrollBar* m_horizontalScrollBar;
|
|
|
|
QScrollBar* m_verticalScrollBar;
|
|
|
|
PDFDrawWidgetProxy* m_proxy;
|
2019-02-24 19:42:00 +01:00
|
|
|
PageRenderingErrors m_pageRenderingErrors;
|
2020-04-20 19:03:32 +02:00
|
|
|
std::vector<IDrawWidgetInputInterface*> m_inputInterfaces;
|
2019-01-27 17:55:22 +01:00
|
|
|
};
|
|
|
|
|
2019-09-01 18:26:52 +02:00
|
|
|
template<typename BaseWidget>
|
|
|
|
class PDFDrawWidgetBase : public BaseWidget, public IDrawWidget
|
2019-01-27 17:55:22 +01:00
|
|
|
{
|
|
|
|
public:
|
2019-09-01 18:26:52 +02:00
|
|
|
explicit PDFDrawWidgetBase(PDFWidget* widget, QWidget* parent);
|
|
|
|
virtual ~PDFDrawWidgetBase() override = default;
|
2019-01-27 17:55:22 +01:00
|
|
|
|
2019-02-24 19:42:00 +01:00
|
|
|
/// Returns page indices, which are currently displayed in the widget
|
2019-09-01 18:26:52 +02:00
|
|
|
virtual std::vector<PDFInteger> getCurrentPages() const override;
|
2019-02-24 19:42:00 +01:00
|
|
|
|
2019-01-27 17:55:22 +01:00
|
|
|
virtual QSize minimumSizeHint() const override;
|
2019-09-01 18:26:52 +02:00
|
|
|
virtual QWidget* getWidget() override { return this; }
|
2019-01-27 17:55:22 +01:00
|
|
|
|
|
|
|
protected:
|
2020-05-10 11:38:33 +02:00
|
|
|
virtual bool event(QEvent* event) override;
|
2019-01-27 17:55:22 +01:00
|
|
|
virtual void keyPressEvent(QKeyEvent* event) override;
|
2020-04-28 19:55:30 +02:00
|
|
|
virtual void keyReleaseEvent(QKeyEvent* event) override;
|
2019-02-02 18:10:00 +01:00
|
|
|
virtual void mousePressEvent(QMouseEvent* event) override;
|
|
|
|
virtual void mouseReleaseEvent(QMouseEvent* event) override;
|
|
|
|
virtual void mouseMoveEvent(QMouseEvent* event) override;
|
|
|
|
virtual void wheelEvent(QWheelEvent* event) override;
|
2019-01-27 17:55:22 +01:00
|
|
|
|
2019-09-01 18:26:52 +02:00
|
|
|
PDFWidget* getPDFWidget() const { return m_widget; }
|
|
|
|
|
2019-01-27 17:55:22 +01:00
|
|
|
private:
|
2020-01-25 17:36:25 +01:00
|
|
|
void updateCursor();
|
|
|
|
|
2020-04-20 19:03:32 +02:00
|
|
|
template<typename Event, void(IDrawWidgetInputInterface::* Function)(QWidget*, Event*)>
|
|
|
|
bool processEvent(Event* event);
|
|
|
|
|
2019-02-02 18:10:00 +01:00
|
|
|
enum class MouseOperation
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Translate
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Performs the mouse operation (under the current mouse position)
|
|
|
|
/// \param currentMousePosition Current position of the mouse
|
|
|
|
void performMouseOperation(QPoint currentMousePosition);
|
|
|
|
|
2019-01-27 17:55:22 +01:00
|
|
|
PDFWidget* m_widget;
|
2019-02-02 18:10:00 +01:00
|
|
|
QPoint m_lastMousePosition;
|
|
|
|
MouseOperation m_mouseOperation;
|
2019-01-27 17:55:22 +01:00
|
|
|
};
|
|
|
|
|
2019-09-01 18:26:52 +02:00
|
|
|
class PDFOpenGLDrawWidget : public PDFDrawWidgetBase<QOpenGLWidget>
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFDrawWidgetBase<QOpenGLWidget>;
|
|
|
|
|
|
|
|
public:
|
2019-09-08 11:13:59 +02:00
|
|
|
explicit PDFOpenGLDrawWidget(PDFWidget* widget, int samplesCount, QWidget* parent);
|
2019-09-01 18:26:52 +02:00
|
|
|
virtual ~PDFOpenGLDrawWidget() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void resizeGL(int w, int h) override;
|
|
|
|
virtual void initializeGL() override;
|
|
|
|
virtual void paintGL() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PDFDrawWidget : public PDFDrawWidgetBase<QWidget>
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFDrawWidgetBase<QWidget>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFDrawWidget(PDFWidget* widget, QWidget* parent);
|
|
|
|
virtual ~PDFDrawWidget() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void paintEvent(QPaintEvent* event) override;
|
|
|
|
virtual void resizeEvent(QResizeEvent* event) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern template class PDFDrawWidgetBase<QOpenGLWidget>;
|
|
|
|
extern template class PDFDrawWidgetBase<QWidget>;
|
|
|
|
|
2019-01-27 17:55:22 +01:00
|
|
|
} // namespace pdf
|
|
|
|
|
|
|
|
#endif // PDFDRAWWIDGET_H
|