Dimension plugins - basic tools

This commit is contained in:
Jakub Melka 2020-11-21 16:56:10 +01:00
parent 3b2d3877f7
commit ae970640bb
15 changed files with 989 additions and 19 deletions

View File

@ -730,14 +730,19 @@ PDFToolManager::PDFToolManager(PDFDrawWidgetProxy* proxy, Actions actions, QObje
for (PDFWidgetTool* tool : m_predefinedTools)
{
m_tools.insert(tool);
connect(tool, &PDFWidgetTool::messageDisplayRequest, this, &PDFToolManager::messageDisplayRequest);
addTool(tool);
}
}
if (QAction* action = tool->getAction())
{
m_actionsToTools[action] = tool;
connect(action, &QAction::triggered, this, &PDFToolManager::onToolActionTriggered);
}
void PDFToolManager::addTool(PDFWidgetTool* tool)
{
m_tools.insert(tool);
connect(tool, &PDFWidgetTool::messageDisplayRequest, this, &PDFToolManager::messageDisplayRequest);
if (QAction* action = tool->getAction())
{
m_actionsToTools[action] = tool;
connect(action, &QAction::triggered, this, &PDFToolManager::onToolActionTriggered);
}
}
@ -1142,6 +1147,11 @@ void PDFPickTool::mouseMoveEvent(QWidget* widget, QMouseEvent* event)
}
}
QPointF PDFPickTool::getSnappedPoint() const
{
return m_snapper.getSnappedPoint();
}
void PDFPickTool::setActiveImpl(bool active)
{
BaseClass::setActiveImpl(active);

View File

@ -323,6 +323,12 @@ public:
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
QPointF getSnappedPoint() const;
PDFInteger getPageIndex() const { return m_pageIndex; }
const std::vector<QPointF>& getPickedPoints() const { return m_pickedPoints; }
void resetTool();
signals:
void pointPicked(PDFInteger pageIndex, QPointF pagePoint);
void rectanglePicked(PDFInteger pageIndex, QRectF pageRectangle);
@ -332,7 +338,6 @@ protected:
virtual void setActiveImpl(bool active) override;
private:
void resetTool();
void buildSnapData();
Mode m_mode;
@ -437,6 +442,9 @@ public:
/// Sets active tool
void setActiveTool(PDFWidgetTool* tool);
/// Adds a new tool to tool manager
void addTool(PDFWidgetTool* tool);
/// Returns first active tool from tool set. If no tool is active,
/// then nullptr is returned.
PDFWidgetTool* getActiveTool() const;

View File

@ -64,6 +64,7 @@
#include <QtPrintSupport/QPrintDialog>
#include <QtConcurrent/QtConcurrent>
#include <QPluginLoader>
#include <QToolButton>
#ifdef Q_OS_WIN
#include "Windows.h"
@ -358,10 +359,23 @@ void PDFViewerMainWindow::loadPlugins()
if (!actions.empty())
{
QToolButton* toolbarButton = new QToolButton(ui->mainToolBar);
toolbarButton->setPopupMode(QToolButton::MenuButtonPopup);
toolbarButton->setMenu(new QMenu(toolbarButton));
toolbarButton->setDefaultAction(actions.front());
ui->mainToolBar->addWidget(toolbarButton);
QMenu* menu = ui->menuTools->addMenu(plugin.first.name);
for (QAction* action : actions)
{
if (!action)
{
menu->addSeparator();
toolbarButton->menu()->addSeparator();
}
menu->addAction(action);
toolbarButton->menu()->addAction(action);
connect(action, &QAction::triggered, toolbarButton, [action, toolbarButton](){ toolbarButton->setDefaultAction(action); });
}
}
}
@ -1188,6 +1202,11 @@ void PDFViewerMainWindow::setDocument(pdf::PDFModifiedDocument document)
updateTitle();
updateUI(true);
for (const auto& plugin : m_loadedPlugins)
{
plugin.second->setDocument(document);
}
if (m_pdfDocument && document.hasReset())
{
const pdf::PDFCatalog* catalog = m_pdfDocument->getCatalog();

View File

@ -34,11 +34,13 @@ CONFIG += c++11
SOURCES += \
dimensionsplugin.cpp \
dimensiontool.cpp
dimensiontool.cpp \
settingsdialog.cpp
HEADERS += \
dimensionsplugin.h \
dimensiontool.h
dimensiontool.h \
settingsdialog.h
CONFIG += force_debug_info
@ -47,3 +49,6 @@ DISTFILES += \
RESOURCES += \
icons.qrc
FORMS += \
settingsdialog.ui

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="30mm"
height="30mm"
viewBox="0 0 30 30"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="clear-dimensions.svg">
<defs
id="defs2">
<inkscape:path-effect
effect="spiro"
id="path-effect831"
is_visible="true" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="63.234605"
inkscape:cy="148.69816"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="3840"
inkscape:window-height="2035"
inkscape:window-x="-13"
inkscape:window-y="-13"
inkscape:window-maximized="1"
inkscape:snap-text-baseline="false" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
<dc:creator>
<cc:Agent>
<dc:title>Jakub Melka</dc:title>
</cc:Agent>
</dc:creator>
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="Vrstva 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-267)">
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 11.646391,283.58184 v 0 0"
id="path837"
inkscape:connector-curvature="0" />
<g
aria-label="🗑"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
id="text1421">
<path
d="m 9.9148255,278.00513 q -0.099219,-0.0882 -0.1543403,-0.13229 -0.3858507,-0.31971 -0.3858507,-0.80478 v -1.34496 q 0,-0.68351 0.5622396,-0.99219 1.5213539,-0.82682 4.8727429,-0.82682 3.362413,0 4.883768,0.82682 0.562239,0.30868 0.562239,0.99219 v 1.34496 q 0,0.48507 -0.385851,0.80478 -0.05512,0.0441 -0.15434,0.13229 v 10.55026 q 0,1.14653 -0.529167,1.51033 -1.444184,0.97014 -4.376649,0.97014 -2.921441,0 -4.365625,-0.97014 -0.5291665,-0.3638 -0.5291665,-1.51033 z m 4.9058155,-1.24575 q 2.017448,0 3.450608,-0.33073 1.444184,-0.33072 1.444184,-0.79375 0,-0.44097 -1.554427,-0.81579 -1.554427,-0.37483 -3.351389,-0.37483 -1.81901,0 -3.362413,0.38585 -1.5323785,0.37483 -1.5323785,0.8158 0,0.452 1.4441845,0.78272 1.455208,0.33073 3.461631,0.33073 z m -4.9058155,-0.4079 v 0.33073 q 0,1.84106 4.8947915,1.84106 4.905816,0 4.905816,-1.84106 v -0.33073 q -0.926042,0.47405 -2.160764,0.71658 -1.223698,0.23151 -2.745052,0.23151 -1.51033,0 -2.734028,-0.23151 -1.223698,-0.24253 -2.1607635,-0.71658 z m 0.5512155,1.94028 v 10.23056 q 0,0.98116 0.628385,1.30087 1.333941,0.67248 3.715191,0.67248 2.392274,0 3.726215,-0.67248 0.628386,-0.31971 0.628386,-1.30087 v -10.23056 q -0.374827,0.15434 -0.815799,0.29766 v 10.2967 l -0.540191,0.14332 v -10.29671 q -0.661458,0.12127 -1.631597,0.23151 v 10.30773 h -0.551215 v -10.30773 q -0.661459,0.0331 -0.815799,0.0331 -0.143316,0 -0.815798,-0.0331 v 10.30773 H 13.453628 V 278.96424 Q 12.483489,278.854 11.82203,278.73273 v 10.29671 l -0.540191,-0.14332 v -10.2967 q -0.440972,-0.14332 -0.815798,-0.29766 z"
style="stroke-width:0.26458332"
id="path1423"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -17,13 +17,17 @@
#include "dimensionsplugin.h"
#include "pdfdrawwidget.h"
#include "settingsdialog.h"
namespace pdfplugin
{
DimensionsPlugin::DimensionsPlugin() :
pdf::PDFPlugin(nullptr),
m_dimensionTools()
m_dimensionTools(),
m_showDimensionsAction(nullptr),
m_clearDimensionsAction(nullptr),
m_settingsAction(nullptr)
{
}
@ -46,23 +50,53 @@ void DimensionsPlugin::setWidget(pdf::PDFWidget* widget)
perimeterDimensionAction->setObjectName("dimensiontool_PerimeterAction");
areaDimensionAction->setObjectName("dimensiontool_AreaAction");
horizontalDimensionAction->setCheckable(true);
verticalDimensionAction->setCheckable(true);
linearDimensionAction->setCheckable(true);
perimeterDimensionAction->setCheckable(true);
areaDimensionAction->setCheckable(true);
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);
pdf::PDFToolManager* toolManager = widget->getToolManager();
for (DimensionTool* tool : m_dimensionTools)
{
toolManager->addTool(tool);
connect(tool, &DimensionTool::dimensionCreated, this, &DimensionsPlugin::onDimensionCreated);
}
m_showDimensionsAction = new QAction(QIcon(":/pdfplugins/dimensiontool/show-dimensions.svg"), tr("Show Dimensions"), this);
m_clearDimensionsAction = new QAction(QIcon(":/pdfplugins/dimensiontool/clear-dimensions.svg"), tr("Clear Dimensions"), this);
m_settingsAction = new QAction(QIcon(":/pdfplugins/dimensiontool/settings.svg"), tr("Settings"), this);
m_showDimensionsAction->setCheckable(true);
m_showDimensionsAction->setChecked(true);
connect(m_showDimensionsAction, &QAction::triggered, this, &DimensionsPlugin::onShowDimensionsTriggered);
connect(m_clearDimensionsAction, &QAction::triggered, this, &DimensionsPlugin::onClearDimensionsTriggered);
connect(m_settingsAction, &QAction::triggered, this, &DimensionsPlugin::onSettingsTriggered);
m_lengthUnit = DimensionUnit::getLengthUnits().front();
m_areaUnit = DimensionUnit::getAreaUnits().front();
m_angleUnit = DimensionUnit::getAngleUnits().front();
m_widget->getDrawWidgetProxy()->registerDrawInterface(this);
updateActions();
}
void DimensionsPlugin::setDocument(const pdf::PDFModifiedDocument& document)
{
BaseClass::setDocument(document);
for (DimensionTool* tool : m_dimensionTools)
if (document.hasReset())
{
if (tool)
{
tool->setDocument(document);
}
m_dimensions.clear();
updateActions();
}
}
@ -78,7 +112,73 @@ std::vector<QAction*> DimensionsPlugin::getActions() const
}
}
if (!result.empty())
{
result.push_back(nullptr);
result.push_back(m_showDimensionsAction);
result.push_back(m_clearDimensionsAction);
result.push_back(m_settingsAction);
}
return result;
}
void DimensionsPlugin::drawPage(QPainter* painter,
pdf::PDFInteger pageIndex,
const pdf::PDFPrecompiledPage* compiledPage,
pdf::PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
QList<pdf::PDFRenderError>& errors) const
{
if (!m_showDimensionsAction || !m_showDimensionsAction->isChecked())
{
// Nothing to draw
return;
}
}
void DimensionsPlugin::onShowDimensionsTriggered()
{
if (m_widget)
{
m_widget->update();
}
}
void DimensionsPlugin::onClearDimensionsTriggered()
{
m_dimensions.clear();
if (m_widget)
{
m_widget->update();
}
updateActions();
}
void DimensionsPlugin::onSettingsTriggered()
{
SettingsDialog dialog(m_widget, m_lengthUnit, m_areaUnit, m_angleUnit);
dialog.exec();
m_widget->update();
}
void DimensionsPlugin::onDimensionCreated(Dimension dimension)
{
m_dimensions.emplace_back(qMove(dimension));
updateActions();
}
void DimensionsPlugin::updateActions()
{
if (m_showDimensionsAction)
{
m_showDimensionsAction->setEnabled(!m_dimensions.empty());
}
if (m_clearDimensionsAction)
{
m_clearDimensionsAction->setEnabled(!m_dimensions.empty());
}
}
}

