PDF4QT/PdfForQtLib/sources/pdfdrawwidget.h

110 lines
3.5 KiB
C
Raw Normal View History

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>
namespace pdf
{
class PDFDocument;
class PDFDrawWidget;
class PDFDrawWidgetProxy;
class PDFFORQTLIBSHARED_EXPORT PDFWidget : public QWidget
{
Q_OBJECT
public:
explicit PDFWidget(QWidget* parent);
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,
/// in that case, widget contents are cleared.
/// \param document Document
void setDocument(const PDFDocument* document);
PDFDrawWidget* getDrawWidget() const { return m_drawWidget; }
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-01-27 17:55:22 +01:00
PDFDrawWidget* m_drawWidget;
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
};
class PDFFORQTLIBSHARED_EXPORT PDFDrawWidget : public QWidget
{
Q_OBJECT
public:
explicit PDFDrawWidget(PDFWidget* widget, QWidget* parent);
virtual ~PDFDrawWidget() override;
2019-02-24 19:42:00 +01:00
/// Returns page indices, which are currently displayed in the widget
std::vector<PDFInteger> getCurrentPages() const;
2019-01-27 17:55:22 +01:00
virtual QSize minimumSizeHint() const override;
protected:
virtual void paintEvent(QPaintEvent* event) override;
virtual void resizeEvent(QResizeEvent* event) override;
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
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
};
} // namespace pdf
#endif // PDFDRAWWIDGET_H