PDF4QT/PdfForQtLib/sources/pdfdrawwidget.h

112 lines
3.7 KiB
C++

// Copyright (C) 2018-2019 Jakub Melka
//
// 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"
#include "pdfrenderer.h"
#include <QWidget>
#include <QScrollBar>
namespace pdf
{
class PDFDocument;
class PDFDrawWidget;
class PDFDrawWidgetProxy;
class PDFFORQTLIBSHARED_EXPORT PDFWidget : public QWidget
{
Q_OBJECT
public:
explicit PDFWidget(QWidget* parent);
virtual ~PDFWidget() override;
using PageRenderingErrors = std::map<PDFInteger, QList<PDFRenderError>>;
/// Sets the document to be viewed in this widget. Document can be nullptr,
/// in that case, widget contents are cleared. Optional content activity can be nullptr,
/// if this occurs, no content is suppressed.
/// \param document Document
/// \param optionalContentActivity Optional content activity
void setDocument(const PDFDocument* document, const PDFOptionalContentActivity* optionalContentActivity);
PDFDrawWidget* getDrawWidget() const { return m_drawWidget; }
QScrollBar* getHorizontalScrollbar() const { return m_horizontalScrollBar; }
QScrollBar* getVerticalScrollbar() const { return m_verticalScrollBar; }
PDFDrawWidgetProxy* getDrawWidgetProxy() const { return m_proxy; }
const PageRenderingErrors* getPageRenderingErrors() const { return &m_pageRenderingErrors; }
int getPageRenderingErrorCount() const;
signals:
void pageRenderingErrorsChanged(PDFInteger pageIndex, int errorsCount);
private:
void onRenderingError(PDFInteger pageIndex, const QList<PDFRenderError>& errors);
PDFDrawWidget* m_drawWidget;
QScrollBar* m_horizontalScrollBar;
QScrollBar* m_verticalScrollBar;
PDFDrawWidgetProxy* m_proxy;
PageRenderingErrors m_pageRenderingErrors;
};
class PDFFORQTLIBSHARED_EXPORT PDFDrawWidget : public QWidget
{
Q_OBJECT
public:
explicit PDFDrawWidget(PDFWidget* widget, QWidget* parent);
virtual ~PDFDrawWidget() override;
/// Returns page indices, which are currently displayed in the widget
std::vector<PDFInteger> getCurrentPages() const;
virtual QSize minimumSizeHint() const override;
protected:
virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
virtual void keyPressEvent(QKeyEvent* event) override;
virtual void mousePressEvent(QMouseEvent* event) override;
virtual void mouseReleaseEvent(QMouseEvent* event) override;
virtual void mouseMoveEvent(QMouseEvent* event) override;
virtual void wheelEvent(QWheelEvent* event) override;
private:
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);
PDFWidget* m_widget;
QPoint m_lastMousePosition;
MouseOperation m_mouseOperation;
};
} // namespace pdf
#endif // PDFDRAWWIDGET_H