Signature plugin: style settings

This commit is contained in:
Jakub Melka
2022-04-10 19:30:12 +02:00
parent e5dd010609
commit 1325f87a10
11 changed files with 527 additions and 77 deletions

View File

@@ -139,6 +139,7 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget)
for (pdf::PDFWidgetTool* tool : m_tools)
{
toolManager->addTool(tool);
connect(tool, &pdf::PDFWidgetTool::toolActivityChanged, this, &SignaturePlugin::onToolActivityChanged);
}
m_widget->addInputInterface(&m_scene);
@@ -206,6 +207,76 @@ void SignaturePlugin::onWidgetSelectionChanged()
m_scene.setSelectedElementIds(m_editorWidget->getSelection());
}
pdf::PDFWidgetTool* SignaturePlugin::getActiveTool()
{
for (pdf::PDFWidgetTool* currentTool : m_tools)
{
if (currentTool->isActive())
{
return currentTool;
}
}
return nullptr;
}
void SignaturePlugin::onToolActivityChanged()
{
if (m_editorWidget)
{
pdf::PDFWidgetTool* activeTool = getActiveTool();
const pdf::PDFPageContentElement* element = nullptr;
pdf::PDFCreatePCElementTool* tool = qobject_cast<pdf::PDFCreatePCElementTool*>(activeTool);
if (tool)
{
element = tool->getElement();
}
m_editorWidget->loadStyleFromElement(element);
}
}
void SignaturePlugin::onPenChanged(const QPen& pen)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setPen(pen);
}
}
void SignaturePlugin::onBrushChanged(const QBrush& brush)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setBrush(brush);
}
}
void SignaturePlugin::onFontChanged(const QFont& font)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setFont(font);
}
}
void SignaturePlugin::onAlignmentChanged(Qt::Alignment alignment)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setAlignment(alignment);
}
}
void SignaturePlugin::onTextAngleChanged(pdf::PDFReal angle)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
{
activeTool->setTextAngle(angle);
}
}
void SignaturePlugin::setActive(bool active)
{
if (m_scene.isActive() != active)
@@ -325,6 +396,12 @@ void SignaturePlugin::updateDockWidget()
{
m_editorWidget->addAction(action);
}
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::penChanged, this, &SignaturePlugin::onPenChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::brushChanged, this, &SignaturePlugin::onBrushChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::fontChanged, this, &SignaturePlugin::onFontChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::alignmentChanged, this, &SignaturePlugin::onAlignmentChanged);
connect(m_editorWidget, &pdf::PDFPageContentEditorWidget::textAngleChanged, this, &SignaturePlugin::onTextAngleChanged);
}
}

View File

@@ -51,6 +51,13 @@ private:
void onSceneChanged(bool graphicsOnly);
void onSceneSelectionChanged();
void onWidgetSelectionChanged();
void onToolActivityChanged();
void onPenChanged(const QPen& pen);
void onBrushChanged(const QBrush& brush);
void onFontChanged(const QFont& font);
void onAlignmentChanged(Qt::Alignment alignment);
void onTextAngleChanged(pdf::PDFReal angle);
enum Action
{
@@ -106,6 +113,7 @@ private:
pdf::PDFPageContentScene m_scene;
bool m_sceneSelectionChangeEnabled;
pdf::PDFWidgetTool* getActiveTool();
};
} // namespace pdfplugin