2021-04-30 20:12:10 +02:00
|
|
|
// Copyright (C) 2020-2021 Jakub Melka
|
2020-12-03 19:58:50 +01:00
|
|
|
//
|
2021-08-10 19:22:56 +02:00
|
|
|
// This file is part of PDF4QT.
|
2020-12-03 19:58:50 +01:00
|
|
|
//
|
2021-08-10 19:22:56 +02:00
|
|
|
// PDF4QT is free software: you can redistribute it and/or modify
|
2020-12-03 19:58: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-12-03 19:58:50 +01:00
|
|
|
//
|
2021-08-10 19:22:56 +02:00
|
|
|
// PDF4QT is distributed in the hope that it will be useful,
|
2020-12-03 19:58: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-12-03 19:58:50 +01:00
|
|
|
|
|
|
|
#ifndef PDFADVANCEDTOOLS_H
|
|
|
|
#define PDFADVANCEDTOOLS_H
|
|
|
|
|
|
|
|
#include "pdfwidgettool.h"
|
|
|
|
#include "pdfannotation.h"
|
|
|
|
|
|
|
|
class QActionGroup;
|
|
|
|
|
|
|
|
namespace pdf
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Tool that creates 'sticky note' annotations. Multiple types of sticky
|
|
|
|
/// notes are available, user can select a type of sticky note. When
|
|
|
|
/// user select a point, popup window appears and user can enter a text.
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateStickyNoteTool : public PDFWidgetTool
|
2020-12-03 19:58:50 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFWidgetTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateStickyNoteTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QActionGroup* actionGroup, QObject* parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void updateActions() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onActionTriggered(QAction* action);
|
|
|
|
void onPointPicked(PDFInteger pageIndex, QPointF pagePoint);
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
QActionGroup* m_actionGroup;
|
|
|
|
PDFPickTool* m_pickTool;
|
2020-12-04 19:22:20 +01:00
|
|
|
TextAnnotationIcon m_icon;
|
2020-12-03 19:58:50 +01:00
|
|
|
};
|
|
|
|
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateAnnotationTool : public PDFWidgetTool
|
2020-12-05 17:51:54 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFWidgetTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateAnnotationTool(PDFDrawWidgetProxy* proxy, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void updateActions() override;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Tool that creates url link annotation. Multiple types of link highlights
|
|
|
|
/// are available, user can select a link highlight. When link annotation
|
|
|
|
/// is clicked, url address is triggered.
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateHyperlinkTool : public PDFCreateAnnotationTool
|
2020-12-05 17:51:54 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFCreateAnnotationTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateHyperlinkTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
LinkHighlightMode getHighlightMode() const;
|
|
|
|
void setHighlightMode(const LinkHighlightMode& highlightMode);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
PDFPickTool* m_pickTool;
|
|
|
|
LinkHighlightMode m_highlightMode = LinkHighlightMode::Outline;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Tool that creates free text note without callout line.
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateFreeTextTool : public PDFCreateAnnotationTool
|
2020-12-05 17:51:54 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFCreateAnnotationTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateFreeTextTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
PDFPickTool* m_pickTool;
|
|
|
|
};
|
|
|
|
|
2020-12-06 18:51:33 +01:00
|
|
|
/// Tool that creates line/polyline/polygon annotations.
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateLineTypeTool : public PDFCreateAnnotationTool
|
2020-12-06 18:51:33 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFCreateAnnotationTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum class Type
|
|
|
|
{
|
|
|
|
Line,
|
|
|
|
PolyLine,
|
|
|
|
Polygon
|
|
|
|
};
|
|
|
|
|
|
|
|
explicit PDFCreateLineTypeTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, Type type, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event) override;
|
|
|
|
virtual void keyReleaseEvent(QWidget* widget, QKeyEvent* event) override;
|
|
|
|
virtual void drawPage(QPainter* painter, PDFInteger pageIndex,
|
|
|
|
const PDFPrecompiledPage* compiledPage,
|
|
|
|
PDFTextLayoutGetter& layoutGetter,
|
|
|
|
const QMatrix& pagePointToDevicePointMatrix,
|
|
|
|
QList<PDFRenderError>& errors) const override;
|
|
|
|
|
|
|
|
PDFReal getPenWidth() const;
|
|
|
|
void setPenWidth(PDFReal penWidth);
|
|
|
|
|
|
|
|
QColor getStrokeColor() const;
|
|
|
|
void setStrokeColor(const QColor& strokeColor);
|
|
|
|
|
|
|
|
QColor getFillColor() const;
|
|
|
|
void setFillColor(const QColor& fillColor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onPointPicked(PDFInteger pageIndex, QPointF pagePoint);
|
|
|
|
void finishDefinition();
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
PDFPickTool* m_pickTool;
|
|
|
|
Type m_type;
|
|
|
|
PDFReal m_penWidth;
|
|
|
|
QColor m_strokeColor;
|
|
|
|
QColor m_fillColor;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Tool that creates ellipse annotation.
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateEllipseTool : public PDFCreateAnnotationTool
|
2020-12-06 18:51:33 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFCreateAnnotationTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateEllipseTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
virtual void drawPage(QPainter* painter, PDFInteger pageIndex,
|
|
|
|
const PDFPrecompiledPage* compiledPage,
|
|
|
|
PDFTextLayoutGetter& layoutGetter,
|
|
|
|
const QMatrix& pagePointToDevicePointMatrix,
|
|
|
|
QList<PDFRenderError>& errors) const override;
|
|
|
|
|
|
|
|
PDFReal getPenWidth() const;
|
|
|
|
void setPenWidth(PDFReal penWidth);
|
|
|
|
|
|
|
|
QColor getStrokeColor() const;
|
|
|
|
void setStrokeColor(const QColor& strokeColor);
|
|
|
|
|
|
|
|
QColor getFillColor() const;
|
|
|
|
void setFillColor(const QColor& fillColor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
PDFPickTool* m_pickTool;
|
|
|
|
PDFReal m_penWidth;
|
|
|
|
QColor m_strokeColor;
|
|
|
|
QColor m_fillColor;
|
|
|
|
};
|
|
|
|
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateFreehandCurveTool : public PDFCreateAnnotationTool
|
2020-12-08 20:18:11 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFCreateAnnotationTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateFreehandCurveTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
virtual void drawPage(QPainter* painter, PDFInteger pageIndex,
|
|
|
|
const PDFPrecompiledPage* compiledPage,
|
|
|
|
PDFTextLayoutGetter& layoutGetter,
|
|
|
|
const QMatrix& pagePointToDevicePointMatrix,
|
|
|
|
QList<PDFRenderError>& errors) const override;
|
|
|
|
|
|
|
|
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
|
|
|
|
PDFReal getPenWidth() const;
|
|
|
|
void setPenWidth(const PDFReal& penWidth);
|
|
|
|
|
|
|
|
QColor getStrokeColor() const;
|
|
|
|
void setStrokeColor(const QColor& strokeColor);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void resetTool();
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
PDFInteger m_pageIndex;
|
|
|
|
std::vector<QPointF> m_pickedPoints;
|
|
|
|
PDFReal m_penWidth;
|
|
|
|
QColor m_strokeColor;
|
|
|
|
};
|
|
|
|
|
2020-12-10 19:27:26 +01:00
|
|
|
/// Tool that creates 'stamp' annotations. Multiple types of stamps
|
|
|
|
/// are available, user can select a type of stamp (text).
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateStampTool : public PDFWidgetTool
|
2020-12-10 19:27:26 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFWidgetTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateStampTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QActionGroup* actionGroup, QObject* parent);
|
|
|
|
|
|
|
|
virtual void drawPage(QPainter* painter, PDFInteger pageIndex,
|
|
|
|
const PDFPrecompiledPage* compiledPage,
|
|
|
|
PDFTextLayoutGetter& layoutGetter,
|
|
|
|
const QMatrix& pagePointToDevicePointMatrix,
|
|
|
|
QList<PDFRenderError>& errors) const override;
|
|
|
|
|
|
|
|
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void updateActions() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onActionTriggered(QAction* action);
|
|
|
|
void onPointPicked(PDFInteger pageIndex, QPointF pagePoint);
|
|
|
|
|
|
|
|
pdf::PDFInteger m_pageIndex;
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
QActionGroup* m_actionGroup;
|
|
|
|
PDFPickTool* m_pickTool;
|
|
|
|
PDFStampAnnotation m_stampAnnotation;
|
|
|
|
};
|
|
|
|
|
2020-12-11 18:59:39 +01:00
|
|
|
/// Tool for highlighting of text in document
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateHighlightTextTool : public PDFWidgetTool
|
2020-12-11 18:59:39 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
2020-12-12 18:08:37 +01:00
|
|
|
using BaseClass = PDFWidgetTool;
|
2020-12-11 18:59:39 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Creates new highlight text tool
|
|
|
|
/// \param proxy Proxy
|
|
|
|
/// \param type Annotation type, must be one of: Highlight, Underline, Squiggly, StrikeOut
|
2020-12-12 18:08:37 +01:00
|
|
|
/// \param actionGroup Action group with actions. Each action must define annotation type.
|
2020-12-11 18:59:39 +01:00
|
|
|
/// \param parent Parent
|
2020-12-12 18:08:37 +01:00
|
|
|
explicit PDFCreateHighlightTextTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QActionGroup* actionGroup, QObject* parent);
|
2020-12-11 18:59:39 +01:00
|
|
|
|
|
|
|
virtual void drawPage(QPainter* painter,
|
|
|
|
PDFInteger pageIndex,
|
|
|
|
const PDFPrecompiledPage* compiledPage,
|
|
|
|
PDFTextLayoutGetter& layoutGetter,
|
|
|
|
const QMatrix& pagePointToDevicePointMatrix,
|
|
|
|
QList<PDFRenderError>& errors) const override;
|
|
|
|
|
|
|
|
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
|
|
|
|
protected:
|
2020-12-12 18:08:37 +01:00
|
|
|
virtual void updateActions() override;
|
2020-12-11 18:59:39 +01:00
|
|
|
virtual void setActiveImpl(bool active) override;
|
|
|
|
|
|
|
|
private:
|
2020-12-12 18:08:37 +01:00
|
|
|
void onActionTriggered(QAction* action);
|
2020-12-11 18:59:39 +01:00
|
|
|
void updateCursor();
|
|
|
|
void setSelection(pdf::PDFTextSelection&& textSelection);
|
|
|
|
|
|
|
|
struct SelectionInfo
|
|
|
|
{
|
|
|
|
PDFInteger pageIndex = -1;
|
|
|
|
QPointF selectionStartPoint;
|
|
|
|
};
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
2020-12-12 18:08:37 +01:00
|
|
|
QActionGroup* m_actionGroup;
|
2020-12-11 18:59:39 +01:00
|
|
|
AnnotationType m_type;
|
|
|
|
pdf::PDFTextSelection m_textSelection;
|
|
|
|
SelectionInfo m_selectionInfo;
|
|
|
|
bool m_isCursorOverText;
|
|
|
|
};
|
|
|
|
|
2020-12-26 17:59:06 +01:00
|
|
|
/// Tool that creates redaction annotation from rectangle. Rectangle is not
|
|
|
|
/// selected from the text, it is just any rectangle.
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateRedactRectangleTool : public PDFCreateAnnotationTool
|
2020-12-26 17:59:06 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFCreateAnnotationTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateRedactRectangleTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
PDFPickTool* m_pickTool;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Tool for redaction of text in document. Creates redaction annotation from text selection.
|
2021-08-10 19:22:56 +02:00
|
|
|
class PDF4QTLIBSHARED_EXPORT PDFCreateRedactTextTool : public PDFWidgetTool
|
2020-12-26 17:59:06 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private:
|
|
|
|
using BaseClass = PDFWidgetTool;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit PDFCreateRedactTextTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
|
|
|
|
|
|
|
|
virtual void drawPage(QPainter* painter,
|
|
|
|
PDFInteger pageIndex,
|
|
|
|
const PDFPrecompiledPage* compiledPage,
|
|
|
|
PDFTextLayoutGetter& layoutGetter,
|
|
|
|
const QMatrix& pagePointToDevicePointMatrix,
|
|
|
|
QList<PDFRenderError>& errors) const override;
|
|
|
|
|
|
|
|
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void updateActions() override;
|
|
|
|
virtual void setActiveImpl(bool active) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateCursor();
|
|
|
|
void setSelection(pdf::PDFTextSelection&& textSelection);
|
|
|
|
|
|
|
|
struct SelectionInfo
|
|
|
|
{
|
|
|
|
PDFInteger pageIndex = -1;
|
|
|
|
QPointF selectionStartPoint;
|
|
|
|
};
|
|
|
|
|
|
|
|
PDFToolManager* m_toolManager;
|
|
|
|
pdf::PDFTextSelection m_textSelection;
|
|
|
|
SelectionInfo m_selectionInfo;
|
|
|
|
bool m_isCursorOverText;
|
|
|
|
};
|
|
|
|
|
2020-12-03 19:58:50 +01:00
|
|
|
} // namespace pdf
|
|
|
|
|
|
|
|
#endif // PDFADVANCEDTOOLS_H
|