Some advanced creation tools

This commit is contained in:
Jakub Melka 2020-12-05 17:51:54 +01:00
parent da95ffc748
commit 1d4e7d26ab
6 changed files with 269 additions and 1 deletions

View File

@ -47,7 +47,7 @@ void PDFCreateStickyNoteTool::updateActions()
if (m_actionGroup) if (m_actionGroup)
{ {
const bool isEnabled = getDocument() && getDocument()->getStorage().getSecurityHandler()->isAllowed(PDFSecurityHandler::Permission::Modify); const bool isEnabled = getDocument() && getDocument()->getStorage().getSecurityHandler()->isAllowed(PDFSecurityHandler::Permission::ModifyInteractiveItems);
m_actionGroup->setEnabled(isEnabled); m_actionGroup->setEnabled(isEnabled);
if (!isActive() && m_actionGroup->checkedAction()) if (!isActive() && m_actionGroup->checkedAction())
@ -94,4 +94,100 @@ void PDFCreateStickyNoteTool::onPointPicked(PDFInteger pageIndex, QPointF pagePo
} }
} }
PDFCreateHyperlinkTool::PDFCreateHyperlinkTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent) :
BaseClass(proxy, action, parent),
m_toolManager(toolManager),
m_pickTool(nullptr)
{
m_pickTool = new PDFPickTool(proxy, PDFPickTool::Mode::Rectangles, this);
addTool(m_pickTool);
connect(m_pickTool, &PDFPickTool::rectanglePicked, this, &PDFCreateHyperlinkTool::onRectanglePicked);
updateActions();
}
LinkHighlightMode PDFCreateHyperlinkTool::getHighlightMode() const
{
return m_highlightMode;
}
void PDFCreateHyperlinkTool::setHighlightMode(const LinkHighlightMode& highlightMode)
{
m_highlightMode = highlightMode;
}
void PDFCreateHyperlinkTool::onRectanglePicked(PDFInteger pageIndex, QRectF pageRectangle)
{
bool ok = false;
QString url = QInputDialog::getText(getProxy()->getWidget(), tr("Hyperlink"), tr("Enter url address of the hyperlink"), QLineEdit::Normal, QString(), &ok);
if (ok && !url.isEmpty())
{
PDFDocumentModifier modifier(getDocument());
QString userName = PDFSysUtils::getUserName();
PDFObjectReference page = getDocument()->getCatalog()->getPage(pageIndex)->getPageReference();
modifier.getBuilder()->createAnnotationLink(page, pageRectangle, url, m_highlightMode);
modifier.markAnnotationsChanged();
if (modifier.finalize())
{
emit m_toolManager->documentModified(PDFModifiedDocument(modifier.getDocument(), nullptr, modifier.getFlags()));
}
setActive(false);
}
}
PDFCreateFreeTextTool::PDFCreateFreeTextTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent) :
BaseClass(proxy, action, parent),
m_toolManager(toolManager),
m_pickTool(nullptr)
{
m_pickTool = new PDFPickTool(proxy, PDFPickTool::Mode::Rectangles, this);
addTool(m_pickTool);
connect(m_pickTool, &PDFPickTool::rectanglePicked, this, &PDFCreateFreeTextTool::onRectanglePicked);
updateActions();
}
void PDFCreateFreeTextTool::onRectanglePicked(PDFInteger pageIndex, QRectF pageRectangle)
{
bool ok = false;
QString text = QInputDialog::getMultiLineText(getProxy()->getWidget(), tr("Text"), tr("Enter text for free text panel"), QString(), &ok);
if (ok && !text.isEmpty())
{
PDFDocumentModifier modifier(getDocument());
QString userName = PDFSysUtils::getUserName();
PDFObjectReference page = getDocument()->getCatalog()->getPage(pageIndex)->getPageReference();
modifier.getBuilder()->createAnnotationFreeText(page, pageRectangle, PDFSysUtils::getUserName(), QString(), text, TextAlignment(Qt::AlignLeft | Qt::AlignTop));
modifier.markAnnotationsChanged();
if (modifier.finalize())
{
emit m_toolManager->documentModified(PDFModifiedDocument(modifier.getDocument(), nullptr, modifier.getFlags()));
}
setActive(false);
}
}
PDFCreateAnnotationTool::PDFCreateAnnotationTool(PDFDrawWidgetProxy* proxy, QAction* action, QObject* parent) :
BaseClass(proxy, action, parent)
{
}
void PDFCreateAnnotationTool::updateActions()
{
if (QAction* action = getAction())
{
const bool isEnabled = getDocument() && getDocument()->getStorage().getSecurityHandler()->isAllowed(PDFSecurityHandler::Permission::ModifyInteractiveItems);
action->setChecked(isActive());
action->setEnabled(isEnabled);
}
}
} // namespace pdf } // namespace pdf

