mirror of
https://github.com/JakubMelka/PDF4QT.git
synced 2025-06-05 21:59:17 +02:00
AudioBook Plugin: Display texts on page
This commit is contained in:
@@ -704,7 +704,7 @@ void PDFCreateFreehandCurveTool::mouseReleaseEvent(QWidget* widget, QMouseEvent*
|
||||
resetTool();
|
||||
}
|
||||
|
||||
getProxy()->repaintNeeded();
|
||||
emit getProxy()->repaintNeeded();
|
||||
}
|
||||
|
||||
void PDFCreateFreehandCurveTool::mouseMoveEvent(QWidget* widget, QMouseEvent* event)
|
||||
|
@@ -71,7 +71,8 @@ public:
|
||||
{
|
||||
ToolPriority = 10,
|
||||
FormPriority = 20,
|
||||
AnnotationPriority = 30
|
||||
AnnotationPriority = 30,
|
||||
UserPriority = 40
|
||||
};
|
||||
|
||||
/// Handles shortcut override event. Accept this event, when you want given
|
||||
|
@@ -798,6 +798,11 @@ void PDFDocumentTextFlowEditor::setSelectionActive(bool active)
|
||||
}
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::select(size_t index, bool select)
|
||||
{
|
||||
getEditedItem(index)->editedItemFlags.setFlag(Selected, select);
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::deselect()
|
||||
{
|
||||
for (auto& item : m_editedTextFlow)
|
||||
@@ -820,6 +825,7 @@ void PDFDocumentTextFlowEditor::clear()
|
||||
{
|
||||
m_originalTextFlow = PDFDocumentTextFlow();
|
||||
m_editedTextFlow.clear();
|
||||
m_pageIndicesMapping.clear();
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::setText(const QString& text, size_t index)
|
||||
@@ -834,6 +840,11 @@ bool PDFDocumentTextFlowEditor::isSelectionEmpty() const
|
||||
return std::all_of(m_editedTextFlow.cbegin(), m_editedTextFlow.cend(), [](const auto& item) { return !item.editedItemFlags.testFlag(Selected); });
|
||||
}
|
||||
|
||||
bool PDFDocumentTextFlowEditor::isSelectionModified() const
|
||||
{
|
||||
return std::any_of(m_editedTextFlow.cbegin(), m_editedTextFlow.cend(), [](const auto& item) { return item.editedItemFlags.testFlag(Selected) && item.editedItemFlags.testFlag(Modified); });
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::selectByRectangle(QRectF rectangle)
|
||||
{
|
||||
for (auto& item : m_editedTextFlow)
|
||||
@@ -882,6 +893,40 @@ void PDFDocumentTextFlowEditor::selectByPageIndices(const pdf::PDFClosedInterval
|
||||
}
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::restoreOriginalTexts()
|
||||
{
|
||||
for (auto& item : m_editedTextFlow)
|
||||
{
|
||||
if (item.editedItemFlags.testFlag(Selected))
|
||||
{
|
||||
item.text = m_originalTextFlow.getItem(item.originalIndex)->text;
|
||||
item.editedItemFlags.setFlag(Modified, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PDFDocumentTextFlowEditor::PageIndicesMappingRange PDFDocumentTextFlowEditor::getItemsForPageIndex(PDFInteger pageIndex) const
|
||||
{
|
||||
auto comparator = [](const auto& l, const auto& r)
|
||||
{
|
||||
return l.first < r.first;
|
||||
};
|
||||
return std::equal_range(m_pageIndicesMapping.cbegin(), m_pageIndicesMapping.cend(), std::make_pair(pageIndex, size_t(0)), comparator);
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::createPageMapping()
|
||||
{
|
||||
m_pageIndicesMapping.clear();
|
||||
m_pageIndicesMapping.reserve(m_editedTextFlow.size());
|
||||
|
||||
for (size_t i = 0; i < m_editedTextFlow.size(); ++i)
|
||||
{
|
||||
m_pageIndicesMapping.emplace_back(m_editedTextFlow[i].pageIndex, i);
|
||||
}
|
||||
|
||||
std::sort(m_pageIndicesMapping.begin(), m_pageIndicesMapping.end());
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::createEditedFromOriginalTextFlow()
|
||||
{
|
||||
const size_t count = m_originalTextFlow.getSize();
|
||||
@@ -902,6 +947,8 @@ void PDFDocumentTextFlowEditor::createEditedFromOriginalTextFlow()
|
||||
editedItem.editedItemFlags = None;
|
||||
m_editedTextFlow.emplace_back(std::move(editedItem));
|
||||
}
|
||||
|
||||
createPageMapping();
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditor::updateModifiedFlag(size_t index)
|
||||
|
@@ -147,6 +147,11 @@ public:
|
||||
/// \param active Active
|
||||
void setSelectionActive(bool active);
|
||||
|
||||
/// Selects or deselects item
|
||||
/// \param index Index
|
||||
/// \param select Select (true) or deselect (false)
|
||||
void select(size_t index, bool select);
|
||||
|
||||
/// Deselects all selected items
|
||||
void deselect();
|
||||
|
||||
@@ -171,6 +176,9 @@ public:
|
||||
};
|
||||
|
||||
using EditedItems = std::vector<EditedItem>;
|
||||
using PageIndicesMapping = std::vector<std::pair<PDFInteger, size_t>>;
|
||||
using PageIndicesMappingIterator = PageIndicesMapping::const_iterator;
|
||||
using PageIndicesMappingRange = std::pair<PageIndicesMappingIterator, PageIndicesMappingIterator>;
|
||||
|
||||
/// Returns true, if item is active
|
||||
/// \param index Index
|
||||
@@ -202,6 +210,9 @@ public:
|
||||
/// Returns true, if text selection is empty
|
||||
bool isSelectionEmpty() const;
|
||||
|
||||
/// Returns true, if selection contains modified items
|
||||
bool isSelectionModified() const;
|
||||
|
||||
/// Returns item count in edited text flow
|
||||
size_t getItemCount() const { return m_editedTextFlow.size(); }
|
||||
|
||||
@@ -230,16 +241,27 @@ public:
|
||||
/// \param indices Indices
|
||||
void selectByPageIndices(const PDFClosedIntervalSet& indices);
|
||||
|
||||
/// Restores original texts in selected items
|
||||
void restoreOriginalTexts();
|
||||
|
||||
/// Returns item indices for a given page index, i.e.
|
||||
/// index of items which are lying on a page.
|
||||
/// \param pageIndex Page index
|
||||
PageIndicesMappingRange getItemsForPageIndex(PDFInteger pageIndex) const;
|
||||
|
||||
const EditedItem* getEditedItem(size_t index) const { return &m_editedTextFlow.at(index); }
|
||||
|
||||
private:
|
||||
void createPageMapping();
|
||||
void createEditedFromOriginalTextFlow();
|
||||
void updateModifiedFlag(size_t index);
|
||||
|
||||
const PDFDocumentTextFlow::Item* getOriginalItem(size_t index) const { return m_originalTextFlow.getItem(index); }
|
||||
EditedItem* getEditedItem(size_t index) { return &m_editedTextFlow.at(index); }
|
||||
const EditedItem* getEditedItem(size_t index) const { return &m_editedTextFlow.at(index); }
|
||||
|
||||
PDFDocumentTextFlow m_originalTextFlow;
|
||||
EditedItems m_editedTextFlow;
|
||||
PageIndicesMapping m_pageIndicesMapping;
|
||||
};
|
||||
|
||||
} // namespace pdf
|
||||
|
@@ -229,6 +229,18 @@ void PDFDocumentTextFlowEditorModel::endFlowChange()
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditorModel::clear()
|
||||
{
|
||||
if (!m_editor || m_editor->isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
beginFlowChange();
|
||||
m_editor->clear();
|
||||
endFlowChange();
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditorModel::setSelectionActivated(bool activate)
|
||||
{
|
||||
if (!m_editor || m_editor->isEmpty())
|
||||
@@ -285,4 +297,26 @@ void PDFDocumentTextFlowEditorModel::selectByPageIndices(const PDFClosedInterval
|
||||
emit dataChanged(index(0, 0), index(rowCount(QModelIndex()) - 1, ColumnLast));
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditorModel::restoreOriginalTexts()
|
||||
{
|
||||
if (!m_editor || m_editor->isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_editor->restoreOriginalTexts();
|
||||
m_editor->deselect();
|
||||
emit dataChanged(index(0, 0), index(rowCount(QModelIndex()) - 1, ColumnLast));
|
||||
}
|
||||
|
||||
void PDFDocumentTextFlowEditorModel::notifyDataChanged()
|
||||
{
|
||||
if (!m_editor || m_editor->isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
emit dataChanged(index(0, 0), index(rowCount(QModelIndex()) - 1, ColumnLast));
|
||||
}
|
||||
|
||||
} // namespace pdf
|
||||
|
@@ -62,11 +62,14 @@ public:
|
||||
void beginFlowChange();
|
||||
void endFlowChange();
|
||||
|
||||
void clear();
|
||||
void setSelectionActivated(bool activate);
|
||||
void selectByRectangle(QRectF rectangle);
|
||||
void selectByContainedText(QString text);
|
||||
void selectByRegularExpression(const QRegularExpression& expression);
|
||||
void selectByPageIndices(const pdf::PDFClosedIntervalSet& indices);
|
||||
void restoreOriginalTexts();
|
||||
void notifyDataChanged();
|
||||
|
||||
private:
|
||||
PDFDocumentTextFlowEditor* m_editor;
|
||||
|
@@ -99,6 +99,9 @@ public:
|
||||
PDFFormManager* getFormManager() const;
|
||||
void setFormManager(PDFFormManager* formManager);
|
||||
|
||||
void removeInputInterface(IDrawWidgetInputInterface* inputInterface);
|
||||
void addInputInterface(IDrawWidgetInputInterface* inputInterface);
|
||||
|
||||
signals:
|
||||
void pageRenderingErrorsChanged(PDFInteger pageIndex, int errorsCount);
|
||||
|
||||
@@ -109,9 +112,6 @@ private:
|
||||
|
||||
IDrawWidget* createDrawWidget(RendererEngine rendererEngine, int samplesCount);
|
||||
|
||||
void removeInputInterface(IDrawWidgetInputInterface* inputInterface);
|
||||
void addInputInterface(IDrawWidgetInputInterface* inputInterface);
|
||||
|
||||
const PDFCMSManager* m_cmsManager;
|
||||
PDFToolManager* m_toolManager;
|
||||
PDFWidgetAnnotationManager* m_annotationManager;
|
||||
|
Reference in New Issue
Block a user