View File

@ -26,7 +26,7 @@
namespace pdfplugin
{
class DimensionsPlugin : public pdf::PDFPlugin
class DimensionsPlugin : public pdf::PDFPlugin, public pdf::IDocumentDrawInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "PdfForQt.DimensionsPlugin" FILE "DimensionsPlugin.json")
@ -41,8 +41,30 @@ public:
virtual void setDocument(const pdf::PDFModifiedDocument& document) override;
virtual std::vector<QAction*> getActions() const override;
virtual void drawPage(QPainter* painter,
pdf::PDFInteger pageIndex,
const pdf::PDFPrecompiledPage* compiledPage,
pdf::PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
QList<pdf::PDFRenderError>& errors) const override;
private:
void onShowDimensionsTriggered();
void onClearDimensionsTriggered();
void onSettingsTriggered();
void onDimensionCreated(Dimension dimension);
void updateActions();
std::array<DimensionTool*, DimensionTool::LastStyle> m_dimensionTools;
std::vector<Dimension> m_dimensions;
QAction* m_showDimensionsAction;
QAction* m_clearDimensionsAction;
QAction* m_settingsAction;
DimensionUnit m_lengthUnit;
DimensionUnit m_areaUnit;
DimensionUnit m_angleUnit;
};
} // namespace pdfplugin

