2019-07-01 12:35:53 +02:00
|
|
|
// Copyright (C) 2018-2019 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;
|
|
|
|
class PDFDrawWidget;
|
|
|
|
class PDFDrawWidgetProxy;
|
|
|
|
|
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.
|
|
|
|
/// \param engine Rendering engine type
|
|
|
|
/// \param samplesCount Samples count for rendering engine MSAA antialiasing
|
|
|
|
explicit PDFWidget(RendererEngine engine, int samplesCount, QWidget* parent);
|
2019-01-27 17:55:22 +01:00
|
|
|
virtual ~PDFWidget() 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
|
2019-07-04 17:52:38 +02:00
|
|
|
/// \param optionalContentActivity Optional content activity
|
|
|
|
void setDocument(const PDFDocument* document, const PDFOptionalContentActivity* optionalContentActivity);
|
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-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;
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void pageRenderingErrorsChanged(PDFInteger pageIndex, int errorsCount);
|
2019-01-27 17:55:22 +01:00
|
|
|
|
|
|
|
private:
|
2019-02-24 19:42:00 +01:00
|
|
|
void onRenderingError(PDFInteger pageIndex, const QList<PDFRenderError>& errors);
|
|
|
|
|
2019-09-08 11:13:59 +02:00
|
|
|
IDrawWidget* createDrawWidget(RendererEngine rendererEngine, int samplesCount);
|
|
|
|
|
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;
|
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:
|
|
|
|
virtual void keyPressEvent(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:
|
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
|