mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
Some advanced creation tools
This commit is contained in:
@ -47,7 +47,7 @@ void PDFCreateStickyNoteTool::updateActions()
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user