diff --git a/Pdf4QtLib/sources/pdfpagecontenteditorwidget.cpp b/Pdf4QtLib/sources/pdfpagecontenteditorwidget.cpp index ca9f58b..ca5cbbe 100644 --- a/Pdf4QtLib/sources/pdfpagecontenteditorwidget.cpp +++ b/Pdf4QtLib/sources/pdfpagecontenteditorwidget.cpp @@ -18,14 +18,20 @@ #include "pdfpagecontenteditorwidget.h" #include "ui_pdfpagecontenteditorwidget.h" +#include +#include + namespace pdf { PDFPageContentEditorWidget::PDFPageContentEditorWidget(QWidget *parent) : QDockWidget(parent), - ui(new Ui::PDFPageContentEditorWidget) + ui(new Ui::PDFPageContentEditorWidget), + m_toolBoxColumnCount(6) { ui->setupUi(this); + + connect(&m_actionMapper, &QSignalMapper::mappedObject, this, &PDFPageContentEditorWidget::onActionTriggerRequest); } PDFPageContentEditorWidget::~PDFPageContentEditorWidget() @@ -33,4 +39,61 @@ PDFPageContentEditorWidget::~PDFPageContentEditorWidget() delete ui; } +void PDFPageContentEditorWidget::addAction(QAction* action) +{ + // First, find position for our action + int row = 0; + int column = 0; + + while (true) + { + if (!ui->toolGroupBoxLayout->itemAtPosition(row, column)) + { + break; + } + + ++column; + + if (column == m_toolBoxColumnCount) + { + column = 0; + ++row; + } + } + + QToolButton* button = new QToolButton(this); + button->setIcon(action->icon()); + button->setText(action->text()); + button->setToolTip(action->toolTip()); + button->setCheckable(action->isCheckable()); + button->setChecked(action->isChecked()); + button->setEnabled(action->isEnabled()); + button->setShortcut(action->shortcut()); + m_actionMapper.setMapping(button, action); + connect(button, &QToolButton::clicked, &m_actionMapper, QOverload<>::of(&QSignalMapper::map)); + connect(action, &QAction::changed, this, &PDFPageContentEditorWidget::onActionChanged); + + ui->toolGroupBoxLayout->addWidget(button, row, column, Qt::AlignCenter); +} + +void PDFPageContentEditorWidget::onActionTriggerRequest(QObject* actionObject) +{ + QAction* action = qobject_cast(actionObject); + Q_ASSERT(action); + + action->trigger(); +} + +void PDFPageContentEditorWidget::onActionChanged() +{ + QAction* action = qobject_cast(sender()); + QToolButton* button = qobject_cast(m_actionMapper.mapping(action)); + + Q_ASSERT(action); + Q_ASSERT(button); + + button->setChecked(action->isChecked()); + button->setEnabled(action->isEnabled()); +} + } // namespace pdf diff --git a/Pdf4QtLib/sources/pdfpagecontenteditorwidget.h b/Pdf4QtLib/sources/pdfpagecontenteditorwidget.h index 392930d..2e2d7b8 100644 --- a/Pdf4QtLib/sources/pdfpagecontenteditorwidget.h +++ b/Pdf4QtLib/sources/pdfpagecontenteditorwidget.h @@ -21,6 +21,7 @@ #include "pdfglobal.h" #include +#include namespace Ui { @@ -38,8 +39,16 @@ public: explicit PDFPageContentEditorWidget(QWidget* parent); virtual ~PDFPageContentEditorWidget() override; + /// Adds external action to the tool box + void addAction(QAction* action); + private: + void onActionTriggerRequest(QObject* actionObject); + void onActionChanged(); + Ui::PDFPageContentEditorWidget* ui; + QSignalMapper m_actionMapper; + int m_toolBoxColumnCount; }; } // namespace pdf diff --git a/Pdf4QtLib/sources/pdfpagecontenteditorwidget.ui b/Pdf4QtLib/sources/pdfpagecontenteditorwidget.ui index 2501476..b74af84 100644 --- a/Pdf4QtLib/sources/pdfpagecontenteditorwidget.ui +++ b/Pdf4QtLib/sources/pdfpagecontenteditorwidget.ui @@ -23,7 +23,7 @@ Toolbox - + @@ -31,7 +31,7 @@ Geometry Tools - + @@ -124,7 +124,7 @@ Layout Tools - + diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/activate.svg b/Pdf4QtViewerPlugins/SignaturePlugin/activate.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/activate.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/certificates.svg b/Pdf4QtViewerPlugins/SignaturePlugin/certificates.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/certificates.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/clear.svg b/Pdf4QtViewerPlugins/SignaturePlugin/clear.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/clear.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-dot.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-dot.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-dot.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-freehand-curve.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-freehand-curve.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-freehand-curve.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-horizontal-line.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-horizontal-line.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-horizontal-line.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-line.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-line.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-line.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-no-mark.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-no-mark.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-no-mark.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-rectangle.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-rectangle.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-rectangle.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-rounded-rectangle.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-rounded-rectangle.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-rounded-rectangle.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-svg-image.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-svg-image.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-svg-image.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-text.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-text.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-text.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-vertical-line.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-vertical-line.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-vertical-line.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/create-yes-mark.svg b/Pdf4QtViewerPlugins/SignaturePlugin/create-yes-mark.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/create-yes-mark.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/icons.qrc b/Pdf4QtViewerPlugins/SignaturePlugin/icons.qrc index bed4028..c53a915 100644 --- a/Pdf4QtViewerPlugins/SignaturePlugin/icons.qrc +++ b/Pdf4QtViewerPlugins/SignaturePlugin/icons.qrc @@ -1,6 +1,22 @@ - accept-mark.svg - reject-mark.svg + accept-mark.svg + reject-mark.svg + activate.svg + certificates.svg + clear.svg + create-dot.svg + create-freehand-curve.svg + create-horizontal-line.svg + create-line.svg + create-no-mark.svg + create-rectangle.svg + create-rounded-rectangle.svg + create-svg-image.svg + create-text.svg + create-vertical-line.svg + create-yes-mark.svg + sign-digitally.svg + sign-electronically.svg diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/sign-digitally.svg b/Pdf4QtViewerPlugins/SignaturePlugin/sign-digitally.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/sign-digitally.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/sign-electronically.svg b/Pdf4QtViewerPlugins/SignaturePlugin/sign-electronically.svg new file mode 100644 index 0000000..a4f2e18 --- /dev/null +++ b/Pdf4QtViewerPlugins/SignaturePlugin/sign-electronically.svg @@ -0,0 +1,59 @@ + + + +image/svg+xml + + + +? + \ No newline at end of file diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.cpp b/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.cpp index 84ad0fc..da0cb29 100644 --- a/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.cpp +++ b/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.cpp @@ -17,8 +17,10 @@ #include "signatureplugin.h" #include "pdfdrawwidget.h" +#include "pdfpagecontenteditorwidget.h" #include +#include namespace pdfplugin { @@ -27,6 +29,7 @@ SignaturePlugin::SignaturePlugin() : pdf::PDFPlugin(nullptr), m_actions({ }), m_tools({ }), + m_editorWidget(nullptr), m_scene(nullptr) { @@ -38,22 +41,22 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget) BaseClass::setWidget(widget); - QAction* activateAction = new QAction(QIcon(":/pdfplugins/signaturetool/activate.svg"), tr("Activate signature creator"), this); - QAction* createTextAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-text.svg"), tr("Create Text Label"), this); - QAction* createFreehandCurveAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-freehand-curve.svg"), tr("Create Freehand Curve"), this); - QAction* createAcceptMarkAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-yes-mark.svg"), tr("Create Accept Mark"), this); - QAction* createRejectMarkAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-no-mark.svg"), tr("Create Reject Mark"), this); - QAction* createRectangleAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-rectangle.svg"), tr("Create Rectangle"), this); - QAction* createRoundedRectangleAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-rounded-rectangle.svg"), tr("Create Rounded Rectangle"), this); - QAction* createHorizontalLineAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-horizontal-line.svg"), tr("Create Horizontal Line"), this); - QAction* createVerticalLineAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-vertical-line.svg"), tr("Create Vertical Line"), this); - QAction* createLineAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-line.svg"), tr("Create Line"), this); - QAction* createDotAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-dot.svg"), tr("Create Dot"), this); - QAction* createSvgImageAction = new QAction(QIcon(":/pdfplugins/signaturetool/create-svg-image.svg"), tr("Create SVG Image"), this); - QAction* clearAction = new QAction(QIcon(":/pdfplugins/signaturetool/clear.svg"), tr("Clear All Graphics"), this); - QAction* signElectronicallyAction = new QAction(QIcon(":/pdfplugins/signaturetool/sign-electronically.svg"), tr("Sign Electronically"), this); - QAction* signDigitallyAction = new QAction(QIcon(":/pdfplugins/signaturetool/sign-digitally.svg"), tr("Sign Digitally With Certificate"), this); - QAction* certificatesAction = new QAction(QIcon(":/pdfplugins/signaturetool/certificates.svg"), tr("Certificates Manager"), this); + QAction* activateAction = new QAction(QIcon(":/pdfplugins/signatureplugin/activate.svg"), tr("Activate signature creator"), this); + QAction* createTextAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-text.svg"), tr("Create Text Label"), this); + QAction* createFreehandCurveAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-freehand-curve.svg"), tr("Create Freehand Curve"), this); + QAction* createAcceptMarkAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-yes-mark.svg"), tr("Create Accept Mark"), this); + QAction* createRejectMarkAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-no-mark.svg"), tr("Create Reject Mark"), this); + QAction* createRectangleAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-rectangle.svg"), tr("Create Rectangle"), this); + QAction* createRoundedRectangleAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-rounded-rectangle.svg"), tr("Create Rounded Rectangle"), this); + QAction* createHorizontalLineAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-horizontal-line.svg"), tr("Create Horizontal Line"), this); + QAction* createVerticalLineAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-vertical-line.svg"), tr("Create Vertical Line"), this); + QAction* createLineAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-line.svg"), tr("Create Line"), this); + QAction* createDotAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-dot.svg"), tr("Create Dot"), this); + QAction* createSvgImageAction = new QAction(QIcon(":/pdfplugins/signatureplugin/create-svg-image.svg"), tr("Create SVG Image"), this); + QAction* clearAction = new QAction(QIcon(":/pdfplugins/signatureplugin/clear.svg"), tr("Clear All Graphics"), this); + QAction* signElectronicallyAction = new QAction(QIcon(":/pdfplugins/signatureplugin/sign-electronically.svg"), tr("Sign Electronically"), this); + QAction* signDigitallyAction = new QAction(QIcon(":/pdfplugins/signatureplugin/sign-digitally.svg"), tr("Sign Digitally With Certificate"), this); + QAction* certificatesAction = new QAction(QIcon(":/pdfplugins/signatureplugin/certificates.svg"), tr("Certificates Manager"), this); activateAction->setObjectName("signaturetool_activateAction"); createTextAction->setObjectName("signaturetool_createTextAction"); @@ -203,6 +206,10 @@ void SignaturePlugin::setActive(bool active) { m_scene.clear(); } + else + { + updateDockWidget(); + } m_actions[Activate]->setChecked(active); updateActions(); @@ -259,4 +266,22 @@ void SignaturePlugin::updateGraphics() } } +void SignaturePlugin::updateDockWidget() +{ + if (m_editorWidget) + { + return; + } + + m_editorWidget = new pdf::PDFPageContentEditorWidget(m_dataExchangeInterface->getMainWindow()); + m_editorWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + m_dataExchangeInterface->getMainWindow()->addDockWidget(Qt::RightDockWidgetArea, m_editorWidget, Qt::Vertical); + m_editorWidget->setFloating(false); + + for (QAction* action : m_actions) + { + m_editorWidget->addAction(action); + } +} + } diff --git a/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.h b/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.h index 1493d3b..d76a99b 100644 --- a/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.h +++ b/Pdf4QtViewerPlugins/SignaturePlugin/signatureplugin.h @@ -24,6 +24,11 @@ #include +namespace pdf +{ +class PDFPageContentEditorWidget; +} + namespace pdfplugin { @@ -88,9 +93,11 @@ private: void updateActions(); void updateGraphics(); + void updateDockWidget(); std::array m_actions; std::array m_tools; + pdf::PDFPageContentEditorWidget* m_editorWidget; pdf::PDFPageContentScene m_scene; };