diff --git a/PdfForQtLib/sources/pdfannotation.cpp b/PdfForQtLib/sources/pdfannotation.cpp index c5bafce..2f9a63d 100644 --- a/PdfForQtLib/sources/pdfannotation.cpp +++ b/PdfForQtLib/sources/pdfannotation.cpp @@ -3206,7 +3206,7 @@ void PDFWidgetAnnotation::draw(AnnotationDrawParameters& parameters) const { switch (m_highlightMode) { - case LinkHighlightMode::Invert: + case HighlightMode::Invert: { // Invert all painter->setCompositionMode(QPainter::CompositionMode_Difference); @@ -3214,7 +3214,7 @@ void PDFWidgetAnnotation::draw(AnnotationDrawParameters& parameters) const break; } - case LinkHighlightMode::Outline: + case HighlightMode::Outline: { // Invert the border painter->setCompositionMode(QPainter::CompositionMode_Difference); @@ -3226,7 +3226,7 @@ void PDFWidgetAnnotation::draw(AnnotationDrawParameters& parameters) const break; } - case LinkHighlightMode::Push: + case HighlightMode::Push: { // Draw border painter->setCompositionMode(getCompositionMode()); diff --git a/PdfForQtLib/sources/pdfdrawwidget.cpp b/PdfForQtLib/sources/pdfdrawwidget.cpp index 968e606..14a9933 100644 --- a/PdfForQtLib/sources/pdfdrawwidget.cpp +++ b/PdfForQtLib/sources/pdfdrawwidget.cpp @@ -304,12 +304,12 @@ bool PDFDrawWidgetBase::processEvent(Event* event) // If event is accepted, then update cursor/tooltip and return if (event->isAccepted()) { - setToolTip(tooltip); - updateCursor(); + this->setToolTip(tooltip); + this->updateCursor(); return true; } } - setToolTip(tooltip); + this->setToolTip(tooltip); return false; } diff --git a/PdfForQtLib/sources/pdfflatarray.h b/PdfForQtLib/sources/pdfflatarray.h index 7145680..c7938d4 100644 --- a/PdfForQtLib/sources/pdfflatarray.h +++ b/PdfForQtLib/sources/pdfflatarray.h @@ -41,7 +41,7 @@ template class PDFFlatArray { public: - explicit PDFFlatArray() : + PDFFlatArray() : m_flatBlock(), m_flatBlockItemCount(0), m_variableBlock() @@ -50,7 +50,7 @@ public: } template::type = 0> - explicit inline PDFFlatArray(Arguments... arguments) : + inline PDFFlatArray(Arguments... arguments) : m_flatBlock({ arguments... }), m_flatBlockItemCount(sizeof...(Arguments)), m_variableBlock() diff --git a/PdfForQtLib/sources/pdfform.h b/PdfForQtLib/sources/pdfform.h index fb3cdce..e94161f 100644 --- a/PdfForQtLib/sources/pdfform.h +++ b/PdfForQtLib/sources/pdfform.h @@ -619,7 +619,7 @@ public: const PDFAction* getAction(PDFAnnotationAdditionalActions::Action actionType, const PDFFormWidget* widget); /// Returns default form apperance flags - static constexpr FormAppearanceFlags getDefaultApperanceFlags() { return HighlightFields | HighlightRequiredFields; } + static constexpr FormAppearanceFlags getDefaultApperanceFlags() { return FormAppearanceFlags(HighlightFields | HighlightRequiredFields); } struct MouseEventInfo { diff --git a/PdfForQtLib/sources/pdfplugin.cpp b/PdfForQtLib/sources/pdfplugin.cpp index 5013986..9c920d2 100644 --- a/PdfForQtLib/sources/pdfplugin.cpp +++ b/PdfForQtLib/sources/pdfplugin.cpp @@ -21,19 +21,26 @@ namespace pdf { PDFPlugin::PDFPlugin(QObject* parent) : - QObject(parent) + QObject(parent), + m_widget(nullptr), + m_document(nullptr) { } void PDFPlugin::setWidget(PDFWidget* widget) { - Q_UNUSED(widget) + m_widget = widget; } void PDFPlugin::setDocument(const PDFModifiedDocument& document) { - Q_UNUSED(document) + m_document = document; +} + +std::vector PDFPlugin::getActions() const +{ + return std::vector(); } PDFPluginInfo PDFPluginInfo::loadFromJson(const QJsonObject* json) diff --git a/PdfForQtLib/sources/pdfplugin.h b/PdfForQtLib/sources/pdfplugin.h index 14954fe..76548cc 100644 --- a/PdfForQtLib/sources/pdfplugin.h +++ b/PdfForQtLib/sources/pdfplugin.h @@ -23,6 +23,10 @@ #include #include +#include + +class QAction; + namespace pdf { class PDFWidget; @@ -48,6 +52,11 @@ public: virtual void setWidget(PDFWidget* widget); virtual void setDocument(const PDFModifiedDocument& document); + virtual std::vector getActions() const; + +protected: + PDFWidget* m_widget; + PDFDocument* m_document; }; } // namespace pdf diff --git a/PdfForQtLib/sources/pdfrenderer.h b/PdfForQtLib/sources/pdfrenderer.h index 1f96959..7e6ba4b 100644 --- a/PdfForQtLib/sources/pdfrenderer.h +++ b/PdfForQtLib/sources/pdfrenderer.h @@ -99,7 +99,7 @@ public: static QMatrix createPagePointToDevicePointMatrix(const PDFPage* page, const QRectF& rectangle); /// Returns default renderer features - static constexpr Features getDefaultFeatures() { return Antialiasing | TextAntialiasing | ClipToCropBox | DisplayAnnotations; } + static constexpr Features getDefaultFeatures() { return Features(Antialiasing | TextAntialiasing | ClipToCropBox | DisplayAnnotations); } private: const PDFDocument* m_document; diff --git a/PdfForQtLib/sources/pdfutils.h b/PdfForQtLib/sources/pdfutils.h index 2e2c65f..57b5bde 100644 --- a/PdfForQtLib/sources/pdfutils.h +++ b/PdfForQtLib/sources/pdfutils.h @@ -650,7 +650,7 @@ private: template QDataStream& operator>>(QDataStream& stream, std::vector& vector) { - std::vector::size_type size = 0; + typename std::vector::size_type size = 0; stream >> size; vector.resize(size); for (T& item : vector) @@ -674,7 +674,7 @@ QDataStream& operator<<(QDataStream& stream, const std::vector& vector) template QDataStream& operator>>(QDataStream& stream, std::array& array) { - std::array::size_type size = 0; + typename std::array::size_type size = 0; stream >> size; for (size_t i = 0; i < size; ++i) @@ -713,7 +713,7 @@ QDataStream& operator<<(QDataStream& stream, const std::array& array) template QDataStream& operator>>(QDataStream& stream, std::set& set) { - std::set::size_type size = 0; + typename std::set::size_type size = 0; stream >> size; for (size_t i = 0; i < size; ++i) { diff --git a/PdfForQtViewer/pdfviewermainwindow.cpp b/PdfForQtViewer/pdfviewermainwindow.cpp index f9b456a..3c1e159 100644 --- a/PdfForQtViewer/pdfviewermainwindow.cpp +++ b/PdfForQtViewer/pdfviewermainwindow.cpp @@ -354,6 +354,16 @@ void PDFViewerMainWindow::loadPlugins() for (const auto& plugin : m_loadedPlugins) { plugin.second->setWidget(m_pdfWidget); + std::vector actions = plugin.second->getActions(); + + if (!actions.empty()) + { + QMenu* menu = ui->menuTools->addMenu(plugin.first.name); + for (QAction* action : actions) + { + menu->addAction(action); + } + } } } @@ -1075,12 +1085,12 @@ void PDFViewerMainWindow::onDocumentReadingFinished() setDocument(document); pdf::PDFDocumentRequirements requirements = pdf::PDFDocumentRequirements::parse(&m_pdfDocument->getStorage(), m_pdfDocument->getCatalog()->getRequirements()); - constexpr pdf::PDFDocumentRequirements::Requirements requirementFlags = pdf::PDFDocumentRequirements::OCInteract | - pdf::PDFDocumentRequirements::OCAutoStates | - pdf::PDFDocumentRequirements::Navigation | - pdf::PDFDocumentRequirements::Attachment | - pdf::PDFDocumentRequirements::DigSigValidation | - pdf::PDFDocumentRequirements::Encryption; + constexpr pdf::PDFDocumentRequirements::Requirements requirementFlags = pdf::PDFDocumentRequirements::Requirements(pdf::PDFDocumentRequirements::OCInteract | + pdf::PDFDocumentRequirements::OCAutoStates | + pdf::PDFDocumentRequirements::Navigation | + pdf::PDFDocumentRequirements::Attachment | + pdf::PDFDocumentRequirements::DigSigValidation | + pdf::PDFDocumentRequirements::Encryption); pdf::PDFDocumentRequirements::ValidationResult requirementResult = requirements.validate(requirementFlags); if (requirementResult.isError()) { diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/DimensionsPlugin.pro b/PdfForQtViewerPlugins/DimensionsPlugin/DimensionsPlugin.pro index 9e49dd2..59fca65 100644 --- a/PdfForQtViewerPlugins/DimensionsPlugin/DimensionsPlugin.pro +++ b/PdfForQtViewerPlugins/DimensionsPlugin/DimensionsPlugin.pro @@ -18,6 +18,8 @@ TEMPLATE = lib DEFINES += DIMENSIONPLUGIN_LIBRARY +QT += gui widgets + LIBS += -L$$OUT_PWD/../.. LIBS += -lPDFForQtLib @@ -31,12 +33,17 @@ DESTDIR = $$OUT_PWD/../../pdfplugins CONFIG += c++11 SOURCES += \ - dimensionsplugin.cpp + dimensionsplugin.cpp \ + dimensiontool.cpp HEADERS += \ - dimensionsplugin.h + dimensionsplugin.h \ + dimensiontool.h CONFIG += force_debug_info DISTFILES += \ DimensionsPlugin.json + +RESOURCES += \ + icons.qrc diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/area.svg b/PdfForQtViewerPlugins/DimensionsPlugin/area.svg new file mode 100644 index 0000000..5c5129b --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/area.svg @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + Jakub Melka + + + + + + + + + + + + + + + + + + diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.cpp b/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.cpp index a009ae2..b231a6c 100644 --- a/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.cpp +++ b/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.cpp @@ -1,12 +1,84 @@ +// Copyright (C) 2020 Jakub Melka +// +// This file is part of PdfForQt. +// +// PdfForQt is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// PdfForQt is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with PDFForQt. If not, see . + #include "dimensionsplugin.h" +#include "pdfdrawwidget.h" namespace pdfplugin { DimensionsPlugin::DimensionsPlugin() : - pdf::PDFPlugin(nullptr) + pdf::PDFPlugin(nullptr), + m_dimensionTools() { } +void DimensionsPlugin::setWidget(pdf::PDFWidget* widget) +{ + Q_ASSERT(!m_widget); + + BaseClass::setWidget(widget); + + QAction* horizontalDimensionAction = new QAction(QIcon(":/pdfplugins/dimensiontool/linear-horizontal.svg"), tr("Horizontal Dimension"), this); + QAction* verticalDimensionAction = new QAction(QIcon(":/pdfplugins/dimensiontool/linear-vertical.svg"), tr("Vertical Dimension"), this); + QAction* linearDimensionAction = new QAction(QIcon(":/pdfplugins/dimensiontool/linear.svg"), tr("Linear Dimension"), this); + QAction* perimeterDimensionAction = new QAction(QIcon(":/pdfplugins/dimensiontool/perimeter.svg"), tr("Perimeter"), this); + QAction* areaDimensionAction = new QAction(QIcon(":/pdfplugins/dimensiontool/area.svg"), tr("Area"), this); + + horizontalDimensionAction->setObjectName("dimensiontool_LinearHorizontalAction"); + verticalDimensionAction->setObjectName("dimensiontool_LinearVerticalAction"); + linearDimensionAction->setObjectName("dimensiontool_LinearAction"); + perimeterDimensionAction->setObjectName("dimensiontool_PerimeterAction"); + areaDimensionAction->setObjectName("dimensiontool_AreaAction"); + + m_dimensionTools[DimensionTool::LinearHorizontal] = new DimensionTool(DimensionTool::LinearHorizontal, widget->getDrawWidgetProxy(), horizontalDimensionAction, this); + m_dimensionTools[DimensionTool::LinearVertical] = new DimensionTool(DimensionTool::LinearVertical, widget->getDrawWidgetProxy(), verticalDimensionAction, this); + m_dimensionTools[DimensionTool::Linear] = new DimensionTool(DimensionTool::Linear, widget->getDrawWidgetProxy(), linearDimensionAction, this); + m_dimensionTools[DimensionTool::Perimeter] = new DimensionTool(DimensionTool::Perimeter, widget->getDrawWidgetProxy(), perimeterDimensionAction, this); + m_dimensionTools[DimensionTool::Area] = new DimensionTool(DimensionTool::Area, widget->getDrawWidgetProxy(), areaDimensionAction, this); +} + +void DimensionsPlugin::setDocument(const pdf::PDFModifiedDocument& document) +{ + BaseClass::setDocument(document); + + for (DimensionTool* tool : m_dimensionTools) + { + if (tool) + { + tool->setDocument(document); + } + } +} + +std::vector DimensionsPlugin::getActions() const +{ + std::vector result; + + for (DimensionTool* tool : m_dimensionTools) + { + if (tool) + { + result.push_back(tool->getAction()); + } + } + + return result; +} + } diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.h b/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.h index c9c956c..03e9fae 100644 --- a/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.h +++ b/PdfForQtViewerPlugins/DimensionsPlugin/dimensionsplugin.h @@ -1,7 +1,25 @@ +// Copyright (C) 2020 Jakub Melka +// +// This file is part of PdfForQt. +// +// PdfForQt is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// PdfForQt is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with PDFForQt. If not, see . + #ifndef DIMENSIONSPLUGIN_H #define DIMENSIONSPLUGIN_H #include "pdfplugin.h" +#include "dimensiontool.h" #include @@ -13,8 +31,18 @@ class DimensionsPlugin : public pdf::PDFPlugin Q_OBJECT Q_PLUGIN_METADATA(IID "PdfForQt.DimensionsPlugin" FILE "DimensionsPlugin.json") +private: + using BaseClass = pdf::PDFPlugin; + public: DimensionsPlugin(); + + virtual void setWidget(pdf::PDFWidget* widget) override; + virtual void setDocument(const pdf::PDFModifiedDocument& document) override; + virtual std::vector getActions() const override; + +private: + std::array m_dimensionTools; }; } // namespace pdfplugin diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/dimensiontool.cpp b/PdfForQtViewerPlugins/DimensionsPlugin/dimensiontool.cpp new file mode 100644 index 0000000..217d255 --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/dimensiontool.cpp @@ -0,0 +1,26 @@ +// Copyright (C) 2020 Jakub Melka +// +// This file is part of PdfForQt. +// +// PdfForQt is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// PdfForQt is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with PDFForQt. If not, see . + +#include "dimensiontool.h" + + +DimensionTool::DimensionTool(DimensionTool::Style style, pdf::PDFDrawWidgetProxy* proxy, QAction* action, QObject* parent) : + BaseClass(proxy, action, parent), + m_style(style) +{ + +} diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/dimensiontool.h b/PdfForQtViewerPlugins/DimensionsPlugin/dimensiontool.h new file mode 100644 index 0000000..b37431a --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/dimensiontool.h @@ -0,0 +1,52 @@ +// Copyright (C) 2020 Jakub Melka +// +// This file is part of PdfForQt. +// +// PdfForQt is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// PdfForQt is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with PDFForQt. If not, see . + +#ifndef DIMENSIONTOOL_H +#define DIMENSIONTOOL_H + +#include "pdfwidgettool.h" + +#include +#include + +class DimensionTool : public pdf::PDFWidgetTool +{ + Q_OBJECT + +private: + using BaseClass = pdf::PDFWidgetTool; + +public: + + enum Style + { + LinearHorizontal, + LinearVertical, + Linear, + Perimeter, + Area, + LastStyle + }; + + + explicit DimensionTool(Style style, pdf::PDFDrawWidgetProxy* proxy, QAction* action, QObject* parent); + +private: + Style m_style; +}; + +#endif // DIMENSIONTOOL_H diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/icons.qrc b/PdfForQtViewerPlugins/DimensionsPlugin/icons.qrc new file mode 100644 index 0000000..8ebeb6b --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/icons.qrc @@ -0,0 +1,9 @@ + + + area.svg + linear.svg + linear-horizontal.svg + linear-vertical.svg + perimeter.svg + + diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/linear-horizontal.svg b/PdfForQtViewerPlugins/DimensionsPlugin/linear-horizontal.svg new file mode 100644 index 0000000..45e9e13 --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/linear-horizontal.svg @@ -0,0 +1,114 @@ + + + + + + + + + + + + image/svg+xml + + + + + + Jakub Melka + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/linear-vertical.svg b/PdfForQtViewerPlugins/DimensionsPlugin/linear-vertical.svg new file mode 100644 index 0000000..d4c81d3 --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/linear-vertical.svg @@ -0,0 +1,118 @@ + + + + + + + + + + + + image/svg+xml + + + + + + Jakub Melka + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/linear.svg b/PdfForQtViewerPlugins/DimensionsPlugin/linear.svg new file mode 100644 index 0000000..a5c09ff --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/linear.svg @@ -0,0 +1,118 @@ + + + + + + + + + + + + image/svg+xml + + + + + + Jakub Melka + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PdfForQtViewerPlugins/DimensionsPlugin/perimeter.svg b/PdfForQtViewerPlugins/DimensionsPlugin/perimeter.svg new file mode 100644 index 0000000..fa5dc8c --- /dev/null +++ b/PdfForQtViewerPlugins/DimensionsPlugin/perimeter.svg @@ -0,0 +1,109 @@ + + + + + + + + + + + + image/svg+xml + + + + + + Jakub Melka + + + + + + + + + + + + + + + + + + + + + diff --git a/PdfTool/pdftoolabstractapplication.h b/PdfTool/pdftoolabstractapplication.h index 84e85eb..30ab21e 100644 --- a/PdfTool/pdftoolabstractapplication.h +++ b/PdfTool/pdftoolabstractapplication.h @@ -283,4 +283,6 @@ private: } // namespace pdftool +Q_DECLARE_OPERATORS_FOR_FLAGS(pdftool::PDFToolAbstractApplication::Options) + #endif // PDFTOOLABSTRACTAPPLICATION_H