View File

@ -52,6 +52,62 @@ private:
TextAnnotationIcon m_icon; TextAnnotationIcon m_icon;
}; };
class PDFFORQTLIBSHARED_EXPORT PDFCreateAnnotationTool : public PDFWidgetTool
{
Q_OBJECT
private:
using BaseClass = PDFWidgetTool;
public:
explicit PDFCreateAnnotationTool(PDFDrawWidgetProxy* proxy, QAction* action, QObject* parent);
protected:
virtual void updateActions() override;
};
/// Tool that creates url link annotation. Multiple types of link highlights
/// are available, user can select a link highlight. When link annotation
/// is clicked, url address is triggered.
class PDFFORQTLIBSHARED_EXPORT PDFCreateHyperlinkTool : public PDFCreateAnnotationTool
{
Q_OBJECT
private:
using BaseClass = PDFCreateAnnotationTool;
public:
explicit PDFCreateHyperlinkTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
LinkHighlightMode getHighlightMode() const;
void setHighlightMode(const LinkHighlightMode& highlightMode);
private:
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
PDFToolManager* m_toolManager;
PDFPickTool* m_pickTool;
LinkHighlightMode m_highlightMode = LinkHighlightMode::Outline;
};
/// Tool that creates free text note without callout line.
class PDFFORQTLIBSHARED_EXPORT PDFCreateFreeTextTool : public PDFCreateAnnotationTool
{
Q_OBJECT
private:
using BaseClass = PDFCreateAnnotationTool;
public:
explicit PDFCreateFreeTextTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, QAction* action, QObject* parent);
private:
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
PDFToolManager* m_toolManager;
PDFPickTool* m_pickTool;
};
} // namespace pdf } // namespace pdf
#endif // PDFADVANCEDTOOLS_H #endif // PDFADVANCEDTOOLS_H

View File

@ -52,5 +52,6 @@
<file>resources/result-warning.svg</file> <file>resources/result-warning.svg</file>
<file>resources/signature.svg</file> <file>resources/signature.svg</file>
<file>resources/plugins.svg</file> <file>resources/plugins.svg</file>
<file>resources/hyperlink.svg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -335,6 +335,10 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
// Add special tools // Add special tools
pdf::PDFCreateStickyNoteTool* createStickyNoteTool = new pdf::PDFCreateStickyNoteTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, m_insertStickyNoteGroup, this); pdf::PDFCreateStickyNoteTool* createStickyNoteTool = new pdf::PDFCreateStickyNoteTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, m_insertStickyNoteGroup, this);
m_toolManager->addTool(createStickyNoteTool); m_toolManager->addTool(createStickyNoteTool);
pdf::PDFCreateHyperlinkTool* createHyperlinkTool = new pdf::PDFCreateHyperlinkTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, ui->actionCreateHyperlink, this);
m_toolManager->addTool(createHyperlinkTool);
pdf::PDFCreateFreeTextTool* createFreeTextTool = new pdf::PDFCreateFreeTextTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, ui->actionInlineText, this);
m_toolManager->addTool(createFreeTextTool);
m_annotationManager = new pdf::PDFWidgetAnnotationManager(m_pdfWidget->getDrawWidgetProxy(), this); m_annotationManager = new pdf::PDFWidgetAnnotationManager(m_pdfWidget->getDrawWidgetProxy(), this);
connect(m_annotationManager, &pdf::PDFWidgetAnnotationManager::actionTriggered, this, &PDFViewerMainWindow::onActionTriggered); connect(m_annotationManager, &pdf::PDFWidgetAnnotationManager::actionTriggered, this, &PDFViewerMainWindow::onActionTriggered);

View File

@ -147,6 +147,8 @@
<addaction name="actionStickyNoteParagraph"/> <addaction name="actionStickyNoteParagraph"/>
</widget> </widget>
<addaction name="menuSticky_Note"/> <addaction name="menuSticky_Note"/>
<addaction name="actionCreateHyperlink"/>
<addaction name="actionInlineText"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuEdit"/> <addaction name="menuEdit"/>
@ -624,6 +626,26 @@
<string>Paragraph</string> <string>Paragraph</string>
</property> </property>
</action> </action>
<action name="actionCreateHyperlink">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="pdfforqtviewer.qrc">
<normaloff>:/resources/hyperlink.svg</normaloff>:/resources/hyperlink.svg</iconset>
</property>
<property name="text">
<string>Hyperlink</string>
</property>
</action>
<action name="actionInlineText">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Inline text</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources> <resources>

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.2 KiB