View File

@ -16,11 +16,221 @@
// along with PDFForQt. If not, see <https://www.gnu.org/licenses/>.
#include "dimensiontool.h"
#include "pdfwidgetutils.h"
#include "pdfdrawwidget.h"
#include <QPainter>
DimensionTool::DimensionTool(DimensionTool::Style style, pdf::PDFDrawWidgetProxy* proxy, QAction* action, QObject* parent) :
BaseClass(proxy, action, parent),
m_style(style)
m_style(style),
m_previewPointPixelSize(0),
m_pickTool(nullptr)
{
m_pickTool = new pdf::PDFPickTool(proxy, pdf::PDFPickTool::Mode::Points, this);
addTool(m_pickTool);
connect(m_pickTool, &pdf::PDFPickTool::pointPicked, this, &DimensionTool::onPointPicked);
m_previewPointPixelSize = pdf::PDFWidgetUtils::scaleDPI_x(proxy->getWidget(), 5);
}
void DimensionTool::drawPage(QPainter* painter,
pdf::PDFInteger pageIndex,
const pdf::PDFPrecompiledPage* compiledPage,
pdf::PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
QList<pdf::PDFRenderError>& errors) const
{
Q_UNUSED(compiledPage);
Q_UNUSED(layoutGetter);
Q_UNUSED(errors);
if (m_pickTool->getPageIndex() != pageIndex)
{
// Other page, nothing to draw
return;
}
painter->setPen(Qt::black);
const std::vector<QPointF>& points = m_pickTool->getPickedPoints();
for (size_t i = 1; i < points.size(); ++i)
{
painter->drawLine(pagePointToDevicePointMatrix.map(points[i - 1]), pagePointToDevicePointMatrix.map(points[i]));
}
if (!points.empty())
{
QMatrix inverted = pagePointToDevicePointMatrix.inverted();
QPointF adjustedPoint = adjustPagePoint(inverted.map(m_pickTool->getSnappedPoint()));
painter->drawLine(pagePointToDevicePointMatrix.map(points.back()), pagePointToDevicePointMatrix.map(adjustedPoint));
}
QPen pen = painter->pen();
pen.setWidth(m_previewPointPixelSize);
pen.setCapStyle(Qt::RoundCap);
painter->setPen(pen);
for (size_t i = 0; i < points.size(); ++i)
{
painter->drawPoint(pagePointToDevicePointMatrix.map(points[i]));
}
}
void DimensionTool::onPointPicked(pdf::PDFInteger pageIndex, QPointF pagePoint)
{
if (Dimension::isComplete(getDimensionType(), m_pickTool->getPickedPoints()))
{
// Create a new dimension...
emit dimensionCreated(Dimension(pageIndex, getMeasuredValue(), m_pickTool->getPickedPoints()));
m_pickTool->resetTool();
}
}
QPointF DimensionTool::adjustPagePoint(QPointF pagePoint) const
{
switch (m_style)
{
case Style::LinearHorizontal:
{
const std::vector<QPointF>& pickedPoints = m_pickTool->getPickedPoints();
if (!pickedPoints.empty())
{
pagePoint.setY(pickedPoints.front().y());
}
break;
}
case Style::LinearVertical:
{
const std::vector<QPointF>& pickedPoints = m_pickTool->getPickedPoints();
if (!pickedPoints.empty())
{
pagePoint.setX(pickedPoints.front().x());
}
break;
}
default:
break;
}
return pagePoint;
}
Dimension::Type DimensionTool::getDimensionType() const
{
switch (m_style)
{
case DimensionTool::LinearHorizontal:
case DimensionTool::LinearVertical:
case DimensionTool::Linear:
return Dimension::Type::Linear;
case DimensionTool::Perimeter:
return Dimension::Type::Perimeter;
case DimensionTool::Area:
return Dimension::Type::Area;
}
Q_ASSERT(false);
return Dimension::Type::Linear;
}
pdf::PDFReal DimensionTool::getMeasuredValue() const
{
const std::vector<QPointF>& pickedPoints = m_pickTool->getPickedPoints();
switch (getDimensionType())
{
case Dimension::Linear:
case Dimension::Perimeter:
{
pdf::PDFReal length = 0.0;
for (size_t i = 1; i < pickedPoints.size(); ++i)
{
QPointF vector = pickedPoints[i] - pickedPoints[i - 1];
length += qSqrt(QPointF::dotProduct(vector, vector));
}
break;
}
case Dimension::Area:
{
pdf::PDFReal area = 0.0;
// We calculate the area using standard formula for polygons.
// We determine integral over perimeter (for each edge of the polygon).
for (size_t i = 1; i < pickedPoints.size(); ++i)
{
const QPointF& p1 = pickedPoints[i - 1];
const QPointF& p2 = pickedPoints[i];
area += p1.x() * p2.y() - p1.y() * p2.x();
}
area = qAbs(area) * 0.5;
break;
}
default:
Q_ASSERT(false);
break;
}
return 0.0;
}
bool Dimension::isComplete(Type type, const std::vector<QPointF>& polygon)
{
switch (type)
{
case Dimension::Linear:
return polygon.size() == 2;
case Dimension::Perimeter:
case Dimension::Area:
return polygon.size() > 2 && polygon.front() == polygon.back();
default:
Q_ASSERT(false);
break;
}
return false;
}
DimensionUnits DimensionUnit::getLengthUnits()
{
DimensionUnits units;
units.emplace_back(1.0, DimensionTool::tr("pt"));
units.emplace_back(pdf::PDF_POINT_TO_INCH, DimensionTool::tr("in"));
units.emplace_back(pdf::PDF_POINT_TO_MM, DimensionTool::tr("mm"));
units.emplace_back(pdf::PDF_POINT_TO_MM * 0.1, DimensionTool::tr("cm"));
return units;
}
DimensionUnits DimensionUnit::getAreaUnits()
{
DimensionUnits units;
units.emplace_back(1.0, DimensionTool::tr("sq. pt"));
units.emplace_back(pdf::PDF_POINT_TO_INCH * pdf::PDF_POINT_TO_INCH, DimensionTool::tr("sq. in"));
units.emplace_back(pdf::PDF_POINT_TO_MM * pdf::PDF_POINT_TO_MM, DimensionTool::tr("sq. mm"));
units.emplace_back(pdf::PDF_POINT_TO_MM * 0.1 * pdf::PDF_POINT_TO_MM * 0.1, DimensionTool::tr("sq. cm"));
return units;
}
DimensionUnits DimensionUnit::getAngleUnits()
{
DimensionUnits units;
units.emplace_back(qRadiansToDegrees(1.0), DimensionTool::tr("°"));
units.emplace_back(1.0, DimensionTool::tr("rad"));
return units;
}

