AudioBook Plugin: Display texts on page

This commit is contained in:
Jakub Melka 2021-08-22 18:25:24 +02:00
parent 8ccfbe291d
commit 4cb077f75e
13 changed files with 513 additions and 14 deletions

View File

@ -704,7 +704,7 @@ void PDFCreateFreehandCurveTool::mouseReleaseEvent(QWidget* widget, QMouseEvent*
resetTool();
}
getProxy()->repaintNeeded();
emit getProxy()->repaintNeeded();
}
void PDFCreateFreehandCurveTool::mouseMoveEvent(QWidget* widget, QMouseEvent* event)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -19,10 +19,13 @@
#include "pdfdrawwidget.h"
#include "pdfwidgettool.h"
#include "pdfutils.h"
#include "pdfwidgetutils.h"
#include <QAction>
#include <QPainter>
#include <QMainWindow>
#include <QMessageBox>
#include <QMouseEvent>
#include <QRegularExpression>
namespace pdfplugin
@ -44,7 +47,13 @@ AudioBookPlugin::AudioBookPlugin() :
m_actionMoveSelectionDown(nullptr),
m_actionCreateAudioBook(nullptr),
m_audioTextStreamDockWidget(nullptr),
m_audioTextStreamEditorModel(nullptr)
m_audioTextStreamEditorModel(nullptr),
m_actionClear(nullptr)
{
}
AudioBookPlugin::~AudioBookPlugin()
{
}
@ -62,10 +71,12 @@ void AudioBookPlugin::setWidget(pdf::PDFWidget* widget)
m_actionSynchronizeFromTableToGraphics = new QAction(QIcon(":/pdfplugins/audiobook/synchronize-from-table-to-graphics.svg"), tr("Synchronize Selection from Table to Graphics"), this);
m_actionSynchronizeFromTableToGraphics->setObjectName("actionAudioBook_SynchronizeFromTableToGraphics");
m_actionSynchronizeFromTableToGraphics->setCheckable(true);
m_actionSynchronizeFromTableToGraphics->setChecked(true);
m_actionSynchronizeFromGraphicsToTable = new QAction(QIcon(":/pdfplugins/audiobook/synchronize-from-graphics-to-table.svg"), tr("Synchronize Selection from Graphics to Table"), this);
m_actionSynchronizeFromGraphicsToTable->setObjectName("actionAudioBook_SynchronizeFromGraphicsToTable");
m_actionSynchronizeFromGraphicsToTable->setCheckable(true);
m_actionSynchronizeFromGraphicsToTable->setChecked(true);
m_actionActivateSelection = new QAction(QIcon(":/pdfplugins/audiobook/activate-selection.svg"), tr("Activate Selection"), this);
m_actionActivateSelection->setObjectName("actionAudioBook_ActivateSelection");
@ -93,6 +104,7 @@ void AudioBookPlugin::setWidget(pdf::PDFWidget* widget)
m_actionRestoreOriginalText = new QAction(QIcon(":/pdfplugins/audiobook/restore-original-text.svg"), tr("Restore Original Text"), this);
m_actionRestoreOriginalText->setObjectName("actionAudioBook_RestoreOriginalText");
connect(m_actionRestoreOriginalText, &QAction::triggered, this, &AudioBookPlugin::onRestoreOriginalText);
m_actionMoveSelectionUp = new QAction(QIcon(":/pdfplugins/audiobook/move-selection-up.svg"), tr("Move Selection Up"), this);
m_actionMoveSelectionUp->setObjectName("actionAudioBook_MoveSelectionUp");
@ -103,6 +115,13 @@ void AudioBookPlugin::setWidget(pdf::PDFWidget* widget)
m_actionCreateAudioBook = new QAction(QIcon(":/pdfplugins/audiobook/create-audio-book.svg"), tr("Create Audio Book"), this);
m_actionCreateAudioBook->setObjectName("actionAudioBook_CreateAudioBook");
m_actionClear = new QAction(QIcon(":/pdfplugins/audiobook/clear.svg"), tr("Clear Text Stream"), this);
m_actionClear->setObjectName("actionAudioBook_Clear");
connect(m_actionClear, &QAction::triggered, this, &AudioBookPlugin::onClear);
m_widget->getDrawWidgetProxy()->registerDrawInterface(this);
m_widget->addInputInterface(this);
updateActions();
}
@ -131,7 +150,62 @@ std::vector<QAction*> AudioBookPlugin::getActions() const
return { m_actionCreateTextStream,
m_actionSynchronizeFromTableToGraphics,
m_actionSynchronizeFromGraphicsToTable,
m_actionCreateAudioBook };
m_actionCreateAudioBook,
m_actionClear };
}
void AudioBookPlugin::drawPage(QPainter* painter,
pdf::PDFInteger pageIndex,
const pdf::PDFPrecompiledPage* compiledPage,
pdf::PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
QList<pdf::PDFRenderError>& errors) const
{
Q_UNUSED(compiledPage);
Q_UNUSED(layoutGetter);
Q_UNUSED(errors);
const qreal width = pdf::PDFWidgetUtils::scaleDPI_x(painter->device(), 1.0);
QPen pen;
pen.setWidthF(width);
auto range = m_textFlowEditor.getItemsForPageIndex(pageIndex);
for (auto it = range.first; it != range.second; ++it)
{
const size_t itemIndex = it->second;
const pdf::PDFDocumentTextFlowEditor::EditedItem* item = m_textFlowEditor.getEditedItem(itemIndex);
QRectF boundingRect = item->boundingRect;
QColor color(Qt::green);
if (m_textFlowEditor.isSelected(itemIndex))
{
color = Qt::yellow;
}
else if (m_textFlowEditor.isRemoved(itemIndex))
{
color = Qt::red;
}
else if (m_textFlowEditor.isModified(itemIndex))
{
color = QColor::fromRgb(0xFF, 0xA5, 0, 255);
}
QColor strokeColor = color;
QColor fillColor = color;
fillColor.setAlphaF(0.2);
pen.setColor(strokeColor);
painter->setPen(pen);
painter->setBrush(QBrush(fillColor));
QPainterPath path;
path.addRect(boundingRect);
path = pagePointToDevicePointMatrix.map(path);
painter->drawPath(path);
}
}
void AudioBookPlugin::onCreateTextStreamTriggered()
@ -154,6 +228,7 @@ void AudioBookPlugin::onCreateTextStreamTriggered()
actions.actionMoveSelectionUp = m_actionMoveSelectionUp;
actions.actionMoveSelectionDown = m_actionMoveSelectionDown;
actions.actionCreateAudioBook = m_actionCreateAudioBook;
actions.actionClear = m_actionClear;
m_audioTextStreamDockWidget = new AudioTextStreamEditorDockWidget(actions, m_dataExchangeInterface->getMainWindow());
m_audioTextStreamDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
@ -164,8 +239,8 @@ void AudioBookPlugin::onCreateTextStreamTriggered()
m_audioTextStreamEditorModel = new pdf::PDFDocumentTextFlowEditorModel(m_audioTextStreamDockWidget);
m_audioTextStreamEditorModel->setEditor(&m_textFlowEditor);
m_audioTextStreamDockWidget->setModel(m_audioTextStreamEditorModel);
connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::modelReset, this, &AudioBookPlugin::updateActions);
connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::dataChanged, this, &AudioBookPlugin::updateActions);
connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::modelReset, this, &AudioBookPlugin::onEditedTextFlowChanged);
connect(m_audioTextStreamEditorModel, &pdf::PDFDocumentTextFlowEditorModel::dataChanged, this, &AudioBookPlugin::onEditedTextFlowChanged);
}
m_audioTextStreamDockWidget->show();
@ -202,10 +277,10 @@ void AudioBookPlugin::onSelectByRectangle()
void AudioBookPlugin::onSelectByContainedText()
{
QString text = m_audioTextStreamDockWidget->getSelectionText();
m_audioTextStreamDockWidget->clearSelectionText();
if (!text.isEmpty())
{
m_audioTextStreamDockWidget->clearSelectionText();
m_audioTextStreamEditorModel->selectByContainedText(text);
}
else
@ -217,7 +292,6 @@ void AudioBookPlugin::onSelectByContainedText()
void AudioBookPlugin::onSelectByRegularExpression()
{
QString pattern = m_audioTextStreamDockWidget->getSelectionText();
m_audioTextStreamDockWidget->clearSelectionText();
if (!pattern.isEmpty())
{
@ -225,6 +299,7 @@ void AudioBookPlugin::onSelectByRegularExpression()
if (expression.isValid())
{
m_audioTextStreamDockWidget->clearSelectionText();
m_audioTextStreamEditorModel->selectByRegularExpression(expression);
}
else
@ -241,7 +316,6 @@ void AudioBookPlugin::onSelectByRegularExpression()
void AudioBookPlugin::onSelectByPageList()
{
QString pageIndicesText = m_audioTextStreamDockWidget->getSelectionText();
m_audioTextStreamDockWidget->clearSelectionText();
if (!pageIndicesText.isEmpty())
{
@ -250,6 +324,7 @@ void AudioBookPlugin::onSelectByPageList()
if (errorMessage.isEmpty())
{
m_audioTextStreamDockWidget->clearSelectionText();
m_audioTextStreamEditorModel->selectByPageIndices(pageIndices);
}
else
@ -263,6 +338,38 @@ void AudioBookPlugin::onSelectByPageList()
}
}
void AudioBookPlugin::onRestoreOriginalText()
{
if (!m_textFlowEditor.isSelectionModified())
{
// Nothing to restore
return;
}
if (QMessageBox::question(m_audioTextStreamDockWidget, tr("Question"), tr("Restore original texts in selected items? All changes will be lost."), QMessageBox::No, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
{
m_audioTextStreamEditorModel->restoreOriginalTexts();
}
}
void AudioBookPlugin::onEditedTextFlowChanged()
{
if (m_widget)
{
m_widget->getDrawWidget()->getWidget()->update();
}
updateActions();
}
void AudioBookPlugin::onClear()
{
if (m_audioTextStreamEditorModel)
{
m_audioTextStreamEditorModel->clear();
}
}
void AudioBookPlugin::onRectanglePicked(pdf::PDFInteger pageIndex, QRectF rectangle)
{
Q_UNUSED(pageIndex);
@ -284,6 +391,138 @@ void AudioBookPlugin::updateActions()
m_actionMoveSelectionUp->setEnabled(!m_textFlowEditor.isEmpty());
m_actionMoveSelectionDown->setEnabled(!m_textFlowEditor.isEmpty());
m_actionCreateAudioBook->setEnabled(!m_textFlowEditor.isEmpty());
m_actionClear->setEnabled(!m_textFlowEditor.isEmpty());
}
std::optional<size_t> AudioBookPlugin::getItemIndexForPagePoint(QPoint pos) const
{
QPointF pagePoint;
pdf::PDFInteger pageIndex = m_widget->getDrawWidgetProxy()->getPageUnderPoint(pos, &pagePoint);
pdf::PDFDocumentTextFlowEditor::PageIndicesMappingRange itemRange = m_textFlowEditor.getItemsForPageIndex(pageIndex);
for (auto it = itemRange.first; it != itemRange.second; ++it)
{
const pdf::PDFDocumentTextFlowEditor::EditedItem* item = m_textFlowEditor.getEditedItem(it->second);
if (item->boundingRect.contains(pagePoint))
{
return it->second;
}
}
return std::nullopt;
}
void AudioBookPlugin::shortcutOverrideEvent(QWidget* widget, QKeyEvent* event)
{
Q_UNUSED(widget);
Q_UNUSED(event);
}
void AudioBookPlugin::keyPressEvent(QWidget* widget, QKeyEvent* event)
{
Q_UNUSED(widget);
Q_UNUSED(event);
}
void AudioBookPlugin::keyReleaseEvent(QWidget* widget, QKeyEvent* event)
{
Q_UNUSED(widget);
Q_UNUSED(event);
}
void AudioBookPlugin::mousePressEvent(QWidget* widget, QMouseEvent* event)
{
Q_UNUSED(widget);
if (m_textFlowEditor.isEmpty())
{
// Jakub Melka: do nothing, editor is empty
return;
}
if (event->button() == Qt::LeftButton)
{
std::optional<size_t> index = getItemIndexForPagePoint(event->pos());
if (index)
{
// Scroll to index, if we are synchronizing
if (m_actionSynchronizeFromGraphicsToTable->isChecked() && m_audioTextStreamDockWidget)
{
m_audioTextStreamDockWidget->goToIndex(*index);
}
// Handle selection
const bool add = event->modifiers() & Qt::ControlModifier;
const bool remove = event->modifiers() & Qt::ShiftModifier;
const bool deselect = !add && !remove;
if (deselect)
{
m_textFlowEditor.deselect();
}
m_textFlowEditor.select(*index, !remove);
if (m_audioTextStreamEditorModel)
{
m_audioTextStreamEditorModel->notifyDataChanged();
}
}
}
}
void AudioBookPlugin::mouseDoubleClickEvent(QWidget* widget, QMouseEvent* event)
{
Q_UNUSED(widget);
Q_UNUSED(event);
}
void AudioBookPlugin::mouseReleaseEvent(QWidget* widget, QMouseEvent* event)
{
Q_UNUSED(widget);
Q_UNUSED(event);
}
void AudioBookPlugin::mouseMoveEvent(QWidget* widget, QMouseEvent* event)
{
Q_UNUSED(widget);
if (m_textFlowEditor.isEmpty())
{
// Jakub Melka: do nothing, editor is empty
return;
}
std::optional<size_t> index = getItemIndexForPagePoint(event->pos());
if (index)
{
m_toolTip = m_textFlowEditor.getText(*index);
}
else
{
m_toolTip = QString();
}
}
void AudioBookPlugin::wheelEvent(QWidget* widget, QWheelEvent* event)
{
Q_UNUSED(widget);
Q_UNUSED(event);
}
QString AudioBookPlugin::getTooltip() const
{
return m_toolTip;
}
const std::optional<QCursor>& AudioBookPlugin::getCursor() const
{
return m_cursor;
}
int AudioBookPlugin::getInputPriority() const
{
return UserPriority;
}
} // namespace pdfplugin

View File

@ -21,6 +21,7 @@
#include "pdfplugin.h"
#include "pdfdocumenttextflow.h"
#include "pdfdocumenttextfloweditormodel.h"
#include "pdfdocumentdrawinterface.h"
#include "audiotextstreameditordockwidget.h"
#include <QObject>
@ -28,7 +29,9 @@
namespace pdfplugin
{
class AudioBookPlugin : public pdf::PDFPlugin
class AudioBookPlugin : public pdf::PDFPlugin,
public pdf::IDocumentDrawInterface,
public pdf::IDrawWidgetInputInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "PDF4QT.AudioBookPlugin" FILE "AudioBookPlugin.json")
@ -38,11 +41,33 @@ private:
public:
AudioBookPlugin();
virtual ~AudioBookPlugin() override;
virtual void setWidget(pdf::PDFWidget* widget) override;
virtual void setDocument(const pdf::PDFModifiedDocument& document) override;
virtual std::vector<QAction*> getActions() const override;
virtual void drawPage(QPainter* painter,
pdf::PDFInteger pageIndex,
const pdf::PDFPrecompiledPage* compiledPage,
pdf::PDFTextLayoutGetter& layoutGetter,
const QMatrix& pagePointToDevicePointMatrix,
QList<pdf::PDFRenderError>& errors) const override;
// IDrawWidgetInputInterface interface
public:
virtual void shortcutOverrideEvent(QWidget* widget, QKeyEvent* event) override;
virtual void keyPressEvent(QWidget* widget, QKeyEvent* event) override;
virtual void keyReleaseEvent(QWidget* widget, QKeyEvent* event) override;
virtual void mousePressEvent(QWidget* widget, QMouseEvent* event) override;
virtual void mouseDoubleClickEvent(QWidget* widget, QMouseEvent* event) override;
virtual void mouseReleaseEvent(QWidget* widget, QMouseEvent* event) override;
virtual void mouseMoveEvent(QWidget* widget, QMouseEvent* event) override;
virtual void wheelEvent(QWidget* widget, QWheelEvent* event) override;
virtual QString getTooltip() const override;
virtual const std::optional<QCursor>& getCursor() const override;
virtual int getInputPriority() const override;
private:
void onCreateTextStreamTriggered();
void onActivateSelection();
@ -51,11 +76,16 @@ private:
void onSelectByContainedText();
void onSelectByRegularExpression();
void onSelectByPageList();
void onRestoreOriginalText();
void onEditedTextFlowChanged();
void onClear();
void onRectanglePicked(pdf::PDFInteger pageIndex, QRectF rectangle);
void updateActions();
std::optional<size_t> getItemIndexForPagePoint(QPoint pos) const;
QAction* m_actionCreateTextStream;
QAction* m_actionSynchronizeFromTableToGraphics;
QAction* m_actionSynchronizeFromGraphicsToTable;
@ -69,10 +99,14 @@ private:
QAction* m_actionMoveSelectionUp;
QAction* m_actionMoveSelectionDown;
QAction* m_actionCreateAudioBook;
QAction* m_actionClear;
pdf::PDFDocumentTextFlowEditor m_textFlowEditor;
AudioTextStreamEditorDockWidget* m_audioTextStreamDockWidget;
pdf::PDFDocumentTextFlowEditorModel* m_audioTextStreamEditorModel;
QString m_toolTip;
std::optional<QCursor> m_cursor;
};
} // namespace pdfplugin

View File

@ -65,6 +65,7 @@ AudioTextStreamEditorDockWidget::AudioTextStreamEditorDockWidget(AudioTextStream
actions.actionMoveSelectionDown });
m_toolBar->addSeparator();
m_toolBar->addAction(actions.actionCreateAudioBook);
m_toolBar->addAction(actions.actionClear);
setMinimumSize(pdf::PDFWidgetUtils::scaleDPI(this, QSize(300, 150)));
}
@ -95,4 +96,10 @@ void AudioTextStreamEditorDockWidget::clearSelectionText()
m_selectionTextEdit->clear();
}
void AudioTextStreamEditorDockWidget::goToIndex(size_t index)
{
QModelIndex modelIndex = ui->textStreamTableView->model()->index(int(index), 0);
ui->textStreamTableView->scrollTo(modelIndex);
}
} // namespace pdfplugin

