mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Editor plugin: Disable editation when signature plugin is active and vice versa
This commit is contained in:
@ -158,6 +158,7 @@ void EditorPlugin::setWidget(pdf::PDFWidget* widget)
|
|||||||
connect(clearAction, &QAction::triggered, &m_scene, &pdf::PDFPageContentScene::clear);
|
connect(clearAction, &QAction::triggered, &m_scene, &pdf::PDFPageContentScene::clear);
|
||||||
connect(activateAction, &QAction::triggered, this, &EditorPlugin::onSetActive);
|
connect(activateAction, &QAction::triggered, this, &EditorPlugin::onSetActive);
|
||||||
connect(m_widget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::drawSpaceChanged, this, &EditorPlugin::onDrawSpaceChanged);
|
connect(m_widget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::drawSpaceChanged, this, &EditorPlugin::onDrawSpaceChanged);
|
||||||
|
connect(m_widget, &pdf::PDFWidget::sceneActivityChanged, this, &EditorPlugin::onSceneActivityChanged);
|
||||||
|
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
@ -426,6 +427,11 @@ bool EditorPlugin::save()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorPlugin::onSceneActivityChanged()
|
||||||
|
{
|
||||||
|
updateActions();
|
||||||
|
}
|
||||||
|
|
||||||
void EditorPlugin::onSceneChanged(bool graphicsOnly)
|
void EditorPlugin::onSceneChanged(bool graphicsOnly)
|
||||||
{
|
{
|
||||||
if (!graphicsOnly)
|
if (!graphicsOnly)
|
||||||
@ -591,12 +597,19 @@ void EditorPlugin::setActive(bool active)
|
|||||||
|
|
||||||
m_actions[Activate]->setChecked(active);
|
m_actions[Activate]->setChecked(active);
|
||||||
updateActions();
|
updateActions();
|
||||||
|
|
||||||
|
// If editor is not active, remove the widget
|
||||||
|
if (m_editorWidget && !active)
|
||||||
|
{
|
||||||
|
delete m_editorWidget;
|
||||||
|
m_editorWidget = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorPlugin::onSetActive(bool active)
|
void EditorPlugin::onSetActive(bool active)
|
||||||
{
|
{
|
||||||
if (!active && !save())
|
if (m_scene.isActive() && !active && !save())
|
||||||
{
|
{
|
||||||
updateActions();
|
updateActions();
|
||||||
m_actions[Activate]->setChecked(true);
|
m_actions[Activate]->setChecked(true);
|
||||||
@ -617,6 +630,7 @@ void EditorPlugin::updateActions()
|
|||||||
{
|
{
|
||||||
if (action == m_actions[Activate])
|
if (action == m_actions[Activate])
|
||||||
{
|
{
|
||||||
|
action->setEnabled(m_widget && !m_widget->isAnySceneActive(&m_scene));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ public:
|
|||||||
bool save();
|
bool save();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void onSceneActivityChanged();
|
||||||
void onSceneChanged(bool graphicsOnly);
|
void onSceneChanged(bool graphicsOnly);
|
||||||
void onSceneSelectionChanged();
|
void onSceneSelectionChanged();
|
||||||
void onWidgetSelectionChanged();
|
void onWidgetSelectionChanged();
|
||||||
|
@ -162,6 +162,7 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget)
|
|||||||
connect(signElectronicallyAction, &QAction::triggered, this, &SignaturePlugin::onSignElectronically);
|
connect(signElectronicallyAction, &QAction::triggered, this, &SignaturePlugin::onSignElectronically);
|
||||||
connect(signDigitallyAction, &QAction::triggered, this, &SignaturePlugin::onSignDigitally);
|
connect(signDigitallyAction, &QAction::triggered, this, &SignaturePlugin::onSignDigitally);
|
||||||
connect(certificatesAction, &QAction::triggered, this, &SignaturePlugin::onOpenCertificatesManager);
|
connect(certificatesAction, &QAction::triggered, this, &SignaturePlugin::onOpenCertificatesManager);
|
||||||
|
connect(m_widget, &pdf::PDFWidget::sceneActivityChanged, this, &SignaturePlugin::onSceneActivityChanged);
|
||||||
|
|
||||||
updateActions();
|
updateActions();
|
||||||
}
|
}
|
||||||
@ -508,6 +509,11 @@ void SignaturePlugin::onOpenCertificatesManager()
|
|||||||
dialog.exec();
|
dialog.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SignaturePlugin::onSceneActivityChanged()
|
||||||
|
{
|
||||||
|
updateActions();
|
||||||
|
}
|
||||||
|
|
||||||
void SignaturePlugin::onPenChanged(const QPen& pen)
|
void SignaturePlugin::onPenChanged(const QPen& pen)
|
||||||
{
|
{
|
||||||
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
|
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
|
||||||
@ -577,6 +583,13 @@ void SignaturePlugin::setActive(bool active)
|
|||||||
|
|
||||||
m_actions[Activate]->setChecked(active);
|
m_actions[Activate]->setChecked(active);
|
||||||
updateActions();
|
updateActions();
|
||||||
|
|
||||||
|
// If editor is not active, remove the widget
|
||||||
|
if (m_editorWidget && !active)
|
||||||
|
{
|
||||||
|
delete m_editorWidget;
|
||||||
|
m_editorWidget = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,6 +602,11 @@ void SignaturePlugin::updateActions()
|
|||||||
// Inactive scene - disable all except activate action and certificates
|
// Inactive scene - disable all except activate action and certificates
|
||||||
for (QAction* action : m_actions)
|
for (QAction* action : m_actions)
|
||||||
{
|
{
|
||||||
|
if (action == m_actions[Activate])
|
||||||
|
{
|
||||||
|
action->setEnabled(m_widget && !m_widget->isAnySceneActive(&m_scene));
|
||||||
|
}
|
||||||
|
|
||||||
if (action == m_actions[Activate] ||
|
if (action == m_actions[Activate] ||
|
||||||
action == m_actions[Certificates])
|
action == m_actions[Certificates])
|
||||||
{
|
{
|
||||||
|
@ -57,6 +57,7 @@ private:
|
|||||||
void onSignElectronically();
|
void onSignElectronically();
|
||||||
void onSignDigitally();
|
void onSignDigitally();
|
||||||
void onOpenCertificatesManager();
|
void onOpenCertificatesManager();
|
||||||
|
void onSceneActivityChanged();
|
||||||
|
|
||||||
void onPenChanged(const QPen& pen);
|
void onPenChanged(const QPen& pen);
|
||||||
void onBrushChanged(const QBrush& brush);
|
void onBrushChanged(const QBrush& brush);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "pdfwidgetannotation.h"
|
#include "pdfwidgetannotation.h"
|
||||||
#include "pdfwidgetformmanager.h"
|
#include "pdfwidgetformmanager.h"
|
||||||
#include "pdfblpainter.h"
|
#include "pdfblpainter.h"
|
||||||
|
#include "pdfpagecontentelements.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
@ -145,6 +146,11 @@ void PDFWidget::onPageImageChanged(bool all, const std::vector<PDFInteger>& page
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFWidget::onSceneActiveStateChanged(bool)
|
||||||
|
{
|
||||||
|
Q_EMIT sceneActivityChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void PDFWidget::removeInputInterface(IDrawWidgetInputInterface* inputInterface)
|
void PDFWidget::removeInputInterface(IDrawWidgetInputInterface* inputInterface)
|
||||||
{
|
{
|
||||||
auto it = std::find(m_inputInterfaces.begin(), m_inputInterfaces.end(), inputInterface);
|
auto it = std::find(m_inputInterfaces.begin(), m_inputInterfaces.end(), inputInterface);
|
||||||
@ -152,6 +158,17 @@ void PDFWidget::removeInputInterface(IDrawWidgetInputInterface* inputInterface)
|
|||||||
{
|
{
|
||||||
m_inputInterfaces.erase(it);
|
m_inputInterfaces.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PDFPageContentScene* scene = dynamic_cast<PDFPageContentScene*>(inputInterface);
|
||||||
|
if (scene)
|
||||||
|
{
|
||||||
|
auto itScene = std::find(m_scenes.begin(), m_scenes.end(), inputInterface);
|
||||||
|
if (itScene != m_scenes.end())
|
||||||
|
{
|
||||||
|
m_scenes.erase(itScene);
|
||||||
|
disconnect(scene, &PDFPageContentScene::sceneActiveStateChanged, this, &PDFWidget::onSceneActiveStateChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDFWidget::addInputInterface(IDrawWidgetInputInterface* inputInterface)
|
void PDFWidget::addInputInterface(IDrawWidgetInputInterface* inputInterface)
|
||||||
@ -160,9 +177,29 @@ void PDFWidget::addInputInterface(IDrawWidgetInputInterface* inputInterface)
|
|||||||
{
|
{
|
||||||
m_inputInterfaces.push_back(inputInterface);
|
m_inputInterfaces.push_back(inputInterface);
|
||||||
std::sort(m_inputInterfaces.begin(), m_inputInterfaces.end(), IDrawWidgetInputInterface::Comparator());
|
std::sort(m_inputInterfaces.begin(), m_inputInterfaces.end(), IDrawWidgetInputInterface::Comparator());
|
||||||
|
|
||||||
|
PDFPageContentScene* scene = dynamic_cast<PDFPageContentScene*>(inputInterface);
|
||||||
|
if (scene)
|
||||||
|
{
|
||||||
|
m_scenes.push_back(scene);
|
||||||
|
connect(scene, &PDFPageContentScene::sceneActiveStateChanged, this, &PDFWidget::onSceneActiveStateChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PDFWidget::isAnySceneActive(PDFPageContentScene* sceneToSkip) const
|
||||||
|
{
|
||||||
|
for (PDFPageContentScene* scene : m_scenes)
|
||||||
|
{
|
||||||
|
if (scene->isActive() && scene != sceneToSkip)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
PDFWidgetFormManager* PDFWidget::getFormManager() const
|
PDFWidgetFormManager* PDFWidget::getFormManager() const
|
||||||
{
|
{
|
||||||
return m_formManager;
|
return m_formManager;
|
||||||
|
@ -38,6 +38,7 @@ class PDFDrawWidgetProxy;
|
|||||||
class PDFModifiedDocument;
|
class PDFModifiedDocument;
|
||||||
class PDFWidgetAnnotationManager;
|
class PDFWidgetAnnotationManager;
|
||||||
class IDrawWidgetInputInterface;
|
class IDrawWidgetInputInterface;
|
||||||
|
class PDFPageContentScene;
|
||||||
|
|
||||||
class IDrawWidget
|
class IDrawWidget
|
||||||
{
|
{
|
||||||
@ -105,12 +106,17 @@ public:
|
|||||||
void removeInputInterface(IDrawWidgetInputInterface* inputInterface);
|
void removeInputInterface(IDrawWidgetInputInterface* inputInterface);
|
||||||
void addInputInterface(IDrawWidgetInputInterface* inputInterface);
|
void addInputInterface(IDrawWidgetInputInterface* inputInterface);
|
||||||
|
|
||||||
|
/// Returns true, if any scene is active
|
||||||
|
bool isAnySceneActive(PDFPageContentScene* sceneToSkip) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void sceneActivityChanged();
|
||||||
void pageRenderingErrorsChanged(pdf::PDFInteger pageIndex, int errorsCount);
|
void pageRenderingErrorsChanged(pdf::PDFInteger pageIndex, int errorsCount);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onRenderingError(PDFInteger pageIndex, const QList<PDFRenderError>& errors);
|
void onRenderingError(PDFInteger pageIndex, const QList<PDFRenderError>& errors);
|
||||||
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
|
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
|
||||||
|
void onSceneActiveStateChanged(bool);
|
||||||
|
|
||||||
const PDFCMSManager* m_cmsManager;
|
const PDFCMSManager* m_cmsManager;
|
||||||
PDFToolManager* m_toolManager;
|
PDFToolManager* m_toolManager;
|
||||||
@ -122,6 +128,7 @@ private:
|
|||||||
PDFDrawWidgetProxy* m_proxy;
|
PDFDrawWidgetProxy* m_proxy;
|
||||||
PageRenderingErrors m_pageRenderingErrors;
|
PageRenderingErrors m_pageRenderingErrors;
|
||||||
std::vector<IDrawWidgetInputInterface*> m_inputInterfaces;
|
std::vector<IDrawWidgetInputInterface*> m_inputInterfaces;
|
||||||
|
std::vector<PDFPageContentScene*> m_scenes;
|
||||||
RendererEngine m_rendererEngine;
|
RendererEngine m_rendererEngine;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -870,6 +870,7 @@ void PDFPageContentScene::setActive(bool newIsActive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Q_EMIT sceneChanged(false);
|
Q_EMIT sceneChanged(false);
|
||||||
|
Q_EMIT sceneActiveStateChanged(newIsActive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,6 +643,8 @@ signals:
|
|||||||
/// Request to edit the elements
|
/// Request to edit the elements
|
||||||
void editElementRequest(const std::set<PDFInteger>& elements);
|
void editElementRequest(const std::set<PDFInteger>& elements);
|
||||||
|
|
||||||
|
void sceneActiveStateChanged(bool activated);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct MouseEventInfo
|
struct MouseEventInfo
|
||||||
|
Reference in New Issue
Block a user