View File

@ -23,6 +23,56 @@
#include <QAction>
#include <QPolygonF>
struct DimensionUnit;
using DimensionUnits = std::vector<DimensionUnit>;
struct DimensionUnit
{
explicit inline DimensionUnit() = default;
explicit inline DimensionUnit(pdf::PDFReal scale, QString symbol) :
scale(scale),
symbol(qMove(symbol))
{
}
pdf::PDFReal scale = 1.0;
QString symbol;
static DimensionUnits getLengthUnits();
static DimensionUnits getAreaUnits();
static DimensionUnits getAngleUnits();
};
class Dimension
{
public:
inline explicit Dimension() = default;
inline explicit Dimension(pdf::PDFInteger pageIndex, pdf::PDFReal measuredValue, std::vector<QPointF> polygon) :
m_pageIndex(pageIndex),
m_measuredValue(measuredValue),
m_polygon(qMove(polygon))
{
}
enum Type
{
Linear,
Perimeter,
Area
};
/// Returns true, if definition fo given type is complete
static bool isComplete(Type type, const std::vector<QPointF>& polygon);
private:
pdf::PDFInteger m_pageIndex = -1;
pdf::PDFReal m_measuredValue = 0.0;
std::vector<QPointF> m_polygon;
};
class DimensionTool : public pdf::PDFWidgetTool
{
Q_OBJECT
@ -45,8 +95,25 @@ public:
explicit DimensionTool(Style style, pdf::PDFDrawWidgetProxy* proxy, QAction* action, QObject* parent);
void drawPage(QPainter* painter,
pdf::PDFInteger pageIndex,
const pdf::PDFPrecompiledPage* compiledPage,
pdf::PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
QList<pdf::PDFRenderError>& errors) const override;
signals:
void dimensionCreated(Dimension dimension);
private:
void onPointPicked(pdf::PDFInteger pageIndex, QPointF pagePoint);
QPointF adjustPagePoint(QPointF pagePoint) const;
Dimension::Type getDimensionType() const;
pdf::PDFReal getMeasuredValue() const;
Style m_style;
int m_previewPointPixelSize;
pdf::PDFPickTool* m_pickTool;
};
#endif // DIMENSIONTOOL_H

