2021-04-30 20:12:10 +02:00
|
|
|
// Copyright (C) 2020-2021 Jakub Melka
|
2020-03-07 17:38:50 +01:00
|
|
|
//
|
2021-08-10 19:22:56 +02:00
|
|
|
// This file is part of PDF4QT.
|
2020-03-07 17:38:50 +01:00
|
|
|
//
|
2021-08-10 19:22:56 +02:00
|
|
|
// PDF4QT is free software: you can redistribute it and/or modify
|
2020-03-07 17:38:50 +01:00
|
|
|
// 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
|
2021-04-30 20:12:10 +02:00
|
|
|
// with the written consent of the copyright owner, any later version.
|
2020-03-07 17:38:50 +01:00
|
|
|
//
|
2021-08-10 19:22:56 +02:00
|
|
|
// PDF4QT is distributed in the hope that it will be useful,
|
2020-03-07 17:38:50 +01:00
|
|
|
// 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
|
2021-08-10 19:22:56 +02:00
|
|
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
2020-03-07 17:38:50 +01:00
|
|
|
|
|
|
|
#ifndef PDFDOCUMENTDRAWINTERFACE_H
|
|
|
|
#define PDFDOCUMENTDRAWINTERFACE_H
|
|
|
|
|
|
|
|
#include "pdfglobal.h"
|
2020-04-18 19:01:49 +02:00
|
|
|
#include "pdfexception.h"
|
2020-03-07 17:38:50 +01:00
|
|
|
|
|
|
|
class QPainter;
|
2020-04-20 19:03:32 +02:00
|
|
|
class QKeyEvent;
|
|
|
|
class QMouseEvent;
|
|
|
|
class QWheelEvent;
|
2020-03-07 17:38:50 +01:00
|
|
|
|
|
|
|
namespace pdf
|
|
|
|
{
|
|
|
|
class PDFPrecompiledPage;
|
|
|
|
class PDFTextLayoutGetter;
|
|
|
|
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT IDocumentDrawInterface
|
2020-03-07 17:38:50 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit inline IDocumentDrawInterface() = default;
|
|
|
|
virtual ~IDocumentDrawInterface() = default;
|
|
|
|
|
|
|
|
/// Performs drawing of additional graphics onto the painter using precompiled page,
|
|
|
|
/// optionally text layout and page point to device point matrix.
|
|
|
|
/// \param painter Painter
|
|
|
|
/// \param pageIndex Page index
|
|
|
|
/// \param compiledPage Compiled page
|
|
|
|
/// \param layoutGetter Layout getter
|
|
|
|
/// \param pagePointToDevicePointMatrix Matrix mapping page space to device point space
|
2020-04-18 19:01:49 +02:00
|
|
|
/// \param[out] errors Output parameter - rendering errors
|
2020-03-07 17:38:50 +01:00
|
|
|
virtual void drawPage(QPainter* painter,
|
|
|
|
pdf::PDFInteger pageIndex,
|
|
|
|
const PDFPrecompiledPage* compiledPage,
|
|
|
|
PDFTextLayoutGetter& layoutGetter,
|
2020-04-18 19:01:49 +02:00
|
|
|
const QMatrix& pagePointToDevicePointMatrix,
|
|
|
|
QList<PDFRenderError>& errors) const;
|
2020-03-07 17:38:50 +01:00
|
|
|
|
|
|
|
/// Performs drawing of additional graphics after all pages are drawn onto the painter.
|
|
|
|
/// \param painter Painter
|
|
|
|
/// \param rect Draw rectangle (usually viewport rectangle of the pdf widget)
|
|
|
|
virtual void drawPostRendering(QPainter* painter, QRect rect) const;
|
|
|
|
};
|
|
|
|
|
2020-04-20 19:03:32 +02:00
|
|
|
/// Input interface for handling events. Implementations should react on these events,
|
|
|
|
/// and set it to accepted, if they were consumed by the interface. Interface, which
|
|
|
|
/// consumes mouse press event, should also consume mouse release event.
|
|
|
|
class IDrawWidgetInputInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit inline IDrawWidgetInputInterface() = default;
|
|
|
|
virtual ~IDrawWidgetInputInterface() = default;
|
|
|
|
|
|
|
|
enum InputPriority
|
|
|
|
{
|
|
|
|
ToolPriority = 10,
|
|
|
|
FormPriority = 20,
|
|
|
|
AnnotationPriority = 30
|
|
|
|
};
|
|
|
|
|
2020-05-10 11:38:33 +02:00
|
|
|
/// Handles shortcut override event. Accept this event, when you want given
|
|
|
|
/// key sequence to be propagated to keyPressEvent.
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) = 0;
|
|
|
|
|
2020-04-20 19:03:32 +02:00
|
|
|
/// Handles key press event from widget
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event) = 0;
|
|
|
|
|
2020-04-28 19:55:30 +02:00
|
|
|
/// Handles key release event from widget
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void keyReleaseEvent(QWidget* widget, QKeyEvent* event) = 0;
|
|
|
|
|
2020-04-20 19:03:32 +02:00
|
|
|
/// Handles mouse press event from widget
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) = 0;
|
|
|
|
|
2020-05-10 16:41:06 +02:00
|
|
|
/// Handles mouse double click event from widget
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void mouseDoubleClickEvent(QWidget* widget, QMouseEvent* event) = 0;
|
|
|
|
|
2020-04-20 19:03:32 +02:00
|
|
|
/// Handles mouse release event from widget
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) = 0;
|
|
|
|
|
|
|
|
/// Handles mouse move event from widget
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) = 0;
|
|
|
|
|
|
|
|
/// Handles mouse wheel event from widget
|
|
|
|
/// \param widget Widget
|
|
|
|
/// \param event Event
|
|
|
|
virtual void wheelEvent(QWidget* widget, QWheelEvent* event) = 0;
|
|
|
|
|
|
|
|
/// Returns tooltip
|
|
|
|
virtual QString getTooltip() const = 0;
|
|
|
|
|
|
|
|
/// Returns current cursor
|
|
|
|
virtual const std::optional<QCursor>& getCursor() const = 0;
|
|
|
|
|
|
|
|
/// Returns input priority (interfaces with higher priority
|
|
|
|
/// will get input events before interfaces with lower priority)
|
|
|
|
virtual int getInputPriority() const = 0;
|
|
|
|
|
|
|
|
class Comparator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit constexpr inline Comparator() = default;
|
|
|
|
|
|
|
|
bool operator()(IDrawWidgetInputInterface* left, IDrawWidgetInputInterface* right) const
|
|
|
|
{
|
|
|
|
return std::make_pair(left->getInputPriority(), left) < std::make_pair(right->getInputPriority(), right);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr Comparator getComparator() { return Comparator(); }
|
|
|
|
};
|
|
|
|
|
2020-03-07 17:38:50 +01:00
|
|
|
} // namespace pdf
|
|
|
|
|
|
|
|
#endif // PDFDOCUMENTDRAWINTERFACE_H
|