Signature plugin: dot plugin

This commit is contained in:
Jakub Melka 2022-02-27 17:08:24 +01:00
parent c642722faf
commit 7d84f26476
7 changed files with 104 additions and 12 deletions

View File

@ -309,4 +309,63 @@ void PDFCreatePCElementSvgTool::onRectanglePicked(PDFInteger pageIndex, QRectF p
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

View File

@ -25,6 +25,7 @@ namespace pdf
class PDFPageContentScene;
class PDFPageContentSvgElement;
class PDFPageContentElementDot;
class PDFPageContentElementLine;
class PDFPageContentElementRectangle;
@ -135,6 +136,35 @@ private:
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
#endif // PDFPAGECONTENTEDITORTOOLS_H

View File

@ -17,6 +17,7 @@
#include "pdfpagecontenteditorwidget.h"
#include "ui_pdfpagecontenteditorwidget.h"
#include "pdfwidgetutils.h"
#include <QAction>
#include <QToolButton>
@ -31,6 +32,13 @@ PDFPageContentEditorWidget::PDFPageContentEditorWidget(QWidget *parent) :
{
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);
}
@ -69,6 +77,7 @@ void PDFPageContentEditorWidget::addAction(QAction* action)
button->setChecked(action->isChecked());
button->setEnabled(action->isEnabled());
button->setShortcut(action->shortcut());
button->setIconSize(m_toolButtonIconSize);
m_actionMapper.setMapping(button, action);
connect(button, &QToolButton::clicked, &m_actionMapper, QOverload<>::of(&QSignalMapper::map));
connect(action, &QAction::changed, this, &PDFPageContentEditorWidget::onActionChanged);

View File

@ -49,6 +49,7 @@ private:
Ui::PDFPageContentEditorWidget* ui;
QSignalMapper m_actionMapper;
int m_toolBoxColumnCount;
QSize m_toolButtonIconSize;
};
} // namespace pdf

View File

@ -426,6 +426,8 @@ void PDFPageContentElementDot::drawPage(QPainter* painter,
PDFPainterStateGuard guard(painter);
painter->setWorldMatrix(pagePointToDevicePointMatrix, true);
painter->setRenderHint(QPainter::Antialiasing);
painter->setPen(getPen());
painter->setBrush(getBrush());
painter->drawPoint(m_point);
}

View File

@ -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[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[DotTool] = new pdf::PDFCreatePCElementDotTool(widget->getDrawWidgetProxy(), &m_scene, createDotAction, this);
pdf::PDFToolManager* toolManager = widget->getToolManager();
for (pdf::PDFWidgetTool* tool : m_tools)
@ -159,18 +160,6 @@ std::vector<QAction*> SignaturePlugin::getActions() const
std::vector<QAction*> result;
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[SignDigitally]);
result.push_back(m_actions[Certificates]);
@ -277,6 +266,7 @@ void SignaturePlugin::updateDockWidget()
m_editorWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
m_dataExchangeInterface->getMainWindow()->addDockWidget(Qt::RightDockWidgetArea, m_editorWidget, Qt::Vertical);
m_editorWidget->setFloating(false);
m_editorWidget->setWindowTitle(tr("Signature Toolbox"));
for (QAction* action : m_actions)
{

View File

@ -86,6 +86,7 @@ private:
HorizontalLineTool,
VerticalLineTool,
LineTool,
DotTool,
LastTool
};