View File

@ -48,6 +48,7 @@ struct AudioTextStreamActions
QAction* actionMoveSelectionUp = nullptr;
QAction* actionMoveSelectionDown = nullptr;
QAction* actionCreateAudioBook = nullptr;
QAction* actionClear = nullptr;
};
class AudioTextStreamEditorDockWidget : public QDockWidget
@ -66,6 +67,8 @@ public:
QString getSelectionText() const;
void clearSelectionText();
void goToIndex(size_t index);
private:
Ui::AudioTextStreamEditorDockWidget* ui;
pdf::PDFDocumentTextFlowEditorModel* m_model;

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="30mm"
height="30mm"
viewBox="0 0 30 30"
version="1.1"
id="svg5291"
inkscape:version="0.92.4 (5da689c313, 2019-01-14)"
sodipodi:docname="insert-image.svg">
<defs
id="defs5285">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 15 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="30 : 15 : 1"
inkscape:persp3d-origin="15 : 10 : 1"
id="perspective5921" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.656854"
inkscape:cx="148.43961"
inkscape:cy="135.18316"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="3840"
inkscape:window-height="2035"
inkscape:window-x="-13"
inkscape:window-y="-13"
inkscape:window-maximized="1" />
<metadata
id="metadata5288">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
<dc:creator>
<cc:Agent>
<dc:title>Jakub Melka</dc:title>
</cc:Agent>
</dc:creator>
<cc:license
rdf:resource="http://creativecommons.org/licenses/by-sa/4.0/" />
</cc:Work>
<cc:License
rdf:about="http://creativecommons.org/licenses/by-sa/4.0/">
<cc:permits
rdf:resource="http://creativecommons.org/ns#Reproduction" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#Distribution" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Notice" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#Attribution" />
<cc:permits
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" />
<cc:requires
rdf:resource="http://creativecommons.org/ns#ShareAlike" />
</cc:License>
</rdf:RDF>
</metadata>
<g
inkscape:label="Vrstva 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-267)">
<flowRoot
xml:space="preserve"
id="flowRoot5913"
style="font-style:normal;font-weight:normal;font-size:40px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none"><flowRegion
id="flowRegion5915"><rect
id="rect5917"
width="129.22377"
height="91.747108"
x="-13.788582"
y="-33.515606" /></flowRegion><flowPara
id="flowPara5919" /></flowRoot> <g
aria-label="?"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:25.39999962px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
id="text849"
transform="translate(-4.7625002,-4.2333335)">
<path
d="m 25.373474,281.70442 q 0,1.21543 -0.434082,2.17041 -0.434082,0.94258 -1.141016,1.67432 -0.694531,0.70693 -1.599902,1.32705 -0.905371,0.62011 -1.922363,1.20302 v 2.79053 h -2.22002 v -3.78271 q 0.806153,-0.45889 1.736328,-1.00459 0.942578,-0.54571 1.537891,-1.10381 0.719336,-0.64492 1.116211,-1.32705 0.396875,-0.69453 0.396875,-1.76114 0,-1.40146 -0.954981,-2.08359 -0.942578,-0.69453 -2.443261,-0.69453 -1.339453,0 -2.542481,0.42168 -1.190625,0.42168 -1.885156,0.85576 h -0.124023 v -2.53008 q 0.868164,-0.33486 2.195214,-0.59531 1.339454,-0.27285 2.530079,-0.27285 2.666503,0 4.204394,1.30224 1.550293,1.28985 1.550293,3.41065 z m -4.898926,14.12627 H 17.94447 v -2.6169 h 2.530078 z"
style="stroke-width:0.26458332"
id="path851"
inkscape:connector-curvature="0" />
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -13,5 +13,6 @@
<file>select-by-regular-expression.svg</file>
<file>synchronize-from-graphics-to-table.svg</file>
<file>synchronize-from-table-to-graphics.svg</file>
<file>clear.svg</file>
</qresource>
</RCC>