mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
DocDiff application: markers
This commit is contained in:
@ -100,6 +100,8 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||||||
ui->actionView_Overlay->setData(int(Operation::ViewOverlay));
|
ui->actionView_Overlay->setData(int(Operation::ViewOverlay));
|
||||||
ui->actionShow_Pages_with_Differences->setData(int(Operation::ShowPageswithDifferences));
|
ui->actionShow_Pages_with_Differences->setData(int(Operation::ShowPageswithDifferences));
|
||||||
ui->actionSave_Differences_to_XML->setData(int(Operation::SaveDifferencesToXML));
|
ui->actionSave_Differences_to_XML->setData(int(Operation::SaveDifferencesToXML));
|
||||||
|
ui->actionDisplay_Differences->setData(int(Operation::DisplayDifferences));
|
||||||
|
ui->actionDisplay_Markers->setData(int(Operation::DisplayMarkers));
|
||||||
|
|
||||||
ui->actionSynchronize_View_with_Differences->setChecked(true);
|
ui->actionSynchronize_View_with_Differences->setChecked(true);
|
||||||
|
|
||||||
@ -315,7 +317,12 @@ void MainWindow::loadSettings()
|
|||||||
m_settings.colorAdded = settings.value("colorAdded", m_settings.colorAdded).value<QColor>();
|
m_settings.colorAdded = settings.value("colorAdded", m_settings.colorAdded).value<QColor>();
|
||||||
m_settings.colorRemoved = settings.value("colorRemoved", m_settings.colorRemoved).value<QColor>();
|
m_settings.colorRemoved = settings.value("colorRemoved", m_settings.colorRemoved).value<QColor>();
|
||||||
m_settings.colorReplaced = settings.value("colorReplaced", m_settings.colorReplaced).value<QColor>();
|
m_settings.colorReplaced = settings.value("colorReplaced", m_settings.colorReplaced).value<QColor>();
|
||||||
|
m_settings.displayDifferences = settings.value("displayDifferences", m_settings.displayDifferences).toBool();
|
||||||
|
m_settings.displayMarkers = settings.value("displayMarkers", m_settings.displayDifferences).toBool();
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
|
ui->actionDisplay_Differences->setChecked(m_settings.displayDifferences);
|
||||||
|
ui->actionDisplay_Markers->setChecked(m_settings.displayMarkers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::saveSettings()
|
void MainWindow::saveSettings()
|
||||||
@ -332,6 +339,8 @@ void MainWindow::saveSettings()
|
|||||||
settings.setValue("colorAdded", m_settings.colorAdded);
|
settings.setValue("colorAdded", m_settings.colorAdded);
|
||||||
settings.setValue("colorRemoved", m_settings.colorRemoved);
|
settings.setValue("colorRemoved", m_settings.colorRemoved);
|
||||||
settings.setValue("colorReplaced", m_settings.colorReplaced);
|
settings.setValue("colorReplaced", m_settings.colorReplaced);
|
||||||
|
settings.setValue("displayDifferences", m_settings.displayDifferences);
|
||||||
|
settings.setValue("displayMarkers", m_settings.displayDifferences);
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,6 +388,10 @@ bool MainWindow::canPerformOperation(Operation operation) const
|
|||||||
case Operation::SaveDifferencesToXML:
|
case Operation::SaveDifferencesToXML:
|
||||||
return m_diffResult.isChanged();
|
return m_diffResult.isChanged();
|
||||||
|
|
||||||
|
case Operation::DisplayDifferences:
|
||||||
|
case Operation::DisplayMarkers:
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
break;
|
break;
|
||||||
@ -539,6 +552,16 @@ void MainWindow::performOperation(Operation operation)
|
|||||||
updateCustomPageLayout();
|
updateCustomPageLayout();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Operation::DisplayDifferences:
|
||||||
|
m_settings.displayDifferences = ui->actionDisplay_Differences->isChecked();
|
||||||
|
m_pdfWidget->update();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Operation::DisplayMarkers:
|
||||||
|
m_settings.displayMarkers = ui->actionDisplay_Markers->isChecked();
|
||||||
|
m_pdfWidget->update();
|
||||||
|
break;
|
||||||
|
|
||||||
case Operation::SaveDifferencesToXML:
|
case Operation::SaveDifferencesToXML:
|
||||||
case Operation::CreateCompareReport:
|
case Operation::CreateCompareReport:
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
|
@ -73,7 +73,9 @@ public:
|
|||||||
ViewRight,
|
ViewRight,
|
||||||
ViewOverlay,
|
ViewOverlay,
|
||||||
ShowPageswithDifferences,
|
ShowPageswithDifferences,
|
||||||
SaveDifferencesToXML
|
SaveDifferencesToXML,
|
||||||
|
DisplayDifferences,
|
||||||
|
DisplayMarkers
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void showEvent(QShowEvent* event) override;
|
virtual void showEvent(QShowEvent* event) override;
|
||||||
|
@ -132,6 +132,9 @@
|
|||||||
<addaction name="menuFilter"/>
|
<addaction name="menuFilter"/>
|
||||||
<addaction name="actionShow_Pages_with_Differences"/>
|
<addaction name="actionShow_Pages_with_Differences"/>
|
||||||
<addaction name="actionSynchronize_View_with_Differences"/>
|
<addaction name="actionSynchronize_View_with_Differences"/>
|
||||||
|
<addaction name="separator"/>
|
||||||
|
<addaction name="actionDisplay_Differences"/>
|
||||||
|
<addaction name="actionDisplay_Markers"/>
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menuView"/>
|
<addaction name="menuView"/>
|
||||||
@ -320,6 +323,22 @@
|
|||||||
<string>Synchronize View with Differences</string>
|
<string>Synchronize View with Differences</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionDisplay_Differences">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Display Differences</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
|
<action name="actionDisplay_Markers">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Display Markers</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="resources.qrc"/>
|
<include location="resources.qrc"/>
|
||||||
|
@ -30,6 +30,8 @@ struct Settings
|
|||||||
QColor colorAdded = QColor(125, 250, 0);
|
QColor colorAdded = QColor(125, 250, 0);
|
||||||
QColor colorRemoved = QColor(255, 50, 50);
|
QColor colorRemoved = QColor(255, 50, 50);
|
||||||
QColor colorReplaced = QColor(255, 120, 30);
|
QColor colorReplaced = QColor(255, 120, 30);
|
||||||
|
bool displayDifferences = true;
|
||||||
|
bool displayMarkers = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pdfdocdiff
|
} // namespace pdfdocdiff
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
// along with PDF4QT. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "pdfwidgetutils.h"
|
||||||
|
#include "pdfpainterutils.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
@ -294,6 +296,11 @@ void DifferencesDrawInterface::drawPage(QPainter* painter,
|
|||||||
Q_UNUSED(layoutGetter);
|
Q_UNUSED(layoutGetter);
|
||||||
Q_UNUSED(errors);
|
Q_UNUSED(errors);
|
||||||
|
|
||||||
|
if (!m_settings->displayDifferences)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const size_t differencesCount = m_diffResult->getDifferencesCount();
|
const size_t differencesCount = m_diffResult->getDifferencesCount();
|
||||||
const pdf::PDFInteger leftPageIndex = m_mapper->getLeftPageIndex(pageIndex);
|
const pdf::PDFInteger leftPageIndex = m_mapper->getLeftPageIndex(pageIndex);
|
||||||
const pdf::PDFInteger rightPageIndex = m_mapper->getRightPageIndex(pageIndex);
|
const pdf::PDFInteger rightPageIndex = m_mapper->getRightPageIndex(pageIndex);
|
||||||
@ -308,7 +315,9 @@ void DifferencesDrawInterface::drawPage(QPainter* painter,
|
|||||||
const auto& item = *it;
|
const auto& item = *it;
|
||||||
if (item.first == leftPageIndex)
|
if (item.first == leftPageIndex)
|
||||||
{
|
{
|
||||||
drawRectangle(painter, pagePointToDevicePointMatrix, item.second, i);
|
QColor color = getColorForIndex(i);
|
||||||
|
drawRectangle(painter, pagePointToDevicePointMatrix, item.second, color);
|
||||||
|
drawMarker(painter, pagePointToDevicePointMatrix, item.second, color, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -324,7 +333,9 @@ void DifferencesDrawInterface::drawPage(QPainter* painter,
|
|||||||
const auto& item = *it;
|
const auto& item = *it;
|
||||||
if (item.first == rightPageIndex)
|
if (item.first == rightPageIndex)
|
||||||
{
|
{
|
||||||
drawRectangle(painter, pagePointToDevicePointMatrix, item.second, i);
|
QColor color = getColorForIndex(i);
|
||||||
|
drawRectangle(painter, pagePointToDevicePointMatrix, item.second, color);
|
||||||
|
drawMarker(painter, pagePointToDevicePointMatrix, item.second, color, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,13 +377,72 @@ void DifferencesDrawInterface::drawPostRendering(QPainter* painter, QRect rect)
|
|||||||
void DifferencesDrawInterface::drawRectangle(QPainter* painter,
|
void DifferencesDrawInterface::drawRectangle(QPainter* painter,
|
||||||
const QMatrix& pagePointToDevicePointMatrix,
|
const QMatrix& pagePointToDevicePointMatrix,
|
||||||
const QRectF& rect,
|
const QRectF& rect,
|
||||||
size_t resultIndex) const
|
QColor color) const
|
||||||
{
|
{
|
||||||
QColor color = getColorForIndex(resultIndex);
|
color.setAlphaF(0.5);
|
||||||
color.setAlphaF(0.3);
|
|
||||||
|
|
||||||
QRectF resultRect = pagePointToDevicePointMatrix.mapRect(rect);
|
QRectF resultRect = pagePointToDevicePointMatrix.mapRect(rect);
|
||||||
painter->fillRect(resultRect, color);
|
painter->fillRect(resultRect, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DifferencesDrawInterface::drawMarker(QPainter* painter,
|
||||||
|
const QMatrix& pagePointToDevicePointMatrix,
|
||||||
|
const QRectF& rect,
|
||||||
|
QColor color,
|
||||||
|
bool isLeft) const
|
||||||
|
{
|
||||||
|
if (!m_settings->displayMarkers)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdf::PDFPainterStateGuard guard(painter);
|
||||||
|
QRectF deviceRect = pagePointToDevicePointMatrix.mapRect(rect);
|
||||||
|
|
||||||
|
QPointF snapPoint;
|
||||||
|
QPointF markPoint;
|
||||||
|
|
||||||
|
if (isLeft)
|
||||||
|
{
|
||||||
|
snapPoint.ry() = deviceRect.center().y();
|
||||||
|
snapPoint.rx() = deviceRect.left();
|
||||||
|
markPoint = snapPoint;
|
||||||
|
markPoint.rx() = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
snapPoint.ry() = deviceRect.center().y();
|
||||||
|
snapPoint.rx() = deviceRect.right();
|
||||||
|
markPoint = snapPoint;
|
||||||
|
markPoint.rx() = painter->device()->width();
|
||||||
|
}
|
||||||
|
|
||||||
|
const qreal lineWidthF = pdf::PDFWidgetUtils::scaleDPI_y(painter->device(), 2);
|
||||||
|
|
||||||
|
QPen pen(Qt::DotLine);
|
||||||
|
pen.setColor(color);
|
||||||
|
pen.setWidthF(lineWidthF);
|
||||||
|
|
||||||
|
painter->setBrush(Qt::NoBrush);
|
||||||
|
painter->setPen(pen);
|
||||||
|
painter->drawLine(snapPoint, markPoint);
|
||||||
|
|
||||||
|
const qreal markSizeX = pdf::PDFWidgetUtils::scaleDPI_x(painter->device(), 10);
|
||||||
|
const qreal markSizeY = pdf::PDFWidgetUtils::scaleDPI_y(painter->device(), 10);
|
||||||
|
|
||||||
|
QPointF ptc = markPoint;
|
||||||
|
QPointF ptTop = ptc;
|
||||||
|
QPointF ptBottom = ptc;
|
||||||
|
|
||||||
|
ptTop.ry() -= markSizeY;
|
||||||
|
ptBottom.ry() += markSizeY;
|
||||||
|
ptc.rx() += isLeft ? markSizeX : -markSizeX;
|
||||||
|
|
||||||
|
std::array points = { ptTop, ptc, ptBottom };
|
||||||
|
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(QBrush(color));
|
||||||
|
painter->drawConvexPolygon(points.data(), int(points.size()));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace pdfdocdiff
|
} // namespace pdfdocdiff
|
||||||
|
@ -93,7 +93,13 @@ private:
|
|||||||
void drawRectangle(QPainter* painter,
|
void drawRectangle(QPainter* painter,
|
||||||
const QMatrix& pagePointToDevicePointMatrix,
|
const QMatrix& pagePointToDevicePointMatrix,
|
||||||
const QRectF& rect,
|
const QRectF& rect,
|
||||||
size_t resultIndex) const;
|
QColor color) const;
|
||||||
|
|
||||||
|
void drawMarker(QPainter* painter,
|
||||||
|
const QMatrix& pagePointToDevicePointMatrix,
|
||||||
|
const QRectF& rect,
|
||||||
|
QColor color,
|
||||||
|
bool isLeft) const;
|
||||||
|
|
||||||
QColor getColorForIndex(size_t index) const;
|
QColor getColorForIndex(size_t index) const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user