Some new dimensions

This commit is contained in:
Jakub Melka
2020-11-22 18:43:11 +01:00
parent 762a239193
commit 31b4dac927
11 changed files with 572 additions and 8 deletions

View File

@ -115,6 +115,10 @@ void PDFSnapper::drawSnapPoints(QPainter* painter) const
newColor = Qt::green;
break;
case SnapType::Custom:
newColor = Qt::black;
break;
default:
newColor = Qt::red;
break;
@ -200,6 +204,20 @@ void PDFSnapper::buildSnapPoints(const PDFWidgetSnapshot& snapshot)
m_snapPoints.push_back(qMove(viewportSnapPoint));
}
// Add custom snap points
if (m_currentPage == item.pageIndex)
{
for (const QPointF& customSnapPoint : m_customSnapPoints)
{
ViewportSnapPoint viewportSnapPoint;
viewportSnapPoint.type = SnapType::Custom;
viewportSnapPoint.point = customSnapPoint;
viewportSnapPoint.pageIndex = item.pageIndex;
viewportSnapPoint.viewportPoint = item.pageToDeviceMatrix.map(customSnapPoint);
m_snapPoints.push_back(qMove(viewportSnapPoint));
}
}
// Fill line projections snap points
if (m_currentPage == item.pageIndex && m_referencePoint.has_value())
{
@ -298,12 +316,19 @@ const PDFSnapper::ViewportSnapImage* PDFSnapper::getSnappedImage() const
void PDFSnapper::setReferencePoint(PDFInteger pageIndex, QPointF pagePoint)
{
// Clear custom snap points, if page changes
if (m_currentPage != pageIndex)
{
m_customSnapPoints.clear();
}
m_currentPage = pageIndex;
m_referencePoint = pagePoint;
}
void PDFSnapper::clearReferencePoint()
{
m_customSnapPoints.clear();
m_currentPage = -1;
m_referencePoint = std::nullopt;
}
@ -312,6 +337,7 @@ void PDFSnapper::clear()
{
clearReferencePoint();
m_customSnapPoints.clear();
m_snapPoints.clear();
m_snapImages.clear();
m_snappedPoint = std::nullopt;
@ -319,4 +345,14 @@ void PDFSnapper::clear()
m_mousePoint = QPointF();
}
const std::vector<QPointF>& PDFSnapper::getCustomSnapPoints() const
{
return m_customSnapPoints;
}
void PDFSnapper::setCustomSnapPoints(const std::vector<QPointF>& customSnapPoints)
{
m_customSnapPoints = customSnapPoints;
}
} // namespace pdf

View File

@ -41,7 +41,8 @@ enum class SnapType
PageCenter, ///< Center of page media box
ImageCenter, ///< Center of image
LineCenter, ///< Center of line
GeneratedLineProjection ///< Generated point to line projections
GeneratedLineProjection, ///< Generated point to line projections
Custom ///< Custom snap point
};
/// Contain informations for snap points in the pdf page. Snap points
@ -184,6 +185,14 @@ public:
/// Clears all snapped data, including snap points, images and referenced data.
void clear();
/// Returns a vector of custom snap points
const std::vector<QPointF>& getCustomSnapPoints() const;
/// Sets custom set of snap points. Snap points are always referred to current
/// page index. If page index changes, then custom snap points are cleared.
/// \param customSnapPoints Custom snap points
void setCustomSnapPoints(const std::vector<QPointF>& customSnapPoints);
private:
struct SnappedPoint
{
@ -193,6 +202,7 @@ private:
std::vector<ViewportSnapPoint> m_snapPoints;
std::vector<ViewportSnapImage> m_snapImages;
std::vector<QPointF> m_customSnapPoints;
std::optional<ViewportSnapPoint> m_snappedPoint;
std::optional<ViewportSnapImage> m_snappedImage;
QPointF m_mousePoint;

View File

@ -1152,6 +1152,14 @@ QPointF PDFPickTool::getSnappedPoint() const
return m_snapper.getSnappedPoint();
}
void PDFPickTool::setCustomSnapPoints(PDFInteger pageIndex, const std::vector<QPointF>& snapPoints)
{
if (m_pageIndex == pageIndex)
{
m_snapper.setCustomSnapPoints(snapPoints);
}
}
void PDFPickTool::setActiveImpl(bool active)
{
BaseClass::setActiveImpl(active);

View File

@ -327,6 +327,12 @@ public:
PDFInteger getPageIndex() const { return m_pageIndex; }
const std::vector<QPointF>& getPickedPoints() const { return m_pickedPoints; }
/// Sets custom snap points for given page. If points on page aren't currently picked,
/// function does nothing. Snap data are not updated.
/// \param pageIndex pageIndex
/// \param snapPoints Custom snap points
void setCustomSnapPoints(PDFInteger pageIndex, const std::vector<QPointF>& snapPoints);
void resetTool();
signals: