mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-01-04 20:39:52 +01:00
Editor plugin: Disable editation when signature plugin is active and vice versa
This commit is contained in:
parent
178ef02cc8
commit
b5f102abbd
@ -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;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
bool save();
|
||||
|
||||
private:
|
||||
void onSceneActivityChanged();
|
||||
void onSceneChanged(bool graphicsOnly);
|
||||
void onSceneSelectionChanged();
|
||||
void onWidgetSelectionChanged();
|
||||
|
@ -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])
|
||||
{
|
||||
|
@ -57,6 +57,7 @@ private:
|
||||
void onSignElectronically();
|
||||
void onSignDigitally();
|
||||
void onOpenCertificatesManager();
|
||||
void onSceneActivityChanged();
|
||||
|
||||
void onPenChanged(const QPen& pen);
|
||||
void onBrushChanged(const QBrush& brush);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -870,6 +870,7 @@ void PDFPageContentScene::setActive(bool newIsActive)
|
||||
}
|
||||
|
||||
Q_EMIT sceneChanged(false);
|
||||
Q_EMIT sceneActiveStateChanged(newIsActive);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -643,6 +643,8 @@ signals:
|
||||
/// Request to edit the elements
|
||||
void editElementRequest(const std::set<PDFInteger>& elements);
|
||||
|
||||
void sceneActiveStateChanged(bool activated);
|
||||
|
||||
private:
|
||||
|
||||
struct MouseEventInfo
|
||||
|
Loading…
Reference in New Issue
Block a user