mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-02-28 17:37:46 +01:00
Create sticky note tool
This commit is contained in:
parent
4d0c1e0ab1
commit
da95ffc748
@ -16,8 +16,12 @@
|
||||
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "pdfadvancedtools.h"
|
||||
#include "pdfdocumentbuilder.h"
|
||||
#include "pdfdrawwidget.h"
|
||||
#include "pdfutils.h"
|
||||
|
||||
#include <QActionGroup>
|
||||
#include <QInputDialog>
|
||||
|
||||
namespace pdf
|
||||
{
|
||||
@ -26,7 +30,8 @@ PDFCreateStickyNoteTool::PDFCreateStickyNoteTool(PDFDrawWidgetProxy* proxy, PDFT
|
||||
BaseClass(proxy, parent),
|
||||
m_toolManager(toolManager),
|
||||
m_actionGroup(actionGroup),
|
||||
m_pickTool(nullptr)
|
||||
m_pickTool(nullptr),
|
||||
m_icon(pdf::TextAnnotationIcon::Comment)
|
||||
{
|
||||
m_pickTool = new PDFPickTool(proxy, PDFPickTool::Mode::Points, this);
|
||||
addTool(m_pickTool);
|
||||
@ -55,11 +60,38 @@ void PDFCreateStickyNoteTool::updateActions()
|
||||
void PDFCreateStickyNoteTool::onActionTriggered(QAction* action)
|
||||
{
|
||||
setActive(action && action->isChecked());
|
||||
|
||||
if (action)
|
||||
{
|
||||
m_icon = static_cast<TextAnnotationIcon>(action->data().toInt());
|
||||
}
|
||||
}
|
||||
|
||||
void PDFCreateStickyNoteTool::onPointPicked(PDFInteger pageIndex, QPointF pagePoint)
|
||||
{
|
||||
bool ok = false;
|
||||
QString text = QInputDialog::getText(getProxy()->getWidget(), tr("Sticky note"), tr("Enter text to be displayed in the sticky note"), QLineEdit::Normal, QString(), &ok);
|
||||
|
||||
if (ok && !text.isEmpty())
|
||||
{
|
||||
PDFDocumentModifier modifier(getDocument());
|
||||
|
||||
QString userName = PDFSysUtils::getUserName();
|
||||
PDFObjectReference page = getDocument()->getCatalog()->getPage(pageIndex)->getPageReference();
|
||||
modifier.getBuilder()->createAnnotationText(page, QRectF(pagePoint, QSizeF(0, 0)), m_icon, userName, QString(), text, false);
|
||||
modifier.markAnnotationsChanged();
|
||||
|
||||
if (modifier.finalize())
|
||||
{
|
||||
emit m_toolManager->documentModified(PDFModifiedDocument(modifier.getDocument(), nullptr, modifier.getFlags()));
|
||||
}
|
||||
|
||||
setActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pickTool->resetTool();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -49,6 +49,7 @@ private:
|
||||
PDFToolManager* m_toolManager;
|
||||
QActionGroup* m_actionGroup;
|
||||
PDFPickTool* m_pickTool;
|
||||
TextAnnotationIcon m_icon;
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "pdfutils.h"
|
||||
#include "pdfexception.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <jpeglib.h>
|
||||
#include <ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
@ -25,6 +27,14 @@
|
||||
#include <openssl/opensslv.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define SECURITY_WIN32
|
||||
#include <Windows.h>
|
||||
#include <security.h>
|
||||
#pragma comment(lib, "Secur32.lib")
|
||||
#endif
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:5033)
|
||||
#include <lcms2.h>
|
||||
@ -481,4 +491,30 @@ bool PDFClosedIntervalSet::overlapsOrAdjacent(ClosedInterval a, ClosedInterval b
|
||||
return b.first <= a.second + 1;
|
||||
}
|
||||
|
||||
QString PDFSysUtils::getUserName()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
const EXTENDED_NAME_FORMAT nameFormat = NameDisplay;
|
||||
std::vector<WCHAR> buffer;
|
||||
ULONG size = 0;
|
||||
GetUserNameExW(nameFormat, NULL, &size);
|
||||
if (GetLastError() == ERROR_MORE_DATA)
|
||||
{
|
||||
++size;
|
||||
buffer.resize(size);
|
||||
if (GetUserNameExW(nameFormat, buffer.data(), &size))
|
||||
{
|
||||
return QString::fromWCharArray(buffer.data());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
QString userName = qgetenv("USER");
|
||||
if (userName.isEmpty())
|
||||
{
|
||||
userName = qgetenv("USERNAME");
|
||||
}
|
||||
return userName;
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@ -582,6 +582,14 @@ private:
|
||||
Integer m_flags = Integer();
|
||||
};
|
||||
|
||||
/// Get system information
|
||||
class PDFFORQTLIBSHARED_EXPORT PDFSysUtils
|
||||
{
|
||||
public:
|
||||
|
||||
static QString getUserName();
|
||||
};
|
||||
|
||||
/// Set of closed intervals
|
||||
class PDFFORQTLIBSHARED_EXPORT PDFClosedIntervalSet
|
||||
{
|
||||
|
@ -514,6 +514,10 @@ signals:
|
||||
/// \param timeout Timeout in miliseconds
|
||||
void messageDisplayRequest(const QString& text, int timeout);
|
||||
|
||||
/// This signal is emitted, when tool changes the document by some way
|
||||
/// \param documet Modified document
|
||||
void documentModified(PDFModifiedDocument document);
|
||||
|
||||
private:
|
||||
void onToolActionTriggered(bool checked);
|
||||
|
||||
|
@ -187,6 +187,14 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
|
||||
m_insertStickyNoteGroup->addAction(ui->actionStickyNoteNote);
|
||||
m_insertStickyNoteGroup->addAction(ui->actionStickyNoteParagraph);
|
||||
|
||||
ui->actionStickyNoteComment->setData(int(pdf::TextAnnotationIcon::Comment));
|
||||
ui->actionStickyNoteHelp->setData(int(pdf::TextAnnotationIcon::Help));
|
||||
ui->actionStickyNoteInsert->setData(int(pdf::TextAnnotationIcon::Insert));
|
||||
ui->actionStickyNoteKey->setData(int(pdf::TextAnnotationIcon::Key));
|
||||
ui->actionStickyNoteNewParagraph->setData(int(pdf::TextAnnotationIcon::NewParagraph));
|
||||
ui->actionStickyNoteNote->setData(int(pdf::TextAnnotationIcon::Note));
|
||||
ui->actionStickyNoteParagraph->setData(int(pdf::TextAnnotationIcon::Paragraph));
|
||||
|
||||
ui->actionStickyNoteComment->setIcon(pdf::PDFTextAnnotation::createIcon("Comment", iconSize));
|
||||
ui->actionStickyNoteHelp->setIcon(pdf::PDFTextAnnotation::createIcon("Help", iconSize));
|
||||
ui->actionStickyNoteInsert->setIcon(pdf::PDFTextAnnotation::createIcon("Insert", iconSize));
|
||||
@ -322,6 +330,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
|
||||
m_pdfWidget->setToolManager(m_toolManager);
|
||||
updateMagnifierToolSettings();
|
||||
connect(m_toolManager, &pdf::PDFToolManager::messageDisplayRequest, statusBar(), &QStatusBar::showMessage);
|
||||
connect(m_toolManager, &pdf::PDFToolManager::documentModified, this, &PDFViewerMainWindow::onDocumentModified);
|
||||
|
||||
// Add special tools
|
||||
pdf::PDFCreateStickyNoteTool* createStickyNoteTool = new pdf::PDFCreateStickyNoteTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, m_insertStickyNoteGroup, this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user