mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Signature plugin: dot plugin
This commit is contained in:
@ -309,4 +309,63 @@ void PDFCreatePCElementSvgTool::onRectanglePicked(PDFInteger pageIndex, QRectF p
|
|||||||
setActive(false);
|
setActive(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDFCreatePCElementDotTool::PDFCreatePCElementDotTool(PDFDrawWidgetProxy* proxy,
|
||||||
|
PDFPageContentScene* scene,
|
||||||
|
QAction* action,
|
||||||
|
QObject* parent) :
|
||||||
|
BaseClass(proxy, scene, action, parent),
|
||||||
|
m_pickTool(nullptr),
|
||||||
|
m_element(nullptr)
|
||||||
|
{
|
||||||
|
m_pickTool = new PDFPickTool(proxy, PDFPickTool::Mode::Points, this);
|
||||||
|
m_pickTool->setDrawSelectionRectangle(false);
|
||||||
|
addTool(m_pickTool);
|
||||||
|
connect(m_pickTool, &PDFPickTool::pointPicked, this, &PDFCreatePCElementDotTool::onPointPicked);
|
||||||
|
|
||||||
|
QPen pen(Qt::SolidLine);
|
||||||
|
pen.setWidthF(5.0);
|
||||||
|
pen.setCapStyle(Qt::RoundCap);
|
||||||
|
|
||||||
|
m_element = new PDFPageContentElementDot();
|
||||||
|
m_element->setBrush(Qt::NoBrush);
|
||||||
|
m_element->setPen(std::move(pen));
|
||||||
|
|
||||||
|
updateActions();
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFCreatePCElementDotTool::~PDFCreatePCElementDotTool()
|
||||||
|
{
|
||||||
|
delete m_element;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFCreatePCElementDotTool::drawPage(QPainter* painter,
|
||||||
|
PDFInteger pageIndex,
|
||||||
|
const PDFPrecompiledPage* compiledPage,
|
||||||
|
PDFTextLayoutGetter& layoutGetter,
|
||||||
|
const QMatrix& pagePointToDevicePointMatrix,
|
||||||
|
QList<PDFRenderError>& errors) const
|
||||||
|
{
|
||||||
|
BaseClass::drawPage(painter, pageIndex, compiledPage, layoutGetter, pagePointToDevicePointMatrix, errors);
|
||||||
|
|
||||||
|
QPointF point = pagePointToDevicePointMatrix.inverted().map(m_pickTool->getSnappedPoint());
|
||||||
|
|
||||||
|
PDFPainterStateGuard guard(painter);
|
||||||
|
painter->setWorldMatrix(pagePointToDevicePointMatrix, true);
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter->setPen(m_element->getPen());
|
||||||
|
painter->setBrush(m_element->getBrush());
|
||||||
|
painter->drawPoint(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PDFCreatePCElementDotTool::onPointPicked(PDFInteger pageIndex, QPointF pagePoint)
|
||||||
|
{
|
||||||
|
m_element->setPageIndex(pageIndex);
|
||||||
|
m_element->setPoint(pagePoint);
|
||||||
|
|
||||||
|
m_scene->addElement(m_element->clone());
|
||||||
|
m_element->setPageIndex(-1);
|
||||||
|
|
||||||
|
setActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdf
|
} // namespace pdf
|
||||||
|
@ -25,6 +25,7 @@ namespace pdf
|
|||||||
|
|
||||||
class PDFPageContentScene;
|
class PDFPageContentScene;
|
||||||
class PDFPageContentSvgElement;
|
class PDFPageContentSvgElement;
|
||||||
|
class PDFPageContentElementDot;
|
||||||
class PDFPageContentElementLine;
|
class PDFPageContentElementLine;
|
||||||
class PDFPageContentElementRectangle;
|
class PDFPageContentElementRectangle;
|
||||||
|
|
||||||
@ -135,6 +136,35 @@ private:
|
|||||||
std::optional<QPointF> m_startPoint;
|
std::optional<QPointF> m_startPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Tool that creates dot element.
|
||||||
|
class PDF4QTLIBSHARED_EXPORT PDFCreatePCElementDotTool : public PDFCreatePCElementTool
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
using BaseClass = PDFCreatePCElementTool;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit PDFCreatePCElementDotTool(PDFDrawWidgetProxy* proxy,
|
||||||
|
PDFPageContentScene* scene,
|
||||||
|
QAction* action,
|
||||||
|
QObject* parent);
|
||||||
|
virtual ~PDFCreatePCElementDotTool() override;
|
||||||
|
|
||||||
|
virtual void drawPage(QPainter* painter,
|
||||||
|
PDFInteger pageIndex,
|
||||||
|
const PDFPrecompiledPage* compiledPage,
|
||||||
|
PDFTextLayoutGetter& layoutGetter,
|
||||||
|
const QMatrix& pagePointToDevicePointMatrix,
|
||||||
|
QList<PDFRenderError>& errors) const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onPointPicked(pdf::PDFInteger pageIndex, QPointF pagePoint);
|
||||||
|
|
||||||
|
PDFPickTool* m_pickTool;
|
||||||
|
PDFPageContentElementDot* m_element;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace pdf
|
} // namespace pdf
|
||||||
|
|
||||||
#endif // PDFPAGECONTENTEDITORTOOLS_H
|
#endif // PDFPAGECONTENTEDITORTOOLS_H
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "pdfpagecontenteditorwidget.h"
|
#include "pdfpagecontenteditorwidget.h"
|
||||||
#include "ui_pdfpagecontenteditorwidget.h"
|
#include "ui_pdfpagecontenteditorwidget.h"
|
||||||
|
#include "pdfwidgetutils.h"
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
@ -31,6 +32,13 @@ PDFPageContentEditorWidget::PDFPageContentEditorWidget(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
m_toolButtonIconSize = PDFWidgetUtils::scaleDPI(this, QSize(32, 32));
|
||||||
|
|
||||||
|
for (QToolButton* button : findChildren<QToolButton*>())
|
||||||
|
{
|
||||||
|
button->setIconSize(m_toolButtonIconSize);
|
||||||
|
}
|
||||||
|
|
||||||
connect(&m_actionMapper, &QSignalMapper::mappedObject, this, &PDFPageContentEditorWidget::onActionTriggerRequest);
|
connect(&m_actionMapper, &QSignalMapper::mappedObject, this, &PDFPageContentEditorWidget::onActionTriggerRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,6 +77,7 @@ void PDFPageContentEditorWidget::addAction(QAction* action)
|
|||||||
button->setChecked(action->isChecked());
|
button->setChecked(action->isChecked());
|
||||||
button->setEnabled(action->isEnabled());
|
button->setEnabled(action->isEnabled());
|
||||||
button->setShortcut(action->shortcut());
|
button->setShortcut(action->shortcut());
|
||||||
|
button->setIconSize(m_toolButtonIconSize);
|
||||||
m_actionMapper.setMapping(button, action);
|
m_actionMapper.setMapping(button, action);
|
||||||
connect(button, &QToolButton::clicked, &m_actionMapper, QOverload<>::of(&QSignalMapper::map));
|
connect(button, &QToolButton::clicked, &m_actionMapper, QOverload<>::of(&QSignalMapper::map));
|
||||||
connect(action, &QAction::changed, this, &PDFPageContentEditorWidget::onActionChanged);
|
connect(action, &QAction::changed, this, &PDFPageContentEditorWidget::onActionChanged);
|
||||||
|
@ -49,6 +49,7 @@ private:
|
|||||||
Ui::PDFPageContentEditorWidget* ui;
|
Ui::PDFPageContentEditorWidget* ui;
|
||||||
QSignalMapper m_actionMapper;
|
QSignalMapper m_actionMapper;
|
||||||
int m_toolBoxColumnCount;
|
int m_toolBoxColumnCount;
|
||||||
|
QSize m_toolButtonIconSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pdf
|
} // namespace pdf
|
||||||
|
@ -426,6 +426,8 @@ void PDFPageContentElementDot::drawPage(QPainter* painter,
|
|||||||
PDFPainterStateGuard guard(painter);
|
PDFPainterStateGuard guard(painter);
|
||||||
painter->setWorldMatrix(pagePointToDevicePointMatrix, true);
|
painter->setWorldMatrix(pagePointToDevicePointMatrix, true);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
painter->setPen(getPen());
|
||||||
|
painter->setBrush(getBrush());
|
||||||
painter->drawPoint(m_point);
|
painter->drawPoint(m_point);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,6 +128,7 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget)
|
|||||||
m_tools[HorizontalLineTool] = new pdf::PDFCreatePCElementLineTool(widget->getDrawWidgetProxy(), &m_scene, createHorizontalLineAction, true, false, this);
|
m_tools[HorizontalLineTool] = new pdf::PDFCreatePCElementLineTool(widget->getDrawWidgetProxy(), &m_scene, createHorizontalLineAction, true, false, this);
|
||||||
m_tools[VerticalLineTool] = new pdf::PDFCreatePCElementLineTool(widget->getDrawWidgetProxy(), &m_scene, createVerticalLineAction, false, true, this);
|
m_tools[VerticalLineTool] = new pdf::PDFCreatePCElementLineTool(widget->getDrawWidgetProxy(), &m_scene, createVerticalLineAction, false, true, this);
|
||||||
m_tools[LineTool] = new pdf::PDFCreatePCElementLineTool(widget->getDrawWidgetProxy(), &m_scene, createLineAction, false, false, this);
|
m_tools[LineTool] = new pdf::PDFCreatePCElementLineTool(widget->getDrawWidgetProxy(), &m_scene, createLineAction, false, false, this);
|
||||||
|
m_tools[DotTool] = new pdf::PDFCreatePCElementDotTool(widget->getDrawWidgetProxy(), &m_scene, createDotAction, this);
|
||||||
|
|
||||||
pdf::PDFToolManager* toolManager = widget->getToolManager();
|
pdf::PDFToolManager* toolManager = widget->getToolManager();
|
||||||
for (pdf::PDFWidgetTool* tool : m_tools)
|
for (pdf::PDFWidgetTool* tool : m_tools)
|
||||||
@ -159,18 +160,6 @@ std::vector<QAction*> SignaturePlugin::getActions() const
|
|||||||
std::vector<QAction*> result;
|
std::vector<QAction*> result;
|
||||||
|
|
||||||
result.push_back(m_actions[Activate]);
|
result.push_back(m_actions[Activate]);
|
||||||
result.push_back(m_actions[Text]);
|
|
||||||
result.push_back(m_actions[FreehandCurve]);
|
|
||||||
result.push_back(m_actions[AcceptMark]);
|
|
||||||
result.push_back(m_actions[RejectMark]);
|
|
||||||
result.push_back(m_actions[Rectangle]);
|
|
||||||
result.push_back(m_actions[RoundedRectangle]);
|
|
||||||
result.push_back(m_actions[HorizontalLine]);
|
|
||||||
result.push_back(m_actions[VerticalLine]);
|
|
||||||
result.push_back(m_actions[Line]);
|
|
||||||
result.push_back(m_actions[Dot]);
|
|
||||||
result.push_back(m_actions[Clear]);
|
|
||||||
result.push_back(nullptr);
|
|
||||||
result.push_back(m_actions[SignElectronically]);
|
result.push_back(m_actions[SignElectronically]);
|
||||||
result.push_back(m_actions[SignDigitally]);
|
result.push_back(m_actions[SignDigitally]);
|
||||||
result.push_back(m_actions[Certificates]);
|
result.push_back(m_actions[Certificates]);
|
||||||
@ -277,6 +266,7 @@ void SignaturePlugin::updateDockWidget()
|
|||||||
m_editorWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
m_editorWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
m_dataExchangeInterface->getMainWindow()->addDockWidget(Qt::RightDockWidgetArea, m_editorWidget, Qt::Vertical);
|
m_dataExchangeInterface->getMainWindow()->addDockWidget(Qt::RightDockWidgetArea, m_editorWidget, Qt::Vertical);
|
||||||
m_editorWidget->setFloating(false);
|
m_editorWidget->setFloating(false);
|
||||||
|
m_editorWidget->setWindowTitle(tr("Signature Toolbox"));
|
||||||
|
|
||||||
for (QAction* action : m_actions)
|
for (QAction* action : m_actions)
|
||||||
{
|
{
|
||||||
|
@ -86,6 +86,7 @@ private:
|
|||||||
HorizontalLineTool,
|
HorizontalLineTool,
|
||||||
VerticalLineTool,
|
VerticalLineTool,
|
||||||
LineTool,
|
LineTool,
|
||||||
|
DotTool,
|
||||||
LastTool
|
LastTool
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user