Editor plugin: Disable editation when signature plugin is active and vice versa

This commit is contained in:
Jakub Melka 2024-06-23 19:37:42 +02:00
parent 178ef02cc8
commit b5f102abbd
8 changed files with 82 additions and 1 deletions

View File

@ -158,6 +158,7 @@ void EditorPlugin::setWidget(pdf::PDFWidget* widget)
connect(clearAction, &QAction::triggered, &m_scene, &pdf::PDFPageContentScene::clear);
connect(activateAction, &QAction::triggered, this, &EditorPlugin::onSetActive);
connect(m_widget->getDrawWidgetProxy(), &pdf::PDFDrawWidgetProxy::drawSpaceChanged, this, &EditorPlugin::onDrawSpaceChanged);
connect(m_widget, &pdf::PDFWidget::sceneActivityChanged, this, &EditorPlugin::onSceneActivityChanged);
updateActions();
}
@ -426,6 +427,11 @@ bool EditorPlugin::save()
return true;
}
void EditorPlugin::onSceneActivityChanged()
{
updateActions();
}
void EditorPlugin::onSceneChanged(bool graphicsOnly)
{
if (!graphicsOnly)
@ -591,12 +597,19 @@ void EditorPlugin::setActive(bool active)
m_actions[Activate]->setChecked(active);
updateActions();
// If editor is not active, remove the widget
if (m_editorWidget && !active)
{
delete m_editorWidget;
m_editorWidget = nullptr;
}
}
}
void EditorPlugin::onSetActive(bool active)
{
if (!active && !save())
if (m_scene.isActive() && !active && !save())
{
updateActions();
m_actions[Activate]->setChecked(true);
@ -617,6 +630,7 @@ void EditorPlugin::updateActions()
{
if (action == m_actions[Activate])
{
action->setEnabled(m_widget && !m_widget->isAnySceneActive(&m_scene));
continue;
}

View File

@ -52,6 +52,7 @@ public:
bool save();
private:
void onSceneActivityChanged();
void onSceneChanged(bool graphicsOnly);
void onSceneSelectionChanged();
void onWidgetSelectionChanged();

View File

@ -162,6 +162,7 @@ void SignaturePlugin::setWidget(pdf::PDFWidget* widget)
connect(signElectronicallyAction, &QAction::triggered, this, &SignaturePlugin::onSignElectronically);
connect(signDigitallyAction, &QAction::triggered, this, &SignaturePlugin::onSignDigitally);
connect(certificatesAction, &QAction::triggered, this, &SignaturePlugin::onOpenCertificatesManager);
connect(m_widget, &pdf::PDFWidget::sceneActivityChanged, this, &SignaturePlugin::onSceneActivityChanged);
updateActions();
}
@ -508,6 +509,11 @@ void SignaturePlugin::onOpenCertificatesManager()
dialog.exec();
}
void SignaturePlugin::onSceneActivityChanged()
{
updateActions();
}
void SignaturePlugin::onPenChanged(const QPen& pen)
{
if (pdf::PDFCreatePCElementTool* activeTool = qobject_cast<pdf::PDFCreatePCElementTool*>(getActiveTool()))
@ -577,6 +583,13 @@ void SignaturePlugin::setActive(bool active)
m_actions[Activate]->setChecked(active);
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
for (QAction* action : m_actions)
{
if (action == m_actions[Activate])
{
action->setEnabled(m_widget && !m_widget->isAnySceneActive(&m_scene));
}
if (action == m_actions[Activate] ||
action == m_actions[Certificates])
{

View File

@ -57,6 +57,7 @@ private:
void onSignElectronically();
void onSignDigitally();
void onOpenCertificatesManager();
void onSceneActivityChanged();
void onPenChanged(const QPen& pen);
void onBrushChanged(const QBrush& brush);

View File

@ -23,6 +23,7 @@
#include "pdfwidgetannotation.h"
#include "pdfwidgetformmanager.h"
#include "pdfblpainter.h"
#include "pdfpagecontentelements.h"
#include <QPainter>
#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)
{
auto it = std::find(m_inputInterfaces.begin(), m_inputInterfaces.end(), inputInterface);
@ -152,6 +158,17 @@ void PDFWidget::removeInputInterface(IDrawWidgetInputInterface* inputInterface)
{
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)
@ -160,9 +177,29 @@ void PDFWidget::addInputInterface(IDrawWidgetInputInterface* inputInterface)
{
m_inputInterfaces.push_back(inputInterface);
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
{
return m_formManager;

View File

@ -38,6 +38,7 @@ class PDFDrawWidgetProxy;
class PDFModifiedDocument;
class PDFWidgetAnnotationManager;
class IDrawWidgetInputInterface;
class PDFPageContentScene;
class IDrawWidget
{
@ -105,12 +106,17 @@ public:
void removeInputInterface(IDrawWidgetInputInterface* inputInterface);
void addInputInterface(IDrawWidgetInputInterface* inputInterface);
/// Returns true, if any scene is active
bool isAnySceneActive(PDFPageContentScene* sceneToSkip) const;
signals:
void sceneActivityChanged();
void pageRenderingErrorsChanged(pdf::PDFInteger pageIndex, int errorsCount);
private:
void onRenderingError(PDFInteger pageIndex, const QList<PDFRenderError>& errors);
void onPageImageChanged(bool all, const std::vector<PDFInteger>& pages);
void onSceneActiveStateChanged(bool);
const PDFCMSManager* m_cmsManager;
PDFToolManager* m_toolManager;
@ -122,6 +128,7 @@ private:
PDFDrawWidgetProxy* m_proxy;
PageRenderingErrors m_pageRenderingErrors;
std::vector<IDrawWidgetInputInterface*> m_inputInterfaces;
std::vector<PDFPageContentScene*> m_scenes;
RendererEngine m_rendererEngine;
};

View File

@ -870,6 +870,7 @@ void PDFPageContentScene::setActive(bool newIsActive)
}
Q_EMIT sceneChanged(false);
Q_EMIT sceneActiveStateChanged(newIsActive);
}
}

View File

@ -643,6 +643,8 @@ signals:
/// Request to edit the elements
void editElementRequest(const std::set<PDFInteger>& elements);
void sceneActiveStateChanged(bool activated);
private:
struct MouseEventInfo