mirror of https://github.com/JakubMelka/PDF4QT.git
Issue #100: Annotation rectangle
This commit is contained in:
parent
edc86a84fa
commit
3d32db2046
|
@ -202,9 +202,12 @@ PDFCreateLineTypeTool::PDFCreateLineTypeTool(PDFDrawWidgetProxy* proxy, PDFToolM
|
||||||
m_strokeColor(Qt::red),
|
m_strokeColor(Qt::red),
|
||||||
m_fillColor(Qt::yellow)
|
m_fillColor(Qt::yellow)
|
||||||
{
|
{
|
||||||
m_pickTool = new PDFPickTool(proxy, PDFPickTool::Mode::Points, this);
|
PDFPickTool::Mode mode = (type != Type::Rectangle) ? PDFPickTool::Mode::Points : PDFPickTool::Mode::Rectangles;
|
||||||
|
m_pickTool = new PDFPickTool(proxy, mode, this);
|
||||||
addTool(m_pickTool);
|
addTool(m_pickTool);
|
||||||
connect(m_pickTool, &PDFPickTool::pointPicked, this, &PDFCreateLineTypeTool::onPointPicked);
|
connect(m_pickTool, &PDFPickTool::pointPicked, this, &PDFCreateLineTypeTool::onPointPicked);
|
||||||
|
connect(m_pickTool, &PDFPickTool::rectanglePicked, this, &PDFCreateLineTypeTool::onRectanglePicked);
|
||||||
|
m_pickTool->setDrawSelectionRectangle(false);
|
||||||
|
|
||||||
m_fillColor.setAlphaF(0.2f);
|
m_fillColor.setAlphaF(0.2f);
|
||||||
|
|
||||||
|
@ -222,6 +225,14 @@ void PDFCreateLineTypeTool::onPointPicked(PDFInteger pageIndex, QPointF pagePoin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PDFCreateLineTypeTool::onRectanglePicked(PDFInteger pageIndex, QRectF pageRectangle)
|
||||||
|
{
|
||||||
|
m_rectPageIndex = pageIndex;
|
||||||
|
m_rectOnPage = pageRectangle;
|
||||||
|
|
||||||
|
finishDefinition();
|
||||||
|
}
|
||||||
|
|
||||||
void PDFCreateLineTypeTool::finishDefinition()
|
void PDFCreateLineTypeTool::finishDefinition()
|
||||||
{
|
{
|
||||||
const std::vector<QPointF>& pickedPoints = m_pickTool->getPickedPoints();
|
const std::vector<QPointF>& pickedPoints = m_pickTool->getPickedPoints();
|
||||||
|
@ -309,6 +320,36 @@ void PDFCreateLineTypeTool::finishDefinition()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Type::Rectangle:
|
||||||
|
{
|
||||||
|
if (!m_rectOnPage.isEmpty())
|
||||||
|
{
|
||||||
|
PDFDocumentModifier modifier(getDocument());
|
||||||
|
|
||||||
|
QPolygonF polygon;
|
||||||
|
polygon << m_rectOnPage.topLeft();
|
||||||
|
polygon << m_rectOnPage.topRight();
|
||||||
|
polygon << m_rectOnPage.bottomRight();
|
||||||
|
polygon << m_rectOnPage.bottomLeft();
|
||||||
|
polygon << m_rectOnPage.topLeft();
|
||||||
|
|
||||||
|
QString userName = PDFSysUtils::getUserName();
|
||||||
|
PDFObjectReference page = getDocument()->getCatalog()->getPage(m_pickTool->getPageIndex())->getPageReference();
|
||||||
|
PDFObjectReference annotation = modifier.getBuilder()->createAnnotationPolygon(page, polygon, m_penWidth, m_fillColor, m_strokeColor, userName, QString(), QString());
|
||||||
|
modifier.getBuilder()->setAnnotationFillOpacity(annotation, m_fillColor.alphaF());
|
||||||
|
modifier.getBuilder()->updateAnnotationAppearanceStreams(annotation);
|
||||||
|
modifier.markAnnotationsChanged();
|
||||||
|
|
||||||
|
if (modifier.finalize())
|
||||||
|
{
|
||||||
|
Q_EMIT m_toolManager->documentModified(PDFModifiedDocument(modifier.getDocument(), nullptr, modifier.getFlags()));
|
||||||
|
}
|
||||||
|
|
||||||
|
setActive(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
break;
|
break;
|
||||||
|
@ -476,6 +517,19 @@ void PDFCreateLineTypeTool::drawPage(QPainter* painter,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Type::Rectangle:
|
||||||
|
{
|
||||||
|
QPointF startPoint = points.front();
|
||||||
|
qreal x1 = qMin(startPoint.x(), mousePoint.x());
|
||||||
|
qreal y1 = qMin(startPoint.y(), mousePoint.y());
|
||||||
|
qreal x2 = qMax(startPoint.x(), mousePoint.x());
|
||||||
|
qreal y2 = qMax(startPoint.y(), mousePoint.y());
|
||||||
|
|
||||||
|
QRectF rect(x1, y1, x2 - x1, y2 - y1);
|
||||||
|
painter->drawRect(rect);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -121,7 +121,8 @@ public:
|
||||||
{
|
{
|
||||||
Line,
|
Line,
|
||||||
PolyLine,
|
PolyLine,
|
||||||
Polygon
|
Polygon,
|
||||||
|
Rectangle
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit PDFCreateLineTypeTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, Type type, QAction* action, QObject* parent);
|
explicit PDFCreateLineTypeTool(PDFDrawWidgetProxy* proxy, PDFToolManager* toolManager, Type type, QAction* action, QObject* parent);
|
||||||
|
@ -145,6 +146,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void onPointPicked(PDFInteger pageIndex, QPointF pagePoint);
|
void onPointPicked(PDFInteger pageIndex, QPointF pagePoint);
|
||||||
|
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF pageRectangle);
|
||||||
void finishDefinition();
|
void finishDefinition();
|
||||||
|
|
||||||
PDFToolManager* m_toolManager;
|
PDFToolManager* m_toolManager;
|
||||||
|
@ -153,6 +155,8 @@ private:
|
||||||
PDFReal m_penWidth;
|
PDFReal m_penWidth;
|
||||||
QColor m_strokeColor;
|
QColor m_strokeColor;
|
||||||
QColor m_fillColor;
|
QColor m_fillColor;
|
||||||
|
PDFInteger m_rectPageIndex = 0;
|
||||||
|
QRectF m_rectOnPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Tool that creates ellipse annotation.
|
/// Tool that creates ellipse annotation.
|
||||||
|
|
|
@ -98,5 +98,6 @@
|
||||||
<file>resources/sidebar-thumbnails.png</file>
|
<file>resources/sidebar-thumbnails.png</file>
|
||||||
<file>resources/sidebar-visibility.png</file>
|
<file>resources/sidebar-visibility.png</file>
|
||||||
<file>resources/sidebar-attachment.png</file>
|
<file>resources/sidebar-attachment.png</file>
|
||||||
|
<file>resources/annot-rectangle.svg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -982,6 +982,8 @@ void PDFProgramController::initializeToolManager()
|
||||||
m_toolManager->addTool(createStraightLineTool);
|
m_toolManager->addTool(createStraightLineTool);
|
||||||
pdf::PDFCreateLineTypeTool* createPolylineTool = new pdf::PDFCreateLineTypeTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, pdf::PDFCreateLineTypeTool::Type::PolyLine, m_actionManager->getAction(PDFActionManager::CreatePolyline), this);
|
pdf::PDFCreateLineTypeTool* createPolylineTool = new pdf::PDFCreateLineTypeTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, pdf::PDFCreateLineTypeTool::Type::PolyLine, m_actionManager->getAction(PDFActionManager::CreatePolyline), this);
|
||||||
m_toolManager->addTool(createPolylineTool);
|
m_toolManager->addTool(createPolylineTool);
|
||||||
|
pdf::PDFCreateLineTypeTool* createRectangleTool = new pdf::PDFCreateLineTypeTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, pdf::PDFCreateLineTypeTool::Type::Rectangle, m_actionManager->getAction(PDFActionManager::CreateRectangle), this);
|
||||||
|
m_toolManager->addTool(createRectangleTool);
|
||||||
pdf::PDFCreateLineTypeTool* createPolygonTool = new pdf::PDFCreateLineTypeTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, pdf::PDFCreateLineTypeTool::Type::Polygon, m_actionManager->getAction(PDFActionManager::CreatePolygon), this);
|
pdf::PDFCreateLineTypeTool* createPolygonTool = new pdf::PDFCreateLineTypeTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, pdf::PDFCreateLineTypeTool::Type::Polygon, m_actionManager->getAction(PDFActionManager::CreatePolygon), this);
|
||||||
m_toolManager->addTool(createPolygonTool);
|
m_toolManager->addTool(createPolygonTool);
|
||||||
pdf::PDFCreateEllipseTool* createEllipseTool = new pdf::PDFCreateEllipseTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, m_actionManager->getAction(PDFActionManager::CreateEllipse), this);
|
pdf::PDFCreateEllipseTool* createEllipseTool = new pdf::PDFCreateEllipseTool(m_pdfWidget->getDrawWidgetProxy(), m_toolManager, m_actionManager->getAction(PDFActionManager::CreateEllipse), this);
|
||||||
|
|
|
@ -134,6 +134,7 @@ public:
|
||||||
CreateInlineText,
|
CreateInlineText,
|
||||||
CreateStraightLine,
|
CreateStraightLine,
|
||||||
CreatePolyline,
|
CreatePolyline,
|
||||||
|
CreateRectangle,
|
||||||
CreatePolygon,
|
CreatePolygon,
|
||||||
CreateEllipse,
|
CreateEllipse,
|
||||||
CreateFreehandCurve,
|
CreateFreehandCurve,
|
||||||
|
|
|
@ -141,6 +141,7 @@ PDFViewerMainWindow::PDFViewerMainWindow(QWidget* parent) :
|
||||||
m_actionManager->setAction(PDFActionManager::CreateInlineText, ui->actionInlineText);
|
m_actionManager->setAction(PDFActionManager::CreateInlineText, ui->actionInlineText);
|
||||||
m_actionManager->setAction(PDFActionManager::CreateStraightLine, ui->actionCreateStraightLine);
|
m_actionManager->setAction(PDFActionManager::CreateStraightLine, ui->actionCreateStraightLine);
|
||||||
m_actionManager->setAction(PDFActionManager::CreatePolyline, ui->actionCreatePolyline);
|
m_actionManager->setAction(PDFActionManager::CreatePolyline, ui->actionCreatePolyline);
|
||||||
|
m_actionManager->setAction(PDFActionManager::CreateRectangle, ui->actionCreateRectangle);
|
||||||
m_actionManager->setAction(PDFActionManager::CreatePolygon, ui->actionCreatePolygon);
|
m_actionManager->setAction(PDFActionManager::CreatePolygon, ui->actionCreatePolygon);
|
||||||
m_actionManager->setAction(PDFActionManager::CreateEllipse, ui->actionCreateEllipse);
|
m_actionManager->setAction(PDFActionManager::CreateEllipse, ui->actionCreateEllipse);
|
||||||
m_actionManager->setAction(PDFActionManager::CreateFreehandCurve, ui->actionCreateFreehandCurve);
|
m_actionManager->setAction(PDFActionManager::CreateFreehandCurve, ui->actionCreateFreehandCurve);
|
||||||
|
|
|
@ -181,6 +181,7 @@
|
||||||
<addaction name="actionInlineText"/>
|
<addaction name="actionInlineText"/>
|
||||||
<addaction name="actionCreateStraightLine"/>
|
<addaction name="actionCreateStraightLine"/>
|
||||||
<addaction name="actionCreatePolyline"/>
|
<addaction name="actionCreatePolyline"/>
|
||||||
|
<addaction name="actionCreateRectangle"/>
|
||||||
<addaction name="actionCreatePolygon"/>
|
<addaction name="actionCreatePolygon"/>
|
||||||
<addaction name="actionCreateEllipse"/>
|
<addaction name="actionCreateEllipse"/>
|
||||||
<addaction name="actionCreateFreehandCurve"/>
|
<addaction name="actionCreateFreehandCurve"/>
|
||||||
|
@ -763,6 +764,18 @@
|
||||||
<string>Polyline</string>
|
<string>Polyline</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionCreateRectangle">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="pdf4qtviewer.qrc">
|
||||||
|
<normaloff>:/resources/annot-rectangle.svg</normaloff>:/resources/annot-rectangle.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Rectangle</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="actionCreatePolygon">
|
<action name="actionCreatePolygon">
|
||||||
<property name="checkable">
|
<property name="checkable">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||||
|
|
||||||
|
<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"
|
||||||
|
version="1.1"
|
||||||
|
id="Vrstva_1"
|
||||||
|
x="0px"
|
||||||
|
y="0px"
|
||||||
|
width="24px"
|
||||||
|
height="24px"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
enable-background="new 0 0 24 24"
|
||||||
|
xml:space="preserve"
|
||||||
|
sodipodi:docname="annot-rectangle.svg"
|
||||||
|
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"><metadata
|
||||||
|
id="metadata17"><rdf:RDF><cc:Work
|
||||||
|
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /></cc:Work></rdf:RDF></metadata><defs
|
||||||
|
id="defs15" /><sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="3840"
|
||||||
|
inkscape:window-height="2035"
|
||||||
|
id="namedview13"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="9.8333333"
|
||||||
|
inkscape:cx="12"
|
||||||
|
inkscape:cy="12"
|
||||||
|
inkscape:window-x="-13"
|
||||||
|
inkscape:window-y="-13"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="Vrstva_1" />
|
||||||
|
<g
|
||||||
|
id="g8">
|
||||||
|
<g
|
||||||
|
id="g6">
|
||||||
|
<path
|
||||||
|
d="m 22,10 v 5 c 0,5 -2,7 -7,7 H 9 C 4,22 2,20 2,15 V 9 C 2,4 4,2 9,2 h 5"
|
||||||
|
id="path2"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:none;stroke:#292d32;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round" />
|
||||||
|
<path
|
||||||
|
d="M 22,10 H 18 C 15,10 14,9 14,6 V 2 Z"
|
||||||
|
id="path4"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
style="fill:none;stroke:#292d32;stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
<g
|
||||||
|
id="g10">
|
||||||
|
|
||||||
|
</g>
|
||||||
|
<rect
|
||||||
|
style="opacity:1;fill:none;fill-opacity:1;stroke:#292d32;stroke-width:1.2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;paint-order:stroke fill markers"
|
||||||
|
id="rect824"
|
||||||
|
width="9.1525431"
|
||||||
|
height="7.9322033"
|
||||||
|
x="7.6271186"
|
||||||
|
y="11.694916"
|
||||||
|
ry="0" /></svg>
|
After Width: | Height: | Size: 2.3 KiB |
Loading…
Reference in New Issue