View File

@ -5,5 +5,8 @@
<file>linear-horizontal.svg</file>
<file>linear-vertical.svg</file>
<file>perimeter.svg</file>
<file>clear-dimensions.svg</file>
<file>settings.svg</file>
<file>show-dimensions.svg</file>
</qresource>
</RCC>

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="30mm"
height="30mm"
viewBox="0 0 30 30"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="settings.svg">
<defs
id="defs2">
<inkscape:path-effect
effect="spiro"
id="path-effect831"
is_visible="true" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="7.4236769"
inkscape:cy="148.69816"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="3840"
inkscape:window-height="2035"
inkscape:window-x="-13"
inkscape:window-y="-13"
inkscape:window-maximized="1"
inkscape:snap-text-baseline="false" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
<dc:creator>
<cc:Agent>
<dc:title>Jakub Melka</dc:title>
</cc:Agent>
</dc:creator>
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="Vrstva 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-267)">
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 11.646391,283.58184 v 0 0"
id="path837"
inkscape:connector-curvature="0" />
<g
aria-label="🛠"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:22.57777786px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
id="text1428">
<path
d="m 24.477933,276.6919 q 0.110243,0.38585 0.110243,0.7717 0,1.1355 -0.79375,1.92925 -0.79375,0.79375 -1.929253,0.79375 -0.418924,0 -0.826823,-0.12126 l -2.656858,2.65685 6.030295,5.76572 -2.403298,2.40329 -5.776737,-6.03029 -2.524566,2.53559 q 0.121268,0.4079 0.121268,0.8158 0,1.14653 -0.79375,1.94028 -0.782726,0.79375 -1.929254,0.79375 -0.38585,0 -0.771701,-0.11025 l 2.094618,-2.09461 -2.061545,-2.06155 -2.0946183,2.09462 q -0.110243,-0.38585 -0.110243,-0.7717 0,-1.13551 0.79375,-1.92926 0.79375,-0.79375 1.9402773,-0.79375 0.385851,0 0.771702,0.0992 l 2.590712,-2.57969 -3.748264,-3.91362 1.89618,-1.89618 3.902605,3.74826 2.711979,-2.71198 q -0.09922,-0.37483 -0.09922,-0.76068 0,-1.15755 0.79375,-1.9513 0.79375,-0.79375 1.929253,-0.79375 0.396875,0 0.782726,0.11024 l -2.094618,2.09462 2.050521,2.06155 z m -14.033941,-1.65365 -1.8851563,1.88516 -0.3638021,-0.3638 1.8851564,-1.88516 z m 6.19566,0.30868 q -0.694532,-0.2756 -1.43316,-0.2756 -1.113455,0 -1.830035,0.70555 l -4.1230901,4.12309 0.429948,0.42995 -1.5654514,1.57648 -2.6348091,-2.63481 1.5654514,-1.56545 0.4850695,0.47404 4.1010417,-4.10104 q 0.848871,-0.83785 1.81901,-0.83785 1.631598,0 3.186025,2.10564 z"
style="stroke-width:0.26458332"
id="path1430"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,65 @@
// 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 <https://www.gnu.org/licenses/>.
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include "pdfwidgetutils.h"
SettingsDialog::SettingsDialog(QWidget* parent, DimensionUnit& lengthUnit, DimensionUnit& areaUnit, DimensionUnit& angleUnit) :
QDialog(parent),
ui(new Ui::SettingsDialog),
m_lengthUnit(lengthUnit),
m_areaUnit(areaUnit),
m_angleUnit(angleUnit)
{
ui->setupUi(this);
m_lengthUnits = DimensionUnit::getLengthUnits();
m_areaUnits = DimensionUnit::getAreaUnits();
m_angleUnits = DimensionUnit::getAngleUnits();
initComboBox(m_lengthUnits, m_lengthUnit, ui->lengthsComboBox);
initComboBox(m_areaUnits, m_areaUnit, ui->areasComboBox);
initComboBox(m_angleUnits, m_angleUnit, ui->anglesComboBox);
setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(320, 160)));
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
void SettingsDialog::initComboBox(const DimensionUnits& units, const DimensionUnit& currentUnit, QComboBox* comboBox)
{
for (const DimensionUnit& unit : units)
{
comboBox->addItem(unit.symbol, unit.symbol);
}
comboBox->setCurrentIndex(comboBox->findText(currentUnit.symbol));
}
void SettingsDialog::accept()
{
m_lengthUnit = m_lengthUnits[ui->lengthsComboBox->currentIndex()];
m_areaUnit = m_areaUnits[ui->areasComboBox->currentIndex()];
m_angleUnit = m_angleUnits[ui->anglesComboBox->currentIndex()];
QDialog::accept();
}

