Signature plugin: selection

This commit is contained in:
Jakub Melka 2022-03-08 19:36:52 +01:00
parent 6037f77a22
commit a401b8c031
2 changed files with 80 additions and 3 deletions

View File

@ -296,6 +296,11 @@ void PDFPageContentElementRectangle::performManipulation(uint mode, const QPoint
performRectangleManipulation(m_rectangle, mode, offset); performRectangleManipulation(m_rectangle, mode, offset);
} }
QRectF PDFPageContentElementRectangle::getBoundingBox() const
{
return getRectangle();
}
PDFPageContentScene::PDFPageContentScene(QObject* parent) : PDFPageContentScene::PDFPageContentScene(QObject* parent) :
QObject(parent), QObject(parent),
m_firstFreeId(1), m_firstFreeId(1),
@ -303,7 +308,7 @@ PDFPageContentScene::PDFPageContentScene(QObject* parent) :
m_widget(nullptr), m_widget(nullptr),
m_manipulator(this, nullptr) m_manipulator(this, nullptr)
{ {
connect(&m_manipulator, &PDFPageContentElementManipulator::selectionChanged, this, &PDFPageContentScene::onSelectionChanged);
} }
PDFPageContentScene::~PDFPageContentScene() PDFPageContentScene::~PDFPageContentScene()
@ -724,6 +729,11 @@ void PDFPageContentScene::updateMouseCursor(const MouseEventInfo& info, PDFReal
} }
} }
void PDFPageContentScene::onSelectionChanged()
{
emit sceneChanged(true);
}
PDFWidget* PDFPageContentScene::widget() const PDFWidget* PDFPageContentScene::widget() const
{ {
return m_widget; return m_widget;
@ -820,7 +830,7 @@ uint PDFPageContentElementLine::getManipulationMode(const QPointF& point,
QPointF vl = m_line.p2() - m_line.p1(); QPointF vl = m_line.p2() - m_line.p1();
QPointF vp = point - m_line.p1(); QPointF vp = point - m_line.p1();
const qreal lengthSquared = QPointF::dotProduct(vp, vp); const qreal lengthSquared = QPointF::dotProduct(vl, vl);
if (qFuzzyIsNull(lengthSquared)) if (qFuzzyIsNull(lengthSquared))
{ {
@ -865,6 +875,20 @@ void PDFPageContentElementLine::performManipulation(uint mode, const QPointF& of
} }
} }
QRectF PDFPageContentElementLine::getBoundingBox() const
{
if (!qFuzzyIsNull(m_line.length()))
{
const qreal xMin = qMin(m_line.p1().x(), m_line.p2().x());
const qreal xMax = qMax(m_line.p1().x(), m_line.p2().x());
const qreal yMin = qMin(m_line.p1().y(), m_line.p2().y());
const qreal yMax = qMax(m_line.p1().y(), m_line.p2().y());
return QRectF(xMin, yMin, xMax - xMin, yMax - yMin);
}
return QRectF();
}
PDFPageContentElementLine::LineGeometry PDFPageContentElementLine::getGeometry() const PDFPageContentElementLine::LineGeometry PDFPageContentElementLine::getGeometry() const
{ {
return m_geometry; return m_geometry;
@ -965,6 +989,11 @@ void PDFPageContentSvgElement::performManipulation(uint mode, const QPointF& off
performRectangleManipulation(m_rectangle, mode, offset); performRectangleManipulation(m_rectangle, mode, offset);
} }
QRectF PDFPageContentSvgElement::getBoundingBox() const
{
return getRectangle();
}
const QByteArray& PDFPageContentSvgElement::getContent() const const QByteArray& PDFPageContentSvgElement::getContent() const
{ {
return m_content; return m_content;
@ -1052,6 +1081,11 @@ void PDFPageContentElementDot::performManipulation(uint mode, const QPointF& off
} }
} }
QRectF PDFPageContentElementDot::getBoundingBox() const
{
return QRectF(m_point, QSizeF(0.001, 0.001));
}
QPointF PDFPageContentElementDot::getPoint() const QPointF PDFPageContentElementDot::getPoint() const
{ {
return m_point; return m_point;
@ -1132,6 +1166,11 @@ void PDFPageContentElementFreehandCurve::performManipulation(uint mode, const QP
} }
} }
QRectF PDFPageContentElementFreehandCurve::getBoundingBox() const
{
return m_curve.controlPointRect();
}
QPainterPath PDFPageContentElementFreehandCurve::getCurve() const QPainterPath PDFPageContentElementFreehandCurve::getCurve() const
{ {
return m_curve; return m_curve;
@ -1449,7 +1488,35 @@ void PDFPageContentElementManipulator::drawPage(QPainter* painter,
QList<PDFRenderError>& errors) const QList<PDFRenderError>& errors) const
{ {
// Draw selection // Draw selection
if (!isSelectionEmpty())
{
QPainterPath selectionPath;
for (const PDFInteger id : m_selection)
{
if (PDFPageContentElement* element = m_scene->getElementById(id))
{
QPainterPath tempPath;
tempPath.addRect(element->getBoundingBox());
selectionPath = selectionPath.united(tempPath);
}
}
if (!selectionPath.isEmpty())
{
PDFPainterStateGuard guard(painter);
QPen pen(Qt::SolidLine);
pen.setWidthF(2.0);
pen.setColor(QColor::fromRgbF(0.8, 0.8, 0.1, 0.7));
QBrush brush(Qt::SolidPattern);
brush.setColor(QColor::fromRgbF(1.0, 1.0, 0.0, 0.2));
painter->setPen(std::move(pen));
painter->setBrush(std::move(brush));
selectionPath = pagePointToDevicePointMatrix.map(selectionPath);
painter->drawPath(selectionPath);
}
}
// Draw dragged items // Draw dragged items
if (isManipulationInProgress()) if (isManipulationInProgress())

View File

@ -62,6 +62,9 @@ public:
/// \param offset Offset /// \param offset Offset
virtual void performManipulation(uint mode, const QPointF& offset) = 0; virtual void performManipulation(uint mode, const QPointF& offset) = 0;
/// Returns bounding box of the element
virtual QRectF getBoundingBox() const = 0;
PDFInteger getPageIndex() const; PDFInteger getPageIndex() const;
void setPageIndex(PDFInteger newPageIndex); void setPageIndex(PDFInteger newPageIndex);
@ -143,6 +146,7 @@ public:
PDFReal snapPointDistanceThreshold) const override; PDFReal snapPointDistanceThreshold) const override;
virtual void performManipulation(uint mode, const QPointF& offset) override; virtual void performManipulation(uint mode, const QPointF& offset) override;
virtual QRectF getBoundingBox() const override;
private: private:
bool m_rounded = false; bool m_rounded = false;
@ -174,6 +178,7 @@ public:
PDFReal snapPointDistanceThreshold) const override; PDFReal snapPointDistanceThreshold) const override;
virtual void performManipulation(uint mode, const QPointF& offset) override; virtual void performManipulation(uint mode, const QPointF& offset) override;
virtual QRectF getBoundingBox() const override;
LineGeometry getGeometry() const; LineGeometry getGeometry() const;
void setGeometry(LineGeometry newGeometry); void setGeometry(LineGeometry newGeometry);
@ -204,7 +209,7 @@ public:
PDFReal snapPointDistanceThreshold) const override; PDFReal snapPointDistanceThreshold) const override;
virtual void performManipulation(uint mode, const QPointF& offset) override; virtual void performManipulation(uint mode, const QPointF& offset) override;
virtual QRectF getBoundingBox() const override;
QPointF getPoint() const; QPointF getPoint() const;
void setPoint(QPointF newPoint); void setPoint(QPointF newPoint);
@ -231,6 +236,7 @@ public:
PDFReal snapPointDistanceThreshold) const override; PDFReal snapPointDistanceThreshold) const override;
virtual void performManipulation(uint mode, const QPointF& offset) override; virtual void performManipulation(uint mode, const QPointF& offset) override;
virtual QRectF getBoundingBox() const override;
QPainterPath getCurve() const; QPainterPath getCurve() const;
void setCurve(QPainterPath newCurve); void setCurve(QPainterPath newCurve);
@ -263,6 +269,7 @@ public:
PDFReal snapPointDistanceThreshold) const override; PDFReal snapPointDistanceThreshold) const override;
virtual void performManipulation(uint mode, const QPointF& offset) override; virtual void performManipulation(uint mode, const QPointF& offset) override;
virtual QRectF getBoundingBox() const override;
const QByteArray& getContent() const; const QByteArray& getContent() const;
void setContent(const QByteArray& newContent); void setContent(const QByteArray& newContent);
@ -464,6 +471,9 @@ private:
/// \param snapPointDistanceTreshold Snap point threshold /// \param snapPointDistanceTreshold Snap point threshold
void updateMouseCursor(const MouseEventInfo& info, PDFReal snapPointDistanceThreshold); void updateMouseCursor(const MouseEventInfo& info, PDFReal snapPointDistanceThreshold);
/// Reaction on selection changed
void onSelectionChanged();
PDFInteger m_firstFreeId; PDFInteger m_firstFreeId;
bool m_isActive; bool m_isActive;
PDFWidget* m_widget; PDFWidget* m_widget;