mirror of https://github.com/JakubMelka/PDF4QT.git
DocDiff application: colored icons
This commit is contained in:
parent
d3aa9efcb3
commit
5972e17146
|
@ -21,6 +21,7 @@
|
|||
#include "pdfdiff.h"
|
||||
#include "pdfwidgetutils.h"
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
namespace pdfdocdiff
|
||||
|
@ -42,6 +43,8 @@ void DifferenceItemDelegate::paint(QPainter* painter,
|
|||
QSize DifferenceItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const
|
||||
{
|
||||
QStyleOptionViewItem adjustedOption = option;
|
||||
|
||||
if (!option.rect.isValid())
|
||||
{
|
||||
// Jakub Melka: Why this? We need to use text wrapping. Unfortunately,
|
||||
|
@ -49,7 +52,7 @@ QSize DifferenceItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
|||
// for word wrap calculation. So we must manually calculate rectangle width.
|
||||
// Of course, we cant use visualRect of the tree widget, because of cyclical
|
||||
// dependence.
|
||||
QStyleOptionViewItem adjustedOption = option;
|
||||
|
||||
const QTreeWidget* treeWidget = qobject_cast<const QTreeWidget*>(option.widget);
|
||||
int xOffset = treeWidget->columnViewportPosition(index.column());
|
||||
int height = option.fontMetrics.lineSpacing();
|
||||
|
@ -66,21 +69,25 @@ QSize DifferenceItemDelegate::sizeHint(const QStyleOptionViewItem& option,
|
|||
|
||||
xOffset += level * treeWidget->indentation();
|
||||
adjustedOption.rect = QRect(xOffset, yOffset, width - xOffset, height);
|
||||
}
|
||||
|
||||
return BaseClass::sizeHint(adjustedOption, index);
|
||||
}
|
||||
|
||||
return BaseClass::sizeHint(option, index);
|
||||
}
|
||||
|
||||
DifferencesDockWidget::DifferencesDockWidget(QWidget *parent) :
|
||||
DifferencesDockWidget::DifferencesDockWidget(QWidget* parent,
|
||||
pdf::PDFDiffResult* diffResult,
|
||||
pdf::PDFDiffResultNavigator* diffNavigator,
|
||||
Settings* settings) :
|
||||
QDockWidget(parent),
|
||||
ui(new Ui::DifferencesDockWidget),
|
||||
m_diffResult(nullptr),
|
||||
m_diffNavigator(nullptr)
|
||||
m_diffResult(diffResult),
|
||||
m_diffNavigator(diffNavigator),
|
||||
m_settings(settings)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->differencesTreeWidget->setItemDelegate(new DifferenceItemDelegate(this));
|
||||
ui->differencesTreeWidget->setIconSize(pdf::PDFWidgetUtils::scaleDPI(ui->differencesTreeWidget, QSize(16, 16)));
|
||||
|
||||
setMinimumWidth(pdf::PDFWidgetUtils::scaleDPI_x(this, 120));
|
||||
}
|
||||
|
@ -90,6 +97,32 @@ DifferencesDockWidget::~DifferencesDockWidget()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
QColor DifferencesDockWidget::getColorForIndex(size_t index) const
|
||||
{
|
||||
QColor color;
|
||||
|
||||
const size_t resultIndex = index;
|
||||
|
||||
if (m_diffResult->isReplaceDifference(resultIndex))
|
||||
{
|
||||
color = m_settings->colorReplaced;
|
||||
}
|
||||
else if (m_diffResult->isRemoveDifference(resultIndex))
|
||||
{
|
||||
color = m_settings->colorRemoved;
|
||||
}
|
||||
else if (m_diffResult->isAddDifference(resultIndex))
|
||||
{
|
||||
color = m_settings->colorAdded;
|
||||
}
|
||||
else if (m_diffResult->isPageMoveDifference(resultIndex))
|
||||
{
|
||||
color = m_settings->colorPageMove;
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void DifferencesDockWidget::update()
|
||||
{
|
||||
ui->differencesTreeWidget->clear();
|
||||
|
@ -147,6 +180,17 @@ void DifferencesDockWidget::update()
|
|||
|
||||
QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList() << m_diffResult->getMessage(i));
|
||||
item->setData(0, Qt::UserRole, i);
|
||||
|
||||
QColor color = getColorForIndex(i);
|
||||
|
||||
if (color.isValid())
|
||||
{
|
||||
QPixmap pixmap(ui->differencesTreeWidget->iconSize());
|
||||
pixmap.fill(color);
|
||||
QIcon icon(pixmap);
|
||||
|
||||
item->setData(0, Qt::DecorationRole, icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,14 +198,4 @@ void DifferencesDockWidget::update()
|
|||
ui->differencesTreeWidget->expandAll();
|
||||
}
|
||||
|
||||
void DifferencesDockWidget::setDiffResult(pdf::PDFDiffResult* diffResult)
|
||||
{
|
||||
m_diffResult = diffResult;
|
||||
}
|
||||
|
||||
void DifferencesDockWidget::setDiffNavigator(pdf::PDFDiffResultNavigator* diffNavigator)
|
||||
{
|
||||
m_diffNavigator = diffNavigator;
|
||||
}
|
||||
|
||||
} // namespace pdfdocdiff
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#ifndef DIFFERENCESDOCKWIDGET_H
|
||||
#define DIFFERENCESDOCKWIDGET_H
|
||||
|
||||
#include "settings.h"
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QItemDelegate>
|
||||
|
||||
|
@ -54,19 +56,22 @@ class DifferencesDockWidget : public QDockWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DifferencesDockWidget(QWidget* parent);
|
||||
explicit DifferencesDockWidget(QWidget* parent,
|
||||
pdf::PDFDiffResult* diffResult,
|
||||
pdf::PDFDiffResultNavigator* diffNavigator,
|
||||
Settings* settings);
|
||||
virtual ~DifferencesDockWidget() override;
|
||||
|
||||
void update();
|
||||
|
||||
void setDiffResult(pdf::PDFDiffResult* diffResult);
|
||||
void setDiffNavigator(pdf::PDFDiffResultNavigator* diffNavigator);
|
||||
|
||||
private:
|
||||
Ui::DifferencesDockWidget* ui;
|
||||
|
||||
QColor getColorForIndex(size_t index) const;
|
||||
|
||||
pdf::PDFDiffResult* m_diffResult;
|
||||
pdf::PDFDiffResultNavigator* m_diffNavigator;
|
||||
Settings* m_settings;
|
||||
};
|
||||
|
||||
} // namespace pdfdocdiff
|
||||
|
|
|
@ -58,9 +58,7 @@ MainWindow::MainWindow(QWidget* parent) :
|
|||
m_settingsDockWidget = new SettingsDockWidget(this);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_settingsDockWidget);;
|
||||
|
||||
m_differencesDockWidget = new DifferencesDockWidget(this);
|
||||
m_differencesDockWidget->setDiffResult(&m_filteredDiffResult);
|
||||
m_differencesDockWidget->setDiffNavigator(&m_diffNavigator);
|
||||
m_differencesDockWidget = new DifferencesDockWidget(this, &m_filteredDiffResult, &m_diffNavigator, &m_settings);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_differencesDockWidget);
|
||||
|
||||
ui->menuView->addSeparator();
|
||||
|
@ -233,10 +231,10 @@ void MainWindow::loadSettings()
|
|||
|
||||
settings.beginGroup("Settings");
|
||||
m_settings.directory = settings.value("directory").toString();
|
||||
m_settings.colorPageMove = settings.value("colorPageMove").value<QColor>();
|
||||
m_settings.colorAdded = settings.value("colorAdded").value<QColor>();
|
||||
m_settings.colorRemoved = settings.value("colorRemoved").value<QColor>();
|
||||
m_settings.colorReplaced = settings.value("colorReplaced").value<QColor>();
|
||||
m_settings.colorPageMove = settings.value("colorPageMove", m_settings.colorPageMove).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.colorReplaced = settings.value("colorReplaced", m_settings.colorReplaced).value<QColor>();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
|
|
|
@ -1074,6 +1074,16 @@ void PDFDiffResult::finalize()
|
|||
}
|
||||
}
|
||||
|
||||
uint32_t PDFDiffResult::getTypeFlags(size_t index) const
|
||||
{
|
||||
if (index >= m_differences.size())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return uint32_t(m_differences[index].type);
|
||||
}
|
||||
|
||||
QString PDFDiffResult::getMessage(size_t index) const
|
||||
{
|
||||
if (index >= m_differences.size())
|
||||
|
@ -1154,6 +1164,26 @@ PDFInteger PDFDiffResult::getRightPage(size_t index) const
|
|||
return m_differences[index].pageIndex2;
|
||||
}
|
||||
|
||||
bool PDFDiffResult::isPageMoveDifference(size_t index) const
|
||||
{
|
||||
return getTypeFlags(index) & FLAGS_TYPE_PAGE_MOVE;
|
||||
}
|
||||
|
||||
bool PDFDiffResult::isAddDifference(size_t index) const
|
||||
{
|
||||
return getTypeFlags(index) & FLAGS_TYPE_ADD;
|
||||
}
|
||||
|
||||
bool PDFDiffResult::isRemoveDifference(size_t index) const
|
||||
{
|
||||
return getTypeFlags(index) & FLAGS_TYPE_REMOVE;
|
||||
}
|
||||
|
||||
bool PDFDiffResult::isReplaceDifference(size_t index) const
|
||||
{
|
||||
return getTypeFlags(index) & FLAGS_TYPE_REPLACE;
|
||||
}
|
||||
|
||||
PDFDiffResult PDFDiffResult::filter(bool filterPageMoveDifferences,
|
||||
bool filterTextDifferences,
|
||||
bool filterVectorGraphicsDifferences,
|
||||
|
|
|
@ -87,6 +87,11 @@ public:
|
|||
/// \param index Index
|
||||
PDFInteger getRightPage(size_t index) const;
|
||||
|
||||
bool isPageMoveDifference(size_t index) const;
|
||||
bool isAddDifference(size_t index) const;
|
||||
bool isRemoveDifference(size_t index) const;
|
||||
bool isReplaceDifference(size_t index) const;
|
||||
|
||||
bool hasPageMoveDifferences() const { return m_typeFlags & FLAGS_PAGE_MOVE; }
|
||||
bool hasTextDifferences() const { return m_typeFlags & FLAGS_TEXT; }
|
||||
bool hasVectorGraphicsDifferences() const { return m_typeFlags & FLAGS_VECTOR_GRAPHICS; }
|
||||
|
@ -114,6 +119,11 @@ private:
|
|||
static constexpr uint32_t FLAGS_IMAGE = uint32_t(Type::RemovedImageContent) | uint32_t(Type::AddedImageContent);
|
||||
static constexpr uint32_t FLAGS_SHADING = uint32_t(Type::RemovedShadingContent) | uint32_t(Type::AddedShadingContent);
|
||||
|
||||
static constexpr uint32_t FLAGS_TYPE_PAGE_MOVE = uint32_t(Type::PageMoved);
|
||||
static constexpr uint32_t FLAGS_TYPE_ADD = uint32_t(Type::PageAdded) | uint32_t(Type::AddedTextCharContent) | uint32_t(Type::AddedVectorGraphicContent) | uint32_t(Type::AddedImageContent) | uint32_t(Type::AddedShadingContent) | uint32_t(Type::TextAdded);
|
||||
static constexpr uint32_t FLAGS_TYPE_REMOVE = uint32_t(Type::PageRemoved) | uint32_t(Type::RemovedTextCharContent) | uint32_t(Type::RemovedVectorGraphicContent) | uint32_t(Type::RemovedImageContent) | uint32_t(Type::RemovedShadingContent) | uint32_t(Type::TextRemoved);
|
||||
static constexpr uint32_t FLAGS_TYPE_REPLACE = uint32_t(Type::TextReplaced);
|
||||
|
||||
void addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2);
|
||||
void addPageAdded(PDFInteger pageIndex);
|
||||
void addPageRemoved(PDFInteger pageIndex);
|
||||
|
@ -139,6 +149,8 @@ private:
|
|||
|
||||
void finalize();
|
||||
|
||||
uint32_t getTypeFlags(size_t index) const;
|
||||
|
||||
/// Single content difference descriptor. It describes type
|
||||
/// of difference (such as graphics, image, text change) on a page
|
||||
/// or on a list of multiple pages.
|
||||
|
|
Loading…
Reference in New Issue