View File

@ -0,0 +1,58 @@
// 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 <https://www.gnu.org/licenses/>.
#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H
#include "dimensiontool.h"
#include <QDialog>
class QComboBox;
namespace Ui
{
class SettingsDialog;
}
class SettingsDialog : public QDialog
{
Q_OBJECT
public:
explicit SettingsDialog(QWidget* parent,
DimensionUnit& lengthUnit,
DimensionUnit& areaUnit,
DimensionUnit& angleUnit);
virtual ~SettingsDialog() override;
virtual void accept() override;
private:
Ui::SettingsDialog* ui;
void initComboBox(const DimensionUnits& units, const DimensionUnit& currentUnit, QComboBox* comboBox);
DimensionUnits m_lengthUnits;
DimensionUnits m_areaUnits;
DimensionUnits m_angleUnits;
DimensionUnit& m_lengthUnit;
DimensionUnit& m_areaUnit;
DimensionUnit& m_angleUnit;
};
#endif // SETTINGSDIALOG_H

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SettingsDialog</class>
<widget class="QDialog" name="SettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>254</width>
<height>165</height>
</rect>
</property>
<property name="windowTitle">
<string>Unit Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="unitsGroupBox">
<property name="title">
<string>Units</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="lengthsLabel">
<property name="text">
<string>Lengths</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="lengthsComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="areasLabel">
<property name="text">
<string>Areas</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="areasComboBox"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="anglesLabel">
<property name="text">
<string>Angles</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="anglesComboBox"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="30mm"
height="30mm"
viewBox="0 0 30 30"
version="1.1"
id="svg8"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="show-dimensions.svg">
<defs
id="defs2">
<inkscape:path-effect
effect="spiro"
id="path-effect831"
is_visible="true" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="7.4236769"
inkscape:cy="148.69816"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="3840"
inkscape:window-height="2035"
inkscape:window-x="-13"
inkscape:window-y="-13"
inkscape:window-maximized="1"
inkscape:snap-text-baseline="false" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
<dc:creator>
<cc:Agent>
<dc:title>Jakub Melka</dc:title>
</cc:Agent>
</dc:creator>
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="Vrstva 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-267)">
<path
style="fill:none;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 11.646391,283.58184 v 0 0"
id="path837"
inkscape:connector-curvature="0" />
<g
aria-label="👁"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:33.86666489px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
id="text1414">
<path
d="m 29.186513,281.64292 q -1.273307,2.29857 -3.125391,3.91914 -4.448307,3.93568 -11.046353,3.93568 -6.5980467,0 -11.0628902,-3.93568 -1.8520832,-1.62057 -3.14192692,-3.91914 1.28984372,-2.29857 3.14192692,-3.93567 4.4648435,-3.93568 11.0628902,-3.93568 6.598046,0 11.046353,3.93568 1.852084,1.6371 3.125391,3.93567 z m -2.695443,0 q -0.810286,-1.42213 -1.967838,-2.54661 -2.778125,-2.67891 -6.846094,-3.3569 1.769401,0.76067 2.844271,2.33164 1.091406,1.62057 1.091406,3.57187 0,1.93477 -1.074869,3.52227 -1.058334,1.5875 -2.794662,2.36471 5.986198,-1.02526 8.747786,-5.88698 z m -6.250781,0 q 0,-2.11666 -1.53789,-3.62148 -1.537891,-1.50482 -3.704167,-1.50482 -1.141015,0 -2.166276,0.46302 l -0.545703,-1.24023 q -6.0027337,1.02526 -8.7808586,5.90351 0.8102865,1.42214 1.951302,2.53008 2.7615884,2.66237 6.7799476,3.3569 -1.736328,-0.77721 -2.7946613,-2.36471 -1.0583333,-1.5875 -1.0583333,-3.52227 0,-1.17409 0.4134114,-2.28203 l 1.3229162,0.41341 q -0.3638016,0.90951 -0.3638016,1.86862 0,2.13321 1.5378906,3.63802 1.53789,1.48828 3.704166,1.48828 2.166276,0 3.704167,-1.48828 1.53789,-1.50481 1.53789,-3.63802 z m -1.273307,0 q 0,1.60404 -1.174088,2.74505 -1.157552,1.14102 -2.794662,1.14102 -1.653645,0 -2.811197,-1.14102 -1.157552,-1.14101 -1.157552,-2.74505 0,-0.71107 0.248046,-1.37252 l 4.051433,1.83554 -1.901693,-4.01836 q 0.744141,-0.33072 1.570963,-0.33072 1.63711,0 2.794662,1.14101 1.174088,1.14102 1.174088,2.74505 z"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:33.86666489px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;writing-mode:lr-tb;text-anchor:start;stroke-width:0.26458332"
id="path1416"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 5.2 KiB